Skip to content

Commit c2166b4

Browse files
committed
even better error messages part 3 and faq page
1 parent c223682 commit c2166b4

File tree

15 files changed

+249
-22
lines changed

15 files changed

+249
-22
lines changed

exampleVault/View Fields/View Field.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ Self Loop Error: `VIEW[**{computed}**][text():computed]`
5050
`INPUT[suggester(optionQuery(#example-note), useLinks(false)):file]`
5151
`VIEW[\[\[{file}|link\]\]][text(renderMarkdown)]`
5252

53-
`INPUT[imageSuggester(optionQuery("Other/Images")):image]`
53+
```meta-bind
54+
INPUT[imageSuggester(optionQuery("Other/Images")):image]
55+
```
5456
`VIEW[!\[\[{image}\]\]][text(renderMarkdown)]`
5557

5658
## Arrays and Objects
@@ -61,4 +63,8 @@ Plain Text:
6163

6264
Markdown:
6365
`VIEW[**{list}**][text(renderMarkdown)]`
64-
`VIEW[**{object}**][text(renderMarkdown)]`
66+
`VIEW[**{object}**][text(renderMarkdown)]`
67+
68+
Null:
69+
`VIEW[{someUnknownValue}][text]`
70+
some text

exampleVault/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slider1: 4
2+
slider1: 6
33
suggest: test
44
toggle1: false
55
Domestic_tasks:

src/inputFields/fields/DatePicker/DatePickerComponent.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<style>
3131
.date-picker-input {
32-
background: var(--background-secondary);
32+
background: var(--background-modifier-form-field);
3333
border-radius: var(--mb-border-radius);
3434
border: var(--mb-border-width) solid var(--background-modifier-border);
3535
padding: 5px 5px 5px 7px;

src/main.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type MarkdownPostProcessorContext, Plugin } from 'obsidian';
1+
import { type MarkdownPostProcessorContext, Plugin, type WorkspaceLeaf } from 'obsidian';
22
import { MetaBindSettingTab } from './settings/SettingsTab';
33
import { RenderChildType } from './renderChildren/InputFieldMDRC';
44
import { DateParser } from './parsers/DateParser';
@@ -12,6 +12,7 @@ import { type IPlugin } from './IPlugin';
1212
import { EnclosingPair, ParserUtils } from './utils/ParserUtils';
1313
import { ErrorLevel, MetaBindParsingError } from './utils/errors/MetaBindErrors';
1414
import { ObsidianMetadataAdapter } from './metadata/ObsidianMetadataAdapter';
15+
import { FaqView, MB_FAQ_VIEW_TYPE } from './utils/faq/FaqView';
1516

1617
export default class MetaBindPlugin extends Plugin implements IPlugin {
1718
// @ts-ignore defined in `onload`
@@ -104,6 +105,16 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
104105
},
105106
});
106107

108+
this.addCommand({
109+
id: 'mb-open-faq',
110+
name: 'Open Meta Bind FAQ',
111+
callback: () => {
112+
void this.activateView(MB_FAQ_VIEW_TYPE);
113+
},
114+
});
115+
116+
this.registerView(MB_FAQ_VIEW_TYPE, leaf => new FaqView(leaf));
117+
107118
this.addSettingTab(new MetaBindSettingTab(this.app, this));
108119
}
109120

@@ -206,4 +217,24 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
206217

207218
return oldSettings;
208219
}
220+
221+
async activateView(viewType: string): Promise<void> {
222+
const { workspace } = this.app;
223+
224+
let leaf: WorkspaceLeaf | null = null;
225+
const leaves = workspace.getLeavesOfType(viewType);
226+
227+
if (leaves.length > 0) {
228+
// A leaf with our view already exists, use that
229+
leaf = leaves[0];
230+
} else {
231+
// Our view could not be found in the workspace, create a new leaf
232+
// in the right sidebar for it
233+
leaf = workspace.getLeaf('tab');
234+
await leaf.setViewState({ type: viewType, active: true });
235+
}
236+
237+
// "Reveal" the leaf in case it is in a collapsed sidebar
238+
workspace.revealLeaf(leaf);
239+
}
209240
}

src/metadata/MetadataManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class MetadataManager {
205205
errorLevel: ErrorLevel.ERROR,
206206
effect: 'bind target dependency loop detected',
207207
cause: `the loop is as follows: ${dependencyPath.map(x => `"${bindTargetToString(x.bindTarget)}"`).join(' -> ')}`,
208+
docs: ['https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/guides/viewfields/#circular-dependencies'],
208209
});
209210
}
210211

