Skip to content

Commit a222b00

Browse files
committed
some internal changes
1 parent 577f119 commit a222b00

24 files changed

+143
-175
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Obsidian Meta Bind Changelog
22

3+
# 1.0.4
4+
5+
Changes
6+
7+
- Slightly improved the syncing algorithm and reduced the amount of unnecessary updates
8+
9+
Bug Fixes
10+
11+
- Fixed some issues with the `replaceSelf` button action not replacing the correct lines when the button was moved by some change in the part of the note above the button
12+
- Fixed some unusable API functions for creating meta bind tables, as the required arguments weren't possible to create just using the API
13+
314
# 1.0.3
415

516
Bug Fixes

packages/core/src/IPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { type MetaBindPluginSettings } from 'packages/core/src/Settings';
22
import { type API } from 'packages/core/src/api/API';
33
import { type InternalAPI } from 'packages/core/src/api/InternalAPI';
44
import { type MetadataManager } from 'packages/core/src/metadata/MetadataManager';
5+
import { type MountableManager } from 'packages/core/src/MountableManager';
56

67
export interface IPlugin {
78
readonly api: API<IPlugin>;
89
readonly internal: InternalAPI<IPlugin>;
910
readonly metadataManager: MetadataManager;
11+
readonly mountableManager: MountableManager;
1012

1113
settings: MetaBindPluginSettings;
1214
}

packages/core/src/MountableManager.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { type FieldMountable } from 'packages/core/src/fields/FieldMountable';
2+
3+
export class MountableManager {
4+
activeMountables: Map<string, FieldMountable>;
5+
6+
constructor() {
7+
this.activeMountables = new Map<string, FieldMountable>();
8+
}
9+
10+
unloadFile(filePath: string): void {
11+
for (const mountable of this.activeMountables.values()) {
12+
if (mountable.getFilePath() === filePath) {
13+
console.debug(`meta-bind | MountableManager >> unregistered Mountable ${mountable.getUuid()}`);
14+
mountable.unmount();
15+
}
16+
}
17+
}
18+
19+
unload(): void {
20+
for (const mountable of this.activeMountables.values()) {
21+
console.debug(`meta-bind | MountableManager >> unregistered Mountable ${mountable.getUuid()}`);
22+
mountable.unmount();
23+
}
24+
}
25+
26+
registerMountable(mountable: FieldMountable): void {
27+
console.debug(`meta-bind | MountableManager >> registered Mountable ${mountable.getUuid()}`);
28+
this.activeMountables.set(mountable.getUuid(), mountable);
29+
}
30+
31+
unregisterMountable(mountable: FieldMountable): void {
32+
console.debug(`meta-bind | MountableManager >> unregistered Mountable ${mountable.getUuid()}`);
33+
this.activeMountables.delete(mountable.getUuid());
34+
}
35+
}

packages/core/src/api/Validators.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
type UnvalidatedFieldArgument,
4444
} from 'packages/core/src/parsers/nomParsers/FieldArgumentNomParsers';
4545
import { FieldMountable } from 'packages/core/src/fields/FieldMountable';
46+
import { Mountable } from 'packages/core/src/utils/Mountable';
4647

4748
export const V_FilePath = schemaForType<string>()(z.string());
4849

@@ -61,6 +62,7 @@ export const V_Signal = schemaForType<Signal<unknown>>()(z.instanceof(Signal));
6162
export const V_VoidFunction = schemaForType<() => void>()(z.function().args().returns(z.void()));
6263

6364
export const V_FieldMountable = schemaForType<FieldMountable>()(z.instanceof(FieldMountable));
65+
export const V_Mountable = schemaForType<Mountable>()(z.instanceof(Mountable));
6466

6567
export const V_NotePosition = schemaForType<NotePosition>()(z.instanceof(NotePosition));
6668

