Skip to content

Commit a80b710

Browse files
committed
various fixes including #390
1 parent 089bf1e commit a80b710

File tree

13 files changed

+110
-68
lines changed

13 files changed

+110
-68
lines changed

bun.lockb

440 Bytes
Binary file not shown.

exampleVault/Buttons/Button Example.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
count: 0
2+
count: 10
33
someList:
44
- 1708945050652
55
- 1709918700548
@@ -216,7 +216,7 @@ actions:
216216
- type: updateMetadata
217217
bindTarget: count
218218
evaluate: true
219-
value: x + 1
219+
value: Math.min(10, x + 1)
220220
221221
```
222222

@@ -229,7 +229,7 @@ actions:
229229
- type: updateMetadata
230230
bindTarget: count
231231
evaluate: true
232-
value: x - 1
232+
value: Math.max(0, x - 1)
233233
234234
```
235235

@@ -318,3 +318,14 @@ actions:
318318
319319
```
320320

321+
```meta-bind-button
322+
label: This is a button
323+
icon: ""
324+
hidden: false
325+
class: ""
326+
tooltip: ""
327+
id: test-id
328+
style: default
329+
actions: []
330+
331+
```

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": "LOG_TESTS=false bun test",
1313
"test:log": "LOG_TESTS=true bun test",
1414
"format": "prettier --write --plugin prettier-plugin-svelte .",
15-
"format:check": "prettier --check --plugin prettier-plugin-svelte.",
15+
"format:check": "prettier --check --plugin prettier-plugin-svelte .",
1616
"lint": "eslint --max-warnings=0 packages/**",
1717
"lint:fix": "eslint --max-warnings=0 --fix packages/**",
1818
"svelte-check": "svelte-check --compiler-warnings \"unused-export-let:ignore\"",
@@ -33,10 +33,10 @@
3333
"@happy-dom/global-registrator": "^14.12.3",
3434
"@tsconfig/svelte": "^5.0.4",
3535
"@types/bun": "^1.1.6",
36-
"@typescript-eslint/eslint-plugin": "^7.17.0",
37-
"@typescript-eslint/parser": "^7.17.0",
36+
"@typescript-eslint/eslint-plugin": "^7.18.0",
37+
"@typescript-eslint/parser": "^7.18.0",
3838
"builtin-modules": "^4.0.0",
39-
"elysia": "^1.1.4",
39+
"elysia": "^1.1.5",
4040
"esbuild": "^0.23.0",
4141
"esbuild-plugin-copy-watch": "^2.3.1",
4242
"esbuild-svelte": "^0.8.1",
@@ -49,7 +49,7 @@
4949
"prettier": "^3.3.3",
5050
"prettier-plugin-svelte": "^3.2.6",
5151
"string-argv": "^0.3.2",
52-
"svelte-check": "^3.8.4",
52+
"svelte-check": "^3.8.5",
5353
"svelte-preprocess": "^6.0.2",
5454
"tslib": "^2.6.3",
5555
"typescript": "^5.5.4",
@@ -61,7 +61,7 @@
6161
"itertools-ts": "^1.27.1",
6262
"mathjs": "^12.4.3",
6363
"moment": "^2.30.1",
64-
"svelte": "5.0.0-next.199",
64+
"svelte": "5.0.0-next.208",
6565
"zod": "^3.23.8",
6666
"zod-validation-error": "^2.1.0"
6767
},
@@ -71,6 +71,6 @@
7171
"svelte-preprocess"
7272
],
7373
"patchedDependencies": {
74-
"[email protected].199": "patches/[email protected].199.patch"
74+
"[email protected].208": "patches/[email protected].208.patch"
7575
}
7676
}

packages/core/src/fields/button/ButtonGroupMountable.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,34 @@ export class ButtonGroupMountable extends FieldMountable {
4040

4141
DomHelpers.removeAllClasses(targetEl);
4242

43-
if (!this.declaration.errorCollection.isEmpty()) {
44-
this.plugin.internal.createErrorIndicator(targetEl, {
45-
errorCollection: this.declaration.errorCollection,
46-
errorText:
47-
'Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.',
48-
warningText:
49-
'Warnings will not cause the creation of a field to fail, but they indicate that a part of the declaration was invalid or uses deprecated functionality.',
50-
code: this.declaration.declarationString,
51-
});
52-
return;
43+
if (this.declaration.errorCollection.isEmpty()) {
44+
try {
45+
this.buttonField = new ButtonGroupField(
46+
this.plugin,
47+
this.declaration.referencedButtonIds,
48+
this.getFilePath(),
49+
this.renderChildType,
50+
this.position,
51+
);
52+
this.buttonField.mount(targetEl);
53+
} catch (e) {
54+
this.errorCollection.add(e);
55+
this.renderErrorIndicator(targetEl);
56+
}
57+
} else {
58+
this.renderErrorIndicator(targetEl);
5359
}
60+
}
5461

55-
this.buttonField = new ButtonGroupField(
56-
this.plugin,
57-
this.declaration.referencedButtonIds,
58-
this.getFilePath(),
59-
this.renderChildType,
60-
this.position,
61-
);
62-
this.buttonField.mount(targetEl);
62+
private renderErrorIndicator(targetEl: HTMLElement): void {
63+
this.plugin.internal.createErrorIndicator(targetEl, {
64+
errorCollection: this.errorCollection,
65+
errorText:
66+
'Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.',
67+
warningText:
68+
'Warnings will not cause the creation of a field to fail, but they indicate that a part of the declaration was invalid or uses deprecated functionality.',
69+
code: this.declaration.declarationString,
70+
});
6371
}
6472

6573
protected onUnmount(targetEl: HTMLElement): void {

packages/core/src/fields/button/ButtonMountable.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class ButtonMountable extends FieldMountable {
3030
this.isPreview = isPreview;
3131

3232
this.errorCollection = new ErrorCollection(this.getUuid());
33+
this.errorCollection.merge(declaration.errorCollection);
3334
}
3435

3536
protected onMount(targetEl: HTMLElement): void {
@@ -38,28 +39,36 @@ export class ButtonMountable extends FieldMountable {
3839

3940
DomHelpers.removeAllClasses(targetEl);
4041

41-
if (!this.declaration.config || !this.declaration.errorCollection.isEmpty()) {
42-
this.plugin.internal.createErrorIndicator(targetEl, {
43-
errorCollection: this.declaration.errorCollection,
44-
errorText:
45-
'Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.',
46-
warningText:
47-
'Warnings will not cause the creation of a field to fail, but they indicate that a part of the declaration was invalid or uses deprecated functionality.',
48-
code: this.declaration.declarationString,
49-
});
50-
return;
42+
if (this.declaration.config && this.declaration.errorCollection.isEmpty()) {
43+
try {
44+
this.buttonField = new ButtonField(
45+
this.plugin,
46+
this.declaration.config,
47+
this.getFilePath(),
48+
RenderChildType.BLOCK,
49+
this.position,
50+
false,
51+
this.isPreview,
52+
);
53+
this.buttonField.mount(targetEl);
54+
} catch (e) {
55+
this.errorCollection.add(e);
56+
this.renderErrorIndicator(targetEl);
57+
}
58+
} else {
59+
this.renderErrorIndicator(targetEl);
5160
}
61+
}
5262

53-
this.buttonField = new ButtonField(
54-
this.plugin,
55-
this.declaration.config,
56-
this.getFilePath(),
57-
RenderChildType.BLOCK,
58-
this.position,
59-
false,
60-
this.isPreview,
61-
);
62-
this.buttonField.mount(targetEl);
63+
private renderErrorIndicator(targetEl: HTMLElement): void {
64+
this.plugin.internal.createErrorIndicator(targetEl, {
65+
errorCollection: this.errorCollection,
66+
errorText:
67+
'Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.',
68+
warningText:
69+
'Warnings will not cause the creation of a field to fail, but they indicate that a part of the declaration was invalid or uses deprecated functionality.',
70+
code: this.declaration.declarationString,
71+
});
6372
}
6473

6574
protected onUnmount(targetEl: HTMLElement): void {

packages/core/src/fields/metaBindTable/TableMountable.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { parsePropPath } from 'packages/core/src/utils/prop/PropParser';
1212
import type { Listener } from 'packages/core/src/utils/Signal';
1313
import { Signal } from 'packages/core/src/utils/Signal';
1414
import { showUnloadedMessage } from 'packages/core/src/utils/Utils';
15+
import type { Component as SvelteComponent } from 'svelte';
16+
import { mount, unmount } from 'svelte';
1517

1618
// export type MetaBindTableCell =
1719
// | {
@@ -38,11 +40,13 @@ export interface MetaBindTableRow {
3840

3941
type T = Record<string, MBExtendedLiteral>[];
4042

43+
type TableComponent = SvelteComponent<object, { updateTable(cells: MetaBindTableRow[]): void }>;
44+
4145
export class TableMountable extends FieldMountable {
4246
bindTarget: BindTargetDeclaration;
4347
tableHead: string[];
4448
columns: MetaBindColumnDeclaration[];
45-
tableComponent: MetaBindTableComponent | undefined;
49+
tableComponent: ReturnType<TableComponent> | undefined;
4650

4751
private metadataManagerOutputSignalListener: Listener<unknown> | undefined;
4852

@@ -157,7 +161,6 @@ export class TableMountable extends FieldMountable {
157161
}
158162
}
159163

160-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
161164
this.tableComponent?.updateTable(tableRows);
162165
}
163166

@@ -183,7 +186,7 @@ export class TableMountable extends FieldMountable {
183186
protected onMount(targetEl: HTMLElement): void {
184187
super.onMount(targetEl);
185188

186-
this.tableComponent = new MetaBindTableComponent({
189+
this.tableComponent = mount(MetaBindTableComponent as unknown as TableComponent, {
187190
target: targetEl,
188191
props: {
189192
table: this,
@@ -205,7 +208,9 @@ export class TableMountable extends FieldMountable {
205208
super.onUnmount(targetEl);
206209

207210
this.unregisterSelfFromMetadataManager();
208-
this.tableComponent?.$destroy();
211+
if (this.tableComponent) {
212+
unmount(this.tableComponent);
213+
}
209214

210215
showUnloadedMessage(targetEl, 'table');
211216
}

packages/core/src/utils/errors/ErrorIndicatorComponent.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import type { ErrorIndicatorProps } from 'packages/core/src/api/InternalAPI';
33
import type { IPlugin } from 'packages/core/src/IPlugin';
4+
import { onMount } from 'svelte';
45
56
const {
67
plugin,
@@ -10,6 +11,10 @@
1011
settings: ErrorIndicatorProps;
1112
} = $props();
1213
14+
onMount(() => {
15+
console.log(settings.errorCollection.otherError);
16+
});
17+
1318
function openModal(): void {
1419
plugin.internal.openErrorCollectionViewModal(settings);
1520
}

packages/obsidian/src/settings/buttonTemplateSetting/ButtonTemplatesSettingComponent.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
}
7171
7272
buttonConfigs.push(unvalidatedConfig!);
73-
74-
buttonConfigs = buttonConfigs;
7573
}
7674
7775
function save(): void {

packages/obsidian/src/settings/buttonTemplateSetting/ButtonTemplatesSettingModal.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import type { ErrorCollection } from 'packages/core/src/utils/errors/ErrorCollec
55
import { deepCopy } from 'packages/core/src/utils/Utils';
66
import type MetaBindPlugin from 'packages/obsidian/src/main';
77
import ButtonTemplatesSettingComponent from 'packages/obsidian/src/settings/buttonTemplateSetting/ButtonTemplatesSettingComponent.svelte';
8+
import type { Component as SvelteComponent } from 'svelte';
9+
import { mount, unmount } from 'svelte';
810

911
export class ButtonTemplatesSettingModal extends Modal {
1012
readonly plugin: MetaBindPlugin;
11-
private component: ButtonTemplatesSettingComponent | undefined;
13+
private component: ReturnType<SvelteComponent> | undefined;
1214

1315
constructor(app: App, plugin: MetaBindPlugin) {
1416
super(app);
@@ -18,10 +20,10 @@ export class ButtonTemplatesSettingModal extends Modal {
1820
public onOpen(): void {
1921
this.contentEl.empty();
2022
if (this.component) {
21-
this.component.$destroy();
23+
unmount(this.component);
2224
}
2325

24-
this.component = new ButtonTemplatesSettingComponent({
26+
this.component = mount(ButtonTemplatesSettingComponent, {
2527
target: this.contentEl,
2628
props: {
2729
buttonConfigs: deepCopy(this.plugin.settings.buttonTemplates),
@@ -33,7 +35,7 @@ export class ButtonTemplatesSettingModal extends Modal {
3335
public onClose(): void {
3436
this.contentEl.empty();
3537
if (this.component) {
36-
this.component.$destroy();
38+
unmount(this.component);
3739
}
3840
}
3941

packages/obsidian/src/settings/excludedFoldersSetting/ExcludedFoldersSettingModal.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { Modal } from 'obsidian';
33
import { ErrorCollection } from 'packages/core/src/utils/errors/ErrorCollection';
44
import type MetaBindPlugin from 'packages/obsidian/src/main';
55
import ExcludedFoldersSettingComponent from 'packages/obsidian/src/settings/excludedFoldersSetting/ExcludedFoldersSettingComponent.svelte';
6+
import type { Component as SvelteComponent } from 'svelte';
7+
import { mount, unmount } from 'svelte';
68

79
export class ExcludedFoldersSettingModal extends Modal {
810
private readonly plugin: MetaBindPlugin;
9-
private component: ExcludedFoldersSettingComponent | undefined;
11+
private component: ReturnType<SvelteComponent> | undefined;
1012

1113
constructor(app: App, plugin: MetaBindPlugin) {
1214
super(app);
@@ -16,10 +18,10 @@ export class ExcludedFoldersSettingModal extends Modal {
1618
public onOpen(): void {
1719
this.contentEl.empty();
1820
if (this.component) {
19-
this.component.$destroy();
21+
unmount(this.component);
2022
}
2123

22-
this.component = new ExcludedFoldersSettingComponent({
24+
this.component = mount(ExcludedFoldersSettingComponent, {
2325
target: this.contentEl,
2426
props: {
2527
excludedFolders: this.plugin.settings.excludedFolders.slice(),
@@ -32,7 +34,7 @@ export class ExcludedFoldersSettingModal extends Modal {
3234
public onClose(): void {
3335
this.contentEl.empty();
3436
if (this.component) {
35-
this.component.$destroy();
37+
unmount(this.component);
3638
}
3739
}
3840

0 commit comments

Comments
 (0)