Skip to content

Commit c9d9555

Browse files
committed
fix #179; fix #180; better zod errors and api validation
1 parent 116917e commit c9d9555

31 files changed

+371
-167
lines changed

CHANGELOG.md

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

3+
# Unreleased
4+
5+
- Improved validation errors for buttons and the API
6+
- Removed deprecated input fields that had names in snake_case. Use the camelCase variants instead. The snake_case variants were deprecated since version `0.6.0`.
7+
38
# 0.11.0
49

510
New Features

bun.lockb

412 Bytes
Binary file not shown.

exampleVault/Advanced Examples/Activity Tracker.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
---
22
activities:
3-
- activity: sudying
4-
status: 0
5-
from: 02:02
6-
to: 03:02
3+
- {}
4+
- {}
75
---
86

97
```js-engine
@@ -19,5 +17,21 @@ const columns = [
1917
];
2018
2119
20+
mb.createTable(container, context.file.path, component, bindTarget, tableHead, columns);
21+
```
22+
23+
```js-engine
24+
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
25+
26+
const bindTarget = mb.createBindTarget('activities');
27+
const tableHead = ['From', 'To', 'Activity', 'Status'];
28+
const columns = [
29+
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:scope^from]'),
30+
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:scope^to]'),
31+
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(youtube), option(sudying), option(linch)):scope^activity]'),
32+
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(-, unproductive), option(0, normal), option(+, productive)):scope^status]')
33+
];
34+
35+
2236
mb.createTable(container, context.file.path, component, bindTarget, tableHead, columns);
2337
```

exampleVault/Button Example.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,20 @@ hidden: false
207207
id: ""
208208
style: default
209209
actions:
210-
- type: sl
211-
ms: 1000
210+
- type: sleep
212211
- type: command
213212
command: obsidian-meta-bind-plugin:open-help
214213
215214
```
215+
216+
217+
```meta-bind-button
218+
label: Test
219+
hidden: asdasd
220+
id: ""
221+
style: default
222+
actions:
223+
- type: command
224+
command: obsidian-meta-bind-plugin:open-help
225+
226+
```

exampleVault/Input Fields/Progress Bar.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
progress1: -6
33
progress2: 0.2
4-
progress3: 4
4+
progress3: 2
5+
progress4: 3.6
56
---
67

78
```meta-bind
@@ -16,4 +17,7 @@ INPUT[progressBar(showcase, minValue(0), maxValue(1), stepSize(0.1)):progress2]
1617
INPUT[progressBar(showcase, minValue(0), maxValue(10), stepSize(-1)):progress3]
1718
```
1819

20+
```meta-bind
21+
INPUT[progressBar(showcase, minValue(0), maxValue(10), stepSize(0.1)):progress4]
22+
```
1923

exampleVault/Input Fields/Slider.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
slider1: 51
33
slider2: 2
44
slider3: 233
5+
slider4: 0.1
56
---
67

78
### Simple Slider
@@ -16,7 +17,7 @@ INPUT[slider(showcase):slider1]
1617
INPUT[slider(addLabels, showcase):slider1]
1718
```
1819

19-
### Slider with custom min max values
20+
### Slider with Custom Min Max Values
2021

2122
```meta-bind
2223
INPUT[slider(addLabels, minValue(-20), maxValue(20), showcase):slider2]
@@ -25,3 +26,10 @@ INPUT[slider(addLabels, minValue(-20), maxValue(20), showcase):slider2]
2526
```meta-bind
2627
INPUT[slider(addLabels, minValue(0), maxValue(1000), showcase):slider3]
2728
```
29+
30+
### Slider with Custom Step Size
31+
32+
```meta-bind
33+
INPUT[slider(addLabels, minValue(0), maxValue(10), stepSize(0.1), showcase):slider4]
34+
```
35+

exampleVault/Input Fields/Toggle.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ INPUT[toggle(showcase):toggle1]
99

1010
```meta-bind
1111
INPUT[toggle(showcase, onValue(1), offValue(0), defaultValue(1)):toggle2]
12-
```
12+
```
13+

extraTypes/obsidian-ex.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ declare module 'obsidian' {
5757
removeCommand: (commandId: string) => void;
5858
};
5959
}
60+
61+
interface Menu {
62+
dom: HTMLElement;
63+
items: MenuItem[];
64+
onMouseOver: (evt: MouseEvent) => void;
65+
}
66+
67+
interface MenuItem {
68+
callback: () => void;
69+
dom: HTMLElement;
70+
setSubmenu: () => Menu;
71+
disabled: boolean;
72+
}
6073
}
6174

6275
declare global {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@lemons_dev/parsinom": "^0.0.12",
5858
"itertools-ts": "^1.27.0",
5959
"mathjs": "^12.0.0",
60-
"zod": "^3.22.4"
60+
"zod": "^3.22.4",
61+
"zod-validation-error": "^2.1.0"
6162
}
6263
}

src/EditorMenu.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { type Editor, type Menu, stringifyYaml } from 'obsidian';
2+
import type MetaBindPlugin from './main';
3+
import { createInputFieldInsertExamples, createViewFieldInsertExamples } from './faq/InputFieldExamples';
4+
import { ButtonBuilderModal } from './fields/button/ButtonBuilderModal';
5+
6+
export function createEditorMenu(menu: Menu, editor: Editor, plugin: MetaBindPlugin): void {
7+
const inputFieldExamples = createInputFieldInsertExamples(plugin);
8+
const viewFieldExamples = createViewFieldInsertExamples(plugin);
9+
10+
menu.addItem(mbItem => {
11+
mbItem.setTitle('Meta Bind');
12+
mbItem.setIcon('blocks');
13+
14+
const mbSubmenu = mbItem.setSubmenu();
15+
16+
mbSubmenu.addItem(ipfItem => {
17+
ipfItem.setTitle('Input Field');
18+
19+
const ipfSubmenu = ipfItem.setSubmenu();
20+
21+
for (const [type, declaration] of inputFieldExamples) {
22+
ipfSubmenu.addItem(item => {
23+
item.setTitle(type);
24+
item.onClick(() => insetAtCursor(editor, declaration));
25+
});
26+
}
27+
});
28+
29+
mbSubmenu.addItem(vfItem => {
30+
vfItem.setTitle('View Field');
31+
32+
const vfSubmenu = vfItem.setSubmenu();
33+
34+
for (const [type, declaration] of viewFieldExamples) {
35+
vfSubmenu.addItem(item => {
36+
item.setTitle(type);
37+
item.onClick(() => insetAtCursor(editor, declaration));
38+
});
39+
}
40+
});
41+
42+
mbSubmenu.addItem(inlineButtonItem => {
43+
inlineButtonItem.setTitle('Inline Button');
44+
inlineButtonItem.onClick(() => {
45+
insetAtCursor(editor, '`BUTTON[example-id]`');
46+
});
47+
});
48+
49+
mbSubmenu.addItem(buttonItem => {
50+
buttonItem.setTitle('Button');
51+
buttonItem.onClick(() => {
52+
new ButtonBuilderModal(
53+
plugin,
54+
config => {
55+
insetAtCursor(editor, `\`\`\`meta-bind-button\n${stringifyYaml(config)}\n\`\`\``);
56+
},
57+
'Insert',
58+
).open();
59+
});
60+
});
61+
});
62+
}
63+
64+
function insetAtCursor(editor: Editor, text: string): void {
65+
editor.replaceSelection(text);
66+
}

0 commit comments

Comments
 (0)