packages/core/src/fields/FieldMountable.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ export abstract class FieldMountable extends Mountable {
2121
getFilePath(): string {
2222
return this.filePath;
2323
}
24+
25+
protected onMount(_targetEl: HTMLElement): void {
26+
this.plugin.mountableManager.registerMountable(this);
27+
}
28+
29+
protected onUnmount(_targetEl: HTMLElement): void {
30+
this.plugin.mountableManager.unregisterMountable(this);
31+
}
2432
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class ButtonGroupMountable extends FieldMountable {
3636

3737
protected onMount(targetEl: HTMLElement): void {
3838
console.debug('meta-bind | ButtonGroupMountable >> mount', this.declaration);
39+
super.onMount(targetEl);
3940

4041
DomHelpers.removeAllClasses(targetEl);
4142

@@ -63,6 +64,7 @@ export class ButtonGroupMountable extends FieldMountable {
6364

6465
protected onUnmount(targetEl: HTMLElement): void {
6566
console.debug('meta-bind | ButtonGroupMountable >> destroy', this.declaration);
67+
super.onUnmount(targetEl);
6668

6769
this.buttonField?.unmount();
6870

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class ButtonMountable extends FieldMountable {
3333

3434
protected onMount(targetEl: HTMLElement): void {
3535
console.debug('meta-bind | ButtonMountable >> mount', this.declaration.declarationString);
36+
super.onMount(targetEl);
3637

3738
DomHelpers.removeAllClasses(targetEl);
3839

@@ -61,6 +62,7 @@ export class ButtonMountable extends FieldMountable {
6162

6263
protected onUnmount(targetEl: HTMLElement): void {
6364
console.debug('meta-bind | ButtonMountable >> destroy', this.declaration.declarationString);
65+
super.onUnmount(targetEl);
6466

6567
this.buttonField?.unmount();
6668

packages/core/src/fields/embed/EmbedMountable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ export class EmbedMountable extends FieldMountable {
9292

9393
protected onMount(targetEl: HTMLElement): void {
9494
console.debug('meta-bind | EmbedMountable >> mount', this.content);
95+
super.onMount(targetEl);
9596

9697
void this.renderContent(targetEl);
9798
}
9899

99100
protected onUnmount(targetEl: HTMLElement): void {
100101
console.debug('meta-bind | EmbedMountable >> unmount', this.content);
102+
super.onUnmount(targetEl);
101103

102104
this.markdownUnloadCallback?.();
103105

packages/core/src/fields/excluded/ExcludedMountable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ExcludedMountable extends FieldMountable {
99

1010
protected onMount(targetEl: HTMLElement): void {
1111
console.debug('meta-bind | ExcludedMountable >> mount');
12+
super.onMount(targetEl);
1213

1314
DomHelpers.empty(targetEl);
1415

@@ -20,6 +21,7 @@ export class ExcludedMountable extends FieldMountable {
2021

2122
protected onUnmount(targetEl: HTMLElement): void {
2223
console.debug('meta-bind | ExcludedMountable >> unmount');
24+
super.onUnmount(targetEl);
2325

2426
DomHelpers.empty(targetEl);
2527

packages/core/src/fields/inputFields/InputFieldMountable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class InputFieldMountable extends FieldMountable {
132132

133133
protected onMount(targetEl: HTMLElement): void {
134134
console.debug('meta-bind | InputFieldMountable >> mount', this.declaration);
135+
super.onMount(targetEl);
135136

136137
DomHelpers.empty(targetEl);
137138
DomHelpers.addClass(targetEl, 'mb-input');
@@ -168,6 +169,7 @@ export class InputFieldMountable extends FieldMountable {
168169

169170
protected onUnmount(targetEl: HTMLElement): void {
170171
console.debug('meta-bind | InputFieldMountable >> unmount', this.declaration);
172+
super.onUnmount(targetEl);
171173

172174
this.inputField?.destroy();
173175

0 commit comments

Comments
 (0)