Skip to content

Commit 6e35129

Browse files
committed
update readme + bump metadata lib
1 parent 30207d0 commit 6e35129

File tree

11 files changed

+84
-208
lines changed

11 files changed

+84
-208
lines changed

README.md

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,22 @@
11
# Obsidian Meta Bind Plugin
22

3-
This plugin can create input fields inside your notes and bind them to metadata fields.
3+
This plugin can create input fields inside your notes and bind them to metadata fields, syncing their contents.
4+
Allowing you to create things like checkboxes inside your notes that change a metadata field e.g. `done` when checked.
5+
Or creating a slider inside your movie notes, that syncs up with a metadata field named `rating`.
46

5-
### New docs
7+
### Demo
68

7-
I am currently working on new docs for this plugin.
8-
https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs
9+
![](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/tree/master/images/meta-bind-plugin-demo-3.mp4)
910

10-
### How to use
11+
### Docs
1112

12-
To create an input field you have to write an inline code block or normal code block starting with `INPUT`. Then in square brackets the type of input field, in round brackets arguments and finally behind a colon the metadata field to bind to.
13-
14-
#### Examples:
15-
16-
- `INPUT[toggle]` will create an unbound toggle
17-
- `INPUT[slider:rating]` will create a slider bound to the metadata field `rating` of this note
18-
- `INPUT[text:task#completedOn]` will create a text input bound to the metadata field `completedOn` of the note with the name `task`
19-
20-
The plugin also allows further customization with arguments. So the complete syntax looks like this:
21-
22-
```
23-
INPUT[input_type(argument_name(argument_value), argument_name_2, ...):file_name_or_path#metadata_field]
24-
```
25-
26-
For more examples see the `exampleVault` folder.
27-
28-
#### Input field types
29-
30-
- `slider` a slider from 0 to 100 (custom ranges can be set using `minValue` and `maxValue`, see below)
31-
- `toggle` a toggle element
32-
- `text` a text field
33-
- `text_area` a bigger text field
34-
- `select` a select input field, only for code blocks
35-
- `multi_select` a multi-select input field, only for code blocks
36-
- `date` a date input field
37-
- `date_picker` a date picker
38-
39-
#### Arguments
40-
41-
- `class(class_name)` adds a css class to the input field
42-
- `addLabels` only for slider, adds labels for the min and max values
43-
- `minValue(value)` only for slider, sets the min value
44-
- `maxValue(value)` only for slider, sets the max value
45-
- `option(value)` only for (multi-)selects, adds an option to the select
46-
- `title(value)` only for (multi-)selects, adds a title to the select input
47-
- `alignRight` only for date picker, aligns the date picker popup to the right of the input field
48-
49-
### How to install
50-
51-
You can eiter download it directly through Obsidian's plugin page or you can manually download the zip archive from the latest release here on GitHub.
52-
After downloading, extract the archive into the `.obsidian/plugins` folder in your vault.
53-
54-
The folder structure should look like this:
55-
56-
```
57-
[path to your vault]
58-
|_ .obsidian
59-
|_ plugins
60-
|_ obsidian-meta-bind-plugin
61-
|_ main.js
62-
|_ manifest.json
63-
|_ styles.css
64-
```
13+
The docs are available [here](https://mprojectscode.github.io/obsidian-meta-bind-plugin-docs).
6514

6615
### Problems, unexpected behavior or improvement suggestions?
6716

6817
You are more than welcome to open an issue on [GitHub](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues).
6918

70-
#### The sync seems laggy
19+
#### The sync seems laggy / It takes half a second for the changes to sync
7120

7221
This is intentional. To reduce the load on your hard drive the plugin ony syncs about 5 times a second.
7322
There is a setting to change the sync interval, but I don't recommend changing it.

exampleVault/.obsidian/plugins/obsidian-meta-bind-plugin/main.js

Lines changed: 40 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exampleVault/.obsidian/plugins/obsidian-meta-bind-plugin/styles.css

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
:root {
2-
--meta-bind-plugin-border-width: 1px;
3-
--meta-bind-plugin-border-radius: 5px;
1+
body {
2+
--meta-bind-plugin-border-width: var(--border-width);
3+
--meta-bind-plugin-border-radius: var(--input-radius);
44
--meta-bind-plugin-slider-spacing: 5px;
55
--meta-bind-plugin-select-element-border-width: 5px;
66
--meta-bind-plugin-date-input-year-input-width: 80px;
@@ -87,39 +87,24 @@
8787
height: unset;
8888
align-self: stretch;
8989
}
90-
.meta-bind-plugin-date-input-year-input[type='number']:focus {
91-
width: calc(var(--meta-bind-plugin-date-input-year-input-width) + var(--meta-bind-plugin-border-width));
92-
height: unset;
93-
align-self: stretch;
94-
}
9590

9691
.meta-bind-plugin-input-element-group {
9792
}
9893

99-
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:first-child {
100-
border-radius: var(--meta-bind-plugin-border-radius) 0 0 var(--meta-bind-plugin-border-radius);
94+
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:focus {
95+
z-index: 10;
10196
}
10297

103-
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:not(:first-child):not(:last-child):not(:focus) {
104-
border-radius: 0;
105-
border-left: 0;
98+
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:first-child {
99+
border-radius: var(--meta-bind-plugin-border-radius) 0 0 var(--meta-bind-plugin-border-radius);
106100
}
107101

108-
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:not(:first-child):not(:last-child):focus {
102+
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:not(:first-child):not(:last-child) {
109103
border-radius: 0;
110-
margin-left: calc(var(--meta-bind-plugin-border-width) * -1);
111-
z-index: 10;
112104
}
113105

114-
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:last-child:not(:focus) {
106+
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:last-child {
115107
border-radius: 0 var(--meta-bind-plugin-border-radius) var(--meta-bind-plugin-border-radius) 0;
116-
border-left: 0;
117-
}
118-
119-
.meta-bind-plugin-input-element-group .meta-bind-plugin-input-element-group-element:last-child:focus {
120-
border-radius: 0 var(--meta-bind-plugin-border-radius) var(--meta-bind-plugin-border-radius) 0;
121-
margin-left: calc(var(--meta-bind-plugin-border-width) * -1);
122-
z-index: 10;
123108
}
124109

125110
.meta-bind-full-width {

exampleVault/examples fg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ slider2: 6
88
text1: Test asdasd
99
text_area1: Test teasd
1010
date1: 2022-05-28
11-
select: ""
11+
select: option b
1212
multi_select:
1313
- option a
1414
- option c

exampleVault/other note.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
---
2-
title: >-
3-
This is an example of how the meta bind
4-
abababababababababababababababababaabbababababababababababababababababab
5-
6-
asdasdkahjbd
7-
adjsnbf o
8-
asdoasdasdfm
9-
10-
asodfnsopdnfosndflskxn slsdf
11-
12-
sdf sdjfpsdjfpsodjfpsodjfspodjfspodfjspodfspodfjspdofjspdofpsodfj
2+
title: This is an example of how the meta bind
133
select: option a
14-
multi_select:
15-
- option a
16-
- option c
17-
date: Monday, June 20th 2022
4+
date: Tuesday, June 14th 2022
185
time: 19:20
6+
multi-select:
7+
- option b
8+
- option c
199
---

images/meta-bind-plugin-demo-3.mp4

2.45 MB
Binary file not shown.

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
"typescript": "^4.7.4"
3535
},
3636
"dependencies": {
37-
"@opd-libs/opd-metadata-lib": "^0.0.2"
37+
"@opd-libs/opd-metadata-lib": "0.0.3"
3838
}
3939
}

src/InputFieldMarkdownRenderChild.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationPar
77
import { MetaBindBindTargetError, MetaBindInternalError } from './utils/Utils';
88
import { AbstractInputFieldArgument } from './inputFieldArguments/AbstractInputFieldArgument';
99
import { ClassInputFieldArgument } from './inputFieldArguments/ClassInputFieldArgument';
10-
import { updateOrInsertFieldInTFile } from '@opd-libs/opd-metadata-lib/lib/API';
11-
import { Internal } from '@opd-libs/opd-metadata-lib/lib/Internal';
12-
import getMetadataFromFileCache = Internal.getMetadataFromFileCache;
10+
import { getFrontmatterOfTFile, updateOrInsertFieldInTFile } from '@opd-libs/opd-metadata-lib/lib/API';
1311
import { validatePath as validateObjectPath } from '@opd-libs/opd-metadata-lib/lib/Utils';
1412

1513
export enum InputFieldMarkdownRenderChildType {
@@ -55,8 +53,7 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
5553

5654
if (this.inputFieldDeclaration.isBound) {
5755
this.parseBindTarget();
58-
// @ts-ignore `parseBindTarget` sets `bindTargetFile` and `bindTargetMetadataField` or throws an error.
59-
this.metaData = getMetadataFromFileCache(this.bindTargetFile, this.plugin);
56+
this.metaData = getFrontmatterOfTFile(this.bindTargetFile as TFile, this.plugin);
6057
}
6158

6259
this.inputField = InputFieldFactory.createInputField(this.inputFieldDeclaration.inputFieldType, {

src/main.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { getFileName, isPath, removeFileEnding } from './utils/Utils';
55
import { Logger } from './utils/Logger';
66
import { DateParser } from './parsers/DateParser';
77
import { InputFieldDeclarationParser } from './parsers/InputFieldDeclarationParser';
8-
import { Internal } from '@opd-libs/opd-metadata-lib/lib/Internal';
9-
import getMetadataFromFileCache = Internal.getMetadataFromFileCache;
8+
import { getFrontmatterOfTFile } from '@opd-libs/opd-metadata-lib/lib/API';
109

1110
export default class MetaBindPlugin extends Plugin {
1211
// @ts-ignore defined in `onload`
@@ -17,8 +16,6 @@ export default class MetaBindPlugin extends Plugin {
1716
// @ts-ignore defined in `onload`
1817
markDownInputFieldIndex: number;
1918

20-
frontMatterRexExpPattern = '^(---)\\n[\\s\\S]*?\\n---';
21-
2219
async onload(): Promise<void> {
2320
await this.loadSettings();
2421

@@ -96,7 +93,7 @@ export default class MetaBindPlugin extends Plugin {
9693

9794
if (activeMarkdownInputField.bindTargetFile.path === file.path) {
9895
if (metadata === undefined) {
99-
metadata = getMetadataFromFileCache(file, this);
96+
metadata = getFrontmatterOfTFile(file, this);
10097
}
10198
activeMarkdownInputField.pushToInputFieldValueUpdateQueue(metadata[activeMarkdownInputField.bindTargetMetadataField]);
10299
}

0 commit comments

Comments
 (0)