Skip to content

Commit 94f6382

Browse files
committed
exclude folder
1 parent b251a21 commit 94f6382

18 files changed

+352
-339
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ New Features
1111
- `placeholder` input field argument
1212
- lets you define a placeholder value to be displayed in the input field, if no value is set
1313
- works on the following input fields `text`, `textArea`, `number` and `list`
14+
- specific folders can now be excluded in the setting, excluding means that the plugin will not show input or view fields in these folders
15+
- the `option` argument now allows for a name and a value, e.g. `option(value, displayName)`
16+
- numbers and booleans will now be recognized and treated as such
17+
- e.g. `option(5, 5 Stars)` will set the metadata to the number 5 instead of the string '5'
18+
- e.g. `offValue(0)` will set the metadata to the number 0 instead of the string '0'
1419

1520
Changes
1621

1722
- new parser for input fields, view fields and bind targets
1823
- input fields now display way better error messages
19-
- i tried not to introduce breaking changes, but some might have slipped through
24+
- I tried not to introduce breaking changes, but some might have slipped through
2025
- this is also why the update took so long
2126
- new API to create input field using code (e.g. using dataviewJS or [JS Engine](https://github.com/mProjectsCode/obsidian-js-engine-plugin))
2227
- this is a breaking change
@@ -25,6 +30,7 @@ Bug Fixes
2530

2631
- fixed a bug with the metadata cache when the frontmatter was invalid
2732
- fixed a bug with view fields that caused an error when referencing metadata from another file
33+
- fixed`toggle` with `offValue` sometimes showing the wrong toggle state
2834

2935
# 0.5.1
3036

src/api/API.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Component, MarkdownPostProcessorContext } from 'obsidian';
1010
import { InputFieldAPI } from './InputFieldAPI';
1111
import { UnvalidatedInputFieldDeclaration } from '../parsers/newInputFieldParser/InputFieldDeclarationValidator';
1212
import { IAPI } from './IAPI';
13+
import { ExcludedMDRC } from '../renderChildren/ExcludedMDRC';
1314

1415
export class API implements IAPI {
1516
public plugin: MetaBindPlugin;
@@ -37,7 +38,11 @@ export class API implements IAPI {
3738
filePath: string,
3839
containerEl: HTMLElement,
3940
component: Component | MarkdownPostProcessorContext
40-
): InputFieldMDRC {
41+
): InputFieldMDRC | ExcludedMDRC {
42+
if (this.plugin.isFilePathExcluded(filePath)) {
43+
return this.createExcludedField(containerEl, filePath, component);
44+
}
45+
4146
const declaration = this.newInputFieldParser.validateDeclaration(unvalidatedDeclaration);
4247

4348
const inputField = new InputFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, self.crypto.randomUUID());
@@ -52,7 +57,11 @@ export class API implements IAPI {
5257
filePath: string,
5358
containerEl: HTMLElement,
5459
component: Component | MarkdownPostProcessorContext
55-
): InputFieldMDRC {
60+
): InputFieldMDRC | ExcludedMDRC {
61+
if (this.plugin.isFilePathExcluded(filePath)) {
62+
return this.createExcludedField(containerEl, filePath, component);
63+
}
64+
5665
const declaration: InputFieldDeclaration = this.newInputFieldParser.parseString(fullDeclaration);
5766

5867
const inputField = new InputFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, self.crypto.randomUUID());
@@ -65,12 +74,16 @@ export class API implements IAPI {
6574
fullDeclaration: string,
6675
renderType: RenderChildType,
6776
filePath: string,
68-
container: HTMLElement,
77+
containerEl: HTMLElement,
6978
component: Component | MarkdownPostProcessorContext
70-
): ViewFieldMDRC {
79+
): ViewFieldMDRC | ExcludedMDRC {
80+
if (this.plugin.isFilePathExcluded(filePath)) {
81+
return this.createExcludedField(containerEl, filePath, component);
82+
}
83+
7184
const declaration: ViewFieldDeclaration = this.viewFieldParser.parseString(fullDeclaration);
7285

73-
const viewField = new ViewFieldMDRC(container, renderType, declaration, this.plugin, filePath, self.crypto.randomUUID());
86+
const viewField = new ViewFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, self.crypto.randomUUID());
7487
component.addChild(viewField);
7588

7689
return viewField;
@@ -82,12 +95,23 @@ export class API implements IAPI {
8295
filePath: string,
8396
containerEl: HTMLElement,
8497
component: Component | MarkdownPostProcessorContext
85-
): JsViewFieldMDRC {
98+
): JsViewFieldMDRC | ExcludedMDRC {
99+
if (this.plugin.isFilePathExcluded(filePath)) {
100+
return this.createExcludedField(containerEl, filePath, component);
101+
}
102+
86103
const declaration: JsViewFieldDeclaration = this.viewFieldParser.parseJsString(fullDeclaration);
87104

88105
const viewField = new JsViewFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, self.crypto.randomUUID());
89106
component.addChild(viewField);
90107

91108
return viewField;
92109
}
110+
111+
public createExcludedField(containerEl: HTMLElement, filePath: string, component: Component | MarkdownPostProcessorContext): ExcludedMDRC {
112+
const excludedField = new ExcludedMDRC(containerEl, RenderChildType.INLINE, this.plugin, filePath, self.crypto.randomUUID());
113+
component.addChild(excludedField);
114+
115+
return excludedField;
116+
}
93117
}

src/main.ts

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
6363
const isViewField = content.startsWith('VIEW[') && content.endsWith(']');
6464
if (isInputField) {
6565
const inputField = this.api.createInputFieldFromString(content, RenderChildType.INLINE, ctx.sourcePath, codeBlock, ctx);
66-
ctx.addChild(inputField);
66+
// ctx.addChild(inputField);
6767
}
6868
if (isViewField) {
6969
const viewField = this.api.createViewFieldFromString(content, RenderChildType.INLINE, ctx.sourcePath, codeBlock, ctx);
70-
ctx.addChild(viewField);
70+
// ctx.addChild(viewField);
7171
}
7272
}
7373
}, 100);
@@ -78,22 +78,16 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
7878
const isInputField = content.startsWith('INPUT[') && content.endsWith(']');
7979
if (isInputField) {
8080
const inputField = this.api.createInputFieldFromString(content, RenderChildType.BLOCK, ctx.sourcePath, codeBlock, ctx);
81-
ctx.addChild(inputField);
81+
// ctx.addChild(inputField);
8282
}
8383
});
8484

8585
this.registerMarkdownCodeBlockProcessor('meta-bind-js-view', (source, el, ctx) => {
8686
const inputField = this.api.createJsViewFieldFromString(source, RenderChildType.BLOCK, ctx.sourcePath, el, ctx);
87-
ctx.addChild(inputField);
87+
// ctx.addChild(inputField);
8888
});
8989

90-
// this.registerMarkdownCodeBlockProcessor('meta-bind-js', (source, el, ctx) => {
91-
// ctx.addChild(new ScriptMarkdownRenderChild(el, source, ctx, this));
92-
// });
93-
9490
this.registerEditorExtension(createMarkdownRenderChildWidgetEditorPlugin(this));
95-
// const languageCompartment = new Compartment();
96-
// this.registerEditorExtension(languageCompartment.of(javascript()));
9791

9892
this.addCommand({
9993
id: 'mb-debugger-command',
@@ -103,32 +97,6 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
10397
},
10498
});
10599

106-
// this.addCommand({
107-
// id: 'mb-test-command',
108-
// name: 'test command',
109-
// editorCallback: (editor: Editor, view: MarkdownView | MarkdownFileInfo) => {
110-
// if (view.file) {
111-
// this.app.fileManager.processFrontMatter(view.file, frontmatter => {
112-
// return frontmatter;
113-
// });
114-
// }
115-
// },
116-
// });
117-
118-
// if (this.settings.devMode) {
119-
// this.addCommand({
120-
// id: 'meta-bind-debug',
121-
// name: 'Trip Debugger',
122-
// callback: () => {
123-
// debugger;
124-
// },
125-
// });
126-
// }
127-
//
128-
// this.app.workspace.onLayoutReady(async () => {
129-
// await this.registerCodeMirrorMode();
130-
// });
131-
132100
this.addSettingTab(new MetaBindSettingTab(this.app, this));
133101
}
134102

@@ -159,6 +127,16 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
159127
return filePaths;
160128
}
161129

130+
isFilePathExcluded(path: string): boolean {
131+
for (const excludedFolder of this.settings.excludedFolders) {
132+
if (path.startsWith(excludedFolder)) {
133+
return true;
134+
}
135+
}
136+
137+
return false;
138+
}
139+
162140
async loadSettings(): Promise<void> {
163141
console.log(`meta-bind | Main >> settings load`);
164142

src/metadata/MetadataManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export class MetadataManager {
150150
return;
151151
}
152152

153-
console.warn(pathParts, fileCache.metadata, filePath);
154153
const { parent, child } = traverseObjectToParentByPath(pathParts, fileCache.metadata);
155154

156155
if (parent.value === undefined) {

src/renderChildren/AbstractMDRC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AbstractMDRC extends MarkdownRenderChild {
1717
plugin: MetaBindPlugin,
1818
filePath: string,
1919
uuid: string,
20-
frontmatter: any | null | undefined
20+
frontmatter?: any | null | undefined
2121
) {
2222
super(containerEl);
2323

src/renderChildren/ExcludedMDRC.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { AbstractMDRC } from './AbstractMDRC';
2+
3+
export class ExcludedMDRC extends AbstractMDRC {
4+
public onload(): void {
5+
console.log('meta-bind | ExcludedMDRC >> load', this);
6+
7+
this.containerEl.empty();
8+
9+
this.containerEl.createEl('span', { text: 'this folder has been excluded in the meta bind plugin settings', cls: 'meta-bind-plugin-error' });
10+
}
11+
}

src/renderChildren/ParserTestMDRC.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/renderChildren/ScriptMarkdownRenderChild.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)