Skip to content

Commit

Permalink
fix: Removed deprecated global app reference
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Sep 11, 2024
1 parent 26f5355 commit fde858b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/combatant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
6 changes: 4 additions & 2 deletions src/parser/linkify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { stringify } from "src/util/util";

class LinkifierClass extends Component {
#cache: Map<string, string> = new Map();
app: App;
#addAliasesToCache(aliases: string[], file: TFile) {
for (const alias of aliases) {
this.#cache.set(alias, file.name);
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 8 additions & 6 deletions src/settings/layout/blocks/ui/Creator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -113,7 +113,7 @@
.addItem((item) => {
item.setTitle("Add")
.setIcon("plus-with-circle")
.onClick((e: MouseEvent) => {
.onClick((e: MouseEvent | KeyboardEvent) => {
add(block, evt);
});
})
Expand Down Expand Up @@ -275,10 +275,12 @@
<div
class="action-container statblock-creator-container"
>
<div
class="action-icon"
use:setNodeIcon={block.icon}
/>
{#if block.icon}
<div
class="action-icon"
use:setNodeIcon={block.icon}
/>
{/if}
<div class="icons">
<div
class="icon"
Expand Down
10 changes: 5 additions & 5 deletions src/settings/layout/blocks/ui/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class BasicModal<I extends BasicItem> extends EditorEnabledModal<I> {
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;
})
);
}
Expand Down Expand Up @@ -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;
});
});
Expand Down Expand Up @@ -810,7 +810,7 @@ class SubheadingModal extends BasicModal<SubHeadingItem> {
new Notice("A valid property must be supplied.");
return;
}
block.properties.push(tempProp as keyof Monster);
block.properties.push(tempProp);
this.buildProperties(el);
})
);
Expand All @@ -824,7 +824,7 @@ class SubheadingModal extends BasicModal<SubHeadingItem> {
})
}
});
sub.$on("sorted", (e: CustomEvent<(keyof Monster)[]>) => {
sub.$on("sorted", (e: CustomEvent<string[]>) => {
block.properties = [...e.detail];
});
}
Expand Down Expand Up @@ -903,7 +903,7 @@ class TableModal extends BasicModal<TableItem> {
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);
})
);
Expand Down
14 changes: 8 additions & 6 deletions src/view/Statblock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)) &&
Expand Down Expand Up @@ -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}`
);
}
});
Expand Down Expand Up @@ -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[] = [];
Expand All @@ -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));
Expand Down

0 comments on commit fde858b

Please sign in to comment.