Skip to content

Commit 1b4eb72

Browse files
committed
start of #236
1 parent c143a46 commit 1b4eb72

File tree

13 files changed

+391
-183
lines changed

13 files changed

+391
-183
lines changed

exampleVault/Button Example.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
count: 0
3+
someList:
4+
- 1708945050652
35
---
46
Meta Bind is getting Buttons
57

@@ -138,7 +140,6 @@ actions:
138140
139141
```
140142

141-
142143
```meta-bind-button
143144
label: Show PF2e Examples with Delay
144145
hidden: false
@@ -210,6 +211,21 @@ actions:
210211

211212
`BUTTON[count-decrement, count-reset, count-increment]` `VIEW[{count}]`
212213

214+
```meta-bind-button
215+
label: Add Current Time to List
216+
hidden: false
217+
class: ""
218+
tooltip: ""
219+
id: ""
220+
style: primary
221+
actions:
222+
- type: updateMetadata
223+
bindTarget: someList
224+
evaluate: true
225+
value: "x == null ? [Date.now()] : [...x, Date.now()]"
226+
227+
```
228+
213229
## Button Templates
214230

215231
`BUTTON[test-id]`

exampleVault/View Fields/JS View Field.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
---
2-
number1: 123
2+
number1: 100
33
number2: 43
4-
result: "**5289** km"
4+
result: "**4300** km"
5+
n1clone: 100
6+
cssclasses:
7+
- aa
8+
- test-class
59
---
610
`INPUT[number:number1]`
711
`INPUT[number:number2]`
@@ -12,4 +16,31 @@ result: "**5289** km"
1216
save to {result}
1317
---
1418
return engine.markdown.create(`**${context.bound.n1 * context.bound.n2}** km`);
19+
```
20+
21+
```meta-bind-js-view
22+
{number1} as n1
23+
save to {n1clone}
24+
---
25+
return context.bound.n1;
26+
```
27+
28+
You can also dynamically add CSS classes to your note this way.
29+
30+
```meta-bind-js-view
31+
{number1} as n1
32+
save to {cssclasses}
33+
---
34+
const CLASS = 'test-class';
35+
36+
const addClass = context.bound.n1 >= 100;
37+
let css = new Set(context.metadata.frontmatter.cssclasses ?? []);
38+
39+
if (addClass) {
40+
css.add(CLASS);
41+
} else {
42+
css.delete(CLASS);
43+
}
44+
45+
return [...css.values()];
1546
```

packages/core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# meta-bind-core
22

33
Core Package for Meta Bind. This package is independent of the Obsidian API.
4+
5+
ALL COMMANDS SHOULD BE RUN FROM THE ROOT OF THE REPO.

packages/obsidian/README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
# meta-bind-obsidian
22

3-
To install dependencies:
3+
This is the meta bind adapter package for Obsidian.
44

5-
```bash
6-
bun install
7-
```
8-
9-
To run:
10-
11-
```bash
12-
bun run index.ts
13-
```
14-
15-
This project was created using `bun init` in bun v1.0.27. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
5+
ALL COMMANDS SHOULD BE RUN FROM THE ROOT OF THE REPO.

packages/obsidian/src/ObsidianInternalAPI.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,13 @@ export class ObsidianInternalAPI extends InternalAPI<MetaBindPlugin> {
180180
public createFuzzySearch(): IFuzzySearch {
181181
return new FuzzySearch();
182182
}
183+
184+
public async readFilePath(filePath: string): Promise<string> {
185+
const tFile = this.app.vault.getAbstractFileByPath(filePath);
186+
if (!tFile || !(tFile instanceof TFile)) {
187+
throw new Error(`file not found: ${filePath}`);
188+
}
189+
190+
return this.app.vault.cachedRead(tFile);
191+
}
183192
}

packages/obsidian/src/ObsidianJsRenderer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export class ObsidianJsRenderer implements IJsRenderer {
6060
);
6161
await renderer.render(execution.result);
6262

63-
return renderer.convertToSimpleObject(execution.result);
63+
const simpleObject = renderer.convertToSimpleObject(execution.result);
64+
65+
console.log(simpleObject, typeof simpleObject);
66+
67+
return simpleObject;
6468
} catch (e) {
6569
if (e instanceof Error) {
6670
this.containerEl.innerText = e.message;

packages/obsidian/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src/**/*.ts", "extraTypes/**/*.ts"]
3+
"include": ["src/**/*.ts", "src/**/*.svelte", "extraTypes/**/*.ts"]
44
}

packages/publish/README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
# meta-bind-publish
22

3-
To install dependencies:
3+
This is the meta bind adapter package for Obsidian Publish.
44

5-
```bash
6-
bun install
7-
```
8-
9-
To run:
10-
11-
```bash
12-
bun run index.ts
13-
```
14-
15-
This project was created using `bun init` in bun v1.0.27. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
5+
ALL COMMANDS SHOULD BE RUN FROM THE ROOT OF THE REPO.

packages/publish/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src/**/*.ts", "extraTypes/**/*.ts"]
3+
"include": ["src/**/*.ts", "src/**/*.svelte", "extraTypes/**/*.ts"]
44
}

tests/__mocks__/TestInternalAPI.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,26 @@ export class TestInternalAPI extends InternalAPI<TestPlugin> {
1919
}
2020

2121
public executeCommandById(_id: string): boolean {
22-
throw new Error('not implemented');
22+
return true;
2323
}
2424

2525
public isJsEngineAvailable(): boolean {
2626
return false;
2727
}
2828

2929
public jsEngineRunFile(_filePath: string, _callingFilePath: string, _container?: HTMLElement): Promise<() => void> {
30-
return Promise.reject(new Error('not implemented'));
30+
return Promise.resolve(() => {});
3131
}
3232

3333
public jsEngineRunCode(_code: string, _callingFilePath: string, _container?: HTMLElement): Promise<() => void> {
34-
return Promise.reject(new Error('not implemented'));
34+
return Promise.resolve(() => {});
3535
}
3636

3737
public createJsRenderer(_container: HTMLElement, _filePath: string, _code: string): IJsRenderer {
3838
throw new Error('not implemented');
3939
}
4040

41-
public openFile(_filePath: string, _callingFilePath: string, _newTab: boolean): void {
42-
throw new Error('not implemented');
43-
}
41+
public openFile(_filePath: string, _callingFilePath: string, _newTab: boolean): void {}
4442

4543
public getFilePathByName(name: string, _relativeTo: string = ''): string | undefined {
4644
return name;

0 commit comments

Comments
 (0)