MCPcopy
hub / github.com/callumalpass/tasknotes / DateContextMenu

Class DateContextMenu

src/components/DateContextMenu.ts:69–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69export class DateContextMenu {
70 private static activeMenu: ContextMenu | null = null;
71 private static activeTrigger: Element | null = null;
72
73 private menu: ContextMenu;
74 private options: DateContextMenuOptions;
75
76 constructor(options: DateContextMenuOptions) {
77 this.menu = new ContextMenu();
78 this.options = options;
79 this.buildMenu();
80 }
81
82 private t(key: string, fallback?: string, params?: Record<string, string | number>): string {
83 return this.options.plugin?.i18n.translate(key, params) || fallback || key;
84 }
85
86 private getFirstDayOfWeek(): number {
87 const firstDay = this.options.plugin?.settings?.calendarViewSettings?.firstDay;
88 return typeof firstDay === "number" &&
89 Number.isInteger(firstDay) &&
90 firstDay >= 0 &&
91 firstDay <= 6
92 ? firstDay
93 : 0;
94 }
95
96 private buildMenu(): void {
97 if (this.options.title) {
98 this.menu.addItem((item) => {
99 item.setTitle(this.options.title || "");
100 item.setIcon("calendar");
101 item.setDisabled(true);
102 });
103 this.menu.addSeparator();
104 }
105
106 const dateOptions = this.getDateOptions();
107
108 const incrementOptions = dateOptions.filter((option) => option.category === "increment");
109 if (incrementOptions.length > 0) {
110 incrementOptions.forEach((option) => {
111 this.menu.addItem((item) => {
112 if (option.icon) item.setIcon(option.icon);
113 item.setTitle(option.label);
114 item.onClick(async () => {
115 this.options.onSelect(option.value, null);
116 });
117 });
118 });
119 this.menu.addSeparator();
120 }
121
122 const basicOptions = dateOptions.filter((option) => option.category === "basic");
123 basicOptions.forEach((option) => {
124 this.menu.addItem((item) => {
125 if (option.icon) item.setIcon(option.icon);
126 const isSelected = option.value && option.value === this.options.currentValue;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected