Skip to content

Commit

Permalink
Settings change 2.0 (#77)
Browse files Browse the repository at this point in the history
* chore: add zod

* chore: add zod schemas

* feat: Switch back to storing data in `data.json` with a sync-watcher

* ♻️  chore: strictNullChecks enabled. wow. definitely a chore.

* chore: release 1.0.0-a26

Release-As: 1.0.0-a26

* 💡 chore: comment null isNaN behavior

* chore: Save audit, added debugs.

* chore: Update log message title

* chore: Begin re-enabling deleted calendar restoration

* feat: Enables restoring deleted calendars + undo/redo history in Calendar creator

* fix: can now exit creator again, oops

* fix: Fixes drag and drop jumping (close #49)

* fix: New month and weekday edit modals in creator

* fix: Remove deleted calendars > 7 days old

* chore: Remove logs

* fix: Can now delete calendars permanently from the Restore modal
  • Loading branch information
valentine195 authored Sep 20, 2023
1 parent b2c40bd commit 96cd824
Show file tree
Hide file tree
Showing 71 changed files with 2,272 additions and 1,193 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The Calendarium
# Calendarium

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
Expand Down
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"tslib": "^2.3.0",
"typescript": "^4.2.4",
"vitest": "^0.34.3",
"xmldom": "^0.6.0"
"xmldom": "^0.6.0",
"zod": "^3.22.2"
},
"dependencies": {
"@popperjs/core": "^2.10.2",
Expand Down
16 changes: 8 additions & 8 deletions src/@types/calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface StaticCalendarData {
incrementDay: boolean;
useCustomYears?: boolean;
years?: Year[];
padMonths?:number;
padDays?:number;
padMonths?: number;
padDays?: number;
}

export interface CalDate {
Expand All @@ -58,15 +58,15 @@ export interface TimeSpan {
export type BaseDay = TimeSpan & {
type: "day" | "leapday";
};
export type DefinedeDay = {
export type DefinedBaseDay = {
number: number;
};
export type Day = BaseDay & {
type: "day";
abbreviation?: string;
};
export type DefinedDay = Day &
DefinedDay & {
DefinedBaseDay & {
type: "day";
};
export type LeapDay = BaseDay & {
Expand Down Expand Up @@ -104,10 +104,10 @@ export interface IntercalaryMonth extends BaseMonth {
}
export type Month = RegularMonth | IntercalaryMonth;

interface LeapDayCondition {
ignore: boolean; //ignore offset
exclusive: boolean; //causes failure if true
interval: number; //how many years between checking
export interface LeapDayCondition {
ignore: boolean | null; //ignore offset
exclusive: boolean | null; //causes failure if true
interval: number | null; //how many years between checking
}

/**
Expand Down
36 changes: 1 addition & 35 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
export * from "./calendar";
export * from "./event";
export * from "./moons";

import type { Calendar } from "./calendar";
export * from "../schemas";

export type Nullable<T> = T | null;

export interface CalendariumData {
addToDefaultIfMissing: boolean;
calendars: Calendar[];
configDirectory: string;
dailyNotes: boolean;
dateFormat: string;
defaultCalendar: string;
eventFrontmatter: boolean;
eventPreview: boolean;
exit: {
saving: boolean;
event: boolean;
calendar: boolean;
};
parseDates: boolean;
settingsToggleState: {
calendars: boolean;
events: boolean;
advanced: boolean;
};
showIntercalary: boolean;
version: {
major: number;
minor: number;
patch: number | string;
};
debug: boolean;
askedToMoveFC: boolean;
}

export interface CalendariumCodeBlockParameters {
/** Name of the calendar you wish to display.
* If omitted, the code block will display the default calendar specified in settings.
Expand Down
9 changes: 6 additions & 3 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { get } from "svelte/store";
export class API {
constructor(private plugin: Calendarium) {}
#getStore(calendar: string | Calendar): CalendarStore {
let store: CalendarStore;
let store: CalendarStore | null = null;
if (typeof calendar === "string") {
store = this.plugin.getStore(
this.plugin.data.calendars.find((c) => c.name == calendar).id
this.plugin.data.calendars.find((c) => c.name == calendar)
?.id ?? ""
);
} else {
store = this.plugin.getStoreByCalendar(calendar);
Expand All @@ -27,7 +28,9 @@ export class API {
* @returns An instance of the Calendar API.
*/
getAPI(calendarName: string): CalendarAPI {
const calendar = this.plugin.data.calendars.find((c) => c.name == calendarName);
const calendar = this.plugin.data.calendars.find(
(c) => c.name == calendarName
);
if (!calendar)
throw new ReferenceError("No calendar store by that name exists.");
const store = this.#getStore(calendar);
Expand Down
8 changes: 4 additions & 4 deletions src/calendar/codeblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ export class CalendariumEditorSuggester extends EditorSuggest<string> {
cursor: EditorPosition,
editor: Editor,
file: TFile
): EditorSuggestTriggerInfo {
): EditorSuggestTriggerInfo | null {
const range = editor.getRange({ line: 0, ch: 0 }, cursor);

if (range.indexOf("```calendarium\n") === -1) return;
if (range.indexOf("```calendarium\n") === -1) return null;

const split = range.split("\n").reverse();

let inBlock = false;
for (const line of split) {
if (/^```$/.test(line)) return;
if (/^```$/.test(line)) return null;
if (/^```calendarium/.test(line)) {
inBlock = true;
break;
}
}
if (!inBlock) return;
if (!inBlock) return null;

const line = editor.getLine(cursor.line);
//not inside the bracket
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/event-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class ViewEventModal extends CalendariumModal {
this.contentEl.createEl("h4", { text: this.event.name });

await MarkdownRenderer.renderMarkdown(
this.event.description,
this.event.description ?? "",
this.contentEl,
this.event.note,
this.event.note ?? "",
new Component()
);
}
Expand Down
10 changes: 7 additions & 3 deletions src/calendar/ui/Calendar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
menu.addItem((item) =>
item.setTitle(calendar.name).onClick(() => {
const newStore = plugin.getStore(calendar.id);
if (!newStore)
throw new Error(
"Could not find a calendar by that name"
);
global.set(newStore);
ephemeral.set(newStore.ephemeralStore);
if (view) {
Expand All @@ -59,11 +63,11 @@
menu.showAtMouseEvent(evt);
};
$: weekForDay = $daysAsWeeks.find((w) =>
w.find((day) => day.number == $displaying.day)
);
w.find((day) => day && day.number == $displaying.day)
) ?? [];
$: weekNumber =
$daysAsWeeks.findIndex((w) =>
w.find((day) => day.number == $displaying.day)
w.find((day) => day && day.number == $displaying.day)
) +
$firstWeekNumber +
1;
Expand Down
33 changes: 19 additions & 14 deletions src/calendar/ui/Day/DayView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
$: store = $global;
$: viewing = $ephemeral.viewing;
$: if (!$viewing) viewing = $ephemeral.displaying;
$: date = dateString($viewing, $store);
$: date = dateString($viewing!, $store);
$: yearCalculator = store.yearCalculator;
$: displayedMonth = yearCalculator
.getYearFromCache($viewing.year)
.getMonthFromCache($viewing.month);
.getYearFromCache($viewing!.year)
.getMonthFromCache($viewing!.month);
$: daysBeforeMonth = displayedMonth.daysBefore;
$: daysBeforeDay = $daysBeforeMonth + $viewing.day;
$: events = store.eventStore.getEventsForDate($viewing);
$: moons = store.moonCache.getItemsOrRecalculate($viewing);
$: daysBeforeDay = $daysBeforeMonth + $viewing!.day;
$: events = store.eventStore.getEventsForDate($viewing!);
$: moons = store.moonCache.getItemsOrRecalculate($viewing!);
$: displayDayNumber = $ephemeral.displayDayNumber;
$: displayMoons = $ephemeral.displayMoons;
Expand Down Expand Up @@ -52,6 +52,9 @@
<div
use:reveal
on:click={() => {
if (!$viewing) {
viewing = $ephemeral.displaying;
}
$ephemeral.displayDate($viewing);
}}
/>
Expand Down Expand Up @@ -98,14 +101,16 @@
</div>
{/if}
{#key $events}
<Flags
events={$events}
dayView={true}
date={$viewing}
on:event-click
on:event-mouseover
on:event-context
/>
{#if $viewing}
<Flags
events={$events}
dayView={true}
date={$viewing}
on:event-click
on:event-mouseover
on:event-context
/>
{/if}
{/key}
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ui/Events/Dot.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
export let isFilled: boolean = true;
export let isActive: boolean = false;
export let color: string;
export let color: string | undefined;
</script>

<svg
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ui/Events/Flag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
};
export let flag: HTMLElement = null;
export let flag: HTMLElement | null = null;
const contextMenu = (evt: MouseEvent) => {
evt.stopPropagation();
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ui/Events/Flags.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
0
);
if (remaining < 0 && height != 0) {
target.lastElementChild.detach();
target.lastElementChild?.detach();
overflow = events.length - events.indexOf(event);
break;
} else if (remaining == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ui/Moon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export let label: boolean = true;
export let size = 28;
$: path = SHADOW_MAP[moon.phase];
$: path = SHADOW_MAP[moon.phase ?? "New Moon"];
</script>

<svg
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ui/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
/>
<div
class="reset-button calendar-clickable"
on:click={() => $ephemeral.displayDate()}
on:click={() => $ephemeral.displayDate(null)}
aria-label="Today is {$currentDisplay}"
>
<span>Today</span>
Expand Down
Loading

0 comments on commit 96cd824

Please sign in to comment.