From fde858ba4f941cb6d7f4e8a8a7299b6c8b27b38c Mon Sep 17 00:00:00 2001 From: Jeremy Valentine <38669521+valentine195@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:12:52 -0400 Subject: [PATCH] fix: Removed deprecated global app reference --- src/combatant/index.ts | 2 +- src/main.ts | 2 +- src/parser/linkify.ts | 6 ++++-- src/settings/layout/blocks/ui/Creator.svelte | 14 ++++++++------ src/settings/layout/blocks/ui/block.ts | 10 +++++----- src/view/Statblock.svelte | 14 ++++++++------ 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/combatant/index.ts b/src/combatant/index.ts index 090b8af9..3e75c398 100644 --- a/src/combatant/index.ts +++ b/src/combatant/index.ts @@ -36,7 +36,7 @@ export class CreatureView extends ItemView { }, 10) ); this.containerEl.on("click", "a.internal-link", (ev) => - app.workspace.openLinkText( + this.app.workspace.openLinkText( (ev.target as HTMLAnchorElement).dataset.href, "fantasy-statblocks" ) diff --git a/src/main.ts b/src/main.ts index 9ee9e056..33d2e664 100644 --- a/src/main.ts +++ b/src/main.ts @@ -139,7 +139,7 @@ export default class StatBlockPlugin extends Plugin { this.register(() => this.manager.unload()); Bestiary.initialize(this); - Linkifier.initialize(this.app.metadataCache); + Linkifier.initialize(this.app.metadataCache, this.app); this.register(() => Linkifier.unload()); diff --git a/src/parser/linkify.ts b/src/parser/linkify.ts index 22af1fee..44e30833 100644 --- a/src/parser/linkify.ts +++ b/src/parser/linkify.ts @@ -16,6 +16,7 @@ import { stringify } from "src/util/util"; class LinkifierClass extends Component { #cache: Map = new Map(); + app: App; #addAliasesToCache(aliases: string[], file: TFile) { for (const alias of aliases) { this.#cache.set(alias, file.name); @@ -47,13 +48,14 @@ class LinkifierClass extends Component { : null; return { alias, - file: app.metadataCache.getFirstLinkpathDest(filePath, context) + file: this.app.metadataCache.getFirstLinkpathDest(filePath, context) }; } metadataCache: MetadataCache; - initialize(metadataCache: MetadataCache) { + initialize(metadataCache: MetadataCache, app: App) { this.load(); + this.app = app; this.metadataCache = metadataCache; if (metadataCache.initialized) { this.buildCache(); diff --git a/src/settings/layout/blocks/ui/Creator.svelte b/src/settings/layout/blocks/ui/Creator.svelte index abb1c85e..d23f5f27 100644 --- a/src/settings/layout/blocks/ui/Creator.svelte +++ b/src/settings/layout/blocks/ui/Creator.svelte @@ -13,7 +13,7 @@ import { blockGenerator } from "../add"; import { getModalForBlock } from "./block"; import Rule from "src/view/ui/Rule.svelte"; - import { StatblockItem, TypeNames } from "src/layouts/layout.types"; + import { type StatblockItem, TypeNames } from "src/layouts/layout.types"; import { setNodeIcon } from "src/util"; const dispatch = createEventDispatcher(); @@ -113,7 +113,7 @@ .addItem((item) => { item.setTitle("Add") .setIcon("plus-with-circle") - .onClick((e: MouseEvent) => { + .onClick((e: MouseEvent | KeyboardEvent) => { add(block, evt); }); }) @@ -275,10 +275,12 @@
-
+ {#if block.icon} +
+ {/if}
extends EditorEnabledModal { const block = this.block; new Setting(el).setName("Link Monster Property").addText((t) => t.setValue(block.properties[0]).onChange((v) => { - block.properties[0] = v as keyof Monster; + block.properties[0] = v; }) ); } @@ -641,7 +641,7 @@ return ["The monster guesses you have: ", { text: diceText }, " freckles."]; "The dice roller will parse this property instead of the original." ) .addText((t) => { - t.setValue(block.diceProperty).onChange((v) => { + t.setValue(`${block.diceProperty}`).onChange((v) => { block.diceProperty = v as keyof Monster; }); }); @@ -810,7 +810,7 @@ class SubheadingModal extends BasicModal { new Notice("A valid property must be supplied."); return; } - block.properties.push(tempProp as keyof Monster); + block.properties.push(tempProp); this.buildProperties(el); }) ); @@ -824,7 +824,7 @@ class SubheadingModal extends BasicModal { }) } }); - sub.$on("sorted", (e: CustomEvent<(keyof Monster)[]>) => { + sub.$on("sorted", (e: CustomEvent) => { block.properties = [...e.detail]; }); } @@ -903,7 +903,7 @@ class TableModal extends BasicModal { new Notice("A valid property must be supplied."); return; } - this.block.headers.push(tempProp as keyof Monster); + this.block.headers.push(tempProp); this.buildProperties(el); }) ); diff --git a/src/view/Statblock.svelte b/src/view/Statblock.svelte index c81d4b62..9ca2a7fe 100644 --- a/src/view/Statblock.svelte +++ b/src/view/Statblock.svelte @@ -16,7 +16,7 @@ onMount, setContext } from "svelte"; - import { Writable, writable } from "svelte/store"; + import { type Writable, writable } from "svelte/store"; import type StatBlockRenderer from "./statblock"; import Bar from "./ui/Bar.svelte"; @@ -33,7 +33,7 @@ export let canSave: boolean = true; export let icons = true; - const monsterStore = writable(); + const monsterStore = writable(monster); $: $monsterStore = monster; const maxColumns = !isNaN(Number(monster.columns ?? layout.columns)) && @@ -119,9 +119,9 @@ try { await navigator.clipboard.writeText(stringifyYaml(monster)); new Notice("Creature YAML copied to clipboard"); - } catch (e) { + } catch (e: unknown) { new Notice( - `There was an issue copying the yaml:\n\n${e.message}` + `There was an issue copying the yaml:\n\n${(e as Error).message}` ); } }); @@ -149,7 +149,7 @@ const slugify = (str: string, fallback: string = "") => str?.toLowerCase().replace(/\s+/g, "-") ?? fallback; - $: name = slugify(monster.name, "no-name"); + $: name = slugify(monster.name ?? "", "no-name"); $: layoutName = slugify(layout.name, "no-layout"); const getNestedLayouts = (blocks: StatblockItem[]): string[] => { const classes: string[] = []; @@ -158,7 +158,9 @@ const layout = plugin.manager .getAllLayouts() .find((l) => l.id == block.layout); - classes.push(slugify(layout?.name)); + if (layout) { + classes.push(slugify(layout.name)); + } } if ("nested" in block) { classes.push(...getNestedLayouts(block.nested));