Files
2026-08-16 17:19:17 +03:00

7919 lines
235 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// vendor/obsidian-daily-notes-interface/index.js
var require_obsidian_daily_notes_interface = __commonJS({
"vendor/obsidian-daily-notes-interface/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var obsidian = require("obsidian");
var DEFAULT_DAILY_NOTE_FORMAT2 = "YYYY-MM-DD";
var DEFAULT_WEEKLY_NOTE_FORMAT = "gggg-[W]ww";
var DEFAULT_MONTHLY_NOTE_FORMAT = "YYYY-MM";
function shouldUsePeriodicNotesSettings(periodicity) {
var _a, _b;
const periodicNotes = window.app.plugins.getPlugin("periodic-notes");
return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a[periodicity]) == null ? void 0 : _b.enabled);
}
function getDailyNoteSettings4() {
var _a, _b, _c, _d;
try {
const { internalPlugins, plugins } = window.app;
if (shouldUsePeriodicNotesSettings("daily")) {
const { format: format2, folder: folder2, template: template2 } = ((_b = (_a = plugins.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.daily) || {};
return {
format: format2 || DEFAULT_DAILY_NOTE_FORMAT2,
folder: (folder2 == null ? void 0 : folder2.trim()) || "",
template: (template2 == null ? void 0 : template2.trim()) || ""
};
}
const { folder, format, template } = ((_d = (_c = internalPlugins.getPluginById("daily-notes")) == null ? void 0 : _c.instance) == null ? void 0 : _d.options) || {};
return {
format: format || DEFAULT_DAILY_NOTE_FORMAT2,
folder: (folder == null ? void 0 : folder.trim()) || "",
template: (template == null ? void 0 : template.trim()) || ""
};
} catch (err) {
console.info("No custom daily note settings found!", err);
}
}
function getWeeklyNoteSettings2() {
var _a, _b, _c, _d, _e, _f, _g;
try {
const pluginManager = window.app.plugins;
const calendarSettings = (_a = pluginManager.getPlugin("calendar")) == null ? void 0 : _a.options;
const periodicNotesSettings = (_c = (_b = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _b.settings) == null ? void 0 : _c.weekly;
if (shouldUsePeriodicNotesSettings("weekly")) {
return {
format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT,
folder: ((_d = periodicNotesSettings.folder) == null ? void 0 : _d.trim()) || "",
template: ((_e = periodicNotesSettings.template) == null ? void 0 : _e.trim()) || ""
};
}
const settings2 = calendarSettings || {};
return {
format: settings2.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT,
folder: ((_f = settings2.weeklyNoteFolder) == null ? void 0 : _f.trim()) || "",
template: ((_g = settings2.weeklyNoteTemplate) == null ? void 0 : _g.trim()) || ""
};
} catch (err) {
console.info("No custom weekly note settings found!", err);
}
}
function getMonthlyNoteSettings() {
var _a, _b, _c, _d;
const pluginManager = window.app.plugins;
try {
const settings2 = shouldUsePeriodicNotesSettings("monthly") && ((_b = (_a = pluginManager.getPlugin("periodic-notes")) == null ? void 0 : _a.settings) == null ? void 0 : _b.monthly) || {};
return {
format: settings2.format || DEFAULT_MONTHLY_NOTE_FORMAT,
folder: ((_c = settings2.folder) == null ? void 0 : _c.trim()) || "",
template: ((_d = settings2.template) == null ? void 0 : _d.trim()) || ""
};
} catch (err) {
console.info("No custom monthly note settings found!", err);
}
}
function getDateUID6(date, granularity = "day") {
const ts = date.clone().startOf(granularity).format();
return `${granularity}-${ts}`;
}
function removeEscapedCharacters3(format) {
return format.replace(/\[[^\]]*\]/g, "");
}
function isFormatAmbiguous(format, granularity) {
if (granularity === "week") {
const cleanFormat = removeEscapedCharacters3(format);
return /w{1,2}/i.test(cleanFormat) && (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat));
}
return false;
}
function getDateFromFile(file, granularity) {
const getSettings = {
day: getDailyNoteSettings4,
week: getWeeklyNoteSettings2,
month: getMonthlyNoteSettings
};
const format = getSettings[granularity]().format.split("/").pop();
const noteDate = window.moment(file.basename, format, true);
if (!noteDate.isValid()) {
return null;
}
if (isFormatAmbiguous(format, granularity)) {
if (granularity === "week") {
const cleanFormat = removeEscapedCharacters3(format);
if (/w{1,2}/i.test(cleanFormat)) {
return window.moment(
file.basename,
// If format contains week, remove day & month formatting
format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""),
false
);
}
}
}
return noteDate;
}
function join(...partSegments) {
let parts = [];
for (let i = 0, l = partSegments.length; i < l; i++) {
parts = parts.concat(partSegments[i].split("/"));
}
const newParts = [];
for (let i = 0, l = parts.length; i < l; i++) {
const part = parts[i];
if (!part || part === ".")
continue;
else
newParts.push(part);
}
if (parts[0] === "")
newParts.unshift("");
return newParts.join("/");
}
async function ensureFolderExists2(path) {
const dirs = path.replace(/\\/g, "/").split("/");
dirs.pop();
if (dirs.length) {
const dir = join(...dirs);
if (!window.app.vault.getAbstractFileByPath(dir)) {
await window.app.vault.createFolder(dir);
}
}
}
async function getNotePath2(directory, filename) {
if (!filename.endsWith(".md")) {
filename += ".md";
}
const path = obsidian.normalizePath(join(directory, filename));
await ensureFolderExists2(path);
return path;
}
async function getTemplateInfo(template) {
const { metadataCache, vault } = window.app;
const templatePath = obsidian.normalizePath(template);
if (templatePath === "/") {
return Promise.resolve(["", null]);
}
try {
const templateFile = metadataCache.getFirstLinkpathDest(templatePath, "");
const contents = await vault.cachedRead(templateFile);
const IFoldInfo = window.app.foldManager.load(templateFile);
return [contents, IFoldInfo];
} catch (err) {
console.error(`Failed to read the daily note template '${templatePath}'`, err);
new obsidian.Notice("Failed to read the daily note template");
return ["", null];
}
}
var DailyNotesFolderMissingError = class extends Error {
};
async function createDailyNote2(date) {
const app = window.app;
const { vault } = app;
const moment = window.moment;
const { template, format, folder } = getDailyNoteSettings4();
const [templateContents, IFoldInfo] = await getTemplateInfo(template);
const filename = date.format(format);
const normalizedPath = await getNotePath2(folder, filename);
try {
const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename).replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => {
const now = moment();
const currentDate = date.clone().set({
hour: now.get("hour"),
minute: now.get("minute"),
second: now.get("second")
});
if (calc) {
currentDate.add(parseInt(timeDelta, 10), unit);
}
if (momentFormat) {
return currentDate.format(momentFormat.substring(1).trim());
}
return currentDate.format(format);
}).replace(/{{\s*yesterday\s*}}/gi, date.clone().subtract(1, "day").format(format)).replace(/{{\s*tomorrow\s*}}/gi, date.clone().add(1, "d").format(format)));
app.foldManager.save(createdFile, IFoldInfo);
return createdFile;
} catch (err) {
console.error(`Failed to create file: '${normalizedPath}'`, err);
new obsidian.Notice("Unable to create new file.");
}
}
function getDailyNote5(date, dailyNotes2) {
var _a;
return (_a = dailyNotes2[getDateUID6(date, "day")]) != null ? _a : null;
}
function getAllDailyNotes2() {
const { vault } = window.app;
const { folder } = getDailyNoteSettings4();
const dailyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder));
if (!dailyNotesFolder) {
throw new DailyNotesFolderMissingError("Failed to find daily notes folder");
}
const dailyNotes2 = {};
obsidian.Vault.recurseChildren(dailyNotesFolder, (note) => {
if (note instanceof obsidian.TFile) {
const date = getDateFromFile(note, "day");
if (date) {
const dateString = getDateUID6(date, "day");
dailyNotes2[dateString] = note;
}
}
});
return dailyNotes2;
}
var WeeklyNotesFolderMissingError = class extends Error {
};
function getDaysOfWeek2() {
const { moment } = window;
let weekStart = moment.localeData()._week.dow;
const daysOfWeek = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
];
while (weekStart) {
daysOfWeek.push(daysOfWeek.shift());
weekStart--;
}
return daysOfWeek;
}
function getDayOfWeekNumericalValue(dayOfWeekName) {
return getDaysOfWeek2().indexOf(dayOfWeekName.toLowerCase());
}
async function createWeeklyNote2(date) {
const { vault } = window.app;
const { template, format, folder } = getWeeklyNoteSettings2();
const [templateContents, IFoldInfo] = await getTemplateInfo(template);
const filename = date.format(format);
const normalizedPath = await getNotePath2(folder, filename);
try {
const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => {
const now = window.moment();
const currentDate = date.clone().set({
hour: now.get("hour"),
minute: now.get("minute"),
second: now.get("second")
});
if (calc) {
currentDate.add(parseInt(timeDelta, 10), unit);
}
if (momentFormat) {
return currentDate.format(momentFormat.substring(1).trim());
}
return currentDate.format(format);
}).replace(/{{\s*title\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi, (_, dayOfWeek, momentFormat) => {
const day = getDayOfWeekNumericalValue(dayOfWeek);
return date.weekday(day).format(momentFormat.trim());
}));
window.app.foldManager.save(createdFile, IFoldInfo);
return createdFile;
} catch (err) {
console.error(`Failed to create file: '${normalizedPath}'`, err);
new obsidian.Notice("Unable to create new file.");
}
}
function getWeeklyNote2(date, weeklyNotes2) {
var _a;
return (_a = weeklyNotes2[getDateUID6(date, "week")]) != null ? _a : null;
}
function getAllWeeklyNotes2() {
const { vault } = window.app;
const { folder } = getWeeklyNoteSettings2();
const weeklyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder));
if (!weeklyNotesFolder) {
throw new WeeklyNotesFolderMissingError("Failed to find weekly notes folder");
}
const weeklyNotes2 = {};
obsidian.Vault.recurseChildren(weeklyNotesFolder, (note) => {
if (note instanceof obsidian.TFile) {
const date = getDateFromFile(note, "week");
if (date) {
const dateString = getDateUID6(date, "week");
weeklyNotes2[dateString] = note;
}
}
});
return weeklyNotes2;
}
var MonthlyNotesFolderMissingError = class extends Error {
};
async function createMonthlyNote(date) {
const { vault } = window.app;
const { template, format, folder } = getMonthlyNoteSettings();
const [templateContents, IFoldInfo] = await getTemplateInfo(template);
const filename = date.format(format);
const normalizedPath = await getNotePath2(folder, filename);
try {
const createdFile = await vault.create(normalizedPath, templateContents.replace(/{{\s*(date|time)\s*:(.*?)}}/gi, (_, _timeOrDate, momentFormat) => {
const now = window.moment();
return date.set({
hour: now.get("hour"),
minute: now.get("minute"),
second: now.get("second")
}).format(momentFormat.trim());
}).replace(/{{\s*date\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi, filename));
window.app.foldManager.save(createdFile, IFoldInfo);
return createdFile;
} catch (err) {
console.error(`Failed to create file: '${normalizedPath}'`, err);
new obsidian.Notice("Unable to create new file.");
}
}
function getMonthlyNote(date, monthlyNotes) {
var _a;
return (_a = monthlyNotes[getDateUID6(date, "month")]) != null ? _a : null;
}
function getAllMonthlyNotes() {
const { vault } = window.app;
const { folder } = getMonthlyNoteSettings();
const monthlyNotesFolder = vault.getAbstractFileByPath(obsidian.normalizePath(folder));
if (!monthlyNotesFolder) {
throw new MonthlyNotesFolderMissingError("Failed to find monthly notes folder");
}
const monthlyNotes = {};
obsidian.Vault.recurseChildren(monthlyNotesFolder, (note) => {
if (note instanceof obsidian.TFile) {
const date = getDateFromFile(note, "month");
if (date) {
const dateString = getDateUID6(date, "month");
monthlyNotes[dateString] = note;
}
}
});
return monthlyNotes;
}
function appHasDailyNotesPluginLoaded2() {
var _a, _b;
const { app } = window;
const dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"];
if (dailyNotesPlugin && dailyNotesPlugin.enabled) {
return true;
}
const periodicNotes = app.plugins.getPlugin("periodic-notes");
return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.daily) == null ? void 0 : _b.enabled);
}
function appHasWeeklyNotesPluginLoaded() {
var _a, _b;
const { app } = window;
if (app.plugins.getPlugin("calendar")) {
return true;
}
const periodicNotes = app.plugins.getPlugin("periodic-notes");
return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.weekly) == null ? void 0 : _b.enabled);
}
function appHasMonthlyNotesPluginLoaded() {
var _a, _b;
const { app } = window;
const periodicNotes = app.plugins.getPlugin("periodic-notes");
return periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.monthly) == null ? void 0 : _b.enabled);
}
exports.DEFAULT_DAILY_NOTE_FORMAT = DEFAULT_DAILY_NOTE_FORMAT2;
exports.DEFAULT_MONTHLY_NOTE_FORMAT = DEFAULT_MONTHLY_NOTE_FORMAT;
exports.DEFAULT_WEEKLY_NOTE_FORMAT = DEFAULT_WEEKLY_NOTE_FORMAT;
exports.appHasDailyNotesPluginLoaded = appHasDailyNotesPluginLoaded2;
exports.appHasMonthlyNotesPluginLoaded = appHasMonthlyNotesPluginLoaded;
exports.appHasWeeklyNotesPluginLoaded = appHasWeeklyNotesPluginLoaded;
exports.createDailyNote = createDailyNote2;
exports.createMonthlyNote = createMonthlyNote;
exports.createWeeklyNote = createWeeklyNote2;
exports.getAllDailyNotes = getAllDailyNotes2;
exports.getAllMonthlyNotes = getAllMonthlyNotes;
exports.getAllWeeklyNotes = getAllWeeklyNotes2;
exports.getDailyNote = getDailyNote5;
exports.getDailyNoteSettings = getDailyNoteSettings4;
exports.getDateFromFile = getDateFromFile;
exports.getDateUID = getDateUID6;
exports.getMonthlyNote = getMonthlyNote;
exports.getMonthlyNoteSettings = getMonthlyNoteSettings;
exports.getTemplateInfo = getTemplateInfo;
exports.getWeeklyNote = getWeeklyNote2;
exports.getWeeklyNoteSettings = getWeeklyNoteSettings2;
}
});
// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => CalendarPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian11 = require("obsidian");
// src/constants.ts
var DEFAULT_WEEK_FORMAT = "gggg-[W]ww";
var DEFAULT_WORDS_PER_DOT = 250;
var VIEW_TYPE_CALENDAR = "calendar-hub";
var VIEW_TYPE_LIST = "calendar-hub-list";
var PLUGIN_ID = "calendar-hub";
var TRIGGER_ON_OPEN = "calendar-hub:open";
// node_modules/svelte/internal/index.mjs
function noop() {
}
function run(fn) {
return fn();
}
function blank_object() {
return /* @__PURE__ */ Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === "function";
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function");
}
function not_equal(a, b) {
return a != a ? b == b : a !== b;
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function subscribe(store, ...callbacks) {
if (store == null) {
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function get_store_value(store) {
let value;
subscribe(store, (_) => value = _)();
return value;
}
function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
}
var globals = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : global;
var ResizeObserverSingleton = class _ResizeObserverSingleton {
constructor(options) {
this.options = options;
this._listeners = "WeakMap" in globals ? /* @__PURE__ */ new WeakMap() : void 0;
}
observe(element3, listener) {
this._listeners.set(element3, listener);
this._getObserver().observe(element3, this.options);
return () => {
this._listeners.delete(element3);
this._observer.unobserve(element3);
};
}
_getObserver() {
var _a;
return (_a = this._observer) !== null && _a !== void 0 ? _a : this._observer = new ResizeObserver((entries) => {
var _a2;
for (const entry of entries) {
_ResizeObserverSingleton.entries.set(entry.target, entry);
(_a2 = this._listeners.get(entry.target)) === null || _a2 === void 0 ? void 0 : _a2(entry);
}
});
}
};
ResizeObserverSingleton.entries = "WeakMap" in globals ? /* @__PURE__ */ new WeakMap() : void 0;
var is_hydrating = false;
function start_hydrating() {
is_hydrating = true;
}
function end_hydrating() {
is_hydrating = false;
}
function append(target, node) {
target.appendChild(node);
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
function element(name) {
return document.createElement(name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(" ");
}
function empty() {
return text("");
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function children(element3) {
return Array.from(element3.childNodes);
}
function set_data(text3, data) {
data = "" + data;
if (text3.data === data)
return;
text3.data = data;
}
function set_style(node, key, value, important) {
if (value == null) {
node.style.removeProperty(key);
} else {
node.style.setProperty(key, value, important ? "important" : "");
}
}
function select_option(select, value, mounting) {
for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i];
if (option.__value === value) {
option.selected = true;
return;
}
}
if (!mounting || value !== void 0) {
select.selectedIndex = -1;
}
}
function toggle_class(element3, name, toggle) {
element3.classList[toggle ? "add" : "remove"](name);
}
var current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error("Function called outside component initialization");
return current_component;
}
function onMount(fn) {
get_current_component().$$.on_mount.push(fn);
}
function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}
var dirty_components = [];
var binding_callbacks = [];
var render_callbacks = [];
var flush_callbacks = [];
var resolved_promise = /* @__PURE__ */ Promise.resolve();
var update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
function add_flush_callback(fn) {
flush_callbacks.push(fn);
}
var seen_callbacks = /* @__PURE__ */ new Set();
var flushidx = 0;
function flush() {
if (flushidx !== 0) {
return;
}
const saved_component = current_component;
do {
try {
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
} catch (e) {
dirty_components.length = 0;
flushidx = 0;
throw e;
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
seen_callbacks.clear();
set_current_component(saved_component);
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
function flush_render_callbacks(fns) {
const filtered = [];
const targets = [];
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
targets.forEach((c) => c());
render_callbacks = filtered;
}
var outroing = /* @__PURE__ */ new Set();
var outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros
// parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach3, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach3)
block.d(1);
callback();
}
});
block.o(local);
} else if (callback) {
callback();
}
}
function destroy_block(block, lookup) {
block.d(1);
lookup.delete(block.key);
}
function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block5, next, get_context) {
let o = old_blocks.length;
let n = list.length;
let i = o;
const old_indexes = {};
while (i--)
old_indexes[old_blocks[i].key] = i;
const new_blocks = [];
const new_lookup = /* @__PURE__ */ new Map();
const deltas = /* @__PURE__ */ new Map();
const updates = [];
i = n;
while (i--) {
const child_ctx = get_context(ctx, list, i);
const key = get_key(child_ctx);
let block = lookup.get(key);
if (!block) {
block = create_each_block5(key, child_ctx);
block.c();
} else if (dynamic) {
updates.push(() => block.p(child_ctx, dirty));
}
new_lookup.set(key, new_blocks[i] = block);
if (key in old_indexes)
deltas.set(key, Math.abs(i - old_indexes[key]));
}
const will_move = /* @__PURE__ */ new Set();
const did_move = /* @__PURE__ */ new Set();
function insert3(block) {
transition_in(block, 1);
block.m(node, next);
lookup.set(block.key, block);
next = block.first;
n--;
}
while (o && n) {
const new_block = new_blocks[n - 1];
const old_block = old_blocks[o - 1];
const new_key = new_block.key;
const old_key = old_block.key;
if (new_block === old_block) {
next = new_block.first;
o--;
n--;
} else if (!new_lookup.has(old_key)) {
destroy(old_block, lookup);
o--;
} else if (!lookup.has(new_key) || will_move.has(new_key)) {
insert3(new_block);
} else if (did_move.has(old_key)) {
o--;
} else if (deltas.get(new_key) > deltas.get(old_key)) {
did_move.add(new_key);
insert3(new_block);
} else {
will_move.add(old_key);
o--;
}
}
while (o--) {
const old_block = old_blocks[o];
if (!new_lookup.has(old_block.key))
destroy(old_block, lookup);
}
while (n)
insert3(new_blocks[n - 1]);
run_all(updates);
return new_blocks;
}
var _boolean_attributes = [
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"inert",
"ismap",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected"
];
var boolean_attributes = /* @__PURE__ */ new Set([..._boolean_attributes]);
function bind(component, name, callback) {
const index = component.$$.props[name];
if (index !== void 0) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
}
}
function create_component(block) {
block && block.c();
}
function mount_component(component, target, anchor, customElement) {
const { fragment, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
add_render_callback(() => {
const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
if (component.$$.on_destroy) {
component.$$.on_destroy.push(...new_on_destroy);
} else {
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
flush_render_callbacks($$.after_update);
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
}
function init(component, options, instance5, create_fragment5, not_equal3, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: [],
// state
props,
update: noop,
not_equal: not_equal3,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles && append_styles($$.root);
let ready = false;
$$.ctx = instance5 ? instance5(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal3($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
}) : [];
$$.update();
ready = true;
run_all($$.before_update);
$$.fragment = create_fragment5 ? create_fragment5($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
start_hydrating();
const nodes = children(options.target);
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
} else {
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor, options.customElement);
end_hydrating();
flush();
}
set_current_component(parent_component);
}
var SvelteElement;
if (typeof HTMLElement === "function") {
SvelteElement = class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
const { on_mount } = this.$$;
this.$$.on_disconnect = on_mount.map(run).filter(is_function);
for (const key in this.$$.slotted) {
this.appendChild(this.$$.slotted[key]);
}
}
attributeChangedCallback(attr3, _oldValue, newValue) {
this[attr3] = newValue;
}
disconnectedCallback() {
run_all(this.$$.on_disconnect);
}
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
if (!is_function(callback)) {
return noop;
}
const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
};
}
var SvelteComponent = class {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
if (!is_function(callback)) {
return noop;
}
const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
};
// node_modules/svelte/store/index.mjs
var subscriber_queue = [];
function writable(value, start = noop) {
let stop;
const subscribers = /* @__PURE__ */ new Set();
function set(new_value) {
if (safe_not_equal(value, new_value)) {
value = new_value;
if (stop) {
const run_queue = !subscriber_queue.length;
for (const subscriber of subscribers) {
subscriber[1]();
subscriber_queue.push(subscriber, value);
}
if (run_queue) {
for (let i = 0; i < subscriber_queue.length; i += 2) {
subscriber_queue[i][0](subscriber_queue[i + 1]);
}
subscriber_queue.length = 0;
}
}
}
}
function update3(fn) {
set(fn(value));
}
function subscribe2(run3, invalidate = noop) {
const subscriber = [run3, invalidate];
subscribers.add(subscriber);
if (subscribers.size === 1) {
stop = start(set) || noop;
}
run3(value);
return () => {
subscribers.delete(subscriber);
if (subscribers.size === 0 && stop) {
stop();
stop = null;
}
};
}
return { set, update: update3, subscribe: subscribe2 };
}
// src/settings.ts
var import_obsidian2 = require("obsidian");
// src/io/folderRules.ts
function parseFolderRules(value) {
return value.split(/[,\n]/).map((entry) => entry.trim()).filter(Boolean).map((entry) => {
const excluded = entry.startsWith("-");
const raw = excluded ? entry.slice(1).trim() : entry;
const path = normalizeFolderPath(raw);
return { path, excluded };
});
}
function serializeFolderRules(rules) {
return rules.map((rule) => rule.excluded ? `-${rule.path}` : rule.path).join(", ");
}
function normalizeFolderPath(path) {
const stripped = path.replace(/^\/+|\/+$/g, "");
return stripped === "." ? "" : stripped;
}
function ruleDepth(rule) {
return rule.path === "" ? 0 : rule.path.split("/").length;
}
function folderMatchesRule(folderPath, rule) {
if (rule.path === "") {
return true;
}
return folderPath === rule.path || folderPath.startsWith(`${rule.path}/`);
}
function fileMatchesRule(filePath, rule) {
if (rule.path === "") {
return true;
}
return filePath === `${rule.path}.md` || filePath.startsWith(`${rule.path}/`);
}
function decide(rules, matches) {
let decision = null;
let decisionDepth = -1;
for (const rule of rules) {
if (!matches(rule)) {
continue;
}
const depth = ruleDepth(rule);
if (depth > decisionDepth || depth === decisionDepth && rule.excluded) {
decision = !rule.excluded;
decisionDepth = depth;
}
}
if (decision !== null) {
return decision;
}
return rules.every((rule) => rule.excluded);
}
function isFolderIncluded(folderPath, rules) {
return decide(rules, (rule) => folderMatchesRule(folderPath, rule));
}
function shouldIncludeFilePath(filePath, rules) {
return decide(rules, (rule) => fileMatchesRule(filePath, rule));
}
function getFolderCheckState(folderPath, rules) {
const included = isFolderIncluded(folderPath, rules);
const prefix = `${folderPath}/`;
const mixed = rules.some(
(rule) => rule.path.startsWith(prefix) && rule.excluded === included
);
if (mixed) {
return "partial";
}
return included ? "checked" : "none";
}
function toggleFolderRule(folderPath, rules) {
const state = getFolderCheckState(folderPath, rules);
const prefix = `${folderPath}/`;
const withoutSubtree = rules.filter(
(rule) => rule.path !== folderPath && !rule.path.startsWith(prefix)
);
if (state === "checked") {
if (isFolderIncluded(folderPath, withoutSubtree)) {
return [...withoutSubtree, { path: folderPath, excluded: true }];
}
return withoutSubtree;
}
const hadIncludes = rules.some((rule) => !rule.excluded);
const stillHasIncludes = withoutSubtree.some((rule) => !rule.excluded);
if (hadIncludes && !stillHasIncludes) {
return [...withoutSubtree, { path: folderPath, excluded: false }];
}
if (isFolderIncluded(folderPath, withoutSubtree)) {
return withoutSubtree;
}
return [...withoutSubtree, { path: folderPath, excluded: false }];
}
// src/io/folderTree.ts
function flattenFolderTree(nodes, expanded) {
const rows = [];
const visit = (node, depth) => {
const isExpanded = expanded.has(node.path);
rows.push({
path: node.path,
name: node.name,
depth,
hasChildren: node.children.length > 0,
expanded: isExpanded
});
if (isExpanded) {
node.children.forEach((child) => visit(child, depth + 1));
}
};
nodes.forEach((node) => visit(node, 0));
return rows;
}
function getAncestorPaths(path) {
const segments = path.split("/");
const ancestors = [];
for (let end = 1; end < segments.length; end++) {
ancestors.push(segments.slice(0, end).join("/"));
}
return ancestors;
}
function getExpansionForSelection(selectedFolders) {
return new Set(
selectedFolders.flatMap((folder) => getAncestorPaths(folder))
);
}
// src/io/vaultFolders.ts
var import_obsidian = require("obsidian");
function getVaultFolderTree() {
const toNode = (folder) => ({
path: folder.path,
name: folder.name,
children: folder.children.filter((child) => child instanceof import_obsidian.TFolder).map(toNode).sort((a, b) => a.name.localeCompare(b.name))
});
return window.app.vault.getRoot().children.filter((child) => child instanceof import_obsidian.TFolder).map(toNode).sort((a, b) => a.name.localeCompare(b.name));
}
// src/ui/FolderRuleTree.svelte
function get_each_context(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[8] = list[i];
const constants_0 = getFolderCheckState(
/*row*/
child_ctx[8].path,
/*rules*/
child_ctx[0]
);
child_ctx[9] = constants_0;
return child_ctx;
}
function create_if_block(ctx) {
let div;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let each_value = (
/*visibleFolderRows*/
ctx[2]
);
const get_key = (ctx2) => (
/*row*/
ctx2[8].path
);
for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context(ctx, each_value, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
}
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(div, "class", "calendar-folder-list");
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(div, null);
}
}
},
p(ctx2, dirty) {
if (dirty & /*visibleFolderRows, getFolderCheckState, rules, onToggleFolder, handleToggleFolderExpansion*/
15) {
each_value = /*visibleFolderRows*/
ctx2[2];
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div, destroy_block, create_each_block, null, get_each_context);
}
},
d(detaching) {
if (detaching) detach(div);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function create_else_block(ctx) {
let span;
return {
c() {
span = element("span");
attr(span, "class", "calendar-folder-expand-spacer");
},
m(target, anchor) {
insert(target, span, anchor);
},
p: noop,
d(detaching) {
if (detaching) detach(span);
}
};
}
function create_if_block_1(ctx) {
let button;
let t_value = (
/*row*/
ctx[8].expanded ? "\u25BE" : "\u25B8"
);
let t;
let button_aria_expanded_value;
let button_aria_label_value;
let mounted;
let dispose;
function click_handler() {
return (
/*click_handler*/
ctx[6](
/*row*/
ctx[8]
)
);
}
return {
c() {
button = element("button");
t = text(t_value);
attr(button, "class", "calendar-folder-expand");
attr(button, "type", "button");
attr(button, "aria-expanded", button_aria_expanded_value = /*row*/
ctx[8].expanded);
attr(button, "aria-label", button_aria_label_value = /*row*/
ctx[8].expanded ? "Collapse folder" : "Expand folder");
},
m(target, anchor) {
insert(target, button, anchor);
append(button, t);
if (!mounted) {
dispose = listen(button, "click", click_handler);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty & /*visibleFolderRows*/
4 && t_value !== (t_value = /*row*/
ctx[8].expanded ? "\u25BE" : "\u25B8")) set_data(t, t_value);
if (dirty & /*visibleFolderRows*/
4 && button_aria_expanded_value !== (button_aria_expanded_value = /*row*/
ctx[8].expanded)) {
attr(button, "aria-expanded", button_aria_expanded_value);
}
if (dirty & /*visibleFolderRows*/
4 && button_aria_label_value !== (button_aria_label_value = /*row*/
ctx[8].expanded ? "Collapse folder" : "Expand folder")) {
attr(button, "aria-label", button_aria_label_value);
}
},
d(detaching) {
if (detaching) detach(button);
mounted = false;
dispose();
}
};
}
function create_each_block(key_1, ctx) {
let div;
let t0;
let label;
let input;
let input_checked_value;
let input_indeterminate_value;
let t1;
let span;
let t2_value = (
/*row*/
ctx[8].name + ""
);
let t2;
let label_title_value;
let t3;
let mounted;
let dispose;
function select_block_type(ctx2, dirty) {
if (
/*row*/
ctx2[8].hasChildren
) return create_if_block_1;
return create_else_block;
}
let current_block_type = select_block_type(ctx, -1);
let if_block = current_block_type(ctx);
function change_handler() {
return (
/*change_handler*/
ctx[7](
/*row*/
ctx[8]
)
);
}
return {
key: key_1,
first: null,
c() {
div = element("div");
if_block.c();
t0 = space();
label = element("label");
input = element("input");
t1 = space();
span = element("span");
t2 = text(t2_value);
t3 = space();
attr(input, "type", "checkbox");
input.checked = input_checked_value = /*state*/
ctx[9] === "checked";
input.indeterminate = input_indeterminate_value = /*state*/
ctx[9] === "partial";
attr(span, "class", "calendar-folder-path");
attr(label, "class", "calendar-folder-option");
attr(label, "title", label_title_value = /*row*/
ctx[8].path);
attr(div, "class", "calendar-folder-row");
set_style(
div,
"padding-left",
/*row*/
ctx[8].depth * 14 + "px"
);
this.first = div;
},
m(target, anchor) {
insert(target, div, anchor);
if_block.m(div, null);
append(div, t0);
append(div, label);
append(label, input);
append(label, t1);
append(label, span);
append(span, t2);
append(div, t3);
if (!mounted) {
dispose = listen(input, "change", change_handler);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (current_block_type === (current_block_type = select_block_type(ctx, dirty)) && if_block) {
if_block.p(ctx, dirty);
} else {
if_block.d(1);
if_block = current_block_type(ctx);
if (if_block) {
if_block.c();
if_block.m(div, t0);
}
}
if (dirty & /*visibleFolderRows, rules*/
5 && input_checked_value !== (input_checked_value = /*state*/
ctx[9] === "checked")) {
input.checked = input_checked_value;
}
if (dirty & /*visibleFolderRows, rules*/
5 && input_indeterminate_value !== (input_indeterminate_value = /*state*/
ctx[9] === "partial")) {
input.indeterminate = input_indeterminate_value;
}
if (dirty & /*visibleFolderRows*/
4 && t2_value !== (t2_value = /*row*/
ctx[8].name + "")) set_data(t2, t2_value);
if (dirty & /*visibleFolderRows*/
4 && label_title_value !== (label_title_value = /*row*/
ctx[8].path)) {
attr(label, "title", label_title_value);
}
if (dirty & /*visibleFolderRows*/
4) {
set_style(
div,
"padding-left",
/*row*/
ctx[8].depth * 14 + "px"
);
}
},
d(detaching) {
if (detaching) detach(div);
if_block.d();
mounted = false;
dispose();
}
};
}
function create_fragment(ctx) {
let if_block_anchor;
let if_block = (
/*visibleFolderRows*/
ctx[2].length && create_if_block(ctx)
);
return {
c() {
if (if_block) if_block.c();
if_block_anchor = empty();
},
m(target, anchor) {
if (if_block) if_block.m(target, anchor);
insert(target, if_block_anchor, anchor);
},
p(ctx2, [dirty]) {
if (
/*visibleFolderRows*/
ctx2[2].length
) {
if (if_block) {
if_block.p(ctx2, dirty);
} else {
if_block = create_if_block(ctx2);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
i: noop,
o: noop,
d(detaching) {
if (if_block) if_block.d(detaching);
if (detaching) detach(if_block_anchor);
}
};
}
function instance($$self, $$props, $$invalidate) {
let visibleFolderRows;
let { rules } = $$props;
let { onToggleFolder } = $$props;
let folderTree = [];
let expandedFolders = /* @__PURE__ */ new Set();
onMount(() => {
$$invalidate(4, folderTree = getVaultFolderTree());
$$invalidate(5, expandedFolders = getExpansionForSelection(rules.map((rule) => rule.path)));
});
function handleToggleFolderExpansion(folder) {
const next = new Set(expandedFolders);
if (next.has(folder)) {
next.delete(folder);
} else {
next.add(folder);
}
$$invalidate(5, expandedFolders = next);
}
const click_handler = (row) => handleToggleFolderExpansion(row.path);
const change_handler = (row) => onToggleFolder(row.path);
$$self.$$set = ($$props2) => {
if ("rules" in $$props2) $$invalidate(0, rules = $$props2.rules);
if ("onToggleFolder" in $$props2) $$invalidate(1, onToggleFolder = $$props2.onToggleFolder);
};
$$self.$$.update = () => {
if ($$self.$$.dirty & /*folderTree, expandedFolders*/
48) {
$: $$invalidate(2, visibleFolderRows = flattenFolderTree(folderTree, expandedFolders));
}
};
return [
rules,
onToggleFolder,
visibleFolderRows,
handleToggleFolderExpansion,
folderTree,
expandedFolders,
click_handler,
change_handler
];
}
var FolderRuleTree = class extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, not_equal, { rules: 0, onToggleFolder: 1 });
}
};
var FolderRuleTree_default = FolderRuleTree;
// src/settings.ts
var import_obsidian_daily_notes_interface = __toESM(require_obsidian_daily_notes_interface());
var weekdays = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
];
var defaultSettings = Object.freeze({
shouldConfirmBeforeCreate: true,
shouldIndexDailyNotesInAllFolders: true,
dailyNoteFilenameDateFormat: "",
shouldIndexDailyNotesFromFrontmatter: false,
dailyNoteFrontmatterDateFields: "date, daily_date, calendar_date",
shouldIndexDailyNotesFromCreationDate: false,
dailyNoteIncludedFolders: "",
sidebarViewMode: "calendar",
listGrouping: "month",
listSortOrder: "desc",
listFolderFilter: "",
weekStart: "locale",
wordsPerDot: DEFAULT_WORDS_PER_DOT,
showWeeklyNote: false,
weeklyNoteFormat: "",
weeklyNoteTemplate: "",
weeklyNoteFolder: "",
shouldIndexWeeklyNotesInAllFolders: true,
weeklyNoteFilenameDateFormat: "",
shouldIndexWeeklyNotesFromFrontmatter: false,
weeklyNoteFrontmatterDateFields: "week, weekly_date",
weeklyNoteIncludedFolders: "",
localeOverride: "system-default"
});
function appHasPeriodicNotesPluginLoaded() {
var _a, _b;
const periodicNotes = window.app.plugins.getPlugin("periodic-notes");
return !!((_b = (_a = periodicNotes == null ? void 0 : periodicNotes.settings) == null ? void 0 : _a.weekly) == null ? void 0 : _b.enabled);
}
var CalendarSettingsTab = class extends import_obsidian2.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.folderTreeComponent = null;
this.plugin = plugin;
}
hide() {
this.destroyFolderTree();
}
destroyFolderTree() {
var _a;
(_a = this.folderTreeComponent) == null ? void 0 : _a.$destroy();
this.folderTreeComponent = null;
}
display() {
this.destroyFolderTree();
this.containerEl.empty();
if (!(0, import_obsidian_daily_notes_interface.appHasDailyNotesPluginLoaded)()) {
this.containerEl.createDiv("settings-banner", (banner) => {
banner.createEl("div", {
cls: "settings-banner-title",
text: "Daily Notes plugin not enabled"
});
banner.createEl("p", {
cls: "setting-item-description",
text: "Calendar Hub works best with either the Daily Notes plugin or the Periodic Notes plugin."
});
});
}
this.addWeekStartSetting();
this.addConfirmCreateSetting();
new import_obsidian2.Setting(this.containerEl).setName("Date matching").setHeading();
this.addIndexDailyNotesInAllFoldersSetting();
this.addDailyNoteIncludedFoldersSetting();
this.addIndexDailyNotesFromFrontmatterSetting();
this.addDailyNoteFrontmatterDateFieldsSetting();
this.addDailyNoteFilenameDateFormatSetting();
this.addIndexDailyNotesFromCreationDateSetting();
new import_obsidian2.Setting(this.containerEl).setName("Weekly notes").setHeading();
this.addShowWeeklyNoteSetting();
if (this.plugin.options.showWeeklyNote && !appHasPeriodicNotesPluginLoaded()) {
this.containerEl.createEl("p", {
cls: "setting-item-description",
text: "Weekly note support is kept for compatibility. For richer periodic notes, consider using the Periodic Notes plugin."
});
this.addWeeklyNoteFormatSetting();
this.addWeeklyNoteTemplateSetting();
this.addWeeklyNoteFolderSetting();
this.addIndexWeeklyNotesInAllFoldersSetting();
this.addWeeklyNoteIncludedFoldersSetting();
this.addWeeklyNoteFilenameDateFormatSetting();
this.addIndexWeeklyNotesFromFrontmatterSetting();
this.addWeeklyNoteFrontmatterDateFieldsSetting();
}
new import_obsidian2.Setting(this.containerEl).setName("Advanced").setHeading();
this.addLocaleOverrideSetting();
}
addWeekStartSetting() {
const { moment } = window;
const localizedWeekdays = moment.weekdays();
const localeWeekStartNum = window._bundledLocaleWeekSpec.dow;
const localeWeekStart = moment.weekdays()[localeWeekStartNum];
new import_obsidian2.Setting(this.containerEl).setName("Start week on:").setDesc(
"Choose what day of the week to start. Select 'Locale default' to use the default specified by moment.js"
).addDropdown((dropdown) => {
dropdown.addOption("locale", `Locale default (${localeWeekStart})`);
localizedWeekdays.forEach((day, i) => {
dropdown.addOption(weekdays[i], day);
});
dropdown.setValue(this.plugin.options.weekStart);
dropdown.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
weekStart: value
}));
});
});
}
addConfirmCreateSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Confirm before creating new note").setDesc("Show a confirmation modal before creating a new note").addToggle((toggle) => {
toggle.setValue(this.plugin.options.shouldConfirmBeforeCreate);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldConfirmBeforeCreate: value
}));
});
});
}
addIndexDailyNotesInAllFoldersSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Detect daily notes in all folders").setDesc(
"Find every Markdown file whose file name matches the daily note format, even outside the configured daily notes folder. Matching notes for the selected date appear below the calendar."
).addToggle((toggle) => {
toggle.setValue(this.plugin.options.shouldIndexDailyNotesInAllFolders);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldIndexDailyNotesInAllFolders: value
}));
});
});
}
addDailyNoteFilenameDateFormatSetting() {
const presetFormats = [
"YYYYMMDD",
"YYYY-MM-DD",
"YYYY_MM_DD",
"YYYY.MM.DD",
"DD-MM-YYYY",
"MM-DD-YYYY",
"YYYYMMDDTHHmmss",
"YYYYMMDDTHHmmssZZ"
];
let formatField = null;
new import_obsidian2.Setting(this.containerEl).setName("Date format inside daily note filenames").setDesc(
"Optional. Calendar Hub already looks for the Daily Notes date format anywhere in the file name. Pick common formats from the dropdown (each pick appends to the list) or type your own comma-separated moment.js formats, such as YYYYMMDD for files like 'meeting 20260529.md', or YYYYMMDDTHHmmssZZ for timestamps like 'sync 20260529T143025Z.md'."
).addDropdown((dropdown) => {
dropdown.addOption("", "Add a common format\u2026");
presetFormats.forEach((format) => {
dropdown.addOption(format, format);
});
dropdown.setValue("");
dropdown.onChange((value) => {
if (!value) {
return;
}
const current = this.plugin.options.dailyNoteFilenameDateFormat.split(/[,\n]/).map((entry) => entry.trim()).filter(Boolean);
if (!current.includes(value)) {
const next = [...current, value].join(", ");
void this.plugin.writeOptions(() => ({
dailyNoteFilenameDateFormat: next
}));
formatField == null ? void 0 : formatField.setValue(next);
}
dropdown.setValue("");
});
}).addText((textfield) => {
formatField = textfield;
textfield.setPlaceholder("YYYYMMDD");
textfield.setValue(this.plugin.options.dailyNoteFilenameDateFormat);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
dailyNoteFilenameDateFormat: value
}));
});
});
}
addIndexDailyNotesFromFrontmatterSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Use frontmatter dates").setDesc(
"Read the configured frontmatter fields for a date and prefer it over any date in the file name. Notes without a frontmatter date fall back to file name matching."
).addToggle((toggle) => {
toggle.setValue(
this.plugin.options.shouldIndexDailyNotesFromFrontmatter
);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldIndexDailyNotesFromFrontmatter: value
}));
});
});
}
addDailyNoteFrontmatterDateFieldsSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Frontmatter date fields").setDesc(
"Comma-separated field names to read when frontmatter dates are enabled. Fields are tried in this order and the first one with a valid date wins, so put the field you trust most first. Nested fields can use dot notation, such as calendar.date."
).addText((textfield) => {
textfield.setPlaceholder("date, daily_date, calendar_date");
textfield.setValue(this.plugin.options.dailyNoteFrontmatterDateFields);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
dailyNoteFrontmatterDateFields: value
}));
});
});
}
addIndexDailyNotesFromCreationDateSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Use file creation date fallback").setDesc(
"When neither the file name nor frontmatter yields a date, map the note to the day the file was created. Creation times are set by your device and can change when files are copied or re-synced, so file name and frontmatter dates always take priority."
).addToggle((toggle) => {
toggle.setValue(
this.plugin.options.shouldIndexDailyNotesFromCreationDate
);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldIndexDailyNotesFromCreationDate: value
}));
});
});
}
addDailyNoteIncludedFoldersSetting() {
let foldersField = null;
new import_obsidian2.Setting(this.containerEl).setName("Folders to scan for daily notes").setDesc(
"Optional. Leave blank to scan the whole vault. Tick folders in the tree below or add comma-separated folder paths to limit filename and frontmatter matching. Prefix a path with '-' to exclude its subtree, e.g. '30 Macro, -30 Macro/Archive'; deeper rules win."
).addTextArea((textarea) => {
foldersField = textarea;
textarea.setPlaceholder(
"Journal, Work/Daily, Projects/Research"
);
textarea.setValue(this.plugin.options.dailyNoteIncludedFolders);
textarea.onChange(async (value) => {
var _a;
await this.plugin.writeOptions(() => ({
dailyNoteIncludedFolders: value
}));
(_a = this.folderTreeComponent) == null ? void 0 : _a.$set({
rules: parseFolderRules(value)
});
});
});
const treeEl = this.containerEl.createDiv("calendar-settings-folder-tree");
this.folderTreeComponent = new FolderRuleTree_default({
target: treeEl,
props: {
rules: parseFolderRules(this.plugin.options.dailyNoteIncludedFolders),
onToggleFolder: (folder) => {
var _a;
const next = toggleFolderRule(
folder,
parseFolderRules(this.plugin.options.dailyNoteIncludedFolders)
);
const value = serializeFolderRules(next);
void this.plugin.writeOptions(() => ({
dailyNoteIncludedFolders: value
}));
(_a = this.folderTreeComponent) == null ? void 0 : _a.$set({ rules: next });
foldersField == null ? void 0 : foldersField.setValue(value);
}
}
});
}
addShowWeeklyNoteSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Show week number").setDesc("Enable this to add a column with the week number").addToggle((toggle) => {
toggle.setValue(this.plugin.options.showWeeklyNote);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({ showWeeklyNote: value }));
this.display();
});
});
}
addWeeklyNoteFormatSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Weekly note format").setDesc("For more syntax help, refer to format reference").addText((textfield) => {
textfield.setValue(this.plugin.options.weeklyNoteFormat);
textfield.setPlaceholder(DEFAULT_WEEK_FORMAT);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({ weeklyNoteFormat: value }));
});
});
}
addWeeklyNoteTemplateSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Weekly note template").setDesc(
"Choose the file you want to use as the template for your weekly notes"
).addText((textfield) => {
textfield.setValue(this.plugin.options.weeklyNoteTemplate);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({ weeklyNoteTemplate: value }));
});
});
}
addWeeklyNoteFolderSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Weekly note folder").setDesc("New weekly notes will be placed here").addText((textfield) => {
textfield.setValue(this.plugin.options.weeklyNoteFolder);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({ weeklyNoteFolder: value }));
});
});
}
addIndexWeeklyNotesInAllFoldersSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Detect weekly notes in all folders").setDesc(
"Find every Markdown file that resolves to a week, even outside the weekly notes folder. Matching notes for the selected week appear below the calendar."
).addToggle((toggle) => {
toggle.setValue(this.plugin.options.shouldIndexWeeklyNotesInAllFolders);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldIndexWeeklyNotesInAllFolders: value
}));
});
});
}
addWeeklyNoteIncludedFoldersSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Folders to scan for weekly notes").setDesc(
"Optional. Leave blank to scan the whole vault. Add comma-separated folder paths to limit weekly filename and frontmatter matching. Prefix a path with '-' to exclude its subtree; deeper rules win."
).addTextArea((textarea) => {
textarea.setPlaceholder("Journal, Work/Weekly, Reviews");
textarea.setValue(this.plugin.options.weeklyNoteIncludedFolders);
textarea.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
weeklyNoteIncludedFolders: value
}));
});
});
}
addWeeklyNoteFilenameDateFormatSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Week format inside weekly note filenames").setDesc(
"Optional. Calendar Hub already looks for the weekly note format anywhere in the file name. Add extra comma-separated formats here, such as GGGG-[W]WW for files like 'review 2026-W23.md'."
).addText((textfield) => {
textfield.setPlaceholder("GGGG-[W]WW");
textfield.setValue(this.plugin.options.weeklyNoteFilenameDateFormat);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
weeklyNoteFilenameDateFormat: value
}));
});
});
}
addIndexWeeklyNotesFromFrontmatterSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Use frontmatter dates for weekly notes").setDesc(
"Read the configured frontmatter fields for a week and prefer them over the file name (a week string or a date both work). Notes without a frontmatter value fall back to file name matching."
).addToggle((toggle) => {
toggle.setValue(
this.plugin.options.shouldIndexWeeklyNotesFromFrontmatter
);
toggle.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
shouldIndexWeeklyNotesFromFrontmatter: value
}));
});
});
}
addWeeklyNoteFrontmatterDateFieldsSetting() {
new import_obsidian2.Setting(this.containerEl).setName("Weekly frontmatter fields").setDesc(
"Comma-separated field names to read when weekly frontmatter dates are enabled. Fields are tried in this order and the first one with a valid value wins. Nested fields can use dot notation, such as calendar.week."
).addText((textfield) => {
textfield.setPlaceholder("week, weekly_date");
textfield.setValue(this.plugin.options.weeklyNoteFrontmatterDateFields);
textfield.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
weeklyNoteFrontmatterDateFields: value
}));
});
});
}
addLocaleOverrideSetting() {
var _a;
const { moment } = window;
const sysLocale = (_a = navigator.language) == null ? void 0 : _a.toLowerCase();
new import_obsidian2.Setting(this.containerEl).setName("Override locale:").setDesc(
"Set this if you want to use a locale different from the default"
).addDropdown((dropdown) => {
dropdown.addOption("system-default", `Same as system (${sysLocale})`);
moment.locales().forEach((locale) => {
dropdown.addOption(locale, locale);
});
dropdown.setValue(this.plugin.options.localeOverride);
dropdown.onChange(async (value) => {
await this.plugin.writeOptions(() => ({
localeOverride: value
}));
});
});
}
};
// src/io/dailyNoteIndex.ts
var import_obsidian_daily_notes_interface2 = __toESM(require_obsidian_daily_notes_interface());
function buildNotesByDate(files, options) {
var _a, _b, _c;
const notesByDate = {};
const { format, granularity } = options;
const folderRules = parseFolderRules((_a = options.includedFolders) != null ? _a : "");
const frontmatterDateFields = getListValues(
(_b = options.frontmatterDateFields) != null ? _b : ""
);
const extractionFormats = getExtractionFormats(
format,
(_c = options.filenameDateFormat) != null ? _c : ""
);
files.forEach((file) => {
var _a2;
if (!shouldIncludeFilePath(file.path, folderRules)) {
return;
}
let noteDate = getDateFromFrontmatter(
file,
frontmatterDateFields,
extractionFormats
);
if (!noteDate.isValid()) {
noteDate = getDateFromFilename(
file.basename,
format,
options.filenameDateFormat
);
}
if (!noteDate.isValid() && options.useCreationDateFallback) {
noteDate = getDateFromCreationTime(file);
}
if (!noteDate.isValid()) {
return;
}
const id = (0, import_obsidian_daily_notes_interface2.getDateUID)(noteDate, granularity);
const notes = (_a2 = notesByDate[id]) != null ? _a2 : [];
notes.push(file);
notesByDate[id] = notes;
});
Object.values(notesByDate).forEach(
(notes) => notes.sort((a, b) => a.path.localeCompare(b.path))
);
return notesByDate;
}
function buildDailyNotesByDate(files, options = "") {
const indexOptions = normalizeIndexOptions(options);
const { format = import_obsidian_daily_notes_interface2.DEFAULT_DAILY_NOTE_FORMAT } = (0, import_obsidian_daily_notes_interface2.getDailyNoteSettings)();
return buildNotesByDate(files, {
format,
granularity: "day",
filenameDateFormat: indexOptions.filenameDateFormat,
frontmatterDateFields: indexOptions.frontmatterDateFields,
useCreationDateFallback: indexOptions.useCreationDateFallback,
includedFolders: indexOptions.includedFolders
});
}
function normalizeIndexOptions(options) {
if (typeof options === "string") {
return { filenameDateFormat: options };
}
return options;
}
function getDateFromFilename(basename, dailyNoteFormat, filenameDateFormat = "") {
const exactDate = parseNoteDate(basename, dailyNoteFormat);
if (exactDate.isValid()) {
return exactDate;
}
for (const extractionFormat of getExtractionFormats(
dailyNoteFormat,
filenameDateFormat
)) {
const candidateLengths = getCandidateLengths(extractionFormat);
for (const length of candidateLengths) {
for (let start = 0; start <= basename.length - length; start++) {
const candidate = basename.substring(start, start + length);
const embeddedDate = parseNoteDate(candidate, extractionFormat);
if (embeddedDate.isValid()) {
return embeddedDate;
}
}
}
}
return exactDate;
}
function getDateFromFrontmatter(file, frontmatterDateFields, formats) {
var _a;
if (!frontmatterDateFields.length) {
return window.moment.invalid();
}
const frontmatter = (_a = window.app.metadataCache.getFileCache(file)) == null ? void 0 : _a.frontmatter;
if (!frontmatter) {
return window.moment.invalid();
}
for (const field of frontmatterDateFields) {
const date = getDateFromFrontmatterValue(
getFrontmatterValue(frontmatter, field),
formats
);
if (date.isValid()) {
return date;
}
}
return window.moment.invalid();
}
function getExtractionFormats(dailyNoteFormat, filenameDateFormat) {
return Array.from(
/* @__PURE__ */ new Set([
dailyNoteFormat,
...filenameDateFormat.split(",").map((format) => format.trim()).filter(Boolean)
])
);
}
function getDateFromFrontmatterValue(value, formats) {
if (Array.isArray(value)) {
for (const item of value) {
const date = getDateFromFrontmatterValue(item, formats);
if (date.isValid()) {
return date;
}
}
return window.moment.invalid();
}
if (value instanceof Date) {
return window.moment(value);
}
if (typeof value !== "string" && typeof value !== "number") {
return window.moment.invalid();
}
const valueText = String(value).trim();
for (const format of getFrontmatterFormats(formats)) {
const date = parseNoteDate(valueText, format);
if (date.isValid()) {
return date;
}
}
const isoDate = parseNoteDate(valueText, window.moment.ISO_8601);
return isoDate.isValid() ? isoDate : window.moment.invalid();
}
function getFrontmatterFormats(formats) {
return Array.from(
/* @__PURE__ */ new Set([
...formats,
"YYYY-MM-DD",
"YYYYMMDD"
])
);
}
function getFrontmatterValue(frontmatter, field) {
return field.split(".").reduce((value, key) => {
if (!value || typeof value !== "object") {
return void 0;
}
return value[key];
}, frontmatter);
}
function getDateFromCreationTime(file) {
var _a;
const ctime = (_a = file.stat) == null ? void 0 : _a.ctime;
return ctime ? window.moment(ctime) : window.moment.invalid();
}
function getListValues(value) {
return value.split(/[,\n]/).map((entry) => entry.trim()).filter(Boolean);
}
function parseNoteDate(text3, format) {
const parsed = window.moment(text3, format, true);
if (!parsed.isValid() || !hasExplicitUtcOffset(text3, format)) {
return parsed;
}
const literal = window.moment.parseZone(text3, format, true);
return window.moment({
year: literal.year(),
month: literal.month(),
date: literal.date()
});
}
function hasExplicitUtcOffset(text3, format) {
if (typeof format === "string") {
return /Z/.test(removeEscapedCharacters(format));
}
return /(Z|[+-]\d{2}:\d{2}|[+-]\d{4})$/.test(text3);
}
function removeEscapedCharacters(format) {
return format.replace(/\[[^\]]*\]/g, "");
}
function getCandidateLengths(format) {
var _a;
const sampleDates = [
window.moment("2000-01-02", "YYYY-MM-DD"),
window.moment("2000-11-22", "YYYY-MM-DD")
];
const offsetTokens = (_a = removeEscapedCharacters(format).match(/ZZ|Z/g)) != null ? _a : [];
let literalUtcShrink = 0;
for (const token of offsetTokens) {
literalUtcShrink += token === "ZZ" ? 4 : 5;
}
const lengths = /* @__PURE__ */ new Set();
sampleDates.forEach((date) => {
const length = date.format(format).length;
lengths.add(length);
if (literalUtcShrink > 0) {
lengths.add(length - literalUtcShrink);
}
});
return Array.from(lengths).sort((a, b) => b - a);
}
function dailyNotesByDateToSingleNotes(notesByDate) {
return Object.entries(notesByDate).reduce(
(notes, [dateUID, files]) => {
const firstFile = files[0];
if (firstFile) {
notes[dateUID] = firstFile;
}
return notes;
},
{}
);
}
function singleDailyNotesToDailyNotesByDate(dailyNotes2) {
return Object.entries(dailyNotes2).reduce(
(notes, [dateUID, file]) => {
notes[dateUID] = [file];
return notes;
},
{}
);
}
function getDailyNotesForDate(date, notesByDate, fallbackDailyNotes) {
const dateUID = (0, import_obsidian_daily_notes_interface2.getDateUID)(date, "day");
const matchingNotes = notesByDate == null ? void 0 : notesByDate[dateUID];
if (matchingNotes == null ? void 0 : matchingNotes.length) {
return matchingNotes;
}
const dailyNote = (0, import_obsidian_daily_notes_interface2.getDailyNote)(date, fallbackDailyNotes != null ? fallbackDailyNotes : {});
return dailyNote ? [dailyNote] : [];
}
// src/io/dailyNotes.ts
var import_obsidian4 = require("obsidian");
var import_obsidian_daily_notes_interface3 = __toESM(require_obsidian_daily_notes_interface());
// src/ui/modal.ts
var import_obsidian3 = require("obsidian");
var ConfirmationModal = class extends import_obsidian3.Modal {
constructor(app, config) {
super(app);
const { cta, onAccept, text: text3, title } = config;
this.contentEl.createEl("h2", { text: title });
this.contentEl.createEl("p", { text: text3 });
this.contentEl.createDiv("modal-button-container", (buttonsEl) => {
buttonsEl.createEl("button", { text: "Never mind" }).addEventListener("click", () => this.close());
buttonsEl.createEl("button", {
cls: "mod-cta",
text: cta
}).addEventListener("click", (e) => {
void onAccept(e).then(() => this.close());
});
});
}
};
function createConfirmationDialog({
cta,
onAccept,
text: text3,
title
}) {
new ConfirmationModal(window.app, { cta, onAccept, text: text3, title }).open();
}
// src/io/dailyNotes.ts
function getDayDateFromFile(file) {
var _a;
const format = (_a = (0, import_obsidian_daily_notes_interface3.getDailyNoteSettings)().format.split("/").pop()) != null ? _a : "";
const noteDate = window.moment(file.basename, format, true);
return noteDate.isValid() ? noteDate : null;
}
function getAllDailyNotes() {
const { vault } = window.app;
const { folder } = (0, import_obsidian_daily_notes_interface3.getDailyNoteSettings)();
const dailyNotesFolder = folder ? vault.getAbstractFileByPath((0, import_obsidian4.normalizePath)(folder)) : vault.getRoot();
if (!(dailyNotesFolder instanceof import_obsidian4.TFolder)) {
throw new Error("Failed to find daily notes folder");
}
const dailyNotes2 = {};
import_obsidian4.Vault.recurseChildren(dailyNotesFolder, (note) => {
if (note instanceof import_obsidian4.TFile) {
const date = getDayDateFromFile(note);
if (date) {
dailyNotes2[(0, import_obsidian_daily_notes_interface3.getDateUID)(date, "day")] = note;
}
}
});
return dailyNotes2;
}
async function tryToCreateDailyNote(date, inNewSplit, settings2, cb) {
const { workspace } = window.app;
const { format } = (0, import_obsidian_daily_notes_interface3.getDailyNoteSettings)();
const filename = date.format(format);
const createFile = async () => {
const dailyNote = await (0, import_obsidian_daily_notes_interface3.createDailyNote)(date);
const leaf = workspace.getLeaf(inNewSplit ? "split" : false);
await leaf.openFile(dailyNote, { active: true });
cb == null ? void 0 : cb(dailyNote);
};
if (settings2.shouldConfirmBeforeCreate) {
createConfirmationDialog({
cta: "Create",
onAccept: createFile,
text: `File ${filename} does not exist. Would you like to create it?`,
title: "New Daily Note"
});
} else {
await createFile();
}
}
// src/io/weeklyNotes.ts
var import_obsidian5 = require("obsidian");
var import_obsidian_daily_notes_interface4 = __toESM(require_obsidian_daily_notes_interface());
function getWeeklyNoteSettings() {
var _a, _b, _c, _d, _e, _f, _g;
const { plugins } = window.app;
const periodicNotes = plugins.getPlugin("periodic-notes");
if (periodicNotes && ((_b = (_a = periodicNotes.settings) == null ? void 0 : _a.weekly) == null ? void 0 : _b.enabled)) {
const weekly = periodicNotes.settings.weekly;
return {
format: weekly.format || DEFAULT_WEEK_FORMAT,
folder: ((_c = weekly.folder) == null ? void 0 : _c.trim()) || "",
template: ((_d = weekly.template) == null ? void 0 : _d.trim()) || ""
};
}
const options = ((_e = plugins.getPlugin(PLUGIN_ID)) == null ? void 0 : _e.options) || {};
return {
format: options.weeklyNoteFormat || DEFAULT_WEEK_FORMAT,
folder: ((_f = options.weeklyNoteFolder) == null ? void 0 : _f.trim()) || "",
template: ((_g = options.weeklyNoteTemplate) == null ? void 0 : _g.trim()) || ""
};
}
function removeEscapedCharacters2(format) {
return format.replace(/\[[^\]]*\]/g, "");
}
function getWeekDateFromFile(file) {
var _a;
const format = (_a = getWeeklyNoteSettings().format.split("/").pop()) != null ? _a : "";
const noteDate = window.moment(file.basename, format, true);
if (!noteDate.isValid()) {
return null;
}
const cleanFormat = removeEscapedCharacters2(format);
const isAmbiguous = /w{1,2}/i.test(cleanFormat) && (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat));
if (isAmbiguous) {
return window.moment(
file.basename,
format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""),
false
);
}
return noteDate;
}
function getWeeklyNote(date, weeklyNotes2) {
var _a;
return (_a = weeklyNotes2[(0, import_obsidian_daily_notes_interface4.getDateUID)(date, "week")]) != null ? _a : null;
}
function buildWeeklyNotesByDate(files, options = {}) {
return buildNotesByDate(files, {
format: getWeeklyNoteSettings().format,
granularity: "week",
filenameDateFormat: options.filenameDateFormat,
frontmatterDateFields: options.frontmatterDateFields,
includedFolders: options.includedFolders
});
}
function getWeeklyNotesForDate(date, notesByDate, fallback) {
const id = (0, import_obsidian_daily_notes_interface4.getDateUID)(date, "week");
const matching = notesByDate == null ? void 0 : notesByDate[id];
if (matching == null ? void 0 : matching.length) {
return matching;
}
const note = getWeeklyNote(date, fallback != null ? fallback : {});
return note ? [note] : [];
}
function getAllWeeklyNotes() {
const { vault } = window.app;
const { folder } = getWeeklyNoteSettings();
const weeklyNotesFolder = folder ? vault.getAbstractFileByPath((0, import_obsidian5.normalizePath)(folder)) : vault.getRoot();
if (!(weeklyNotesFolder instanceof import_obsidian5.TFolder)) {
throw new Error("Failed to find weekly notes folder");
}
const weeklyNotes2 = {};
import_obsidian5.Vault.recurseChildren(weeklyNotesFolder, (note) => {
if (note instanceof import_obsidian5.TFile) {
const date = getWeekDateFromFile(note);
if (date) {
weeklyNotes2[(0, import_obsidian_daily_notes_interface4.getDateUID)(date, "week")] = note;
}
}
});
return weeklyNotes2;
}
async function ensureFolderExists(path) {
const dirs = path.split("/").slice(0, -1).filter(Boolean);
if (!dirs.length) {
return;
}
const dir = dirs.join("/");
if (!window.app.vault.getAbstractFileByPath(dir)) {
await window.app.vault.createFolder(dir);
}
}
async function getNotePath(folder, filename) {
const name = filename.endsWith(".md") ? filename : `${filename}.md`;
const path = (0, import_obsidian5.normalizePath)([folder, name].filter(Boolean).join("/"));
await ensureFolderExists(path);
return path;
}
async function getTemplateContents(template) {
const { metadataCache, vault } = window.app;
const templatePath = (0, import_obsidian5.normalizePath)(template);
if (templatePath === "/") {
return "";
}
try {
const templateFile = metadataCache.getFirstLinkpathDest(templatePath, "");
return templateFile ? await vault.cachedRead(templateFile) : "";
} catch (err) {
console.error(
`[Calendar Hub] Failed to read the weekly note template '${templatePath}'`,
err
);
new import_obsidian5.Notice("Failed to read the weekly note template");
return "";
}
}
var DAYS_OF_WEEK = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
];
async function createWeeklyNote(date) {
const { vault } = window.app;
const { template, format, folder } = getWeeklyNoteSettings();
const templateContents = await getTemplateContents(template);
const filename = date.format(format);
const normalizedPath = await getNotePath(folder, filename);
try {
return await vault.create(
normalizedPath,
templateContents.replace(
/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,
(_, _timeOrDate, calc, timeDelta, unit, momentFormat) => {
const now = window.moment();
const currentDate = date.clone().set({
hour: now.get("hour"),
minute: now.get("minute"),
second: now.get("second")
});
if (calc) {
currentDate.add(
parseInt(timeDelta, 10),
unit
);
}
if (momentFormat) {
return currentDate.format(momentFormat.substring(1).trim());
}
return currentDate.format(format);
}
).replace(/{{\s*title\s*}}/gi, filename).replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")).replace(
/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi,
(_, dayOfWeek, momentFormat) => {
const day = DAYS_OF_WEEK.indexOf(dayOfWeek.toLowerCase());
return date.clone().weekday(day).format(momentFormat.trim());
}
)
);
} catch (err) {
console.error(
`[Calendar Hub] Failed to create file: '${normalizedPath}'`,
err
);
new import_obsidian5.Notice("Unable to create new file.");
throw err;
}
}
async function tryToCreateWeeklyNote(date, inNewSplit, settings2, cb) {
const { workspace } = window.app;
const { format } = getWeeklyNoteSettings();
const filename = date.format(format);
const createFile = async () => {
const weeklyNote = await createWeeklyNote(date);
const leaf = workspace.getLeaf(inNewSplit ? "split" : false);
await leaf.openFile(weeklyNote, { active: true });
cb == null ? void 0 : cb(weeklyNote);
};
if (settings2.shouldConfirmBeforeCreate) {
createConfirmationDialog({
cta: "Create",
onAccept: createFile,
text: `File ${filename} does not exist. Would you like to create it?`,
title: "New Weekly Note"
});
} else {
await createFile();
}
}
// src/ui/utils.ts
var import_obsidian_daily_notes_interface5 = __toESM(require_obsidian_daily_notes_interface());
var classList = (obj) => {
return Object.entries(obj).filter(([, v]) => !!v).map(([k]) => k);
};
function partition(arr, predicate) {
const pass = [];
const fail = [];
arr.forEach((elem) => {
if (predicate(elem)) {
pass.push(elem);
} else {
fail.push(elem);
}
});
return [pass, fail];
}
function getDateUIDFromFile(file) {
if (!file) {
return null;
}
const dayDate = getDayDateFromFile(file);
if (dayDate) {
return (0, import_obsidian_daily_notes_interface5.getDateUID)(dayDate, "day");
}
const weekDate = getWeekDateFromFile(file);
if (weekDate) {
return (0, import_obsidian_daily_notes_interface5.getDateUID)(weekDate, "week");
}
return null;
}
// src/ui/stores.ts
var settings = writable(defaultSettings);
var dailyNotesByDate = writable({});
var weeklyNotesByDate = writable({});
function createDailyNotesStore() {
let hasError = false;
const store = writable(null);
return {
reindex: () => {
try {
const shouldIndexAllFolders = get_store_value(
settings
).shouldIndexDailyNotesInAllFolders;
const notesByDate = shouldIndexAllFolders ? buildDailyNotesByDate(
window.app.vault.getMarkdownFiles(),
{
filenameDateFormat: get_store_value(settings).dailyNoteFilenameDateFormat,
frontmatterDateFields: get_store_value(settings).shouldIndexDailyNotesFromFrontmatter ? get_store_value(settings).dailyNoteFrontmatterDateFields : "",
useCreationDateFallback: get_store_value(settings).shouldIndexDailyNotesFromCreationDate,
includedFolders: get_store_value(settings).dailyNoteIncludedFolders
}
) : singleDailyNotesToDailyNotesByDate(getAllDailyNotes());
const dailyNotes2 = dailyNotesByDateToSingleNotes(notesByDate);
store.set(dailyNotes2);
dailyNotesByDate.set(notesByDate);
hasError = false;
} catch (err) {
if (!hasError) {
console.warn(
"[Calendar Hub] Failed to find daily notes folder",
err
);
}
store.set({});
dailyNotesByDate.set({});
hasError = true;
}
},
...store
};
}
function createWeeklyNotesStore() {
let hasError = false;
const store = writable(null);
return {
reindex: () => {
try {
const currentSettings = get_store_value(settings);
const notesByDate = currentSettings.shouldIndexWeeklyNotesInAllFolders ? buildWeeklyNotesByDate(window.app.vault.getMarkdownFiles(), {
filenameDateFormat: currentSettings.weeklyNoteFilenameDateFormat,
frontmatterDateFields: currentSettings.shouldIndexWeeklyNotesFromFrontmatter ? currentSettings.weeklyNoteFrontmatterDateFields : "",
includedFolders: currentSettings.weeklyNoteIncludedFolders
}) : singleDailyNotesToDailyNotesByDate(getAllWeeklyNotes());
const weeklyNotes2 = dailyNotesByDateToSingleNotes(notesByDate);
store.set(weeklyNotes2);
weeklyNotesByDate.set(notesByDate);
hasError = false;
} catch (err) {
if (!hasError) {
console.warn(
"[Calendar Hub] Failed to find weekly notes folder",
err
);
}
store.set({});
weeklyNotesByDate.set({});
hasError = true;
}
},
...store
};
}
var dailyNotes = createDailyNotesStore();
var weeklyNotes = createWeeklyNotesStore();
function createSelectedFileStore() {
const store = writable(null);
return {
setFile: (file) => {
const id = getDateUIDFromFile(file);
store.set(id);
},
...store
};
}
var activeFile = createSelectedFileStore();
// src/listView.ts
var import_obsidian6 = require("obsidian");
// src/ui/listViewModel.ts
function parseDayUID(uid) {
return window.moment(
uid.replace(/^day-/, ""),
window.moment.ISO_8601,
true
);
}
function yearKeyOf(date, grouping) {
return grouping === "week" ? date.format("GGGG") : date.format("YYYY");
}
function subgroupOf(date, grouping) {
switch (grouping) {
case "quarter":
return {
key: `${date.format("YYYY")}-Q${date.quarter()}`,
label: `Q${date.quarter()}`
};
case "month":
return { key: date.format("YYYY-MM"), label: date.format("MMMM") };
case "week":
return {
key: date.format("GGGG-[W]WW"),
label: date.format("[W]WW")
};
default:
return { key: `${date.format("YYYY")}-all`, label: null };
}
}
function getListKeysForDate(date, grouping) {
return {
yearKey: yearKeyOf(date, grouping),
subgroupKey: subgroupOf(date, grouping).key
};
}
function buildListModel(notesByDate, grouping, order, filterRules = []) {
var _a, _b, _c;
const years = /* @__PURE__ */ new Map();
for (const [uid, files] of Object.entries(notesByDate)) {
const scoped = filterRules.length && (files == null ? void 0 : files.length) ? files.filter((file) => shouldIncludeFilePath(file.path, filterRules)) : files;
if (!(scoped == null ? void 0 : scoped.length)) {
continue;
}
const date = parseDayUID(uid);
if (!date.isValid()) {
continue;
}
const yearKey = yearKeyOf(date, grouping);
const subgroup = subgroupOf(date, grouping);
const dateStr = date.format("YYYY-MM-DD");
const subgroups = (_a = years.get(yearKey)) != null ? _a : /* @__PURE__ */ new Map();
years.set(yearKey, subgroups);
const bucket = (_b = subgroups.get(subgroup.key)) != null ? _b : {
label: subgroup.label,
days: /* @__PURE__ */ new Map()
};
subgroups.set(subgroup.key, bucket);
const day = (_c = bucket.days.get(dateStr)) != null ? _c : {
dateStr,
label: date.format("MMM D, ddd"),
files: []
};
day.files = [...day.files, ...scoped];
bucket.days.set(dateStr, day);
}
const direction = order === "asc" ? 1 : -1;
const byKey = (a, b) => direction * a.key.localeCompare(b.key);
return Array.from(years.entries()).map(([yearKey, subgroups]) => {
const shapedSubgroups = Array.from(subgroups.entries()).map(([key, bucket]) => {
const days = Array.from(bucket.days.values()).sort(
(a, b) => direction * a.dateStr.localeCompare(b.dateStr)
);
return {
key,
label: bucket.label,
noteCount: days.reduce((count, day) => count + day.files.length, 0),
days
};
}).sort(byKey);
return {
key: yearKey,
label: yearKey,
noteCount: shapedSubgroups.reduce(
(count, subgroup) => count + subgroup.noteCount,
0
),
subgroups: shapedSubgroups
};
}).sort(byKey);
}
// src/ui/ListPanel.svelte
function get_each_context2(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[22] = list[i];
return child_ctx;
}
function get_each_context_1(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[25] = list[i];
return child_ctx;
}
function get_each_context_2(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[28] = list[i];
return child_ctx;
}
function get_each_context_3(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[31] = list[i];
return child_ctx;
}
function create_if_block_4(ctx) {
let div1;
let folderruletree;
let t0;
let div0;
let button;
let t1;
let button_disabled_value;
let current;
let mounted;
let dispose;
folderruletree = new FolderRuleTree_default({
props: {
rules: (
/*listFilterRules*/
ctx[0]
),
onToggleFolder: (
/*handleToggleListFilterFolder*/
ctx[10]
)
}
});
return {
c() {
div1 = element("div");
create_component(folderruletree.$$.fragment);
t0 = space();
div0 = element("div");
button = element("button");
t1 = text("All notes");
attr(button, "class", "calendar-filter-action");
attr(button, "type", "button");
button.disabled = button_disabled_value = !/*$settings*/
ctx[3].listFolderFilter;
attr(div0, "class", "calendar-filter-actions");
attr(div1, "class", "calendar-list-filter-body");
},
m(target, anchor) {
insert(target, div1, anchor);
mount_component(folderruletree, div1, null);
append(div1, t0);
append(div1, div0);
append(div0, button);
append(button, t1);
current = true;
if (!mounted) {
dispose = listen(
button,
"click",
/*handleClearListFilter*/
ctx[11]
);
mounted = true;
}
},
p(ctx2, dirty) {
const folderruletree_changes = {};
if (dirty[0] & /*listFilterRules*/
1) folderruletree_changes.rules = /*listFilterRules*/
ctx2[0];
folderruletree.$set(folderruletree_changes);
if (!current || dirty[0] & /*$settings*/
8 && button_disabled_value !== (button_disabled_value = !/*$settings*/
ctx2[3].listFolderFilter)) {
button.disabled = button_disabled_value;
}
},
i(local) {
if (current) return;
transition_in(folderruletree.$$.fragment, local);
current = true;
},
o(local) {
transition_out(folderruletree.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach(div1);
destroy_component(folderruletree);
mounted = false;
dispose();
}
};
}
function create_else_block2(ctx) {
let div;
return {
c() {
div = element("div");
div.textContent = "No dated notes";
attr(div, "class", "calendar-note-empty");
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}
function create_if_block2(ctx) {
let div;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let each_value = (
/*listModel*/
ctx[2]
);
const get_key = (ctx2) => (
/*yearGroup*/
ctx2[22].key
);
for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context2(ctx, each_value, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block2(key, child_ctx));
}
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(div, "class", "calendar-list-tree");
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(div, null);
}
}
},
p(ctx2, dirty) {
if (dirty[0] & /*listModel, handleOpenNote, expandedListGroups, handleToggleListGroup*/
4614) {
each_value = /*listModel*/
ctx2[2];
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div, destroy_block, create_each_block2, null, get_each_context2);
}
},
d(detaching) {
if (detaching) detach(div);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function create_if_block_12(ctx) {
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let each_1_anchor;
let each_value_1 = (
/*yearGroup*/
ctx[22].subgroups
);
const get_key = (ctx2) => (
/*subgroup*/
ctx2[25].key
);
for (let i = 0; i < each_value_1.length; i += 1) {
let child_ctx = get_each_context_1(ctx, each_value_1, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block_1(key, child_ctx));
}
return {
c() {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
each_1_anchor = empty();
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(target, anchor);
}
}
insert(target, each_1_anchor, anchor);
},
p(ctx2, dirty) {
if (dirty[0] & /*listModel, handleOpenNote, expandedListGroups, handleToggleListGroup*/
4614) {
each_value_1 = /*yearGroup*/
ctx2[22].subgroups;
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value_1, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block_1, each_1_anchor, get_each_context_1);
}
},
d(detaching) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d(detaching);
}
if (detaching) detach(each_1_anchor);
}
};
}
function create_if_block_3(ctx) {
var _a;
let button;
let span0;
let t0_value = (
/*expandedListGroups*/
((_a = ctx[1]) == null ? void 0 : _a.has(
/*subgroup*/
ctx[25].key
)) ? "\u25BE" : "\u25B8"
);
let t0;
let t1;
let span1;
let t2_value = (
/*subgroup*/
ctx[25].label + ""
);
let t2;
let t3;
let span2;
let t4_value = (
/*subgroup*/
ctx[25].noteCount + ""
);
let t4;
let button_aria_expanded_value;
let mounted;
let dispose;
function click_handler_2() {
return (
/*click_handler_2*/
ctx[18](
/*subgroup*/
ctx[25]
)
);
}
return {
c() {
var _a2, _b;
button = element("button");
span0 = element("span");
t0 = text(t0_value);
t1 = space();
span1 = element("span");
t2 = text(t2_value);
t3 = space();
span2 = element("span");
t4 = text(t4_value);
attr(span0, "class", "calendar-list-caret");
attr(span1, "class", "calendar-list-label");
attr(span2, "class", "calendar-list-count");
attr(button, "class", "calendar-list-group calendar-list-subgroup");
attr(button, "type", "button");
attr(button, "aria-expanded", button_aria_expanded_value = /*expandedListGroups*/
(_b = (_a2 = ctx[1]) == null ? void 0 : _a2.has(
/*subgroup*/
ctx[25].key
)) != null ? _b : false);
},
m(target, anchor) {
insert(target, button, anchor);
append(button, span0);
append(span0, t0);
append(button, t1);
append(button, span1);
append(span1, t2);
append(button, t3);
append(button, span2);
append(span2, t4);
if (!mounted) {
dispose = listen(button, "click", click_handler_2);
mounted = true;
}
},
p(new_ctx, dirty) {
var _a2, _b, _c;
ctx = new_ctx;
if (dirty[0] & /*expandedListGroups, listModel*/
6 && t0_value !== (t0_value = /*expandedListGroups*/
((_a2 = ctx[1]) == null ? void 0 : _a2.has(
/*subgroup*/
ctx[25].key
)) ? "\u25BE" : "\u25B8")) set_data(t0, t0_value);
if (dirty[0] & /*listModel*/
4 && t2_value !== (t2_value = /*subgroup*/
ctx[25].label + "")) set_data(t2, t2_value);
if (dirty[0] & /*listModel*/
4 && t4_value !== (t4_value = /*subgroup*/
ctx[25].noteCount + "")) set_data(t4, t4_value);
if (dirty[0] & /*expandedListGroups, listModel*/
6 && button_aria_expanded_value !== (button_aria_expanded_value = /*expandedListGroups*/
(_c = (_b = ctx[1]) == null ? void 0 : _b.has(
/*subgroup*/
ctx[25].key
)) != null ? _c : false)) {
attr(button, "aria-expanded", button_aria_expanded_value);
}
},
d(detaching) {
if (detaching) detach(button);
mounted = false;
dispose();
}
};
}
function create_if_block_2(ctx) {
let div;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let t;
let each_value_2 = (
/*subgroup*/
ctx[25].days
);
const get_key = (ctx2) => (
/*day*/
ctx2[28].dateStr
);
for (let i = 0; i < each_value_2.length; i += 1) {
let child_ctx = get_each_context_2(ctx, each_value_2, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block_2(key, child_ctx));
}
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
t = space();
attr(div, "class", "calendar-list-days");
toggle_class(
div,
"calendar-list-days-nested",
/*subgroup*/
ctx[25].label !== null
);
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(div, null);
}
}
append(div, t);
},
p(ctx2, dirty) {
if (dirty[0] & /*listModel, handleOpenNote*/
4100) {
each_value_2 = /*subgroup*/
ctx2[25].days;
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value_2, each_1_lookup, div, destroy_block, create_each_block_2, t, get_each_context_2);
}
if (dirty[0] & /*listModel*/
4) {
toggle_class(
div,
"calendar-list-days-nested",
/*subgroup*/
ctx2[25].label !== null
);
}
},
d(detaching) {
if (detaching) detach(div);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function create_each_block_3(key_1, ctx) {
let button;
let t_value = (
/*note*/
ctx[31].basename + ""
);
let t;
let button_title_value;
let mounted;
let dispose;
function click_handler_3(...args) {
return (
/*click_handler_3*/
ctx[19](
/*note*/
ctx[31],
...args
)
);
}
return {
key: key_1,
first: null,
c() {
button = element("button");
t = text(t_value);
attr(button, "class", "calendar-list-note");
attr(button, "type", "button");
attr(button, "title", button_title_value = /*note*/
ctx[31].path);
this.first = button;
},
m(target, anchor) {
insert(target, button, anchor);
append(button, t);
if (!mounted) {
dispose = listen(button, "click", click_handler_3);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty[0] & /*listModel*/
4 && t_value !== (t_value = /*note*/
ctx[31].basename + "")) set_data(t, t_value);
if (dirty[0] & /*listModel*/
4 && button_title_value !== (button_title_value = /*note*/
ctx[31].path)) {
attr(button, "title", button_title_value);
}
},
d(detaching) {
if (detaching) detach(button);
mounted = false;
dispose();
}
};
}
function create_each_block_2(key_1, ctx) {
let div;
let t0_value = (
/*day*/
ctx[28].label + ""
);
let t0;
let t1;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let each_1_anchor;
let each_value_3 = (
/*day*/
ctx[28].files
);
const get_key = (ctx2) => (
/*note*/
ctx2[31].path
);
for (let i = 0; i < each_value_3.length; i += 1) {
let child_ctx = get_each_context_3(ctx, each_value_3, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block_3(key, child_ctx));
}
return {
key: key_1,
first: null,
c() {
div = element("div");
t0 = text(t0_value);
t1 = space();
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
each_1_anchor = empty();
attr(div, "class", "calendar-list-day");
this.first = div;
},
m(target, anchor) {
insert(target, div, anchor);
append(div, t0);
insert(target, t1, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(target, anchor);
}
}
insert(target, each_1_anchor, anchor);
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty[0] & /*listModel*/
4 && t0_value !== (t0_value = /*day*/
ctx[28].label + "")) set_data(t0, t0_value);
if (dirty[0] & /*listModel, handleOpenNote*/
4100) {
each_value_3 = /*day*/
ctx[28].files;
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value_3, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block_3, each_1_anchor, get_each_context_3);
}
},
d(detaching) {
if (detaching) detach(div);
if (detaching) detach(t1);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d(detaching);
}
if (detaching) detach(each_1_anchor);
}
};
}
function create_each_block_1(key_1, ctx) {
var _a;
let first;
let t;
let show_if = (
/*subgroup*/
ctx[25].label === null || /*expandedListGroups*/
((_a = ctx[1]) == null ? void 0 : _a.has(
/*subgroup*/
ctx[25].key
))
);
let if_block1_anchor;
let if_block0 = (
/*subgroup*/
ctx[25].label !== null && create_if_block_3(ctx)
);
let if_block1 = show_if && create_if_block_2(ctx);
return {
key: key_1,
first: null,
c() {
first = empty();
if (if_block0) if_block0.c();
t = space();
if (if_block1) if_block1.c();
if_block1_anchor = empty();
this.first = first;
},
m(target, anchor) {
insert(target, first, anchor);
if (if_block0) if_block0.m(target, anchor);
insert(target, t, anchor);
if (if_block1) if_block1.m(target, anchor);
insert(target, if_block1_anchor, anchor);
},
p(new_ctx, dirty) {
var _a2;
ctx = new_ctx;
if (
/*subgroup*/
ctx[25].label !== null
) {
if (if_block0) {
if_block0.p(ctx, dirty);
} else {
if_block0 = create_if_block_3(ctx);
if_block0.c();
if_block0.m(t.parentNode, t);
}
} else if (if_block0) {
if_block0.d(1);
if_block0 = null;
}
if (dirty[0] & /*listModel, expandedListGroups*/
6) show_if = /*subgroup*/
ctx[25].label === null || /*expandedListGroups*/
((_a2 = ctx[1]) == null ? void 0 : _a2.has(
/*subgroup*/
ctx[25].key
));
if (show_if) {
if (if_block1) {
if_block1.p(ctx, dirty);
} else {
if_block1 = create_if_block_2(ctx);
if_block1.c();
if_block1.m(if_block1_anchor.parentNode, if_block1_anchor);
}
} else if (if_block1) {
if_block1.d(1);
if_block1 = null;
}
},
d(detaching) {
if (detaching) detach(first);
if (if_block0) if_block0.d(detaching);
if (detaching) detach(t);
if (if_block1) if_block1.d(detaching);
if (detaching) detach(if_block1_anchor);
}
};
}
function create_each_block2(key_1, ctx) {
var _a, _b;
let button;
let span0;
let t0_value = (
/*expandedListGroups*/
((_a = ctx[1]) == null ? void 0 : _a.has(
/*yearGroup*/
ctx[22].key
)) ? "\u25BE" : "\u25B8"
);
let t0;
let t1;
let span1;
let t2_value = (
/*yearGroup*/
ctx[22].label + ""
);
let t2;
let t3;
let span2;
let t4_value = (
/*yearGroup*/
ctx[22].noteCount + ""
);
let t4;
let button_aria_expanded_value;
let t5;
let show_if = (
/*expandedListGroups*/
(_b = ctx[1]) == null ? void 0 : _b.has(
/*yearGroup*/
ctx[22].key
)
);
let if_block_anchor;
let mounted;
let dispose;
function click_handler_1() {
return (
/*click_handler_1*/
ctx[17](
/*yearGroup*/
ctx[22]
)
);
}
let if_block = show_if && create_if_block_12(ctx);
return {
key: key_1,
first: null,
c() {
var _a2, _b2;
button = element("button");
span0 = element("span");
t0 = text(t0_value);
t1 = space();
span1 = element("span");
t2 = text(t2_value);
t3 = space();
span2 = element("span");
t4 = text(t4_value);
t5 = space();
if (if_block) if_block.c();
if_block_anchor = empty();
attr(span0, "class", "calendar-list-caret");
attr(span1, "class", "calendar-list-label");
attr(span2, "class", "calendar-list-count");
attr(button, "class", "calendar-list-group");
attr(button, "type", "button");
attr(button, "aria-expanded", button_aria_expanded_value = /*expandedListGroups*/
(_b2 = (_a2 = ctx[1]) == null ? void 0 : _a2.has(
/*yearGroup*/
ctx[22].key
)) != null ? _b2 : false);
this.first = button;
},
m(target, anchor) {
insert(target, button, anchor);
append(button, span0);
append(span0, t0);
append(button, t1);
append(button, span1);
append(span1, t2);
append(button, t3);
append(button, span2);
append(span2, t4);
insert(target, t5, anchor);
if (if_block) if_block.m(target, anchor);
insert(target, if_block_anchor, anchor);
if (!mounted) {
dispose = listen(button, "click", click_handler_1);
mounted = true;
}
},
p(new_ctx, dirty) {
var _a2, _b2, _c, _d;
ctx = new_ctx;
if (dirty[0] & /*expandedListGroups, listModel*/
6 && t0_value !== (t0_value = /*expandedListGroups*/
((_a2 = ctx[1]) == null ? void 0 : _a2.has(
/*yearGroup*/
ctx[22].key
)) ? "\u25BE" : "\u25B8")) set_data(t0, t0_value);
if (dirty[0] & /*listModel*/
4 && t2_value !== (t2_value = /*yearGroup*/
ctx[22].label + "")) set_data(t2, t2_value);
if (dirty[0] & /*listModel*/
4 && t4_value !== (t4_value = /*yearGroup*/
ctx[22].noteCount + "")) set_data(t4, t4_value);
if (dirty[0] & /*expandedListGroups, listModel*/
6 && button_aria_expanded_value !== (button_aria_expanded_value = /*expandedListGroups*/
(_c = (_b2 = ctx[1]) == null ? void 0 : _b2.has(
/*yearGroup*/
ctx[22].key
)) != null ? _c : false)) {
attr(button, "aria-expanded", button_aria_expanded_value);
}
if (dirty[0] & /*expandedListGroups, listModel*/
6) show_if = /*expandedListGroups*/
(_d = ctx[1]) == null ? void 0 : _d.has(
/*yearGroup*/
ctx[22].key
);
if (show_if) {
if (if_block) {
if_block.p(ctx, dirty);
} else {
if_block = create_if_block_12(ctx);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
d(detaching) {
if (detaching) detach(button);
if (detaching) detach(t5);
if (if_block) if_block.d(detaching);
if (detaching) detach(if_block_anchor);
mounted = false;
dispose();
}
};
}
function create_fragment2(ctx) {
let div1;
let div0;
let select0;
let option0;
let option1;
let option2;
let option3;
let select0_value_value;
let t4;
let select1;
let option4;
let option5;
let select1_value_value;
let t7;
let span0;
let t8_value = formatNoteCount(
/*listTotalNotes*/
ctx[5]
) + "";
let t8;
let t9;
let button;
let span1;
let t11;
let span2;
let t12;
let t13;
let t14;
let current;
let mounted;
let dispose;
let if_block0 = (
/*isListFilterOpen*/
ctx[4] && create_if_block_4(ctx)
);
function select_block_type(ctx2, dirty) {
if (
/*listModel*/
ctx2[2].length
) return create_if_block2;
return create_else_block2;
}
let current_block_type = select_block_type(ctx, [-1, -1]);
let if_block1 = current_block_type(ctx);
return {
c() {
div1 = element("div");
div0 = element("div");
select0 = element("select");
option0 = element("option");
option0.textContent = "Year";
option1 = element("option");
option1.textContent = "Year \u203A Quarter";
option2 = element("option");
option2.textContent = "Year \u203A Month";
option3 = element("option");
option3.textContent = "Year \u203A Week";
t4 = space();
select1 = element("select");
option4 = element("option");
option4.textContent = "Newest first";
option5 = element("option");
option5.textContent = "Oldest first";
t7 = space();
span0 = element("span");
t8 = text(t8_value);
t9 = space();
button = element("button");
span1 = element("span");
span1.textContent = "Filter folders";
t11 = space();
span2 = element("span");
t12 = text(
/*listFilterSummary*/
ctx[6]
);
t13 = space();
if (if_block0) if_block0.c();
t14 = space();
if_block1.c();
option0.__value = "year";
option0.value = option0.__value;
option1.__value = "quarter";
option1.value = option1.__value;
option2.__value = "month";
option2.value = option2.__value;
option3.__value = "week";
option3.value = option3.__value;
attr(select0, "class", "dropdown calendar-list-select");
option4.__value = "desc";
option4.value = option4.__value;
option5.__value = "asc";
option5.value = option5.__value;
attr(select1, "class", "dropdown calendar-list-select");
attr(span0, "class", "calendar-list-total");
attr(div0, "class", "calendar-list-controls");
attr(span2, "class", "calendar-filter-summary");
attr(button, "class", "calendar-filter-toggle calendar-list-filter-toggle");
attr(button, "type", "button");
attr(
button,
"aria-expanded",
/*isListFilterOpen*/
ctx[4]
);
attr(div1, "class", "calendar-hub-list-panel");
},
m(target, anchor) {
insert(target, div1, anchor);
append(div1, div0);
append(div0, select0);
append(select0, option0);
append(select0, option1);
append(select0, option2);
append(select0, option3);
select_option(
select0,
/*$settings*/
ctx[3].listGrouping
);
append(div0, t4);
append(div0, select1);
append(select1, option4);
append(select1, option5);
select_option(
select1,
/*$settings*/
ctx[3].listSortOrder
);
append(div0, t7);
append(div0, span0);
append(span0, t8);
append(div1, t9);
append(div1, button);
append(button, span1);
append(button, t11);
append(button, span2);
append(span2, t12);
append(div1, t13);
if (if_block0) if_block0.m(div1, null);
append(div1, t14);
if_block1.m(div1, null);
current = true;
if (!mounted) {
dispose = [
listen(
select0,
"change",
/*handleChangeListGrouping*/
ctx[7]
),
listen(
select1,
"change",
/*handleChangeListSort*/
ctx[8]
),
listen(
button,
"click",
/*click_handler*/
ctx[16]
)
];
mounted = true;
}
},
p(ctx2, dirty) {
if (!current || dirty[0] & /*$settings*/
8 && select0_value_value !== (select0_value_value = /*$settings*/
ctx2[3].listGrouping)) {
select_option(
select0,
/*$settings*/
ctx2[3].listGrouping
);
}
if (!current || dirty[0] & /*$settings*/
8 && select1_value_value !== (select1_value_value = /*$settings*/
ctx2[3].listSortOrder)) {
select_option(
select1,
/*$settings*/
ctx2[3].listSortOrder
);
}
if ((!current || dirty[0] & /*listTotalNotes*/
32) && t8_value !== (t8_value = formatNoteCount(
/*listTotalNotes*/
ctx2[5]
) + "")) set_data(t8, t8_value);
if (!current || dirty[0] & /*listFilterSummary*/
64) set_data(
t12,
/*listFilterSummary*/
ctx2[6]
);
if (!current || dirty[0] & /*isListFilterOpen*/
16) {
attr(
button,
"aria-expanded",
/*isListFilterOpen*/
ctx2[4]
);
}
if (
/*isListFilterOpen*/
ctx2[4]
) {
if (if_block0) {
if_block0.p(ctx2, dirty);
if (dirty[0] & /*isListFilterOpen*/
16) {
transition_in(if_block0, 1);
}
} else {
if_block0 = create_if_block_4(ctx2);
if_block0.c();
transition_in(if_block0, 1);
if_block0.m(div1, t14);
}
} else if (if_block0) {
group_outros();
transition_out(if_block0, 1, 1, () => {
if_block0 = null;
});
check_outros();
}
if (current_block_type === (current_block_type = select_block_type(ctx2, dirty)) && if_block1) {
if_block1.p(ctx2, dirty);
} else {
if_block1.d(1);
if_block1 = current_block_type(ctx2);
if (if_block1) {
if_block1.c();
if_block1.m(div1, null);
}
}
},
i(local) {
if (current) return;
transition_in(if_block0);
current = true;
},
o(local) {
transition_out(if_block0);
current = false;
},
d(detaching) {
if (detaching) detach(div1);
if (if_block0) if_block0.d();
if_block1.d();
mounted = false;
run_all(dispose);
}
};
}
function formatNoteCount(count) {
return `${count} note${count === 1 ? "" : "s"}`;
}
function instance2($$self, $$props, $$invalidate) {
let listFilterSummary;
let $settings;
let $dailyNotesByDate;
component_subscribe($$self, settings, ($$value) => $$invalidate(3, $settings = $$value));
component_subscribe($$self, dailyNotesByDate, ($$value) => $$invalidate(15, $dailyNotesByDate = $$value));
let { onOpenNote } = $$props;
let { onUpdateSettings } = $$props;
let isListFilterOpen = false;
let listFilterRules = [];
let expandedListGroups = null;
let listModel = [];
let listTotalNotes = 0;
function getTodayListExpansion(grouping) {
const keys = getListKeysForDate(window.moment(), grouping);
return /* @__PURE__ */ new Set([keys.yearKey, keys.subgroupKey]);
}
function handleChangeListGrouping(event) {
const value = event.currentTarget.value;
$$invalidate(1, expandedListGroups = getTodayListExpansion(value));
void onUpdateSettings(() => ({ listGrouping: value }));
}
function handleChangeListSort(event) {
const value = event.currentTarget.value;
void onUpdateSettings(() => ({ listSortOrder: value }));
}
function handleToggleListGroup(key) {
const next = new Set(expandedListGroups !== null && expandedListGroups !== void 0 ? expandedListGroups : []);
if (next.has(key)) {
next.delete(key);
} else {
next.add(key);
}
$$invalidate(1, expandedListGroups = next);
}
function handleToggleListFilterFolder(folder) {
void onUpdateSettings(() => ({
listFolderFilter: serializeFolderRules(toggleFolderRule(folder, listFilterRules))
}));
}
function handleClearListFilter() {
void onUpdateSettings(() => ({ listFolderFilter: "" }));
}
function handleOpenNote(event, file) {
event.preventDefault();
void onOpenNote(file, event.metaKey || event.ctrlKey);
}
function getFilterSummary(value) {
const rules = parseFolderRules(value);
const includes = rules.filter((rule) => !rule.excluded).length;
const excludes = rules.length - includes;
if (!includes && !excludes) {
return "All notes";
}
if (!includes) {
return `All notes \u2212 ${excludes}`;
}
const base = `${includes} folder${includes === 1 ? "" : "s"}`;
return excludes ? `${base} \u2212 ${excludes}` : base;
}
const click_handler = () => $$invalidate(4, isListFilterOpen = !isListFilterOpen);
const click_handler_1 = (yearGroup) => handleToggleListGroup(yearGroup.key);
const click_handler_2 = (subgroup) => handleToggleListGroup(subgroup.key);
const click_handler_3 = (note, event) => handleOpenNote(event, note);
$$self.$$set = ($$props2) => {
if ("onOpenNote" in $$props2) $$invalidate(13, onOpenNote = $$props2.onOpenNote);
if ("onUpdateSettings" in $$props2) $$invalidate(14, onUpdateSettings = $$props2.onUpdateSettings);
};
$$self.$$.update = () => {
if ($$self.$$.dirty[0] & /*$settings*/
8) {
$: $$invalidate(0, listFilterRules = parseFolderRules($settings.listFolderFilter));
}
if ($$self.$$.dirty[0] & /*$settings*/
8) {
$: $$invalidate(6, listFilterSummary = getFilterSummary($settings.listFolderFilter));
}
if ($$self.$$.dirty[0] & /*$dailyNotesByDate, $settings, listFilterRules*/
32777) {
$: $$invalidate(2, listModel = buildListModel($dailyNotesByDate, $settings.listGrouping, $settings.listSortOrder, listFilterRules));
}
if ($$self.$$.dirty[0] & /*listModel*/
4) {
$: $$invalidate(5, listTotalNotes = listModel.reduce((count, year) => count + year.noteCount, 0));
}
if ($$self.$$.dirty[0] & /*expandedListGroups, $settings*/
10) {
$: if (expandedListGroups === null) {
$$invalidate(1, expandedListGroups = getTodayListExpansion($settings.listGrouping));
}
}
};
return [
listFilterRules,
expandedListGroups,
listModel,
$settings,
isListFilterOpen,
listTotalNotes,
listFilterSummary,
handleChangeListGrouping,
handleChangeListSort,
handleToggleListGroup,
handleToggleListFilterFolder,
handleClearListFilter,
handleOpenNote,
onOpenNote,
onUpdateSettings,
$dailyNotesByDate,
click_handler,
click_handler_1,
click_handler_2,
click_handler_3
];
}
var ListPanel = class extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance2, create_fragment2, not_equal, { onOpenNote: 13, onUpdateSettings: 14 }, null, [-1, -1]);
}
};
var ListPanel_default = ListPanel;
// src/listView.ts
var ListView = class extends import_obsidian6.ItemView {
constructor(leaf, plugin) {
super(leaf);
this.panel = null;
this.openNote = async (file, inNewSplit) => {
const leaf = this.app.workspace.getLeaf(inNewSplit ? "split" : false);
await leaf.openFile(file, { active: true });
activeFile.setFile(file);
};
this.plugin = plugin;
}
getViewType() {
return VIEW_TYPE_LIST;
}
getDisplayText() {
return "Calendar Hub list";
}
getIcon() {
return "list";
}
onOpen() {
const openCalendar = () => {
const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR);
if (leaves.length) {
void this.app.workspace.revealLeaf(leaves[0]);
return;
}
this.plugin.initLeaf();
};
this.contentEl.addClass("calendar-hub-view-content");
this.addAction("calendar", "Open calendar view", openCalendar);
const navButton = this.contentEl.createDiv("nav-header calendar-hub-nav").createDiv("nav-buttons-container").createDiv({
cls: "clickable-icon nav-action-button",
attr: { "aria-label": "Open calendar view" }
});
(0, import_obsidian6.setIcon)(navButton, "calendar");
navButton.addEventListener("click", openCalendar);
dailyNotes.reindex();
this.panel = new ListPanel_default({
target: this.contentEl,
props: {
onOpenNote: this.openNote,
onUpdateSettings: (changeOpts) => this.plugin.writeOptions(changeOpts)
}
});
return Promise.resolve();
}
onClose() {
var _a;
(_a = this.panel) == null ? void 0 : _a.$destroy();
this.panel = null;
return Promise.resolve();
}
};
// src/view.ts
var import_obsidian_daily_notes_interface9 = __toESM(require_obsidian_daily_notes_interface());
var import_obsidian10 = require("obsidian");
// vendor/obsidian-calendar-ui/index.js
var import_obsidian7 = require("obsidian");
function noop2() {
}
function assign(tar, src) {
for (const k in src)
tar[k] = src[k];
return tar;
}
function is_promise(value) {
return value && typeof value === "object" && typeof value.then === "function";
}
function run2(fn) {
return fn();
}
function blank_object2() {
return /* @__PURE__ */ Object.create(null);
}
function run_all2(fns) {
fns.forEach(run2);
}
function is_function2(thing) {
return typeof thing === "function";
}
function safe_not_equal2(a, b) {
return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function");
}
function not_equal2(a, b) {
return a != a ? b == b : a !== b;
}
function is_empty2(obj) {
return Object.keys(obj).length === 0;
}
function create_slot(definition, ctx, $$scope, fn) {
if (definition) {
const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
return definition[0](slot_ctx);
}
}
function get_slot_context(definition, ctx, $$scope, fn) {
return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;
}
function get_slot_changes(definition, $$scope, dirty, fn) {
if (definition[2] && fn) {
const lets = definition[2](fn(dirty));
if ($$scope.dirty === void 0) {
return lets;
}
if (typeof lets === "object") {
const merged = [];
const len = Math.max($$scope.dirty.length, lets.length);
for (let i = 0; i < len; i += 1) {
merged[i] = $$scope.dirty[i] | lets[i];
}
return merged;
}
return $$scope.dirty | lets;
}
return $$scope.dirty;
}
function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) {
const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn);
if (slot_changes) {
const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
slot.p(slot_context, slot_changes);
}
}
function null_to_empty(value) {
return value == null ? "" : value;
}
function append2(target, node) {
target.appendChild(node);
}
function insert2(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach2(node) {
node.parentNode.removeChild(node);
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element2(name) {
return document.createElement(name);
}
function svg_element(name) {
return document.createElementNS("http://www.w3.org/2000/svg", name);
}
function text2(data) {
return document.createTextNode(data);
}
function space2() {
return text2(" ");
}
function empty2() {
return text2("");
}
function listen2(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr2(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function set_attributes(node, attributes) {
const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
for (const key in attributes) {
if (attributes[key] == null) {
node.removeAttribute(key);
} else if (key === "style") {
node.style.cssText = attributes[key];
} else if (key === "__value") {
node.value = node[key] = attributes[key];
} else if (descriptors[key] && descriptors[key].set) {
node[key] = attributes[key];
} else {
attr2(node, key, attributes[key]);
}
}
}
function children2(element3) {
return Array.from(element3.childNodes);
}
function set_data2(text3, data) {
data = "" + data;
if (text3.wholeText !== data)
text3.data = data;
}
function toggle_class2(element3, name, toggle) {
element3.classList[toggle ? "add" : "remove"](name);
}
var current_component2;
function set_current_component2(component) {
current_component2 = component;
}
function get_current_component2() {
if (!current_component2)
throw new Error("Function called outside component initialization");
return current_component2;
}
var dirty_components2 = [];
var binding_callbacks2 = [];
var render_callbacks2 = [];
var flush_callbacks2 = [];
var resolved_promise2 = Promise.resolve();
var update_scheduled2 = false;
function schedule_update2() {
if (!update_scheduled2) {
update_scheduled2 = true;
resolved_promise2.then(flush2);
}
}
function add_render_callback2(fn) {
render_callbacks2.push(fn);
}
var flushing = false;
var seen_callbacks2 = /* @__PURE__ */ new Set();
function flush2() {
if (flushing)
return;
flushing = true;
do {
for (let i = 0; i < dirty_components2.length; i += 1) {
const component = dirty_components2[i];
set_current_component2(component);
update2(component.$$);
}
set_current_component2(null);
dirty_components2.length = 0;
while (binding_callbacks2.length)
binding_callbacks2.pop()();
for (let i = 0; i < render_callbacks2.length; i += 1) {
const callback = render_callbacks2[i];
if (!seen_callbacks2.has(callback)) {
seen_callbacks2.add(callback);
callback();
}
}
render_callbacks2.length = 0;
} while (dirty_components2.length);
while (flush_callbacks2.length) {
flush_callbacks2.pop()();
}
update_scheduled2 = false;
flushing = false;
seen_callbacks2.clear();
}
function update2($$) {
if ($$.fragment !== null) {
$$.update();
run_all2($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback2);
}
}
var outroing2 = /* @__PURE__ */ new Set();
var outros2;
function group_outros2() {
outros2 = {
r: 0,
c: [],
p: outros2
// parent group
};
}
function check_outros2() {
if (!outros2.r) {
run_all2(outros2.c);
}
outros2 = outros2.p;
}
function transition_in2(block, local) {
if (block && block.i) {
outroing2.delete(block);
block.i(local);
}
}
function transition_out2(block, local, detach3, callback) {
if (block && block.o) {
if (outroing2.has(block))
return;
outroing2.add(block);
outros2.c.push(() => {
outroing2.delete(block);
if (callback) {
if (detach3)
block.d(1);
callback();
}
});
block.o(local);
}
}
function handle_promise(promise, info) {
const token = info.token = {};
function update3(type, index, key, value) {
if (info.token !== token)
return;
info.resolved = value;
let child_ctx = info.ctx;
if (key !== void 0) {
child_ctx = child_ctx.slice();
child_ctx[key] = value;
}
const block = type && (info.current = type)(child_ctx);
let needs_flush = false;
if (info.block) {
if (info.blocks) {
info.blocks.forEach((block2, i) => {
if (i !== index && block2) {
group_outros2();
transition_out2(block2, 1, 1, () => {
if (info.blocks[i] === block2) {
info.blocks[i] = null;
}
});
check_outros2();
}
});
} else {
info.block.d(1);
}
block.c();
transition_in2(block, 1);
block.m(info.mount(), info.anchor);
needs_flush = true;
}
info.block = block;
if (info.blocks)
info.blocks[index] = block;
if (needs_flush) {
flush2();
}
}
if (is_promise(promise)) {
const current_component3 = get_current_component2();
promise.then((value) => {
set_current_component2(current_component3);
update3(info.then, 1, info.value, value);
set_current_component2(null);
}, (error) => {
set_current_component2(current_component3);
update3(info.catch, 2, info.error, error);
set_current_component2(null);
if (!info.hasCatch) {
throw error;
}
});
if (info.current !== info.pending) {
update3(info.pending, 0);
return true;
}
} else {
if (info.current !== info.then) {
update3(info.then, 1, info.value, promise);
return true;
}
info.resolved = promise;
}
}
function outro_and_destroy_block(block, lookup) {
transition_out2(block, 1, 1, () => {
lookup.delete(block.key);
});
}
function update_keyed_each2(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block5, next, get_context) {
let o = old_blocks.length;
let n = list.length;
let i = o;
const old_indexes = {};
while (i--)
old_indexes[old_blocks[i].key] = i;
const new_blocks = [];
const new_lookup = /* @__PURE__ */ new Map();
const deltas = /* @__PURE__ */ new Map();
i = n;
while (i--) {
const child_ctx = get_context(ctx, list, i);
const key = get_key(child_ctx);
let block = lookup.get(key);
if (!block) {
block = create_each_block5(key, child_ctx);
block.c();
} else if (dynamic) {
block.p(child_ctx, dirty);
}
new_lookup.set(key, new_blocks[i] = block);
if (key in old_indexes)
deltas.set(key, Math.abs(i - old_indexes[key]));
}
const will_move = /* @__PURE__ */ new Set();
const did_move = /* @__PURE__ */ new Set();
function insert3(block) {
transition_in2(block, 1);
block.m(node, next);
lookup.set(block.key, block);
next = block.first;
n--;
}
while (o && n) {
const new_block = new_blocks[n - 1];
const old_block = old_blocks[o - 1];
const new_key = new_block.key;
const old_key = old_block.key;
if (new_block === old_block) {
next = new_block.first;
o--;
n--;
} else if (!new_lookup.has(old_key)) {
destroy(old_block, lookup);
o--;
} else if (!lookup.has(new_key) || will_move.has(new_key)) {
insert3(new_block);
} else if (did_move.has(old_key)) {
o--;
} else if (deltas.get(new_key) > deltas.get(old_key)) {
did_move.add(new_key);
insert3(new_block);
} else {
will_move.add(old_key);
o--;
}
}
while (o--) {
const old_block = old_blocks[o];
if (!new_lookup.has(old_block.key))
destroy(old_block, lookup);
}
while (n)
insert3(new_blocks[n - 1]);
return new_blocks;
}
function get_spread_update(levels, updates) {
const update3 = {};
const to_null_out = {};
const accounted_for = { $$scope: 1 };
let i = levels.length;
while (i--) {
const o = levels[i];
const n = updates[i];
if (n) {
for (const key in o) {
if (!(key in n))
to_null_out[key] = 1;
}
for (const key in n) {
if (!accounted_for[key]) {
update3[key] = n[key];
accounted_for[key] = 1;
}
}
levels[i] = n;
} else {
for (const key in o) {
accounted_for[key] = 1;
}
}
}
for (const key in to_null_out) {
if (!(key in update3))
update3[key] = void 0;
}
return update3;
}
function get_spread_object(spread_props) {
return typeof spread_props === "object" && spread_props !== null ? spread_props : {};
}
function create_component2(block) {
block && block.c();
}
function mount_component2(component, target, anchor, customElement) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
add_render_callback2(() => {
const new_on_destroy = on_mount.map(run2).filter(is_function2);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
} else {
run_all2(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback2);
}
function destroy_component2(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
run_all2($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty2(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components2.push(component);
schedule_update2();
component.$$.dirty.fill(0);
}
component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
}
function init2(component, options, instance5, create_fragment5, not_equal3, props, dirty = [-1]) {
const parent_component = current_component2;
set_current_component2(component);
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props,
update: noop2,
not_equal: not_equal3,
bound: blank_object2(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : []),
// everything else
callbacks: blank_object2(),
dirty,
skip_bound: false
};
let ready = false;
$$.ctx = instance5 ? instance5(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal3($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty2(component, i);
}
return ret;
}) : [];
$$.update();
ready = true;
run_all2($$.before_update);
$$.fragment = create_fragment5 ? create_fragment5($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
const nodes = children2(options.target);
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach2);
} else {
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in2(component.$$.fragment);
mount_component2(component, options.target, options.anchor, options.customElement);
flush2();
}
set_current_component2(parent_component);
}
var SvelteComponent2 = class {
$destroy() {
destroy_component2(this, 1);
this.$destroy = noop2;
}
$on(type, callback) {
const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty2($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
};
function getDateUID5(date, granularity = "day") {
const ts = date.clone().startOf(granularity).format();
return `${granularity}-${ts}`;
}
var getDateUID_1 = getDateUID5;
function add_css$5() {
var style = element2("style");
style.id = "svelte-1widvzq-style";
style.textContent = ".dot.svelte-1widvzq,.hollow.svelte-1widvzq{display:inline-block;height:6px;width:6px;margin:0 1px}.filled.svelte-1widvzq{fill:var(--color-dot)}.active.filled.svelte-1widvzq{fill:var(--text-on-accent)}.hollow.svelte-1widvzq{fill:none;stroke:var(--color-dot)}.active.hollow.svelte-1widvzq{fill:none;stroke:var(--text-on-accent)}";
append2(document.head, style);
}
function create_else_block$1(ctx) {
let svg;
let circle;
let svg_class_value;
return {
c() {
svg = svg_element("svg");
circle = svg_element("circle");
attr2(circle, "cx", "3");
attr2(circle, "cy", "3");
attr2(circle, "r", "2");
attr2(svg, "class", svg_class_value = null_to_empty(`hollow ${/*className*/
ctx[0]}`) + " svelte-1widvzq");
attr2(svg, "viewBox", "0 0 6 6");
attr2(svg, "xmlns", "http://www.w3.org/2000/svg");
toggle_class2(
svg,
"active",
/*isActive*/
ctx[2]
);
},
m(target, anchor) {
insert2(target, svg, anchor);
append2(svg, circle);
},
p(ctx2, dirty) {
if (dirty & /*className*/
1 && svg_class_value !== (svg_class_value = null_to_empty(`hollow ${/*className*/
ctx2[0]}`) + " svelte-1widvzq")) {
attr2(svg, "class", svg_class_value);
}
if (dirty & /*className, isActive*/
5) {
toggle_class2(
svg,
"active",
/*isActive*/
ctx2[2]
);
}
},
d(detaching) {
if (detaching) detach2(svg);
}
};
}
function create_if_block$2(ctx) {
let svg;
let circle;
let svg_class_value;
return {
c() {
svg = svg_element("svg");
circle = svg_element("circle");
attr2(circle, "cx", "3");
attr2(circle, "cy", "3");
attr2(circle, "r", "2");
attr2(svg, "class", svg_class_value = null_to_empty(`dot filled ${/*className*/
ctx[0]}`) + " svelte-1widvzq");
attr2(svg, "viewBox", "0 0 6 6");
attr2(svg, "xmlns", "http://www.w3.org/2000/svg");
toggle_class2(
svg,
"active",
/*isActive*/
ctx[2]
);
},
m(target, anchor) {
insert2(target, svg, anchor);
append2(svg, circle);
},
p(ctx2, dirty) {
if (dirty & /*className*/
1 && svg_class_value !== (svg_class_value = null_to_empty(`dot filled ${/*className*/
ctx2[0]}`) + " svelte-1widvzq")) {
attr2(svg, "class", svg_class_value);
}
if (dirty & /*className, isActive*/
5) {
toggle_class2(
svg,
"active",
/*isActive*/
ctx2[2]
);
}
},
d(detaching) {
if (detaching) detach2(svg);
}
};
}
function create_fragment$6(ctx) {
let if_block_anchor;
function select_block_type(ctx2, dirty) {
if (
/*isFilled*/
ctx2[1]
) return create_if_block$2;
return create_else_block$1;
}
let current_block_type = select_block_type(ctx);
let if_block = current_block_type(ctx);
return {
c() {
if_block.c();
if_block_anchor = empty2();
},
m(target, anchor) {
if_block.m(target, anchor);
insert2(target, if_block_anchor, anchor);
},
p(ctx2, [dirty]) {
if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block) {
if_block.p(ctx2, dirty);
} else {
if_block.d(1);
if_block = current_block_type(ctx2);
if (if_block) {
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
}
},
i: noop2,
o: noop2,
d(detaching) {
if_block.d(detaching);
if (detaching) detach2(if_block_anchor);
}
};
}
function instance$6($$self, $$props, $$invalidate) {
let { className = "" } = $$props;
let { isFilled } = $$props;
let { isActive } = $$props;
$$self.$$set = ($$props2) => {
if ("className" in $$props2) $$invalidate(0, className = $$props2.className);
if ("isFilled" in $$props2) $$invalidate(1, isFilled = $$props2.isFilled);
if ("isActive" in $$props2) $$invalidate(2, isActive = $$props2.isActive);
};
return [className, isFilled, isActive];
}
var Dot = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-1widvzq-style")) add_css$5();
init2(this, options, instance$6, create_fragment$6, safe_not_equal2, { className: 0, isFilled: 1, isActive: 2 });
}
};
var get_default_slot_changes_1 = (dirty) => ({});
var get_default_slot_context_1 = (ctx) => ({ metadata: null });
var get_default_slot_changes = (dirty) => ({ metadata: dirty & /*metadata*/
1 });
var get_default_slot_context = (ctx) => ({ metadata: (
/*resolvedMeta*/
ctx[3]
) });
function create_else_block3(ctx) {
let current;
const default_slot_template = (
/*#slots*/
ctx[2].default
);
const default_slot = create_slot(
default_slot_template,
ctx,
/*$$scope*/
ctx[1],
get_default_slot_context_1
);
return {
c() {
if (default_slot) default_slot.c();
},
m(target, anchor) {
if (default_slot) {
default_slot.m(target, anchor);
}
current = true;
},
p(ctx2, dirty) {
if (default_slot) {
if (default_slot.p && dirty & /*$$scope*/
2) {
update_slot(
default_slot,
default_slot_template,
ctx2,
/*$$scope*/
ctx2[1],
dirty,
get_default_slot_changes_1,
get_default_slot_context_1
);
}
}
},
i(local) {
if (current) return;
transition_in2(default_slot, local);
current = true;
},
o(local) {
transition_out2(default_slot, local);
current = false;
},
d(detaching) {
if (default_slot) default_slot.d(detaching);
}
};
}
function create_if_block$1(ctx) {
let await_block_anchor;
let promise;
let current;
let info = {
ctx,
current: null,
token: null,
hasCatch: false,
pending: create_pending_block,
then: create_then_block,
catch: create_catch_block,
value: 3,
blocks: [, , ,]
};
handle_promise(promise = /*metadata*/
ctx[0], info);
return {
c() {
await_block_anchor = empty2();
info.block.c();
},
m(target, anchor) {
insert2(target, await_block_anchor, anchor);
info.block.m(target, info.anchor = anchor);
info.mount = () => await_block_anchor.parentNode;
info.anchor = await_block_anchor;
current = true;
},
p(new_ctx, dirty) {
ctx = new_ctx;
info.ctx = ctx;
if (dirty & /*metadata*/
1 && promise !== (promise = /*metadata*/
ctx[0]) && handle_promise(promise, info)) ;
else {
const child_ctx = ctx.slice();
child_ctx[3] = info.resolved;
info.block.p(child_ctx, dirty);
}
},
i(local) {
if (current) return;
transition_in2(info.block);
current = true;
},
o(local) {
for (let i = 0; i < 3; i += 1) {
const block = info.blocks[i];
transition_out2(block);
}
current = false;
},
d(detaching) {
if (detaching) detach2(await_block_anchor);
info.block.d(detaching);
info.token = null;
info = null;
}
};
}
function create_catch_block(ctx) {
return {
c: noop2,
m: noop2,
p: noop2,
i: noop2,
o: noop2,
d: noop2
};
}
function create_then_block(ctx) {
let current;
const default_slot_template = (
/*#slots*/
ctx[2].default
);
const default_slot = create_slot(
default_slot_template,
ctx,
/*$$scope*/
ctx[1],
get_default_slot_context
);
return {
c() {
if (default_slot) default_slot.c();
},
m(target, anchor) {
if (default_slot) {
default_slot.m(target, anchor);
}
current = true;
},
p(ctx2, dirty) {
if (default_slot) {
if (default_slot.p && dirty & /*$$scope, metadata*/
3) {
update_slot(
default_slot,
default_slot_template,
ctx2,
/*$$scope*/
ctx2[1],
dirty,
get_default_slot_changes,
get_default_slot_context
);
}
}
},
i(local) {
if (current) return;
transition_in2(default_slot, local);
current = true;
},
o(local) {
transition_out2(default_slot, local);
current = false;
},
d(detaching) {
if (default_slot) default_slot.d(detaching);
}
};
}
function create_pending_block(ctx) {
return {
c: noop2,
m: noop2,
p: noop2,
i: noop2,
o: noop2,
d: noop2
};
}
function create_fragment$5(ctx) {
let current_block_type_index;
let if_block;
let if_block_anchor;
let current;
const if_block_creators = [create_if_block$1, create_else_block3];
const if_blocks = [];
function select_block_type(ctx2, dirty) {
if (
/*metadata*/
ctx2[0]
) return 0;
return 1;
}
current_block_type_index = select_block_type(ctx);
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
return {
c() {
if_block.c();
if_block_anchor = empty2();
},
m(target, anchor) {
if_blocks[current_block_type_index].m(target, anchor);
insert2(target, if_block_anchor, anchor);
current = true;
},
p(ctx2, [dirty]) {
let previous_block_index = current_block_type_index;
current_block_type_index = select_block_type(ctx2);
if (current_block_type_index === previous_block_index) {
if_blocks[current_block_type_index].p(ctx2, dirty);
} else {
group_outros2();
transition_out2(if_blocks[previous_block_index], 1, 1, () => {
if_blocks[previous_block_index] = null;
});
check_outros2();
if_block = if_blocks[current_block_type_index];
if (!if_block) {
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2);
if_block.c();
} else {
if_block.p(ctx2, dirty);
}
transition_in2(if_block, 1);
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
},
i(local) {
if (current) return;
transition_in2(if_block);
current = true;
},
o(local) {
transition_out2(if_block);
current = false;
},
d(detaching) {
if_blocks[current_block_type_index].d(detaching);
if (detaching) detach2(if_block_anchor);
}
};
}
function instance$5($$self, $$props, $$invalidate) {
let { $$slots: slots = {}, $$scope } = $$props;
let { metadata } = $$props;
$$self.$$set = ($$props2) => {
if ("metadata" in $$props2) $$invalidate(0, metadata = $$props2.metadata);
if ("$$scope" in $$props2) $$invalidate(1, $$scope = $$props2.$$scope);
};
return [metadata, $$scope, slots];
}
var MetadataResolver = class extends SvelteComponent2 {
constructor(options) {
super();
init2(this, options, instance$5, create_fragment$5, not_equal2, { metadata: 0 });
}
};
function isMacOS() {
return navigator.appVersion.indexOf("Mac") !== -1;
}
function isMetaPressed(e) {
return isMacOS() ? e.metaKey : e.ctrlKey;
}
function getDaysOfWeek(..._args) {
return window.moment.weekdaysShort(true);
}
function isWeekend(date) {
return date.isoWeekday() === 6 || date.isoWeekday() === 7;
}
function getStartOfWeek(days) {
return days[0].weekday(0);
}
function getMonth(displayedMonth, ..._args) {
const locale = window.moment().locale();
const month = [];
let week;
const startOfMonth = displayedMonth.clone().locale(locale).date(1);
const startOffset = startOfMonth.weekday();
let date = startOfMonth.clone().subtract(startOffset, "days");
for (let _day = 0; _day < 42; _day++) {
if (_day % 7 === 0) {
week = {
days: [],
weekNum: date.week()
};
month.push(week);
}
week.days.push(date);
date = date.clone().add(1, "days");
}
return month;
}
function add_css$4() {
var style = element2("style");
style.id = "svelte-q3wqg9-style";
style.textContent = ".day.svelte-q3wqg9{background-color:var(--color-background-day);border-radius:4px;color:var(--color-text-day);cursor:pointer;font-size:0.8em;height:100%;padding:4px;position:relative;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.day.svelte-q3wqg9:hover{background-color:var(--interactive-hover)}.day.active.svelte-q3wqg9:hover{background-color:var(--interactive-accent-hover)}.adjacent-month.svelte-q3wqg9{opacity:0.25}.today.svelte-q3wqg9{color:var(--color-text-today)}.day.svelte-q3wqg9:active,.active.svelte-q3wqg9,.active.today.svelte-q3wqg9{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-q3wqg9{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}";
append2(document.head, style);
}
function get_each_context$2(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[11] = list[i];
return child_ctx;
}
function create_each_block$2(ctx) {
let dot;
let current;
const dot_spread_levels = [
/*dot*/
ctx[11]
];
let dot_props = {};
for (let i = 0; i < dot_spread_levels.length; i += 1) {
dot_props = assign(dot_props, dot_spread_levels[i]);
}
dot = new Dot({ props: dot_props });
return {
c() {
create_component2(dot.$$.fragment);
},
m(target, anchor) {
mount_component2(dot, target, anchor);
current = true;
},
p(ctx2, dirty) {
const dot_changes = dirty & /*metadata*/
128 ? get_spread_update(dot_spread_levels, [get_spread_object(
/*dot*/
ctx2[11]
)]) : {};
dot.$set(dot_changes);
},
i(local) {
if (current) return;
transition_in2(dot.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(dot.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component2(dot, detaching);
}
};
}
function create_default_slot$1(ctx) {
let div1;
let t0_value = (
/*date*/
ctx[0].format("D") + ""
);
let t0;
let t1;
let div0;
let div1_class_value;
let current;
let mounted;
let dispose;
let each_value = (
/*metadata*/
ctx[7].dots
);
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
}
const out = (i) => transition_out2(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
let div1_levels = [
{
class: div1_class_value = `day ${/*metadata*/
ctx[7].classes.join(" ")}`
},
/*metadata*/
ctx[7].dataAttributes || {}
];
let div1_data = {};
for (let i = 0; i < div1_levels.length; i += 1) {
div1_data = assign(div1_data, div1_levels[i]);
}
return {
c() {
div1 = element2("div");
t0 = text2(t0_value);
t1 = space2();
div0 = element2("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr2(div0, "class", "dot-container svelte-q3wqg9");
set_attributes(div1, div1_data);
toggle_class2(
div1,
"active",
/*selectedId*/
ctx[6] === getDateUID_1(
/*date*/
ctx[0],
"day"
)
);
toggle_class2(div1, "adjacent-month", !/*date*/
ctx[0].isSame(
/*displayedMonth*/
ctx[5],
"month"
));
toggle_class2(
div1,
"today",
/*date*/
ctx[0].isSame(
/*today*/
ctx[4],
"day"
)
);
toggle_class2(div1, "svelte-q3wqg9", true);
},
m(target, anchor) {
insert2(target, div1, anchor);
append2(div1, t0);
append2(div1, t1);
append2(div1, div0);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div0, null);
}
current = true;
if (!mounted) {
dispose = [
listen2(div1, "click", function() {
if (is_function2(
/*onClick*/
ctx[2] && /*click_handler*/
ctx[8]
)) /*onClick*/
(ctx[2] && /*click_handler*/
ctx[8]).apply(this, arguments);
}),
listen2(div1, "contextmenu", function() {
if (is_function2(
/*onContextMenu*/
ctx[3] && /*contextmenu_handler*/
ctx[9]
)) /*onContextMenu*/
(ctx[3] && /*contextmenu_handler*/
ctx[9]).apply(this, arguments);
}),
listen2(div1, "pointerover", function() {
if (is_function2(
/*onHover*/
ctx[1] && /*pointerover_handler*/
ctx[10]
)) /*onHover*/
(ctx[1] && /*pointerover_handler*/
ctx[10]).apply(this, arguments);
})
];
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if ((!current || dirty & /*date*/
1) && t0_value !== (t0_value = /*date*/
ctx[0].format("D") + "")) set_data2(t0, t0_value);
if (dirty & /*metadata*/
128) {
each_value = /*metadata*/
ctx[7].dots;
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$2(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in2(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block$2(child_ctx);
each_blocks[i].c();
transition_in2(each_blocks[i], 1);
each_blocks[i].m(div0, null);
}
}
group_outros2();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros2();
}
set_attributes(div1, div1_data = get_spread_update(div1_levels, [
(!current || dirty & /*metadata*/
128 && div1_class_value !== (div1_class_value = `day ${/*metadata*/
ctx[7].classes.join(" ")}`)) && { class: div1_class_value },
dirty & /*metadata*/
128 && /*metadata*/
(ctx[7].dataAttributes || {})
]));
toggle_class2(
div1,
"active",
/*selectedId*/
ctx[6] === getDateUID_1(
/*date*/
ctx[0],
"day"
)
);
toggle_class2(div1, "adjacent-month", !/*date*/
ctx[0].isSame(
/*displayedMonth*/
ctx[5],
"month"
));
toggle_class2(
div1,
"today",
/*date*/
ctx[0].isSame(
/*today*/
ctx[4],
"day"
)
);
toggle_class2(div1, "svelte-q3wqg9", true);
},
i(local) {
if (current) return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in2(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out2(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach2(div1);
destroy_each(each_blocks, detaching);
mounted = false;
run_all2(dispose);
}
};
}
function create_fragment$4(ctx) {
let td;
let metadataresolver;
let current;
metadataresolver = new MetadataResolver({
props: {
metadata: (
/*metadata*/
ctx[7]
),
$$slots: {
default: [
create_default_slot$1,
({ metadata }) => ({ 7: metadata }),
({ metadata }) => metadata ? 128 : 0
]
},
$$scope: { ctx }
}
});
return {
c() {
td = element2("td");
create_component2(metadataresolver.$$.fragment);
},
m(target, anchor) {
insert2(target, td, anchor);
mount_component2(metadataresolver, td, null);
current = true;
},
p(ctx2, [dirty]) {
const metadataresolver_changes = {};
if (dirty & /*metadata*/
128) metadataresolver_changes.metadata = /*metadata*/
ctx2[7];
if (dirty & /*$$scope, metadata, selectedId, date, displayedMonth, today, onClick, onContextMenu, onHover*/
16639) {
metadataresolver_changes.$$scope = { dirty, ctx: ctx2 };
}
metadataresolver.$set(metadataresolver_changes);
},
i(local) {
if (current) return;
transition_in2(metadataresolver.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(metadataresolver.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach2(td);
destroy_component2(metadataresolver);
}
};
}
function instance$4($$self, $$props, $$invalidate) {
let { date } = $$props;
let { metadata } = $$props;
let { onHover } = $$props;
let { onClick } = $$props;
let { onContextMenu } = $$props;
let { today } = $$props;
let { displayedMonth = null } = $$props;
let { selectedId = null } = $$props;
const click_handler = (e) => onClick(date, isMetaPressed(e));
const contextmenu_handler = (e) => onContextMenu(date, e);
const pointerover_handler = (e) => onHover(date, e.target, isMetaPressed(e));
$$self.$$set = ($$props2) => {
if ("date" in $$props2) $$invalidate(0, date = $$props2.date);
if ("metadata" in $$props2) $$invalidate(7, metadata = $$props2.metadata);
if ("onHover" in $$props2) $$invalidate(1, onHover = $$props2.onHover);
if ("onClick" in $$props2) $$invalidate(2, onClick = $$props2.onClick);
if ("onContextMenu" in $$props2) $$invalidate(3, onContextMenu = $$props2.onContextMenu);
if ("today" in $$props2) $$invalidate(4, today = $$props2.today);
if ("displayedMonth" in $$props2) $$invalidate(5, displayedMonth = $$props2.displayedMonth);
if ("selectedId" in $$props2) $$invalidate(6, selectedId = $$props2.selectedId);
};
return [
date,
onHover,
onClick,
onContextMenu,
today,
displayedMonth,
selectedId,
metadata,
click_handler,
contextmenu_handler,
pointerover_handler
];
}
var Day = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-q3wqg9-style")) add_css$4();
init2(this, options, instance$4, create_fragment$4, not_equal2, {
date: 0,
metadata: 7,
onHover: 1,
onClick: 2,
onContextMenu: 3,
today: 4,
displayedMonth: 5,
selectedId: 6
});
}
};
function add_css$3() {
var style = element2("style");
style.id = "svelte-156w7na-style";
style.textContent = ".arrow.svelte-156w7na.svelte-156w7na{align-items:center;cursor:pointer;display:flex;justify-content:center;width:24px}.arrow.is-mobile.svelte-156w7na.svelte-156w7na{width:32px}.right.svelte-156w7na.svelte-156w7na{transform:rotate(180deg)}.arrow.svelte-156w7na svg.svelte-156w7na{color:var(--color-arrow);height:16px;width:16px}";
append2(document.head, style);
}
function create_fragment$3(ctx) {
let div;
let svg;
let path;
let mounted;
let dispose;
return {
c() {
div = element2("div");
svg = svg_element("svg");
path = svg_element("path");
attr2(path, "fill", "currentColor");
attr2(path, "d", "M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z");
attr2(svg, "focusable", "false");
attr2(svg, "role", "img");
attr2(svg, "xmlns", "http://www.w3.org/2000/svg");
attr2(svg, "viewBox", "0 0 320 512");
attr2(svg, "class", "svelte-156w7na");
attr2(div, "class", "arrow svelte-156w7na");
attr2(
div,
"aria-label",
/*tooltip*/
ctx[1]
);
toggle_class2(
div,
"is-mobile",
/*isMobile*/
ctx[3]
);
toggle_class2(
div,
"right",
/*direction*/
ctx[2] === "right"
);
},
m(target, anchor) {
insert2(target, div, anchor);
append2(div, svg);
append2(svg, path);
if (!mounted) {
dispose = listen2(div, "click", function() {
if (is_function2(
/*onClick*/
ctx[0]
)) ctx[0].apply(this, arguments);
});
mounted = true;
}
},
p(new_ctx, [dirty]) {
ctx = new_ctx;
if (dirty & /*tooltip*/
2) {
attr2(
div,
"aria-label",
/*tooltip*/
ctx[1]
);
}
if (dirty & /*direction*/
4) {
toggle_class2(
div,
"right",
/*direction*/
ctx[2] === "right"
);
}
},
i: noop2,
o: noop2,
d(detaching) {
if (detaching) detach2(div);
mounted = false;
dispose();
}
};
}
function instance$3($$self, $$props, $$invalidate) {
let { onClick } = $$props;
let { tooltip } = $$props;
let { direction } = $$props;
let isMobile = window.app.isMobile;
$$self.$$set = ($$props2) => {
if ("onClick" in $$props2) $$invalidate(0, onClick = $$props2.onClick);
if ("tooltip" in $$props2) $$invalidate(1, tooltip = $$props2.tooltip);
if ("direction" in $$props2) $$invalidate(2, direction = $$props2.direction);
};
return [onClick, tooltip, direction, isMobile];
}
var Arrow = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-156w7na-style")) add_css$3();
init2(this, options, instance$3, create_fragment$3, safe_not_equal2, { onClick: 0, tooltip: 1, direction: 2 });
}
};
function add_css$2() {
var style = element2("style");
style.id = "svelte-1vwr9dd-style";
style.textContent = ".nav.svelte-1vwr9dd.svelte-1vwr9dd{align-items:center;display:flex;margin:0.6em 0 1em;padding:0 8px;width:100%}.nav.is-mobile.svelte-1vwr9dd.svelte-1vwr9dd{padding:0}.title.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--color-text-title);font-size:1.5em;margin:0}.is-mobile.svelte-1vwr9dd .title.svelte-1vwr9dd{font-size:1.3em}.month.svelte-1vwr9dd.svelte-1vwr9dd{font-weight:500;text-transform:capitalize}.year.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--interactive-accent)}.right-nav.svelte-1vwr9dd.svelte-1vwr9dd{display:flex;justify-content:center;margin-left:auto}.reset-button.svelte-1vwr9dd.svelte-1vwr9dd{cursor:pointer;border-radius:4px;color:var(--text-muted);font-size:0.7em;font-weight:600;letter-spacing:1px;margin:0 4px;padding:0px 4px;text-transform:uppercase}.is-mobile.svelte-1vwr9dd .reset-button.svelte-1vwr9dd{display:none}";
append2(document.head, style);
}
function create_fragment$2(ctx) {
let div2;
let h3;
let span0;
let t0_value = (
/*displayedMonth*/
ctx[0].format("MMM") + ""
);
let t0;
let t1;
let span1;
let t2_value = (
/*displayedMonth*/
ctx[0].format("YYYY") + ""
);
let t2;
let t3;
let div1;
let arrow0;
let t4;
let div0;
let t6;
let arrow1;
let current;
let mounted;
let dispose;
arrow0 = new Arrow({
props: {
direction: "left",
onClick: (
/*decrementDisplayedMonth*/
ctx[3]
),
tooltip: "Previous Month"
}
});
arrow1 = new Arrow({
props: {
direction: "right",
onClick: (
/*incrementDisplayedMonth*/
ctx[2]
),
tooltip: "Next Month"
}
});
return {
c() {
div2 = element2("div");
h3 = element2("h3");
span0 = element2("span");
t0 = text2(t0_value);
t1 = space2();
span1 = element2("span");
t2 = text2(t2_value);
t3 = space2();
div1 = element2("div");
create_component2(arrow0.$$.fragment);
t4 = space2();
div0 = element2("div");
div0.textContent = `${/*todayDisplayStr*/
ctx[4]}`;
t6 = space2();
create_component2(arrow1.$$.fragment);
attr2(span0, "class", "month svelte-1vwr9dd");
attr2(span1, "class", "year svelte-1vwr9dd");
attr2(h3, "class", "title svelte-1vwr9dd");
attr2(div0, "class", "reset-button svelte-1vwr9dd");
attr2(div1, "class", "right-nav svelte-1vwr9dd");
attr2(div2, "class", "nav svelte-1vwr9dd");
toggle_class2(
div2,
"is-mobile",
/*isMobile*/
ctx[5]
);
},
m(target, anchor) {
insert2(target, div2, anchor);
append2(div2, h3);
append2(h3, span0);
append2(span0, t0);
append2(h3, t1);
append2(h3, span1);
append2(span1, t2);
append2(div2, t3);
append2(div2, div1);
mount_component2(arrow0, div1, null);
append2(div1, t4);
append2(div1, div0);
append2(div1, t6);
mount_component2(arrow1, div1, null);
current = true;
if (!mounted) {
dispose = [
listen2(h3, "click", function() {
if (is_function2(
/*resetDisplayedMonth*/
ctx[1]
)) ctx[1].apply(this, arguments);
}),
listen2(div0, "click", function() {
if (is_function2(
/*resetDisplayedMonth*/
ctx[1]
)) ctx[1].apply(this, arguments);
})
];
mounted = true;
}
},
p(new_ctx, [dirty]) {
ctx = new_ctx;
if ((!current || dirty & /*displayedMonth*/
1) && t0_value !== (t0_value = /*displayedMonth*/
ctx[0].format("MMM") + "")) set_data2(t0, t0_value);
if ((!current || dirty & /*displayedMonth*/
1) && t2_value !== (t2_value = /*displayedMonth*/
ctx[0].format("YYYY") + "")) set_data2(t2, t2_value);
const arrow0_changes = {};
if (dirty & /*decrementDisplayedMonth*/
8) arrow0_changes.onClick = /*decrementDisplayedMonth*/
ctx[3];
arrow0.$set(arrow0_changes);
const arrow1_changes = {};
if (dirty & /*incrementDisplayedMonth*/
4) arrow1_changes.onClick = /*incrementDisplayedMonth*/
ctx[2];
arrow1.$set(arrow1_changes);
},
i(local) {
if (current) return;
transition_in2(arrow0.$$.fragment, local);
transition_in2(arrow1.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(arrow0.$$.fragment, local);
transition_out2(arrow1.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach2(div2);
destroy_component2(arrow0);
destroy_component2(arrow1);
mounted = false;
run_all2(dispose);
}
};
}
function instance$2($$self, $$props, $$invalidate) {
let { displayedMonth } = $$props;
let { today } = $$props;
let { resetDisplayedMonth } = $$props;
let { incrementDisplayedMonth } = $$props;
let { decrementDisplayedMonth } = $$props;
const todayDisplayStr = today.calendar().split(/\d|\s/)[0];
let isMobile = window.app.isMobile;
$$self.$$set = ($$props2) => {
if ("displayedMonth" in $$props2) $$invalidate(0, displayedMonth = $$props2.displayedMonth);
if ("today" in $$props2) $$invalidate(6, today = $$props2.today);
if ("resetDisplayedMonth" in $$props2) $$invalidate(1, resetDisplayedMonth = $$props2.resetDisplayedMonth);
if ("incrementDisplayedMonth" in $$props2) $$invalidate(2, incrementDisplayedMonth = $$props2.incrementDisplayedMonth);
if ("decrementDisplayedMonth" in $$props2) $$invalidate(3, decrementDisplayedMonth = $$props2.decrementDisplayedMonth);
};
return [
displayedMonth,
resetDisplayedMonth,
incrementDisplayedMonth,
decrementDisplayedMonth,
todayDisplayStr,
isMobile,
today
];
}
var Nav = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-1vwr9dd-style")) add_css$2();
init2(this, options, instance$2, create_fragment$2, safe_not_equal2, {
displayedMonth: 0,
today: 6,
resetDisplayedMonth: 1,
incrementDisplayedMonth: 2,
decrementDisplayedMonth: 3
});
}
};
function add_css$1() {
var style = element2("style");
style.id = "svelte-egt0yd-style";
style.textContent = "td.svelte-egt0yd{border-right:1px solid var(--background-modifier-border)}.week-num.svelte-egt0yd{background-color:var(--color-background-weeknum);border-radius:4px;color:var(--color-text-weeknum);cursor:pointer;font-size:0.65em;height:100%;padding:4px;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.week-num.svelte-egt0yd:hover{background-color:var(--interactive-hover)}.week-num.active.svelte-egt0yd:hover{background-color:var(--interactive-accent-hover)}.active.svelte-egt0yd{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-egt0yd{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}";
append2(document.head, style);
}
function get_each_context$1(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[11] = list[i];
return child_ctx;
}
function create_each_block$1(ctx) {
let dot;
let current;
const dot_spread_levels = [
/*dot*/
ctx[11]
];
let dot_props = {};
for (let i = 0; i < dot_spread_levels.length; i += 1) {
dot_props = assign(dot_props, dot_spread_levels[i]);
}
dot = new Dot({ props: dot_props });
return {
c() {
create_component2(dot.$$.fragment);
},
m(target, anchor) {
mount_component2(dot, target, anchor);
current = true;
},
p(ctx2, dirty) {
const dot_changes = dirty & /*metadata*/
64 ? get_spread_update(dot_spread_levels, [get_spread_object(
/*dot*/
ctx2[11]
)]) : {};
dot.$set(dot_changes);
},
i(local) {
if (current) return;
transition_in2(dot.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(dot.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component2(dot, detaching);
}
};
}
function create_default_slot(ctx) {
let div1;
let t0;
let t1;
let div0;
let div1_class_value;
let current;
let mounted;
let dispose;
let each_value = (
/*metadata*/
ctx[6].dots
);
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
}
const out = (i) => transition_out2(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
return {
c() {
div1 = element2("div");
t0 = text2(
/*weekNum*/
ctx[0]
);
t1 = space2();
div0 = element2("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr2(div0, "class", "dot-container svelte-egt0yd");
attr2(div1, "class", div1_class_value = null_to_empty(`week-num ${/*metadata*/
ctx[6].classes.join(" ")}`) + " svelte-egt0yd");
toggle_class2(
div1,
"active",
/*selectedId*/
ctx[5] === getDateUID_1(
/*days*/
ctx[1][0],
"week"
)
);
},
m(target, anchor) {
insert2(target, div1, anchor);
append2(div1, t0);
append2(div1, t1);
append2(div1, div0);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div0, null);
}
current = true;
if (!mounted) {
dispose = [
listen2(div1, "click", function() {
if (is_function2(
/*onClick*/
ctx[3] && /*click_handler*/
ctx[8]
)) /*onClick*/
(ctx[3] && /*click_handler*/
ctx[8]).apply(this, arguments);
}),
listen2(div1, "contextmenu", function() {
if (is_function2(
/*onContextMenu*/
ctx[4] && /*contextmenu_handler*/
ctx[9]
)) /*onContextMenu*/
(ctx[4] && /*contextmenu_handler*/
ctx[9]).apply(this, arguments);
}),
listen2(div1, "pointerover", function() {
if (is_function2(
/*onHover*/
ctx[2] && /*pointerover_handler*/
ctx[10]
)) /*onHover*/
(ctx[2] && /*pointerover_handler*/
ctx[10]).apply(this, arguments);
})
];
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (!current || dirty & /*weekNum*/
1) set_data2(
t0,
/*weekNum*/
ctx[0]
);
if (dirty & /*metadata*/
64) {
each_value = /*metadata*/
ctx[6].dots;
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$1(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in2(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block$1(child_ctx);
each_blocks[i].c();
transition_in2(each_blocks[i], 1);
each_blocks[i].m(div0, null);
}
}
group_outros2();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros2();
}
if (!current || dirty & /*metadata*/
64 && div1_class_value !== (div1_class_value = null_to_empty(`week-num ${/*metadata*/
ctx[6].classes.join(" ")}`) + " svelte-egt0yd")) {
attr2(div1, "class", div1_class_value);
}
if (dirty & /*metadata, selectedId, getDateUID, days*/
98) {
toggle_class2(
div1,
"active",
/*selectedId*/
ctx[5] === getDateUID_1(
/*days*/
ctx[1][0],
"week"
)
);
}
},
i(local) {
if (current) return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in2(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out2(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach2(div1);
destroy_each(each_blocks, detaching);
mounted = false;
run_all2(dispose);
}
};
}
function create_fragment$1(ctx) {
let td;
let metadataresolver;
let current;
metadataresolver = new MetadataResolver({
props: {
metadata: (
/*metadata*/
ctx[6]
),
$$slots: {
default: [
create_default_slot,
({ metadata }) => ({ 6: metadata }),
({ metadata }) => metadata ? 64 : 0
]
},
$$scope: { ctx }
}
});
return {
c() {
td = element2("td");
create_component2(metadataresolver.$$.fragment);
attr2(td, "class", "svelte-egt0yd");
},
m(target, anchor) {
insert2(target, td, anchor);
mount_component2(metadataresolver, td, null);
current = true;
},
p(ctx2, [dirty]) {
const metadataresolver_changes = {};
if (dirty & /*metadata*/
64) metadataresolver_changes.metadata = /*metadata*/
ctx2[6];
if (dirty & /*$$scope, metadata, selectedId, days, onClick, startOfWeek, onContextMenu, onHover, weekNum*/
16639) {
metadataresolver_changes.$$scope = { dirty, ctx: ctx2 };
}
metadataresolver.$set(metadataresolver_changes);
},
i(local) {
if (current) return;
transition_in2(metadataresolver.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(metadataresolver.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach2(td);
destroy_component2(metadataresolver);
}
};
}
function instance$1($$self, $$props, $$invalidate) {
let { weekNum } = $$props;
let { days } = $$props;
let { metadata } = $$props;
let { onHover } = $$props;
let { onClick } = $$props;
let { onContextMenu } = $$props;
let { selectedId = null } = $$props;
let startOfWeek;
const click_handler = (e) => onClick(startOfWeek, isMetaPressed(e));
const contextmenu_handler = (e) => onContextMenu(days[0], e);
const pointerover_handler = (e) => onHover(startOfWeek, e.target, isMetaPressed(e));
$$self.$$set = ($$props2) => {
if ("weekNum" in $$props2) $$invalidate(0, weekNum = $$props2.weekNum);
if ("days" in $$props2) $$invalidate(1, days = $$props2.days);
if ("metadata" in $$props2) $$invalidate(6, metadata = $$props2.metadata);
if ("onHover" in $$props2) $$invalidate(2, onHover = $$props2.onHover);
if ("onClick" in $$props2) $$invalidate(3, onClick = $$props2.onClick);
if ("onContextMenu" in $$props2) $$invalidate(4, onContextMenu = $$props2.onContextMenu);
if ("selectedId" in $$props2) $$invalidate(5, selectedId = $$props2.selectedId);
};
$$self.$$.update = () => {
if ($$self.$$.dirty & /*days*/
2) {
$$invalidate(7, startOfWeek = getStartOfWeek(days));
}
};
return [
weekNum,
days,
onHover,
onClick,
onContextMenu,
selectedId,
metadata,
startOfWeek,
click_handler,
contextmenu_handler,
pointerover_handler
];
}
var WeekNum = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-egt0yd-style")) add_css$1();
init2(this, options, instance$1, create_fragment$1, not_equal2, {
weekNum: 0,
days: 1,
metadata: 6,
onHover: 2,
onClick: 3,
onContextMenu: 4,
selectedId: 5
});
}
};
async function metadataReducer(promisedMetadata) {
const meta = {
dots: [],
classes: [],
dataAttributes: {}
};
const metas = await Promise.all(promisedMetadata);
return metas.reduce((acc, meta2) => ({
classes: [...acc.classes, ...meta2.classes || []],
dataAttributes: Object.assign(acc.dataAttributes, meta2.dataAttributes),
dots: [...acc.dots, ...meta2.dots || []]
}), meta);
}
function getDailyMetadata(sources, date, ..._args) {
return metadataReducer(sources.map((source) => source.getDailyMetadata(date)));
}
function getWeeklyMetadata(sources, date, ..._args) {
return metadataReducer(sources.map((source) => source.getWeeklyMetadata(date)));
}
function add_css() {
var style = element2("style");
style.id = "svelte-pcimu8-style";
style.textContent = ".container.svelte-pcimu8{--color-background-heading:transparent;--color-background-day:transparent;--color-background-weeknum:transparent;--color-background-weekend:transparent;--color-dot:var(--text-muted);--color-arrow:var(--text-muted);--color-button:var(--text-muted);--color-text-title:var(--text-normal);--color-text-heading:var(--text-muted);--color-text-day:var(--text-normal);--color-text-today:var(--interactive-accent);--color-text-weeknum:var(--text-muted)}.container.svelte-pcimu8{padding:0 8px}.container.is-mobile.svelte-pcimu8{padding:0}th.svelte-pcimu8{text-align:center}.weekend.svelte-pcimu8{background-color:var(--color-background-weekend)}.calendar.svelte-pcimu8{border-collapse:collapse;width:100%}th.svelte-pcimu8{background-color:var(--color-background-heading);color:var(--color-text-heading);font-size:0.6em;letter-spacing:1px;padding:4px;text-transform:uppercase}";
append2(document.head, style);
}
function get_each_context3(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[18] = list[i];
return child_ctx;
}
function get_each_context_12(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[21] = list[i];
return child_ctx;
}
function get_each_context_22(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[24] = list[i];
return child_ctx;
}
function get_each_context_32(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[27] = list[i];
return child_ctx;
}
function create_if_block_22(ctx) {
let col;
return {
c() {
col = element2("col");
},
m(target, anchor) {
insert2(target, col, anchor);
},
d(detaching) {
if (detaching) detach2(col);
}
};
}
function create_each_block_32(ctx) {
let col;
return {
c() {
col = element2("col");
attr2(col, "class", "svelte-pcimu8");
toggle_class2(col, "weekend", isWeekend(
/*date*/
ctx[27]
));
},
m(target, anchor) {
insert2(target, col, anchor);
},
p(ctx2, dirty) {
if (dirty & /*isWeekend, month*/
16384) {
toggle_class2(col, "weekend", isWeekend(
/*date*/
ctx2[27]
));
}
},
d(detaching) {
if (detaching) detach2(col);
}
};
}
function create_if_block_13(ctx) {
let th;
return {
c() {
th = element2("th");
th.textContent = "W";
attr2(th, "class", "svelte-pcimu8");
},
m(target, anchor) {
insert2(target, th, anchor);
},
d(detaching) {
if (detaching) detach2(th);
}
};
}
function create_each_block_22(ctx) {
let th;
let t_value = (
/*dayOfWeek*/
ctx[24] + ""
);
let t;
return {
c() {
th = element2("th");
t = text2(t_value);
attr2(th, "class", "svelte-pcimu8");
},
m(target, anchor) {
insert2(target, th, anchor);
append2(th, t);
},
p(ctx2, dirty) {
if (dirty & /*daysOfWeek*/
32768 && t_value !== (t_value = /*dayOfWeek*/
ctx2[24] + "")) set_data2(t, t_value);
},
d(detaching) {
if (detaching) detach2(th);
}
};
}
function create_if_block3(ctx) {
let weeknum;
let current;
const weeknum_spread_levels = [
/*week*/
ctx[18],
{
metadata: getWeeklyMetadata(
/*sources*/
ctx[8],
/*week*/
ctx[18].days[0],
/*today*/
ctx[10]
)
},
{ onClick: (
/*onClickWeek*/
ctx[7]
) },
{
onContextMenu: (
/*onContextMenuWeek*/
ctx[5]
)
},
{ onHover: (
/*onHoverWeek*/
ctx[3]
) },
{ selectedId: (
/*selectedId*/
ctx[9]
) }
];
let weeknum_props = {};
for (let i = 0; i < weeknum_spread_levels.length; i += 1) {
weeknum_props = assign(weeknum_props, weeknum_spread_levels[i]);
}
weeknum = new WeekNum({ props: weeknum_props });
return {
c() {
create_component2(weeknum.$$.fragment);
},
m(target, anchor) {
mount_component2(weeknum, target, anchor);
current = true;
},
p(ctx2, dirty) {
const weeknum_changes = dirty & /*month, getWeeklyMetadata, sources, today, onClickWeek, onContextMenuWeek, onHoverWeek, selectedId*/
18344 ? get_spread_update(weeknum_spread_levels, [
dirty & /*month*/
16384 && get_spread_object(
/*week*/
ctx2[18]
),
dirty & /*getWeeklyMetadata, sources, month, today*/
17664 && {
metadata: getWeeklyMetadata(
/*sources*/
ctx2[8],
/*week*/
ctx2[18].days[0],
/*today*/
ctx2[10]
)
},
dirty & /*onClickWeek*/
128 && { onClick: (
/*onClickWeek*/
ctx2[7]
) },
dirty & /*onContextMenuWeek*/
32 && {
onContextMenu: (
/*onContextMenuWeek*/
ctx2[5]
)
},
dirty & /*onHoverWeek*/
8 && { onHover: (
/*onHoverWeek*/
ctx2[3]
) },
dirty & /*selectedId*/
512 && { selectedId: (
/*selectedId*/
ctx2[9]
) }
]) : {};
weeknum.$set(weeknum_changes);
},
i(local) {
if (current) return;
transition_in2(weeknum.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(weeknum.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component2(weeknum, detaching);
}
};
}
function create_each_block_12(key_1, ctx) {
let first;
let day;
let current;
day = new Day({
props: {
date: (
/*day*/
ctx[21]
),
today: (
/*today*/
ctx[10]
),
displayedMonth: (
/*displayedMonth*/
ctx[0]
),
onClick: (
/*onClickDay*/
ctx[6]
),
onContextMenu: (
/*onContextMenuDay*/
ctx[4]
),
onHover: (
/*onHoverDay*/
ctx[2]
),
metadata: getDailyMetadata(
/*sources*/
ctx[8],
/*day*/
ctx[21],
/*today*/
ctx[10]
),
selectedId: (
/*selectedId*/
ctx[9]
)
}
});
return {
key: key_1,
first: null,
c() {
first = empty2();
create_component2(day.$$.fragment);
this.first = first;
},
m(target, anchor) {
insert2(target, first, anchor);
mount_component2(day, target, anchor);
current = true;
},
p(new_ctx, dirty) {
ctx = new_ctx;
const day_changes = {};
if (dirty & /*month*/
16384) day_changes.date = /*day*/
ctx[21];
if (dirty & /*today*/
1024) day_changes.today = /*today*/
ctx[10];
if (dirty & /*displayedMonth*/
1) day_changes.displayedMonth = /*displayedMonth*/
ctx[0];
if (dirty & /*onClickDay*/
64) day_changes.onClick = /*onClickDay*/
ctx[6];
if (dirty & /*onContextMenuDay*/
16) day_changes.onContextMenu = /*onContextMenuDay*/
ctx[4];
if (dirty & /*onHoverDay*/
4) day_changes.onHover = /*onHoverDay*/
ctx[2];
if (dirty & /*sources, month, today*/
17664) day_changes.metadata = getDailyMetadata(
/*sources*/
ctx[8],
/*day*/
ctx[21],
/*today*/
ctx[10]
);
if (dirty & /*selectedId*/
512) day_changes.selectedId = /*selectedId*/
ctx[9];
day.$set(day_changes);
},
i(local) {
if (current) return;
transition_in2(day.$$.fragment, local);
current = true;
},
o(local) {
transition_out2(day.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach2(first);
destroy_component2(day, detaching);
}
};
}
function create_each_block3(key_1, ctx) {
let tr;
let t0;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let t1;
let current;
let if_block = (
/*showWeekNums*/
ctx[1] && create_if_block3(ctx)
);
let each_value_1 = (
/*week*/
ctx[18].days
);
const get_key = (ctx2) => (
/*day*/
ctx2[21].format()
);
for (let i = 0; i < each_value_1.length; i += 1) {
let child_ctx = get_each_context_12(ctx, each_value_1, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block_12(key, child_ctx));
}
return {
key: key_1,
first: null,
c() {
tr = element2("tr");
if (if_block) if_block.c();
t0 = space2();
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
t1 = space2();
this.first = tr;
},
m(target, anchor) {
insert2(target, tr, anchor);
if (if_block) if_block.m(tr, null);
append2(tr, t0);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(tr, null);
}
append2(tr, t1);
current = true;
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (
/*showWeekNums*/
ctx[1]
) {
if (if_block) {
if_block.p(ctx, dirty);
if (dirty & /*showWeekNums*/
2) {
transition_in2(if_block, 1);
}
} else {
if_block = create_if_block3(ctx);
if_block.c();
transition_in2(if_block, 1);
if_block.m(tr, t0);
}
} else if (if_block) {
group_outros2();
transition_out2(if_block, 1, 1, () => {
if_block = null;
});
check_outros2();
}
if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId*/
18261) {
each_value_1 = /*week*/
ctx[18].days;
group_outros2();
each_blocks = update_keyed_each2(each_blocks, dirty, get_key, 1, ctx, each_value_1, each_1_lookup, tr, outro_and_destroy_block, create_each_block_12, t1, get_each_context_12);
check_outros2();
}
},
i(local) {
if (current) return;
transition_in2(if_block);
for (let i = 0; i < each_value_1.length; i += 1) {
transition_in2(each_blocks[i]);
}
current = true;
},
o(local) {
transition_out2(if_block);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out2(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach2(tr);
if (if_block) if_block.d();
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function create_fragment3(ctx) {
let div;
let nav;
let t0;
let table;
let colgroup;
let t1;
let t2;
let thead;
let tr;
let t3;
let t4;
let tbody;
let each_blocks = [];
let each2_lookup = /* @__PURE__ */ new Map();
let current;
nav = new Nav({
props: {
today: (
/*today*/
ctx[10]
),
displayedMonth: (
/*displayedMonth*/
ctx[0]
),
incrementDisplayedMonth: (
/*incrementDisplayedMonth*/
ctx[11]
),
decrementDisplayedMonth: (
/*decrementDisplayedMonth*/
ctx[12]
),
resetDisplayedMonth: (
/*resetDisplayedMonth*/
ctx[13]
)
}
});
let if_block0 = (
/*showWeekNums*/
ctx[1] && create_if_block_22()
);
let each_value_3 = (
/*month*/
ctx[14][1].days
);
let each_blocks_2 = [];
for (let i = 0; i < each_value_3.length; i += 1) {
each_blocks_2[i] = create_each_block_32(get_each_context_32(ctx, each_value_3, i));
}
let if_block1 = (
/*showWeekNums*/
ctx[1] && create_if_block_13()
);
let each_value_2 = (
/*daysOfWeek*/
ctx[15]
);
let each_blocks_1 = [];
for (let i = 0; i < each_value_2.length; i += 1) {
each_blocks_1[i] = create_each_block_22(get_each_context_22(ctx, each_value_2, i));
}
let each_value = (
/*month*/
ctx[14]
);
const get_key = (ctx2) => (
/*week*/
ctx2[18].weekNum
);
for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context3(ctx, each_value, i);
let key = get_key(child_ctx);
each2_lookup.set(key, each_blocks[i] = create_each_block3(key, child_ctx));
}
return {
c() {
div = element2("div");
create_component2(nav.$$.fragment);
t0 = space2();
table = element2("table");
colgroup = element2("colgroup");
if (if_block0) if_block0.c();
t1 = space2();
for (let i = 0; i < each_blocks_2.length; i += 1) {
each_blocks_2[i].c();
}
t2 = space2();
thead = element2("thead");
tr = element2("tr");
if (if_block1) if_block1.c();
t3 = space2();
for (let i = 0; i < each_blocks_1.length; i += 1) {
each_blocks_1[i].c();
}
t4 = space2();
tbody = element2("tbody");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr2(table, "class", "calendar svelte-pcimu8");
attr2(div, "id", "calendar-container");
attr2(div, "class", "container svelte-pcimu8");
toggle_class2(
div,
"is-mobile",
/*isMobile*/
ctx[16]
);
},
m(target, anchor) {
insert2(target, div, anchor);
mount_component2(nav, div, null);
append2(div, t0);
append2(div, table);
append2(table, colgroup);
if (if_block0) if_block0.m(colgroup, null);
append2(colgroup, t1);
for (let i = 0; i < each_blocks_2.length; i += 1) {
each_blocks_2[i].m(colgroup, null);
}
append2(table, t2);
append2(table, thead);
append2(thead, tr);
if (if_block1) if_block1.m(tr, null);
append2(tr, t3);
for (let i = 0; i < each_blocks_1.length; i += 1) {
each_blocks_1[i].m(tr, null);
}
append2(table, t4);
append2(table, tbody);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(tbody, null);
}
current = true;
},
p(ctx2, [dirty]) {
const nav_changes = {};
if (dirty & /*today*/
1024) nav_changes.today = /*today*/
ctx2[10];
if (dirty & /*displayedMonth*/
1) nav_changes.displayedMonth = /*displayedMonth*/
ctx2[0];
nav.$set(nav_changes);
if (
/*showWeekNums*/
ctx2[1]
) {
if (if_block0) ;
else {
if_block0 = create_if_block_22();
if_block0.c();
if_block0.m(colgroup, t1);
}
} else if (if_block0) {
if_block0.d(1);
if_block0 = null;
}
if (dirty & /*isWeekend, month*/
16384) {
each_value_3 = /*month*/
ctx2[14][1].days;
let i;
for (i = 0; i < each_value_3.length; i += 1) {
const child_ctx = get_each_context_32(ctx2, each_value_3, i);
if (each_blocks_2[i]) {
each_blocks_2[i].p(child_ctx, dirty);
} else {
each_blocks_2[i] = create_each_block_32(child_ctx);
each_blocks_2[i].c();
each_blocks_2[i].m(colgroup, null);
}
}
for (; i < each_blocks_2.length; i += 1) {
each_blocks_2[i].d(1);
}
each_blocks_2.length = each_value_3.length;
}
if (
/*showWeekNums*/
ctx2[1]
) {
if (if_block1) ;
else {
if_block1 = create_if_block_13();
if_block1.c();
if_block1.m(tr, t3);
}
} else if (if_block1) {
if_block1.d(1);
if_block1 = null;
}
if (dirty & /*daysOfWeek*/
32768) {
each_value_2 = /*daysOfWeek*/
ctx2[15];
let i;
for (i = 0; i < each_value_2.length; i += 1) {
const child_ctx = get_each_context_22(ctx2, each_value_2, i);
if (each_blocks_1[i]) {
each_blocks_1[i].p(child_ctx, dirty);
} else {
each_blocks_1[i] = create_each_block_22(child_ctx);
each_blocks_1[i].c();
each_blocks_1[i].m(tr, null);
}
}
for (; i < each_blocks_1.length; i += 1) {
each_blocks_1[i].d(1);
}
each_blocks_1.length = each_value_2.length;
}
if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId, getWeeklyMetadata, onClickWeek, onContextMenuWeek, onHoverWeek, showWeekNums*/
18431) {
each_value = /*month*/
ctx2[14];
group_outros2();
each_blocks = update_keyed_each2(each_blocks, dirty, get_key, 1, ctx2, each_value, each2_lookup, tbody, outro_and_destroy_block, create_each_block3, null, get_each_context3);
check_outros2();
}
},
i(local) {
if (current) return;
transition_in2(nav.$$.fragment, local);
for (let i = 0; i < each_value.length; i += 1) {
transition_in2(each_blocks[i]);
}
current = true;
},
o(local) {
transition_out2(nav.$$.fragment, local);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out2(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach2(div);
destroy_component2(nav);
if (if_block0) if_block0.d();
destroy_each(each_blocks_2, detaching);
if (if_block1) if_block1.d();
destroy_each(each_blocks_1, detaching);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function instance3($$self, $$props, $$invalidate) {
let { localeData } = $$props;
let { showWeekNums = false } = $$props;
let { onHoverDay } = $$props;
let { onHoverWeek } = $$props;
let { onContextMenuDay } = $$props;
let { onContextMenuWeek } = $$props;
let { onClickDay } = $$props;
let { onClickWeek } = $$props;
let { sources = [] } = $$props;
let { selectedId } = $$props;
let { today = window.moment() } = $$props;
let { displayedMonth = today } = $$props;
let { onResetDisplayedMonth } = $$props;
let month;
let daysOfWeek;
let isMobile = window.app.isMobile;
function incrementDisplayedMonth() {
$$invalidate(0, displayedMonth = displayedMonth.clone().add(1, "month"));
}
function decrementDisplayedMonth() {
$$invalidate(0, displayedMonth = displayedMonth.clone().subtract(1, "month"));
}
function resetDisplayedMonth() {
const currentToday = window.moment();
$$invalidate(10, today = currentToday);
$$invalidate(0, displayedMonth = currentToday.clone());
if (is_function2(onResetDisplayedMonth)) onResetDisplayedMonth(currentToday.clone());
}
$$self.$$set = ($$props2) => {
if ("localeData" in $$props2) $$invalidate(17, localeData = $$props2.localeData);
if ("showWeekNums" in $$props2) $$invalidate(1, showWeekNums = $$props2.showWeekNums);
if ("onHoverDay" in $$props2) $$invalidate(2, onHoverDay = $$props2.onHoverDay);
if ("onHoverWeek" in $$props2) $$invalidate(3, onHoverWeek = $$props2.onHoverWeek);
if ("onContextMenuDay" in $$props2) $$invalidate(4, onContextMenuDay = $$props2.onContextMenuDay);
if ("onContextMenuWeek" in $$props2) $$invalidate(5, onContextMenuWeek = $$props2.onContextMenuWeek);
if ("onClickDay" in $$props2) $$invalidate(6, onClickDay = $$props2.onClickDay);
if ("onClickWeek" in $$props2) $$invalidate(7, onClickWeek = $$props2.onClickWeek);
if ("sources" in $$props2) $$invalidate(8, sources = $$props2.sources);
if ("selectedId" in $$props2) $$invalidate(9, selectedId = $$props2.selectedId);
if ("today" in $$props2) $$invalidate(10, today = $$props2.today);
if ("displayedMonth" in $$props2) $$invalidate(0, displayedMonth = $$props2.displayedMonth);
if ("onResetDisplayedMonth" in $$props2) $$invalidate(18, onResetDisplayedMonth = $$props2.onResetDisplayedMonth);
};
$$self.$$.update = () => {
if ($$self.$$.dirty & /*displayedMonth, localeData*/
131073) {
$$invalidate(14, month = getMonth(displayedMonth, localeData));
}
if ($$self.$$.dirty & /*today, localeData*/
132096) {
$$invalidate(15, daysOfWeek = getDaysOfWeek(today, localeData));
}
};
return [
displayedMonth,
showWeekNums,
onHoverDay,
onHoverWeek,
onContextMenuDay,
onContextMenuWeek,
onClickDay,
onClickWeek,
sources,
selectedId,
today,
incrementDisplayedMonth,
decrementDisplayedMonth,
resetDisplayedMonth,
month,
daysOfWeek,
isMobile,
localeData,
onResetDisplayedMonth
];
}
var Calendar = class extends SvelteComponent2 {
constructor(options) {
super();
if (!document.getElementById("svelte-pcimu8-style")) add_css();
init2(this, options, instance3, create_fragment3, not_equal2, {
localeData: 17,
showWeekNums: 1,
onHoverDay: 2,
onHoverWeek: 3,
onContextMenuDay: 4,
onContextMenuWeek: 5,
onClickDay: 6,
onClickWeek: 7,
sources: 8,
selectedId: 9,
today: 10,
displayedMonth: 0,
onResetDisplayedMonth: 18,
incrementDisplayedMonth: 11,
decrementDisplayedMonth: 12,
resetDisplayedMonth: 13
});
}
get incrementDisplayedMonth() {
return this.$$.ctx[11];
}
get decrementDisplayedMonth() {
return this.$$.ctx[12];
}
get resetDisplayedMonth() {
return this.$$.ctx[13];
}
};
var langToMomentLocale = {
en: "en-gb",
zh: "zh-cn",
"zh-TW": "zh-tw",
ru: "ru",
ko: "ko",
it: "it",
id: "id",
ro: "ro",
"pt-BR": "pt-br",
cz: "cs",
da: "da",
de: "de",
es: "es",
fr: "fr",
no: "nn",
pl: "pl",
pt: "pt",
tr: "tr",
hi: "hi",
nl: "nl",
ar: "ar",
ja: "ja"
};
var weekdays2 = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
];
function overrideGlobalMomentWeekStart(weekStart) {
const { moment } = window;
const currentLocale = moment.locale();
if (!window._bundledLocaleWeekSpec) {
window._bundledLocaleWeekSpec = moment.localeData()._week;
}
if (weekStart === "locale") {
moment.updateLocale(currentLocale, {
week: window._bundledLocaleWeekSpec
});
} else {
moment.updateLocale(currentLocale, {
week: {
dow: weekdays2.indexOf(weekStart) || 0
}
});
}
}
function configureGlobalMomentLocale(localeOverride = "system-default", weekStart = "locale") {
var _a;
const obsidianLang = localStorage.getItem("language") || "en";
const systemLang = (_a = navigator.language) === null || _a === void 0 ? void 0 : _a.toLowerCase();
let momentLocale = langToMomentLocale[obsidianLang];
if (localeOverride !== "system-default") {
momentLocale = localeOverride;
} else if (systemLang.startsWith(obsidianLang)) {
momentLocale = systemLang;
}
const currentLocale = window.moment.locale(momentLocale);
console.debug(`[Calendar] Trying to switch Moment.js global locale to ${momentLocale}, got ${currentLocale}`);
overrideGlobalMomentWeekStart(weekStart);
return currentLocale;
}
// src/ui/Calendar.svelte
function get_each_context4(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[35] = list[i];
return child_ctx;
}
function create_if_block4(ctx) {
let section;
let div;
let span0;
let t0;
let t1;
let span1;
let t2_value = formatNoteCount2(
/*selectedNotes*/
ctx[4].length
) + "";
let t2;
let t3;
function select_block_type(ctx2, dirty) {
if (
/*selectedNotes*/
ctx2[4].length
) return create_if_block_14;
return create_else_block4;
}
let current_block_type = select_block_type(ctx, [-1, -1]);
let if_block = current_block_type(ctx);
return {
c() {
section = element("section");
div = element("div");
span0 = element("span");
t0 = text(
/*panelLabel*/
ctx[5]
);
t1 = space();
span1 = element("span");
t2 = text(t2_value);
t3 = space();
if_block.c();
attr(span1, "class", "calendar-note-count");
attr(div, "class", "calendar-note-panel-header");
attr(section, "class", "calendar-note-panel");
},
m(target, anchor) {
insert(target, section, anchor);
append(section, div);
append(div, span0);
append(span0, t0);
append(div, t1);
append(div, span1);
append(span1, t2);
append(section, t3);
if_block.m(section, null);
},
p(ctx2, dirty) {
if (dirty[0] & /*panelLabel*/
32) set_data(
t0,
/*panelLabel*/
ctx2[5]
);
if (dirty[0] & /*selectedNotes*/
16 && t2_value !== (t2_value = formatNoteCount2(
/*selectedNotes*/
ctx2[4].length
) + "")) set_data(t2, t2_value);
if (current_block_type === (current_block_type = select_block_type(ctx2, dirty)) && if_block) {
if_block.p(ctx2, dirty);
} else {
if_block.d(1);
if_block = current_block_type(ctx2);
if (if_block) {
if_block.c();
if_block.m(section, null);
}
}
},
d(detaching) {
if (detaching) detach(section);
if_block.d();
}
};
}
function create_else_block4(ctx) {
let div;
return {
c() {
div = element("div");
div.textContent = "No notes";
attr(div, "class", "calendar-note-empty");
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}
function create_if_block_14(ctx) {
let ul;
let each_blocks = [];
let each_1_lookup = /* @__PURE__ */ new Map();
let each_value = (
/*selectedNotes*/
ctx[4]
);
const get_key = (ctx2) => (
/*note*/
ctx2[35].path
);
for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context4(ctx, each_value, i);
let key = get_key(child_ctx);
each_1_lookup.set(key, each_blocks[i] = create_each_block4(key, child_ctx));
}
return {
c() {
ul = element("ul");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(ul, "class", "calendar-note-list");
},
m(target, anchor) {
insert(target, ul, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(ul, null);
}
}
},
p(ctx2, dirty) {
if (dirty[0] & /*selectedNotes, handleOpenDayNote*/
32784) {
each_value = /*selectedNotes*/
ctx2[4];
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, ul, destroy_block, create_each_block4, null, get_each_context4);
}
},
d(detaching) {
if (detaching) detach(ul);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].d();
}
}
};
}
function create_each_block4(key_1, ctx) {
let li;
let button;
let span0;
let t0_value = (
/*note*/
ctx[35].basename + ""
);
let t0;
let t1;
let span1;
let t2_value = (
/*note*/
ctx[35].path + ""
);
let t2;
let button_title_value;
let t3;
let mounted;
let dispose;
function click_handler(...args) {
return (
/*click_handler*/
ctx[32](
/*note*/
ctx[35],
...args
)
);
}
return {
key: key_1,
first: null,
c() {
li = element("li");
button = element("button");
span0 = element("span");
t0 = text(t0_value);
t1 = space();
span1 = element("span");
t2 = text(t2_value);
t3 = space();
attr(span0, "class", "calendar-note-title");
attr(span1, "class", "calendar-note-path");
attr(button, "class", "calendar-note-list-item");
attr(button, "type", "button");
attr(button, "title", button_title_value = /*note*/
ctx[35].path);
this.first = li;
},
m(target, anchor) {
insert(target, li, anchor);
append(li, button);
append(button, span0);
append(span0, t0);
append(button, t1);
append(button, span1);
append(span1, t2);
append(li, t3);
if (!mounted) {
dispose = listen(button, "click", click_handler);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty[0] & /*selectedNotes*/
16 && t0_value !== (t0_value = /*note*/
ctx[35].basename + "")) set_data(t0, t0_value);
if (dirty[0] & /*selectedNotes*/
16 && t2_value !== (t2_value = /*note*/
ctx[35].path + "")) set_data(t2, t2_value);
if (dirty[0] & /*selectedNotes*/
16 && button_title_value !== (button_title_value = /*note*/
ctx[35].path)) {
attr(button, "title", button_title_value);
}
},
d(detaching) {
if (detaching) detach(li);
mounted = false;
dispose();
}
};
}
function create_fragment4(ctx) {
let calendarbase;
let updating_displayedMonth;
let t;
let if_block_anchor;
let current;
function calendarbase_displayedMonth_binding(value) {
ctx[31](value);
}
let calendarbase_props = {
sources: (
/*sources*/
ctx[1]
),
today: (
/*today*/
ctx[2]
),
onHoverDay: (
/*handleHoverDay*/
ctx[11]
),
onHoverWeek: (
/*handleHoverWeek*/
ctx[12]
),
onContextMenuDay: (
/*handleContextMenuDay*/
ctx[13]
),
onContextMenuWeek: (
/*handleContextMenuWeek*/
ctx[14]
),
onClickDay: (
/*handleClickDay*/
ctx[8]
),
onClickWeek: (
/*handleClickWeek*/
ctx[9]
),
onResetDisplayedMonth: (
/*handleResetDisplayedMonth*/
ctx[10]
),
localeData: (
/*today*/
ctx[2].localeData()
),
selectedId: (
/*$activeFile*/
ctx[7]
),
showWeekNums: (
/*$settings*/
ctx[3].showWeeklyNote
)
};
if (
/*displayedMonth*/
ctx[0] !== void 0
) {
calendarbase_props.displayedMonth = /*displayedMonth*/
ctx[0];
}
calendarbase = new Calendar({ props: calendarbase_props });
binding_callbacks.push(() => bind(calendarbase, "displayedMonth", calendarbase_displayedMonth_binding));
let if_block = (
/*hasSelection*/
ctx[6] && create_if_block4(ctx)
);
return {
c() {
create_component(calendarbase.$$.fragment);
t = space();
if (if_block) if_block.c();
if_block_anchor = empty();
},
m(target, anchor) {
mount_component(calendarbase, target, anchor);
insert(target, t, anchor);
if (if_block) if_block.m(target, anchor);
insert(target, if_block_anchor, anchor);
current = true;
},
p(ctx2, dirty) {
const calendarbase_changes = {};
if (dirty[0] & /*sources*/
2) calendarbase_changes.sources = /*sources*/
ctx2[1];
if (dirty[0] & /*today*/
4) calendarbase_changes.today = /*today*/
ctx2[2];
if (dirty[0] & /*today*/
4) calendarbase_changes.localeData = /*today*/
ctx2[2].localeData();
if (dirty[0] & /*$activeFile*/
128) calendarbase_changes.selectedId = /*$activeFile*/
ctx2[7];
if (dirty[0] & /*$settings*/
8) calendarbase_changes.showWeekNums = /*$settings*/
ctx2[3].showWeeklyNote;
if (!updating_displayedMonth && dirty[0] & /*displayedMonth*/
1) {
updating_displayedMonth = true;
calendarbase_changes.displayedMonth = /*displayedMonth*/
ctx2[0];
add_flush_callback(() => updating_displayedMonth = false);
}
calendarbase.$set(calendarbase_changes);
if (
/*hasSelection*/
ctx2[6]
) {
if (if_block) {
if_block.p(ctx2, dirty);
} else {
if_block = create_if_block4(ctx2);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
i(local) {
if (current) return;
transition_in(calendarbase.$$.fragment, local);
current = true;
},
o(local) {
transition_out(calendarbase.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component(calendarbase, detaching);
if (detaching) detach(t);
if (if_block) if_block.d(detaching);
if (detaching) detach(if_block_anchor);
}
};
}
function formatNoteCount2(count) {
return `${count} note${count === 1 ? "" : "s"}`;
}
function instance4($$self, $$props, $$invalidate) {
let $dailyNotes;
let $dailyNotesByDate;
let $weeklyNotes;
let $weeklyNotesByDate;
let $settings;
let $activeFile;
component_subscribe($$self, dailyNotes, ($$value) => $$invalidate(27, $dailyNotes = $$value));
component_subscribe($$self, dailyNotesByDate, ($$value) => $$invalidate(28, $dailyNotesByDate = $$value));
component_subscribe($$self, weeklyNotes, ($$value) => $$invalidate(29, $weeklyNotes = $$value));
component_subscribe($$self, weeklyNotesByDate, ($$value) => $$invalidate(30, $weeklyNotesByDate = $$value));
component_subscribe($$self, settings, ($$value) => $$invalidate(3, $settings = $$value));
component_subscribe($$self, activeFile, ($$value) => $$invalidate(7, $activeFile = $$value));
let today = null;
let selectedDate = null;
let selectedWeek = null;
let selectionMode = "day";
let selectedNotes = [];
let panelLabel = "";
let hasSelection = false;
let { displayedMonth = null } = $$props;
let { sources } = $$props;
let { onHoverDay } = $$props;
let { onHoverWeek } = $$props;
let { onClickDay } = $$props;
let { onClickWeek } = $$props;
let { onContextMenuDay } = $$props;
let { onContextMenuWeek } = $$props;
let { onOpenDayNote } = $$props;
function tick2() {
$$invalidate(2, today = window.moment());
}
function getToday(settings2) {
configureGlobalMomentLocale(settings2.localeOverride, settings2.weekStart);
dailyNotes.reindex();
weeklyNotes.reindex();
return window.moment();
}
let heartbeat = setInterval(
() => {
tick2();
const isViewingCurrentMonth = displayedMonth.isSame(today, "day");
if (isViewingCurrentMonth) {
$$invalidate(0, displayedMonth = today);
}
},
1e3 * 60
);
onDestroy(() => {
clearInterval(heartbeat);
});
function handleClickDay(date, isMetaPressed2) {
$$invalidate(26, selectionMode = "day");
$$invalidate(24, selectedDate = date.clone());
void onClickDay(date, isMetaPressed2);
}
function handleClickWeek(date, isMetaPressed2) {
$$invalidate(26, selectionMode = "week");
$$invalidate(25, selectedWeek = date.clone());
void onClickWeek(date, isMetaPressed2);
}
function handleResetDisplayedMonth(date) {
$$invalidate(2, today = date.clone());
$$invalidate(0, displayedMonth = date.clone());
$$invalidate(26, selectionMode = "day");
$$invalidate(25, selectedWeek = null);
$$invalidate(24, selectedDate = date.clone());
const todaysNotes = getDailyNotesForDate(date, $dailyNotesByDate, $dailyNotes);
if (todaysNotes.length === 1) {
void onOpenDayNote(todaysNotes[0], false);
}
}
function handleHoverDay(date, targetEl, isMetaPressed2) {
onHoverDay(date, targetEl, isMetaPressed2 !== null && isMetaPressed2 !== void 0 ? isMetaPressed2 : false);
}
function handleHoverWeek(date, targetEl, isMetaPressed2) {
onHoverWeek(date, targetEl, isMetaPressed2 !== null && isMetaPressed2 !== void 0 ? isMetaPressed2 : false);
}
function handleContextMenuDay(date, event) {
onContextMenuDay(date, event);
return true;
}
function handleContextMenuWeek(date, event) {
onContextMenuWeek(date, event);
return true;
}
function handleOpenDayNote(event, file) {
event.preventDefault();
void onOpenDayNote(file, event.metaKey || event.ctrlKey);
}
function calendarbase_displayedMonth_binding(value) {
displayedMonth = value;
$$invalidate(0, displayedMonth), $$invalidate(2, today), $$invalidate(3, $settings);
}
const click_handler = (note, event) => handleOpenDayNote(event, note);
$$self.$$set = ($$props2) => {
if ("displayedMonth" in $$props2) $$invalidate(0, displayedMonth = $$props2.displayedMonth);
if ("sources" in $$props2) $$invalidate(1, sources = $$props2.sources);
if ("onHoverDay" in $$props2) $$invalidate(16, onHoverDay = $$props2.onHoverDay);
if ("onHoverWeek" in $$props2) $$invalidate(17, onHoverWeek = $$props2.onHoverWeek);
if ("onClickDay" in $$props2) $$invalidate(18, onClickDay = $$props2.onClickDay);
if ("onClickWeek" in $$props2) $$invalidate(19, onClickWeek = $$props2.onClickWeek);
if ("onContextMenuDay" in $$props2) $$invalidate(20, onContextMenuDay = $$props2.onContextMenuDay);
if ("onContextMenuWeek" in $$props2) $$invalidate(21, onContextMenuWeek = $$props2.onContextMenuWeek);
if ("onOpenDayNote" in $$props2) $$invalidate(22, onOpenDayNote = $$props2.onOpenDayNote);
};
$$self.$$.update = () => {
if ($$self.$$.dirty[0] & /*$settings*/
8) {
$: $$invalidate(2, today = getToday($settings));
}
if ($$self.$$.dirty[0] & /*displayedMonth, today*/
5) {
$: if (!displayedMonth && today) {
$$invalidate(0, displayedMonth = today.clone());
}
}
if ($$self.$$.dirty[0] & /*selectedDate, today*/
16777220) {
$: if (!selectedDate && today) {
$$invalidate(24, selectedDate = today.clone());
}
}
if ($$self.$$.dirty[0] & /*selectionMode, selectedWeek, $weeklyNotesByDate, $weeklyNotes, selectedDate, $dailyNotesByDate, $dailyNotes*/
2130706432) {
$: $$invalidate(4, selectedNotes = selectionMode === "week" && selectedWeek ? getWeeklyNotesForDate(selectedWeek, $weeklyNotesByDate, $weeklyNotes) : selectedDate ? getDailyNotesForDate(selectedDate, $dailyNotesByDate, $dailyNotes) : []);
}
if ($$self.$$.dirty[0] & /*selectionMode, selectedWeek, selectedDate*/
117440512) {
$: $$invalidate(6, hasSelection = selectionMode === "week" ? !!selectedWeek : !!selectedDate);
}
if ($$self.$$.dirty[0] & /*selectionMode, selectedWeek, selectedDate*/
117440512) {
$: $$invalidate(5, panelLabel = selectionMode === "week" && selectedWeek ? `${selectedWeek.format("GGGG")} \xB7 ${selectedWeek.format("[W]WW")}` : selectedDate ? selectedDate.format("LL") : "");
}
};
return [
displayedMonth,
sources,
today,
$settings,
selectedNotes,
panelLabel,
hasSelection,
$activeFile,
handleClickDay,
handleClickWeek,
handleResetDisplayedMonth,
handleHoverDay,
handleHoverWeek,
handleContextMenuDay,
handleContextMenuWeek,
handleOpenDayNote,
onHoverDay,
onHoverWeek,
onClickDay,
onClickWeek,
onContextMenuDay,
onContextMenuWeek,
onOpenDayNote,
tick2,
selectedDate,
selectedWeek,
selectionMode,
$dailyNotes,
$dailyNotesByDate,
$weeklyNotes,
$weeklyNotesByDate,
calendarbase_displayedMonth_binding,
click_handler
];
}
var Calendar2 = class extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance4,
create_fragment4,
not_equal,
{
displayedMonth: 0,
sources: 1,
onHoverDay: 16,
onHoverWeek: 17,
onClickDay: 18,
onClickWeek: 19,
onContextMenuDay: 20,
onContextMenuWeek: 21,
onOpenDayNote: 22,
tick: 23
},
null,
[-1, -1]
);
}
get tick() {
return this.$$.ctx[23];
}
};
var Calendar_default = Calendar2;
// src/ui/fileMenu.ts
var import_obsidian8 = require("obsidian");
function showFileMenu(app, file, position) {
const fileMenu = new import_obsidian8.Menu();
fileMenu.addItem(
(item) => item.setTitle("Delete").setIcon("trash").onClick(() => {
app.fileManager.promptForFileDeletion(file);
})
);
app.workspace.trigger(
"file-menu",
fileMenu,
file,
"calendar-context-menu",
null
);
fileMenu.showAtPosition(position);
}
// src/ui/sources/streak.ts
var import_obsidian_daily_notes_interface6 = __toESM(require_obsidian_daily_notes_interface());
var getStreakClasses = (file) => {
return classList({
"has-note": !!file
});
};
var streakSource = {
getDailyMetadata: (date) => {
const file = (0, import_obsidian_daily_notes_interface6.getDailyNote)(date, get_store_value(dailyNotes));
return Promise.resolve({
classes: getStreakClasses(file),
dots: []
});
},
getWeeklyMetadata: (date) => {
const file = getWeeklyNote(date, get_store_value(weeklyNotes));
return Promise.resolve({
classes: getStreakClasses(file),
dots: []
});
}
};
// src/ui/sources/tags.ts
var import_obsidian9 = require("obsidian");
var import_obsidian_daily_notes_interface7 = __toESM(require_obsidian_daily_notes_interface());
function getNoteTags(note) {
var _a;
if (!note) {
return [];
}
const { metadataCache } = window.app;
const frontmatter = (_a = metadataCache.getFileCache(note)) == null ? void 0 : _a.frontmatter;
const tags = [];
if (frontmatter) {
const frontmatterTags = (0, import_obsidian9.parseFrontMatterTags)(frontmatter) || [];
tags.push(...frontmatterTags);
}
return tags.map((tag) => tag.substring(1));
}
function getFormattedTagAttributes(note) {
const attrs = {};
const tags = getNoteTags(note);
const [emojiTags, nonEmojiTags] = partition(
tags,
(tag) => /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/.test(
tag
)
);
if (nonEmojiTags) {
attrs["data-tags"] = nonEmojiTags.join(" ");
}
if (emojiTags) {
attrs["data-emoji-tag"] = emojiTags[0];
}
return attrs;
}
var customTagsSource = {
getDailyMetadata: (date) => {
const file = (0, import_obsidian_daily_notes_interface7.getDailyNote)(date, get_store_value(dailyNotes));
return Promise.resolve({
dataAttributes: getFormattedTagAttributes(file),
dots: []
});
},
getWeeklyMetadata: (date) => {
const file = getWeeklyNote(date, get_store_value(weeklyNotes));
return Promise.resolve({
dataAttributes: getFormattedTagAttributes(file),
dots: []
});
}
};
// src/ui/sources/tasks.ts
var import_obsidian_daily_notes_interface8 = __toESM(require_obsidian_daily_notes_interface());
async function getNumberOfRemainingTasks(note) {
if (!note) {
return 0;
}
const { vault } = window.app;
const fileContents = await vault.cachedRead(note);
return (fileContents.match(/(-|\*) \[ \]/g) || []).length;
}
async function getDotsForDailyNote(dailyNote) {
if (!dailyNote) {
return [];
}
const numTasks = await getNumberOfRemainingTasks(dailyNote);
const dots = [];
if (numTasks) {
dots.push({
className: "task",
color: "default",
isFilled: false
});
}
return dots;
}
var tasksSource = {
getDailyMetadata: async (date) => {
const file = (0, import_obsidian_daily_notes_interface8.getDailyNote)(date, get_store_value(dailyNotes));
const dots = await getDotsForDailyNote(file);
return {
dots
};
},
getWeeklyMetadata: async (date) => {
const file = getWeeklyNote(date, get_store_value(weeklyNotes));
const dots = await getDotsForDailyNote(file);
return {
dots
};
}
};
// src/ui/sources/noteCount.ts
var NUM_MAX_DOTS = 5;
function getNoteCountAsDots(noteCount) {
const numSolidDots = Math.min(Math.max(noteCount, 0), NUM_MAX_DOTS);
const dots = [];
for (let i = 0; i < numSolidDots; i++) {
dots.push({
color: "default",
isFilled: true
});
}
return dots;
}
var noteCountSource = {
getDailyMetadata: (date) => {
const notes = getDailyNotesForDate(
date,
get_store_value(dailyNotesByDate),
get_store_value(dailyNotes)
);
return Promise.resolve({
dots: getNoteCountAsDots(notes.length)
});
},
getWeeklyMetadata: (date) => {
const notes = getWeeklyNotesForDate(
date,
get_store_value(weeklyNotesByDate),
get_store_value(weeklyNotes)
);
return Promise.resolve({
dots: getNoteCountAsDots(notes.length)
});
}
};
// src/view.ts
var CalendarView = class extends import_obsidian10.ItemView {
constructor(leaf, plugin) {
super(leaf);
this.calendar = null;
this.listPanel = null;
this.modeAction = null;
this.sources = [];
this.toggleMode = () => {
const next = this.getMode() === "calendar" ? "list" : "calendar";
void this.plugin.writeOptions(() => ({ sidebarViewMode: next }));
this.renderMode(next);
};
this.onHoverDay = (date, targetEl, isMetaPressed2) => {
if (!isMetaPressed2) {
return;
}
const { format } = (0, import_obsidian_daily_notes_interface9.getDailyNoteSettings)();
const note = this.getDailyNotes(date)[0];
this.app.workspace.trigger(
"link-hover",
this,
targetEl,
date.format(format),
note == null ? void 0 : note.path
);
};
this.onHoverWeek = (date, targetEl, isMetaPressed2) => {
if (!isMetaPressed2) {
return;
}
const note = getWeeklyNote(date, get_store_value(weeklyNotes));
const { format } = getWeeklyNoteSettings();
this.app.workspace.trigger(
"link-hover",
this,
targetEl,
date.format(format),
note == null ? void 0 : note.path
);
};
this.onContextMenuDay = (date, event) => {
const note = this.getDailyNotes(date)[0];
if (!note) {
return;
}
showFileMenu(this.app, note, {
x: event.pageX,
y: event.pageY
});
};
this.onContextMenuWeek = (date, event) => {
const note = getWeeklyNote(date, get_store_value(weeklyNotes));
if (!note) {
return;
}
showFileMenu(this.app, note, {
x: event.pageX,
y: event.pageY
});
};
this.onNoteSettingsUpdate = () => {
dailyNotes.reindex();
weeklyNotes.reindex();
this.updateActiveFile();
};
this.onFileDeleted = (file) => {
var _a;
const refreshedDaily = this.refreshCustomDailyNoteIndex(file);
if (!(file instanceof import_obsidian10.TFile)) {
return;
}
if (!refreshedDaily && getDayDateFromFile(file)) {
dailyNotes.reindex();
this.updateActiveFile();
}
if (((_a = this.settings) == null ? void 0 : _a.shouldIndexWeeklyNotesInAllFolders) || getWeekDateFromFile(file)) {
weeklyNotes.reindex();
this.updateActiveFile();
}
};
this.onFileModified = (file) => {
var _a;
const refreshedDaily = this.refreshCustomDailyNoteIndex(file);
if (!(file instanceof import_obsidian10.TFile)) {
return;
}
if ((_a = this.settings) == null ? void 0 : _a.shouldIndexWeeklyNotesInAllFolders) {
weeklyNotes.reindex();
if (this.calendar) {
this.calendar.tick();
}
return;
}
if (refreshedDaily) {
return;
}
const date = getDayDateFromFile(file) || getWeekDateFromFile(file);
if (date && this.calendar) {
this.calendar.tick();
}
};
this.onMetadataChanged = (file) => {
var _a, _b, _c;
if ((_a = this.settings) == null ? void 0 : _a.shouldIndexDailyNotesFromFrontmatter) {
this.refreshCustomDailyNoteIndex(file);
}
if (((_b = this.settings) == null ? void 0 : _b.shouldIndexWeeklyNotesInAllFolders) && ((_c = this.settings) == null ? void 0 : _c.shouldIndexWeeklyNotesFromFrontmatter)) {
weeklyNotes.reindex();
if (this.calendar) {
this.calendar.tick();
}
}
};
this.onFileCreated = (file) => {
var _a;
if (!this.app.workspace.layoutReady || !(this.calendar || this.listPanel)) {
return;
}
const refreshedDaily = this.refreshCustomDailyNoteIndex(file);
if (!(file instanceof import_obsidian10.TFile)) {
return;
}
if (!refreshedDaily && getDayDateFromFile(file)) {
dailyNotes.reindex();
if (this.calendar) {
this.calendar.tick();
}
}
if (((_a = this.settings) == null ? void 0 : _a.shouldIndexWeeklyNotesInAllFolders) || getWeekDateFromFile(file)) {
weeklyNotes.reindex();
if (this.calendar) {
this.calendar.tick();
}
}
};
this.onFileRenamed = (file, oldPath) => {
if (this.app.workspace.layoutReady && (this.calendar || this.listPanel) && (this.isMarkdownFile(file) || oldPath.endsWith(".md"))) {
dailyNotes.reindex();
weeklyNotes.reindex();
this.updateActiveFile();
if (this.calendar) {
this.calendar.tick();
}
}
};
this.onFileOpen = () => {
if (this.app.workspace.layoutReady) {
this.updateActiveFile();
}
};
this.openOrCreateWeeklyNote = async (date, inNewSplit) => {
const existingFiles = this.getWeeklyNotes(date);
if (!existingFiles.length) {
const startOfWeek = date.clone().startOf("week");
void tryToCreateWeeklyNote(
startOfWeek,
inNewSplit,
this.settings,
(file) => {
activeFile.setFile(file);
}
);
return;
}
if (existingFiles.length > 1) {
return;
}
await this.openDailyNoteFile(existingFiles[0], inNewSplit);
};
this.openOrCreateDailyNote = async (date, inNewSplit) => {
const existingFiles = this.getDailyNotes(date);
if (!existingFiles.length) {
void tryToCreateDailyNote(
date,
inNewSplit,
this.settings,
(dailyNote) => {
activeFile.setFile(dailyNote);
}
);
return;
}
if (existingFiles.length > 1) {
return;
}
await this.openDailyNoteFile(existingFiles[0], inNewSplit);
};
this.openDailyNoteFile = async (existingFile, inNewSplit) => {
const { workspace } = this.app;
const leaf = workspace.getLeaf(inNewSplit ? "split" : false);
await leaf.openFile(existingFile, { active: true });
activeFile.setFile(existingFile);
};
this.plugin = plugin;
this.registerEvent(
this.app.workspace.on(
"periodic-notes:settings-updated",
this.onNoteSettingsUpdate
)
);
this.registerEvent(this.app.vault.on("create", this.onFileCreated));
this.registerEvent(this.app.vault.on("delete", this.onFileDeleted));
this.registerEvent(this.app.vault.on("modify", this.onFileModified));
this.registerEvent(this.app.vault.on("rename", this.onFileRenamed));
this.registerEvent(
this.app.metadataCache.on("changed", this.onMetadataChanged)
);
this.registerEvent(this.app.workspace.on("file-open", this.onFileOpen));
this.settings = null;
settings.subscribe((val) => {
this.settings = val;
if (this.calendar) {
this.calendar.tick();
}
});
}
getViewType() {
return VIEW_TYPE_CALENDAR;
}
getDisplayText() {
return "Calendar Hub";
}
getIcon() {
return "calendar-with-checkmark";
}
onClose() {
this.destroyModeComponents();
return Promise.resolve();
}
onOpen() {
this.contentEl.addClass("calendar-hub-view-content");
this.modeAction = this.addAction(
"list",
"Switch to list view",
this.toggleMode
);
this.sources = [
customTagsSource,
streakSource,
noteCountSource,
tasksSource
];
this.app.workspace.trigger(TRIGGER_ON_OPEN, this.sources);
this.renderMode(this.getMode());
return Promise.resolve();
}
getMode() {
var _a;
return ((_a = this.settings) == null ? void 0 : _a.sidebarViewMode) === "list" ? "list" : "calendar";
}
destroyModeComponents() {
var _a, _b;
(_a = this.calendar) == null ? void 0 : _a.$destroy();
this.calendar = null;
(_b = this.listPanel) == null ? void 0 : _b.$destroy();
this.listPanel = null;
}
/** Renders the pane in place: the same leaf flips between the calendar and
* the list, so browsing does not require a second pane. */
renderMode(mode) {
this.destroyModeComponents();
this.contentEl.empty();
const navButton = this.contentEl.createDiv("nav-header calendar-hub-nav").createDiv("nav-buttons-container").createDiv({
cls: "clickable-icon nav-action-button",
attr: {
"aria-label": mode === "calendar" ? "Switch to list view" : "Switch to calendar view"
}
});
(0, import_obsidian10.setIcon)(navButton, mode === "calendar" ? "list" : "calendar");
navButton.addEventListener("click", this.toggleMode);
if (mode === "list") {
this.listPanel = new ListPanel_default({
target: this.contentEl,
props: {
onOpenNote: this.openDailyNoteFile,
onUpdateSettings: (changeOpts) => this.plugin.writeOptions(changeOpts)
}
});
} else {
this.calendar = new Calendar_default({
target: this.contentEl,
props: {
onClickDay: this.openOrCreateDailyNote,
onClickWeek: this.openOrCreateWeeklyNote,
onHoverDay: this.onHoverDay,
onHoverWeek: this.onHoverWeek,
onContextMenuDay: this.onContextMenuDay,
onContextMenuWeek: this.onContextMenuWeek,
onOpenDayNote: this.openDailyNoteFile,
sources: this.sources
}
});
}
if (this.modeAction) {
const title = mode === "calendar" ? "Switch to list view" : "Switch to calendar view";
(0, import_obsidian10.setIcon)(this.modeAction, mode === "calendar" ? "list" : "calendar");
this.modeAction.setAttribute("aria-label", title);
}
}
updateActiveFile() {
var _a;
const view = this.app.workspace.getActiveViewOfType(import_obsidian10.FileView);
activeFile.setFile((_a = view == null ? void 0 : view.file) != null ? _a : null);
if (this.calendar) {
this.calendar.tick();
}
}
revealActiveNote() {
const { moment } = window;
const view = this.app.workspace.getActiveViewOfType(import_obsidian10.FileView);
if (!(view == null ? void 0 : view.file)) {
return;
}
if (!this.calendar) {
void this.plugin.writeOptions(() => ({ sidebarViewMode: "calendar" }));
this.renderMode("calendar");
}
if (!this.calendar) {
return;
}
let date = getDayDateFromFile(view.file);
if (date) {
this.calendar.$set({ displayedMonth: date });
return;
}
const { format } = getWeeklyNoteSettings();
date = moment(view.file.basename, format, true);
if (date.isValid()) {
this.calendar.$set({ displayedMonth: date });
}
}
getWeeklyNotes(date) {
return getWeeklyNotesForDate(date, get_store_value(weeklyNotesByDate), get_store_value(weeklyNotes));
}
getDailyNotes(date) {
return getDailyNotesForDate(date, get_store_value(dailyNotesByDate), get_store_value(dailyNotes));
}
refreshCustomDailyNoteIndex(file) {
var _a;
if (!this.app.workspace.layoutReady || !(this.calendar || this.listPanel) || !((_a = this.settings) == null ? void 0 : _a.shouldIndexDailyNotesInAllFolders) || !this.isMarkdownFile(file)) {
return false;
}
dailyNotes.reindex();
this.updateActiveFile();
if (this.calendar) {
this.calendar.tick();
}
return true;
}
isMarkdownFile(file) {
return file instanceof import_obsidian10.TFile && file.extension === "md";
}
};
// src/main.ts
var CalendarPlugin = class extends import_obsidian11.Plugin {
async onload() {
this.register(
settings.subscribe((value) => {
this.options = value;
})
);
this.registerView(VIEW_TYPE_CALENDAR, (leaf) => {
return new CalendarView(leaf, this);
});
this.registerView(VIEW_TYPE_LIST, (leaf) => {
return new ListView(leaf, this);
});
this.addCommand({
id: "show-list-view",
name: "Open list view",
callback: () => this.initListLeaf()
});
this.addCommand({
id: "show-calendar-view",
name: "Open calendar view",
checkCallback: (checking) => {
if (checking) {
return this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length === 0;
}
this.initLeaf();
}
});
this.addCommand({
id: "open-weekly-note",
name: "Open weekly note",
checkCallback: (checking) => {
if (checking) {
return !appHasPeriodicNotesPluginLoaded();
}
const view = this.getCalendarView();
if (view) {
void view.openOrCreateWeeklyNote(window.moment(), false);
}
}
});
this.addCommand({
id: "reveal-active-note",
name: "Reveal active note in calendar",
callback: () => {
var _a;
return (_a = this.getCalendarView()) == null ? void 0 : _a.revealActiveNote();
}
});
await this.loadOptions();
this.addSettingTab(new CalendarSettingsTab(this.app, this));
this.app.workspace.onLayoutReady(() => this.initLeaf());
}
initListLeaf() {
var _a;
const existing = this.app.workspace.getLeavesOfType(VIEW_TYPE_LIST);
if (existing.length) {
void this.app.workspace.revealLeaf(existing[0]);
return;
}
void ((_a = this.app.workspace.getRightLeaf(false)) == null ? void 0 : _a.setViewState({
type: VIEW_TYPE_LIST,
active: true
}));
}
initLeaf() {
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length) {
return;
}
const leaf = this.app.workspace.getRightLeaf(false);
if (!leaf) {
return;
}
void leaf.setViewState({
type: VIEW_TYPE_CALENDAR
});
}
getCalendarView() {
const leaf = this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR)[0];
return (leaf == null ? void 0 : leaf.view) instanceof CalendarView ? leaf.view : null;
}
async loadOptions() {
const options = await this.loadData();
settings.update((old) => {
return {
...old,
...options || {}
};
});
await this.saveData(this.options);
}
async writeOptions(changeOpts) {
settings.update((old) => ({ ...old, ...changeOpts(old) }));
await this.saveData(this.options);
dailyNotes.reindex();
weeklyNotes.reindex();
}
};
/* nosourcemap */