Skip to content

Commit cc8b286

Browse files
committed
minor changes
1 parent 79733bf commit cc8b286

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

exampleVault/Advanced Use-Cases.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
list:
3+
- 1
4+
- 2
5+
- 3
6+
index: 0
7+
options:
8+
- "1"
9+
- "2"
10+
- "3"
11+
selected: 1
12+
---
13+
14+
## Changing the Bind Target
15+
16+
The `index` determines the element of the `list` array that the number input field binds to.
17+
18+
Index: `INPUT[inlineSelect(option(0), option(1), option(2)):index]`
19+
20+
```meta-bind-js-view
21+
{index} as index
22+
---
23+
const str = `\`INPUT[number:list[${context.bound.index}]]\``;
24+
return engine.markdown.create(str)
25+
```
26+
27+
## Generating a list of Options from Front-matter
28+
29+
`INPUT[inlineList:options]`
30+
31+
```meta-bind-js-view
32+
{options} as options
33+
---
34+
const options = context.bound.options.map(x => `option(${x})`).join(", ");
35+
const str = `\`INPUT[inlineSelect(${options}):selected]\``;
36+
return engine.markdown.create(str);
37+
```

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type MarkdownPostProcessorContext, Plugin, stringifyYaml, type WorkspaceLeaf } from 'obsidian';
1+
import { loadPrism, type MarkdownPostProcessorContext, Plugin, stringifyYaml, type WorkspaceLeaf } from 'obsidian';
22
import { MetaBindSettingTab } from './settings/SettingsTab';
33
import { DateParser } from './parsers/DateParser';
44
import { MetadataManager } from './metadata/MetadataManager';
@@ -8,7 +8,6 @@ import { createMarkdownRenderChildWidgetEditorPlugin } from './cm6/Cm6_ViewPlugi
88
import { MDRCManager } from './MDRCManager';
99
import { DEFAULT_SETTINGS, type MetaBindPluginSettings } from './settings/Settings';
1010
import { type IPlugin } from './IPlugin';
11-
// import { ObsidianMetadataAdapter } from './metadata/ObsidianMetadataAdapter';
1211
import { FaqView, MB_FAQ_VIEW_TYPE } from './faq/FaqView';
1312
import { EMBED_MAX_DEPTH, EmbedMDRC } from './renderChildren/EmbedMDRC';
1413
import { getUUID } from './utils/Utils';
@@ -106,6 +105,9 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
106105
}),
107106
);
108107
}
108+
109+
// we need to wait for prism to load first, otherwise prism will cause problems by highlighting things that it shouldn't
110+
await loadPrism();
109111
}
110112

111113
onunload(): void {

src/metadata/MetadataManager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ export class MetadataManager {
791791
const cacheItem = source.subscribe(subscription);
792792
cacheItem.inactive = false;
793793
cacheItem.cyclesSinceInactive = 0;
794+
795+
// TODO: remove
796+
console.log('meta-bind | MetadataManager >> subscribed', subscription, cacheItem);
797+
794798
subscription.notify(source.readCacheItem(cacheItem, subscription.bindTarget.storageProp));
795799
}
796800

@@ -904,11 +908,10 @@ export class MetadataManager {
904908
if (cacheItem.pendingInternalChange) {
905909
try {
906910
source.syncExternal(cacheItem);
907-
cacheItem.pendingInternalChange = false;
908911
} catch (e) {
909-
cacheItem.pendingInternalChange = false;
910912
console.warn('failed to update frontmatter', e);
911913
}
914+
cacheItem.pendingInternalChange = false;
912915
}
913916
cacheItem.cyclesSinceInternalChange += 1;
914917

src/metadata/ObsidianMetadataSource.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export class ObsidianMetadataSource extends FilePathMetadataSource<ObsidianMetad
3636

3737
const frontmatter = this.plugin.app.metadataCache.getFileCache(file)?.frontmatter;
3838

39+
// TODO: remove
40+
console.log('meta-bind | Obs Source >> default cache', structuredClone(frontmatter), storagePath);
41+
3942
return {
4043
data: structuredClone(frontmatter) ?? {},
4144
storagePath: storagePath,

src/renderChildren/InputFieldMDRC.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ export class InputFieldMDRC extends AbstractMDRC implements IInputFieldBase {
148148
this.containerEl.addClass('mb-input');
149149
this.containerEl.empty();
150150

151+
// const observer = new MutationObserver(mutations => {
152+
// console.trace('meta-bind | InputFieldMDRC >> MutationObserver', mutations);
153+
// });
154+
// observer.observe(this.containerEl, { childList: true, subtree: true });
155+
151156
// --- Register to MDRC manager ---
152157
this.plugin.mdrcManager.registerMDRC(this);
153158

0 commit comments

Comments
 (0)