@schedule-x/calendar-controls
Advanced tools
Comparing version 1.63.1 to 1.64.0-alpha.0
@@ -68,4 +68,4 @@ import { Signal, ReadonlySignal } from "@preact/signals"; | ||
interface Config { | ||
locale: string; | ||
firstDayOfWeek: WeekDay; | ||
locale: Signal<string>; | ||
firstDayOfWeek: Signal<WeekDay>; | ||
} | ||
@@ -212,2 +212,6 @@ declare enum Placement { | ||
} | ||
type DayBoundariesExternal = { | ||
start: string; | ||
end: string; | ||
}; | ||
type DayBoundariesInternal = { | ||
@@ -330,14 +334,14 @@ start: number; | ||
defaultView: ViewName; | ||
views: View[]; | ||
dayBoundaries: DayBoundariesInternal; | ||
weekOptions: WeekOptions; | ||
monthGridOptions: MonthGridOptions; | ||
views: Signal<View[]>; | ||
dayBoundaries: Signal<DayBoundariesInternal>; | ||
weekOptions: Signal<WeekOptions>; | ||
calendars: Signal<Record<string, CalendarType>>; | ||
isDark: Signal<boolean>; | ||
minDate: Signal<string | undefined>; | ||
maxDate: Signal<string | undefined>; | ||
monthGridOptions: Signal<MonthGridOptions>; | ||
plugins: Plugins; | ||
isDark: boolean; | ||
isResponsive: boolean; | ||
callbacks: CalendarCallbacks; | ||
_customComponentFns: CustomComponentFns; | ||
minDate?: string; | ||
maxDate?: string; | ||
// Getters | ||
@@ -400,4 +404,25 @@ isHybridDay: boolean; | ||
setView(view: string): void; | ||
setFirstDayOfWeek(firstDayOfWeek: WeekDay): void; | ||
setLocale(locale: string): void; | ||
setViews(views: [ | ||
View, | ||
...View[] | ||
]): void; | ||
setDayBoundaries(dayBoundaries: DayBoundariesExternal): void; | ||
setWeekOptions(weekOptions: WeekOptions): void; | ||
setCalendars(calendars: Record<string, CalendarType>): void; | ||
setMinDate(minDate: string | undefined): void; | ||
setMaxDate(maxDate: string | undefined): void; | ||
setMonthGridOptions(monthGridOptions: MonthGridOptions): void; | ||
getDate(): string; | ||
getView(): string; | ||
getFirstDayOfWeek(): WeekDay; | ||
getLocale(): string; | ||
getViews(): View[]; | ||
getDayBoundaries(): DayBoundariesExternal; | ||
getWeekOptions(): WeekOptions; | ||
getCalendars(): Record<string, CalendarType>; | ||
getMinDate(): string | undefined; | ||
getMaxDate(): string | undefined; | ||
getMonthGridOptions(): MonthGridOptions; | ||
getRange(): DateRange | null; | ||
@@ -404,0 +429,0 @@ } |
@@ -14,4 +14,53 @@ 'use strict'; | ||
// regex for strings between 00:00 and 23:59 | ||
const timeStringRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/; | ||
const dateStringRegex = /^(\d{4})-(\d{2})-(\d{2})$/; | ||
class InvalidTimeStringError extends Error { | ||
constructor(timeString) { | ||
super(`Invalid time string: ${timeString}`); | ||
} | ||
} | ||
class NumberRangeError extends Error { | ||
constructor(min, max) { | ||
super(`Number must be between ${min} and ${max}.`); | ||
Object.defineProperty(this, "min", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: min | ||
}); | ||
Object.defineProperty(this, "max", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: max | ||
}); | ||
} | ||
} | ||
const doubleDigit = (number) => { | ||
if (number < 0 || number > 99) | ||
throw new NumberRangeError(0, 99); | ||
return String(number).padStart(2, '0'); | ||
}; | ||
const minuteTimePointMultiplier = 1.6666666666666667; // 100 / 60 | ||
const timePointsFromString = (timeString) => { | ||
if (!timeStringRegex.test(timeString) && timeString !== '24:00') | ||
throw new InvalidTimeStringError(timeString); | ||
const [hoursInt, minutesInt] = timeString | ||
.split(':') | ||
.map((time) => parseInt(time, 10)); | ||
let minutePoints = (minutesInt * minuteTimePointMultiplier).toString(); | ||
if (minutePoints.split('.')[0].length < 2) | ||
minutePoints = `0${minutePoints}`; | ||
return Number(hoursInt + minutePoints); | ||
}; | ||
const timeStringFromTimePoints = (timePoints) => { | ||
const hours = Math.floor(timePoints / 100); | ||
const minutes = Math.round((timePoints % 100) / minuteTimePointMultiplier); | ||
return `${doubleDigit(hours)}:${doubleDigit(minutes)}`; | ||
}; | ||
class CalendarControlsPluginImpl { | ||
@@ -31,2 +80,77 @@ constructor() { | ||
}); | ||
Object.defineProperty(this, "getDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.datePickerState.selectedDate.value | ||
}); | ||
Object.defineProperty(this, "getView", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.view.value | ||
}); | ||
Object.defineProperty(this, "getFirstDayOfWeek", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.firstDayOfWeek.value | ||
}); | ||
Object.defineProperty(this, "getLocale", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.locale.value | ||
}); | ||
Object.defineProperty(this, "getViews", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.views.value | ||
}); | ||
Object.defineProperty(this, "getDayBoundaries", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => ({ | ||
start: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.start), | ||
end: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.end), | ||
}) | ||
}); | ||
Object.defineProperty(this, "getWeekOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.weekOptions.value | ||
}); | ||
Object.defineProperty(this, "getCalendars", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.calendars.value | ||
}); | ||
Object.defineProperty(this, "getMinDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.minDate.value | ||
}); | ||
Object.defineProperty(this, "getMaxDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.maxDate.value | ||
}); | ||
Object.defineProperty(this, "getMonthGridOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.monthGridOptions.value | ||
}); | ||
Object.defineProperty(this, "getRange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.range.value | ||
}); | ||
} | ||
@@ -48,16 +172,41 @@ beforeInit($app) { | ||
setView(view) { | ||
const viewToSet = this.$app.config.views.find((v) => v.name === view); | ||
const viewToSet = this.$app.config.views.value.find((v) => v.name === view); | ||
if (!viewToSet) | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.map((v) => v.name).join(', ')}`); | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.value.map((v) => v.name).join(', ')}`); | ||
this.$app.calendarState.setView(view, this.$app.datePickerState.selectedDate.value); | ||
} | ||
getDate() { | ||
return this.$app.datePickerState.selectedDate.value; | ||
setFirstDayOfWeek(firstDayOfWeek) { | ||
this.$app.config.firstDayOfWeek.value = firstDayOfWeek; | ||
} | ||
getView() { | ||
return this.$app.calendarState.view.value; | ||
setLocale(locale) { | ||
this.$app.config.locale.value = locale; | ||
} | ||
getRange() { | ||
return this.$app.calendarState.range.value; | ||
setViews(views) { | ||
const currentViewName = this.$app.calendarState.view.value; | ||
const isCurrentViewInViews = views.some((view) => view.name === currentViewName); | ||
if (!isCurrentViewInViews) | ||
throw new Error(`Currently active view is not in given views. Expected to find ${currentViewName} in ${views.map((view) => view.name).join(',')}`); | ||
this.$app.config.views.value = views; | ||
} | ||
setDayBoundaries(dayBoundaries) { | ||
this.$app.config.dayBoundaries.value = { | ||
start: timePointsFromString(dayBoundaries.start), | ||
end: timePointsFromString(dayBoundaries.end), | ||
}; | ||
} | ||
setWeekOptions(weekOptions) { | ||
this.$app.config.weekOptions.value = weekOptions; | ||
} | ||
setCalendars(calendars) { | ||
this.$app.config.calendars.value = calendars; | ||
} | ||
setMinDate(minDate) { | ||
this.$app.config.minDate.value = minDate; | ||
} | ||
setMaxDate(maxDate) { | ||
this.$app.config.maxDate.value = maxDate; | ||
} | ||
setMonthGridOptions(monthGridOptions) { | ||
this.$app.config.monthGridOptions.value = monthGridOptions; | ||
} | ||
} | ||
@@ -64,0 +213,0 @@ const createCalendarControlsPlugin = () => { |
@@ -68,4 +68,4 @@ import { Signal, ReadonlySignal } from "@preact/signals"; | ||
interface Config { | ||
locale: string; | ||
firstDayOfWeek: WeekDay; | ||
locale: Signal<string>; | ||
firstDayOfWeek: Signal<WeekDay>; | ||
} | ||
@@ -212,2 +212,6 @@ declare enum Placement { | ||
} | ||
type DayBoundariesExternal = { | ||
start: string; | ||
end: string; | ||
}; | ||
type DayBoundariesInternal = { | ||
@@ -330,14 +334,14 @@ start: number; | ||
defaultView: ViewName; | ||
views: View[]; | ||
dayBoundaries: DayBoundariesInternal; | ||
weekOptions: WeekOptions; | ||
monthGridOptions: MonthGridOptions; | ||
views: Signal<View[]>; | ||
dayBoundaries: Signal<DayBoundariesInternal>; | ||
weekOptions: Signal<WeekOptions>; | ||
calendars: Signal<Record<string, CalendarType>>; | ||
isDark: Signal<boolean>; | ||
minDate: Signal<string | undefined>; | ||
maxDate: Signal<string | undefined>; | ||
monthGridOptions: Signal<MonthGridOptions>; | ||
plugins: Plugins; | ||
isDark: boolean; | ||
isResponsive: boolean; | ||
callbacks: CalendarCallbacks; | ||
_customComponentFns: CustomComponentFns; | ||
minDate?: string; | ||
maxDate?: string; | ||
// Getters | ||
@@ -400,4 +404,25 @@ isHybridDay: boolean; | ||
setView(view: string): void; | ||
setFirstDayOfWeek(firstDayOfWeek: WeekDay): void; | ||
setLocale(locale: string): void; | ||
setViews(views: [ | ||
View, | ||
...View[] | ||
]): void; | ||
setDayBoundaries(dayBoundaries: DayBoundariesExternal): void; | ||
setWeekOptions(weekOptions: WeekOptions): void; | ||
setCalendars(calendars: Record<string, CalendarType>): void; | ||
setMinDate(minDate: string | undefined): void; | ||
setMaxDate(maxDate: string | undefined): void; | ||
setMonthGridOptions(monthGridOptions: MonthGridOptions): void; | ||
getDate(): string; | ||
getView(): string; | ||
getFirstDayOfWeek(): WeekDay; | ||
getLocale(): string; | ||
getViews(): View[]; | ||
getDayBoundaries(): DayBoundariesExternal; | ||
getWeekOptions(): WeekOptions; | ||
getCalendars(): Record<string, CalendarType>; | ||
getMinDate(): string | undefined; | ||
getMaxDate(): string | undefined; | ||
getMonthGridOptions(): MonthGridOptions; | ||
getRange(): DateRange | null; | ||
@@ -404,0 +429,0 @@ } |
165
dist/core.js
@@ -12,4 +12,53 @@ var PluginName; | ||
// regex for strings between 00:00 and 23:59 | ||
const timeStringRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/; | ||
const dateStringRegex = /^(\d{4})-(\d{2})-(\d{2})$/; | ||
class InvalidTimeStringError extends Error { | ||
constructor(timeString) { | ||
super(`Invalid time string: ${timeString}`); | ||
} | ||
} | ||
class NumberRangeError extends Error { | ||
constructor(min, max) { | ||
super(`Number must be between ${min} and ${max}.`); | ||
Object.defineProperty(this, "min", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: min | ||
}); | ||
Object.defineProperty(this, "max", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: max | ||
}); | ||
} | ||
} | ||
const doubleDigit = (number) => { | ||
if (number < 0 || number > 99) | ||
throw new NumberRangeError(0, 99); | ||
return String(number).padStart(2, '0'); | ||
}; | ||
const minuteTimePointMultiplier = 1.6666666666666667; // 100 / 60 | ||
const timePointsFromString = (timeString) => { | ||
if (!timeStringRegex.test(timeString) && timeString !== '24:00') | ||
throw new InvalidTimeStringError(timeString); | ||
const [hoursInt, minutesInt] = timeString | ||
.split(':') | ||
.map((time) => parseInt(time, 10)); | ||
let minutePoints = (minutesInt * minuteTimePointMultiplier).toString(); | ||
if (minutePoints.split('.')[0].length < 2) | ||
minutePoints = `0${minutePoints}`; | ||
return Number(hoursInt + minutePoints); | ||
}; | ||
const timeStringFromTimePoints = (timePoints) => { | ||
const hours = Math.floor(timePoints / 100); | ||
const minutes = Math.round((timePoints % 100) / minuteTimePointMultiplier); | ||
return `${doubleDigit(hours)}:${doubleDigit(minutes)}`; | ||
}; | ||
class CalendarControlsPluginImpl { | ||
@@ -29,2 +78,77 @@ constructor() { | ||
}); | ||
Object.defineProperty(this, "getDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.datePickerState.selectedDate.value | ||
}); | ||
Object.defineProperty(this, "getView", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.view.value | ||
}); | ||
Object.defineProperty(this, "getFirstDayOfWeek", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.firstDayOfWeek.value | ||
}); | ||
Object.defineProperty(this, "getLocale", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.locale.value | ||
}); | ||
Object.defineProperty(this, "getViews", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.views.value | ||
}); | ||
Object.defineProperty(this, "getDayBoundaries", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => ({ | ||
start: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.start), | ||
end: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.end), | ||
}) | ||
}); | ||
Object.defineProperty(this, "getWeekOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.weekOptions.value | ||
}); | ||
Object.defineProperty(this, "getCalendars", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.calendars.value | ||
}); | ||
Object.defineProperty(this, "getMinDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.minDate.value | ||
}); | ||
Object.defineProperty(this, "getMaxDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.maxDate.value | ||
}); | ||
Object.defineProperty(this, "getMonthGridOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.monthGridOptions.value | ||
}); | ||
Object.defineProperty(this, "getRange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.range.value | ||
}); | ||
} | ||
@@ -46,16 +170,41 @@ beforeInit($app) { | ||
setView(view) { | ||
const viewToSet = this.$app.config.views.find((v) => v.name === view); | ||
const viewToSet = this.$app.config.views.value.find((v) => v.name === view); | ||
if (!viewToSet) | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.map((v) => v.name).join(', ')}`); | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.value.map((v) => v.name).join(', ')}`); | ||
this.$app.calendarState.setView(view, this.$app.datePickerState.selectedDate.value); | ||
} | ||
getDate() { | ||
return this.$app.datePickerState.selectedDate.value; | ||
setFirstDayOfWeek(firstDayOfWeek) { | ||
this.$app.config.firstDayOfWeek.value = firstDayOfWeek; | ||
} | ||
getView() { | ||
return this.$app.calendarState.view.value; | ||
setLocale(locale) { | ||
this.$app.config.locale.value = locale; | ||
} | ||
getRange() { | ||
return this.$app.calendarState.range.value; | ||
setViews(views) { | ||
const currentViewName = this.$app.calendarState.view.value; | ||
const isCurrentViewInViews = views.some((view) => view.name === currentViewName); | ||
if (!isCurrentViewInViews) | ||
throw new Error(`Currently active view is not in given views. Expected to find ${currentViewName} in ${views.map((view) => view.name).join(',')}`); | ||
this.$app.config.views.value = views; | ||
} | ||
setDayBoundaries(dayBoundaries) { | ||
this.$app.config.dayBoundaries.value = { | ||
start: timePointsFromString(dayBoundaries.start), | ||
end: timePointsFromString(dayBoundaries.end), | ||
}; | ||
} | ||
setWeekOptions(weekOptions) { | ||
this.$app.config.weekOptions.value = weekOptions; | ||
} | ||
setCalendars(calendars) { | ||
this.$app.config.calendars.value = calendars; | ||
} | ||
setMinDate(minDate) { | ||
this.$app.config.minDate.value = minDate; | ||
} | ||
setMaxDate(maxDate) { | ||
this.$app.config.maxDate.value = maxDate; | ||
} | ||
setMonthGridOptions(monthGridOptions) { | ||
this.$app.config.monthGridOptions.value = monthGridOptions; | ||
} | ||
} | ||
@@ -62,0 +211,0 @@ const createCalendarControlsPlugin = () => { |
@@ -68,4 +68,4 @@ import { Signal, ReadonlySignal } from "@preact/signals"; | ||
interface Config { | ||
locale: string; | ||
firstDayOfWeek: WeekDay; | ||
locale: Signal<string>; | ||
firstDayOfWeek: Signal<WeekDay>; | ||
} | ||
@@ -212,2 +212,6 @@ declare enum Placement { | ||
} | ||
type DayBoundariesExternal = { | ||
start: string; | ||
end: string; | ||
}; | ||
type DayBoundariesInternal = { | ||
@@ -330,14 +334,14 @@ start: number; | ||
defaultView: ViewName; | ||
views: View[]; | ||
dayBoundaries: DayBoundariesInternal; | ||
weekOptions: WeekOptions; | ||
monthGridOptions: MonthGridOptions; | ||
views: Signal<View[]>; | ||
dayBoundaries: Signal<DayBoundariesInternal>; | ||
weekOptions: Signal<WeekOptions>; | ||
calendars: Signal<Record<string, CalendarType>>; | ||
isDark: Signal<boolean>; | ||
minDate: Signal<string | undefined>; | ||
maxDate: Signal<string | undefined>; | ||
monthGridOptions: Signal<MonthGridOptions>; | ||
plugins: Plugins; | ||
isDark: boolean; | ||
isResponsive: boolean; | ||
callbacks: CalendarCallbacks; | ||
_customComponentFns: CustomComponentFns; | ||
minDate?: string; | ||
maxDate?: string; | ||
// Getters | ||
@@ -400,4 +404,25 @@ isHybridDay: boolean; | ||
setView(view: string): void; | ||
setFirstDayOfWeek(firstDayOfWeek: WeekDay): void; | ||
setLocale(locale: string): void; | ||
setViews(views: [ | ||
View, | ||
...View[] | ||
]): void; | ||
setDayBoundaries(dayBoundaries: DayBoundariesExternal): void; | ||
setWeekOptions(weekOptions: WeekOptions): void; | ||
setCalendars(calendars: Record<string, CalendarType>): void; | ||
setMinDate(minDate: string | undefined): void; | ||
setMaxDate(maxDate: string | undefined): void; | ||
setMonthGridOptions(monthGridOptions: MonthGridOptions): void; | ||
getDate(): string; | ||
getView(): string; | ||
getFirstDayOfWeek(): WeekDay; | ||
getLocale(): string; | ||
getViews(): View[]; | ||
getDayBoundaries(): DayBoundariesExternal; | ||
getWeekOptions(): WeekOptions; | ||
getCalendars(): Record<string, CalendarType>; | ||
getMinDate(): string | undefined; | ||
getMaxDate(): string | undefined; | ||
getMonthGridOptions(): MonthGridOptions; | ||
getRange(): DateRange | null; | ||
@@ -404,0 +429,0 @@ } |
@@ -18,4 +18,53 @@ (function (global, factory) { | ||
// regex for strings between 00:00 and 23:59 | ||
const timeStringRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/; | ||
const dateStringRegex = /^(\d{4})-(\d{2})-(\d{2})$/; | ||
class InvalidTimeStringError extends Error { | ||
constructor(timeString) { | ||
super(`Invalid time string: ${timeString}`); | ||
} | ||
} | ||
class NumberRangeError extends Error { | ||
constructor(min, max) { | ||
super(`Number must be between ${min} and ${max}.`); | ||
Object.defineProperty(this, "min", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: min | ||
}); | ||
Object.defineProperty(this, "max", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: max | ||
}); | ||
} | ||
} | ||
const doubleDigit = (number) => { | ||
if (number < 0 || number > 99) | ||
throw new NumberRangeError(0, 99); | ||
return String(number).padStart(2, '0'); | ||
}; | ||
const minuteTimePointMultiplier = 1.6666666666666667; // 100 / 60 | ||
const timePointsFromString = (timeString) => { | ||
if (!timeStringRegex.test(timeString) && timeString !== '24:00') | ||
throw new InvalidTimeStringError(timeString); | ||
const [hoursInt, minutesInt] = timeString | ||
.split(':') | ||
.map((time) => parseInt(time, 10)); | ||
let minutePoints = (minutesInt * minuteTimePointMultiplier).toString(); | ||
if (minutePoints.split('.')[0].length < 2) | ||
minutePoints = `0${minutePoints}`; | ||
return Number(hoursInt + minutePoints); | ||
}; | ||
const timeStringFromTimePoints = (timePoints) => { | ||
const hours = Math.floor(timePoints / 100); | ||
const minutes = Math.round((timePoints % 100) / minuteTimePointMultiplier); | ||
return `${doubleDigit(hours)}:${doubleDigit(minutes)}`; | ||
}; | ||
class CalendarControlsPluginImpl { | ||
@@ -35,2 +84,77 @@ constructor() { | ||
}); | ||
Object.defineProperty(this, "getDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.datePickerState.selectedDate.value | ||
}); | ||
Object.defineProperty(this, "getView", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.view.value | ||
}); | ||
Object.defineProperty(this, "getFirstDayOfWeek", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.firstDayOfWeek.value | ||
}); | ||
Object.defineProperty(this, "getLocale", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.locale.value | ||
}); | ||
Object.defineProperty(this, "getViews", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.views.value | ||
}); | ||
Object.defineProperty(this, "getDayBoundaries", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => ({ | ||
start: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.start), | ||
end: timeStringFromTimePoints(this.$app.config.dayBoundaries.value.end), | ||
}) | ||
}); | ||
Object.defineProperty(this, "getWeekOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.weekOptions.value | ||
}); | ||
Object.defineProperty(this, "getCalendars", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.calendars.value | ||
}); | ||
Object.defineProperty(this, "getMinDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.minDate.value | ||
}); | ||
Object.defineProperty(this, "getMaxDate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.maxDate.value | ||
}); | ||
Object.defineProperty(this, "getMonthGridOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.config.monthGridOptions.value | ||
}); | ||
Object.defineProperty(this, "getRange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => this.$app.calendarState.range.value | ||
}); | ||
} | ||
@@ -52,16 +176,41 @@ beforeInit($app) { | ||
setView(view) { | ||
const viewToSet = this.$app.config.views.find((v) => v.name === view); | ||
const viewToSet = this.$app.config.views.value.find((v) => v.name === view); | ||
if (!viewToSet) | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.map((v) => v.name).join(', ')}`); | ||
throw new Error(`Invalid view name. Expected one of ${this.$app.config.views.value.map((v) => v.name).join(', ')}`); | ||
this.$app.calendarState.setView(view, this.$app.datePickerState.selectedDate.value); | ||
} | ||
getDate() { | ||
return this.$app.datePickerState.selectedDate.value; | ||
setFirstDayOfWeek(firstDayOfWeek) { | ||
this.$app.config.firstDayOfWeek.value = firstDayOfWeek; | ||
} | ||
getView() { | ||
return this.$app.calendarState.view.value; | ||
setLocale(locale) { | ||
this.$app.config.locale.value = locale; | ||
} | ||
getRange() { | ||
return this.$app.calendarState.range.value; | ||
setViews(views) { | ||
const currentViewName = this.$app.calendarState.view.value; | ||
const isCurrentViewInViews = views.some((view) => view.name === currentViewName); | ||
if (!isCurrentViewInViews) | ||
throw new Error(`Currently active view is not in given views. Expected to find ${currentViewName} in ${views.map((view) => view.name).join(',')}`); | ||
this.$app.config.views.value = views; | ||
} | ||
setDayBoundaries(dayBoundaries) { | ||
this.$app.config.dayBoundaries.value = { | ||
start: timePointsFromString(dayBoundaries.start), | ||
end: timePointsFromString(dayBoundaries.end), | ||
}; | ||
} | ||
setWeekOptions(weekOptions) { | ||
this.$app.config.weekOptions.value = weekOptions; | ||
} | ||
setCalendars(calendars) { | ||
this.$app.config.calendars.value = calendars; | ||
} | ||
setMinDate(minDate) { | ||
this.$app.config.minDate.value = minDate; | ||
} | ||
setMaxDate(maxDate) { | ||
this.$app.config.maxDate.value = maxDate; | ||
} | ||
setMonthGridOptions(monthGridOptions) { | ||
this.$app.config.monthGridOptions.value = monthGridOptions; | ||
} | ||
} | ||
@@ -68,0 +217,0 @@ const createCalendarControlsPlugin = () => { |
{ | ||
"name": "@schedule-x/calendar-controls", | ||
"umdName": "SXCalendarControls", | ||
"version": "1.63.1", | ||
"version": "1.64.0-alpha.0", | ||
"description": "Plugin for extra controls for the Schedule-X calendar", | ||
@@ -31,3 +31,3 @@ "author": { | ||
"homepage": "https://schedule-x.dev", | ||
"gitHead": "559d32882f6fe764328d542216bb3c2c8813acca" | ||
"gitHead": "f0cfd68222837d0f5c97f0c88386ae8b017d0195" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69112
1903
1