src/settings/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface MetaBindPluginSettings {
5454
maxSyncInterval: number;
5555
minSyncInterval: number;
5656
enableJs: boolean;
57+
viewFieldDisplayNullAsEmpty: boolean;
5758

5859
inputFieldTemplates: InputFieldTemplate[];
5960
excludedFolders: string[];
@@ -77,6 +78,7 @@ export const DEFAULT_SETTINGS: MetaBindPluginSettings = {
7778
minSyncInterval: 50,
7879
maxSyncInterval: 1000,
7980
enableJs: false,
81+
viewFieldDisplayNullAsEmpty: false,
8082

8183
inputFieldTemplates: [],
8284
excludedFolders: ['templates'],

src/settings/SettingsTab.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type MetaBindPlugin from '../main';
33
import { DEFAULT_SETTINGS, weekdays } from './Settings';
44
import { ExcludedFoldersSettingModal } from './excludedFoldersSetting/ExcludedFoldersSettingModal';
55
import { InputFieldTemplatesSettingModal } from './inputFieldTemplateSetting/InputFieldTemplatesSettingModal';
6+
import { DocsHelper } from '../utils/DocsHelper';
7+
import { MB_FAQ_VIEW_TYPE } from '../utils/faq/FaqView';
68

79
export class MetaBindSettingTab extends PluginSettingTab {
810
plugin: MetaBindPlugin;
@@ -23,19 +25,25 @@ export class MetaBindSettingTab extends PluginSettingTab {
2325
cb.setCta();
2426
cb.setButtonText('Docs');
2527
cb.onClick(() => {
26-
window.open('https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/', '_blank');
28+
DocsHelper.open(DocsHelper.linkToHome());
29+
});
30+
})
31+
.addButton(cb => {
32+
cb.setButtonText('Open FAQ');
33+
cb.onClick(() => {
34+
void this.plugin.activateView(MB_FAQ_VIEW_TYPE);
2735
});
2836
})
2937
.addButton(cb => {
3038
cb.setButtonText('GitHub');
3139
cb.onClick(() => {
32-
window.open('https://github.com/mProjectsCode/obsidian-meta-bind-plugin', '_blank');
40+
DocsHelper.open(DocsHelper.linkToGithub());
3341
});
3442
})
3543
.addButton(cb => {
3644
cb.setButtonText('Report Issue');
3745
cb.onClick(() => {
38-
window.open('https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues', '_blank');
46+
DocsHelper.open(DocsHelper.linkToIssues());
3947
});
4048
});
4149

@@ -119,6 +127,17 @@ export class MetaBindSettingTab extends PluginSettingTab {
119127
});
120128
});
121129

130+
new Setting(containerEl)
131+
.setName('View Fields display null as empty')
132+
.setDesc('Display nothing instead of null, if the frontmatter value is empty, in text view fields.')
133+
.addToggle(cb => {
134+
cb.setValue(this.plugin.settings.viewFieldDisplayNullAsEmpty);
135+
cb.onChange(data => {
136+
this.plugin.settings.viewFieldDisplayNullAsEmpty = data;
137+
void this.plugin.saveSettings();
138+
});
139+
});
140+
122141
new Setting(containerEl)
123142
.setName('Enable JS Input Fields')
124143
.setDesc("Enable the processing of JavaScript input fields. This is potentially DANGEROUS, thus it's disabled by default. RESTART REQUIRED.")

src/utils/DocsHelper.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,31 @@ export class DocsHelper {
1717
return `https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/reference/viewfieldarguments/${type.toLowerCase()}/`;
1818
}
1919

20+
static linkToInputFields(): string {
21+
return `https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/guides/inputfields/`;
22+
}
23+
24+
static linkToViewFields(): string {
25+
return `https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/guides/viewfields/`;
26+
}
27+
2028
static linkToSearch(search: string): string {
2129
return `https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/?s=${encodeURIComponent(search)}`;
2230
}
31+
32+
static linkToHome(): string {
33+
return `https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs/`;
34+
}
35+
36+
static linkToGithub(): string {
37+
return `https://github.com/mProjectsCode/obsidian-meta-bind-plugin`;
38+
}
39+
40+
static linkToIssues(): string {
41+
return `https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues`;
42+
}
43+
44+
static open(link: string): void {
45+
window.open(link, '_blank');
46+
}
2347
}

src/utils/Literal.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,18 @@ export function parseUnknownToLiteral(literal: unknown): MBLiteral | undefined {
140140
* Turns a value into a pretty string. Objects get turned to JSON.
141141
*
142142
* @param literal
143+
* @param nullAsEmpty
143144
*/
144-
export function stringifyUnknown(literal: unknown): string {
145+
export function stringifyUnknown(literal: unknown, nullAsEmpty: boolean): string {
145146
if (Array.isArray(literal)) {
146-
return literal.map(x => recStringifyUnknown(x)).join(', ');
147+
return literal.map(x => recStringifyUnknown(x, nullAsEmpty)).join(', ');
147148
}
148-
return recStringifyUnknown(literal);
149+
return recStringifyUnknown(literal, nullAsEmpty);
149150
}
150151

151-
function recStringifyUnknown(literal: unknown): string {
152+
function recStringifyUnknown(literal: unknown, nullAsEmpty: boolean): string {
152153
if (typeof literal === 'object') {
153154
return JSON.stringify(literal);
154155
}
155-
return literal?.toString() ?? 'null';
156+
return literal?.toString() ?? (nullAsEmpty ? '' : 'null');
156157
}

src/utils/errors/ErrorCollectionComponent.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
<p><code class="language-none meta-bind-none">{declaration}</code></p>
1111
{/if}
1212

13+
{#if errorCollection.hasErrors()}
14+
<h6>Errors</h6>
15+
<p>Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.</p>
16+
{#each errorCollection.getErrors() as error}
17+
<MetaBindErrorComponent error={error}></MetaBindErrorComponent>
18+
{/each}
19+
{/if}
1320
{#if errorCollection.hasWarnings()}
1421
<h6>Warnings</h6>
1522
<p>
@@ -19,10 +26,3 @@
1926
<MetaBindErrorComponent error={warning}></MetaBindErrorComponent>
2027
{/each}
2128
{/if}
22-
{#if errorCollection.hasErrors()}
23-
<h6>Errors</h6>
24-
<p>Errors caused the creation of the field to fail. Sometimes one error only occurs because of another.</p>
25-
{#each errorCollection.getErrors() as error}
26-
<MetaBindErrorComponent error={error}></MetaBindErrorComponent>
27-
{/each}
28-
{/if}

0 commit comments

Comments
 (0)