Skip to content

Commit

Permalink
fix #487
Browse files Browse the repository at this point in the history
  • Loading branch information
mProjectsCode committed Dec 22, 2024
1 parent 7bd954c commit 47f146c
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 37 deletions.
Binary file modified bun.lockb
Binary file not shown.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@
"@tsconfig/svelte": "^5.0.4",
"@types/bun": "^1.1.14",
"builtin-modules": "^4.0.0",
"elysia": "^1.1.25",
"esbuild": "^0.24.0",
"elysia": "^1.1.26",
"esbuild": "^0.24.2",
"esbuild-plugin-copy-watch": "^2.3.1",
"esbuild-svelte": "^0.8.2",
"eslint": "^9.15.0",
"eslint": "^9.17.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-isaacscript": "^4.0.0",
"eslint-plugin-no-relative-import-paths": "^1.5.5",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-svelte": "^2.46.0",
"prettier": "^3.4.0",
"eslint-plugin-svelte": "^2.46.1",
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"string-argv": "^0.3.2",
"svelte-check": "^4.1.0",
"svelte-check": "^4.1.1",
"svelte-preprocess": "^6.0.3",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0",
"typescript-eslint": "^8.18.1",
"yaml": "^2.6.1"
},
"dependencies": {
"@codemirror/legacy-modes": "^6.4.2",
"@lemons_dev/parsinom": "^0.0.12",
"itertools-ts": "^1.27.1",
"mathjs": "^14.0.0",
"itertools-ts": "^1.28.0",
"mathjs": "^14.0.1",
"moment": "^2.30.1",
"svelte": "^5.2.8",
"zod": "^3.23.8",
"svelte": "^5.15.0",
"zod": "^3.24.1",
"zod-validation-error": "^3.4.0"
},
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/button/ButtonField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class ButtonField extends Mountable {

protected onUnmount(): void {
if (this.buttonComponent) {
unmount(this.buttonComponent);
void unmount(this.buttonComponent);
}

if (!this.isInline && !this.isPreview) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/fields/button/ButtonGroupField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ButtonGroupField extends Mountable {
buttonId,
(buttonConfig: ButtonConfig) => {
if (initialButton) {
unmount(initialButton);
void unmount(initialButton);
}
initialButton = undefined;
button = new ButtonField(
Expand All @@ -89,7 +89,7 @@ export class ButtonGroupField extends Mountable {

this.registerUnmountCb(() => {
if (initialButton) {
unmount(initialButton);
void unmount(initialButton);
}
initialButton = undefined;
button?.unmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class InputFieldSvelteWrapper<Value, SvelteExports = object> {
*/
public unmount(): void {
if (this.svelteComponentInstance) {
unmount(this.svelteComponentInstance);
void unmount(this.svelteComponentInstance);
}

this.mounted = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/metaBindTable/TableMountable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class TableMountable extends FieldMountable {

this.unregisterSelfFromMetadataManager();
if (this.tableComponent) {
unmount(this.tableComponent);
void unmount(this.tableComponent);
}

showUnloadedMessage(targetEl, 'table');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/fields/viewFields/fields/ImageVF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class ImageVF extends AbstractViewField<string> {
protected async onRerender(container: HTMLElement, value: string | undefined): Promise<void> {
const linkList = value ? MDLinkParser.parseLinkList(value) : [];
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
this.component = mount(ImageGrid, {
target: container,
Expand All @@ -98,7 +98,7 @@ export class ImageVF extends AbstractViewField<string> {
super.onUnmount();

if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/fields/viewFields/fields/LinkVF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class LinkVF extends AbstractViewField<string> {
super.onUnmount();

if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SvelteModalContent<T extends SvelteComponent> extends ModalContent

protected onUnmount(targetEl: HTMLElement): void {
if (this.component) {
unmount(this.component);
void unmount(this.component);
}

DomHelpers.empty(targetEl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ButtonBuilderModal extends ModalContent {
protected onMount(targetEl: HTMLElement): void {
DomHelpers.empty(targetEl);
if (this.component) {
unmount(this.component);
void unmount(this.component);
}

this.component = mount(ButtonBuilderModalComponent, {
Expand All @@ -44,7 +44,7 @@ export class ButtonBuilderModal extends ModalContent {
protected onUnmount(targetEl: HTMLElement): void {
DomHelpers.empty(targetEl);
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/utils/Mountable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export abstract class Mountable {
*/
public mount(targetEl: HTMLElement): void {
if (this.mounted || this.targetEl) {
throw new Error('Mountable is already mounted');
console.warn('Mountable is already mounted', this);
return;
}

if (targetEl === undefined) {
console.error('Mountable target element is undefined', this);
return;
}

this.mounted = true;
Expand All @@ -60,11 +66,11 @@ export abstract class Mountable {

/**
* Unmount the mountable from the current element.
* Will throw an error if the mountable is not mounted.
*/
public unmount(): void {
if (!this.mounted || !this.targetEl) {
throw new Error('Mountable is not mounted');
console.warn('Mountable is not mounted', this);
return;
}

this.mounted = false;
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/utils/components/MountableComponent.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<script lang="ts">
import type { Mountable } from 'packages/core/src/utils/Mountable';
import { onDestroy, onMount } from 'svelte';
import { onDestroy } from 'svelte';
const {
let {
mountable,
}: {
mountable: Mountable;
} = $props();
let element: HTMLElement;
let current: Mountable | undefined;
onMount(() => {
mountable.mount(element);
$effect(() => {
current?.unmount();
current = mountable;
current.mount(element);
});
onDestroy(() => {
mountable.unmount();
current?.unmount();
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion packages/obsidian/src/playground/PlaygroundView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class PlaygroundView extends ItemView {

async onClose(): Promise<void> {
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ButtonTemplatesSettingModal extends Modal {
public onOpen(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}

this.component = mount(ButtonTemplatesSettingComponent, {
Expand All @@ -35,7 +35,7 @@ export class ButtonTemplatesSettingModal extends Modal {
public onClose(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ExcludedFoldersSettingModal extends Modal {
public onOpen(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}

this.component = mount(ExcludedFoldersSettingComponent, {
Expand All @@ -34,7 +34,7 @@ export class ExcludedFoldersSettingModal extends Modal {
public onClose(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class InputFieldTemplatesSettingModal extends Modal {
public onOpen(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}

this.component = mount(InputFieldTemplatesSettingComponent, {
Expand All @@ -35,7 +35,7 @@ export class InputFieldTemplatesSettingModal extends Modal {
public onClose(): void {
this.contentEl.empty();
if (this.component) {
unmount(this.component);
void unmount(this.component);
}
}

Expand Down

0 comments on commit 47f146c

Please sign in to comment.