Skip to content

Commit 5791c87

Browse files
committed
more comments, prepare for next release
1 parent 2455d19 commit 5791c87

File tree

14 files changed

+98
-59
lines changed

14 files changed

+98
-59
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22

33
# Unreleased
44

5+
New Features
6+
7+
- The in plugin offline FAQ/Help Page now includes a preview of all available input fields
8+
- New view field type `link`
9+
- displays a link to the note specified in the metadata
10+
- works with lists of notes
11+
- works with external URLs
12+
513
Breaking Changes
614

715
- removed setting migrations for settings from plugin versions earlier than `0.6.0`
16+
- migrated the JS View Field to use JS Engine
17+
- the docs will include a migration guide soon
18+
19+
Bug Fixes
20+
21+
- Fixed Metadata cache does not update on file rename or delete [#142](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/142)
22+
- now all Input and View Fields bound to the renamed or deleted note will unload
823

924
# 0.7.2
1025

exampleVault/Advanced Examples/PF2e DC Calcualtor.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ baseDC: 15
55
baseSpellDC: 15
66
---
77

8-
98
### DC by Proficiency
109

1110
| Proficiency | DC |

exampleVault/Advanced Examples/PF2e Encounter Calculator.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,13 @@ test:
2424
- c
2525
---
2626

27-
28-
2927
### Party Info
3028

3129
Players: `INPUT[number:playerCount]`
3230
Player Level: `INPUT[number:playerLevel]`
3331

3432
### Enemies
3533

36-
%%
37-
| Name | Level | Count |
38-
| --------------------------- | ---------------------------- | ---------------------------- |
39-
| `INPUT[text:enemy[0].name]` | `INPUT[number:enemy[0].level]` | `INPUT[number:enemy[0].count]` |
40-
| `INPUT[text:enemy[1].name]` | `INPUT[number:enemy[1].level]` | `INPUT[number:enemy[1].count]` |
41-
| `INPUT[text:enemy[2].name]` | `INPUT[number:enemy[2].level]` | `INPUT[number:enemy[2].count]` |
42-
| `INPUT[text:enemy[3].name]` | `INPUT[number:enemy[3].level]` | `INPUT[number:enemy[3].count]` |
43-
| `INPUT[text:enemy[4].name]` | `INPUT[number:enemy[4].level]` | `INPUT[number:enemy[4].count]` |
44-
45-
```js
46-
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
47-
48-
function render(enemies) {
49-
const md = engine.markdown.createBuilder();
50-
md.createTable(
51-
['Name', 'Level', 'Count'],
52-
enemies.map((x, i) => {
53-
return [
54-
`\`INPUT[text:enemy[${i}].name]\``,
55-
`\`INPUT[text:enemy[${i}].level]\``,
56-
`\`INPUT[text:enemy[${i}].count]\``
57-
]
58-
})
59-
);
60-
return md;
61-
}
62-
63-
const signal = mb.createSignal([]);
64-
const unregisterCb = mb.listenToMetadata(signal, context.file.path, ['enemy'], false);
65-
66-
const reactive = engine.reactive(render, signal.get());
67-
68-
component.register(unregisterCb);
69-
70-
return reactive;
71-
```
72-
%%
73-
74-
7534
```js-engine
7635
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
7736
@@ -87,7 +46,6 @@ const columns = [
8746
mb.createTable(container, context.file.path, component, bindTarget, tableHead, columns);
8847
```
8948

90-
9149
### Encounter Stats
9250

9351
```meta-bind-js-view

exampleVault/Input Fields/Progress Bar.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ progress3: 4
88
INPUT[progressBar(showcase, minValue(-10), maxValue(3)):progress1]
99
```
1010

11-
1211
```meta-bind
1312
INPUT[progressBar(showcase, minValue(0), maxValue(1), stepSize(0.1)):progress2]
1413
```

exampleVault/Input Fields/Select and Multi Select.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ multiSelect3:
1515
---
1616

1717
### Select
18+
1819
```meta-bind
1920
INPUT[select(
2021
option(1, option 1),

exampleVault/Input Fields/Slider.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ slider3: 233
55
---
66

77
### Simple Slider
8+
89
```meta-bind
910
INPUT[slider(showcase):slider1]
1011
```
1112

1213
### Slider with Labels
14+
1315
```meta-bind
1416
INPUT[slider(addLabels, showcase):slider1]
1517
```
1618

1719
### Slider with custom min max values
20+
1821
```meta-bind
1922
INPUT[slider(addLabels, minValue(-20), maxValue(20), showcase):slider2]
2023
```

exampleVault/Input Fields/Suggester.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ suggest: option 2
55
---
66

77
### Simple Suggester
8+
89
```meta-bind
910
INPUT[suggester(
1011
option(option 1),

exampleVault/Input Fields/Text.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ textArea: textArea
44
---
55

66
### Text
7+
78
```meta-bind
89
INPUT[text(showcase):text]
910
```
@@ -13,6 +14,7 @@ INPUT[text(showcase, limit(10)):text]
1314
```
1415

1516
### Text Area
17+
1618
```meta-bind
1719
INPUT[text_area(showcase, class(meta-bind-full-width), class(meta-bind-high)):textArea]
1820
```

exampleVault/Input Fields/Toggle.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
toggle2: 1
3-
toggle1: false
3+
toggle1: true
44
---
55

6-
76
```meta-bind
87
INPUT[toggle(showcase):toggle1]
98
```

src/cm6/Cm6_ViewPlugin.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
1212
return ViewPlugin.fromClass(
1313
class {
1414
decorations: DecorationSet;
15+
/**
16+
* Component for unloading the widgets if the view plugin is destroyed.
17+
*/
1518
component: Component;
1619

1720
constructor(view: EditorView) {
@@ -20,6 +23,12 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
2023
this.decorations = this.renderWidgets(view) ?? Decoration.none;
2124
}
2225

26+
/**
27+
* Triggered by codemirror when the view updates.
28+
* Depending on the update type, the decorations are either updated or recreated.
29+
*
30+
* @param update
31+
*/
2332
update(update: ViewUpdate): void {
2433
// only activate in LP and not source mode
2534
// @ts-ignore some strange private field not being assignable
@@ -41,6 +50,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
4150
}
4251
}
4352

53+
/**
54+
* Updates all the widgets by traversing the syntax tree.
55+
*
56+
* @param view
57+
*/
4458
updateTree(view: EditorView): void {
4559
for (const { from, to } of view.visibleRanges) {
4660
syntaxTree(view.state).iterate({
@@ -70,6 +84,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
7084
}
7185
}
7286

87+
/**
88+
* Removes all decorations at a given node.
89+
*
90+
* @param node
91+
*/
7392
removeDecoration(node: SyntaxNode): void {
7493
this.decorations.between(node.from - 1, node.to + 1, (from, to, _) => {
7594
this.decorations = this.decorations.update({
@@ -80,6 +99,14 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
8099
});
81100
}
82101

102+
/**
103+
* Adds a widget at a given node if it does not exist yet.
104+
*
105+
* @param node the note where to add the widget
106+
* @param view
107+
* @param content the content of the node
108+
* @param widgetType the type of the widget to add
109+
*/
83110
addDecoration(node: SyntaxNode, view: EditorView, content: string, widgetType: MBWidgetType): void {
84111
const from = node.from - 1;
85112
const to = node.to + 1;
@@ -106,7 +133,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
106133
}
107134

108135
/**
109-
* return weather to render the widget and the type of the widget to render.
136+
* Checks whether to render a widget at a given node and the type of the widget to render.
110137
*
111138
* @param view
112139
* @param node
@@ -137,7 +164,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
137164
}
138165

139166
/**
140-
* reads the node, returning its content and widgetType.
167+
* Reads the content of an editor range and checks if it is a declaration if so also returning the widget type.
141168
*
142169
* @param view
143170
* @param from
@@ -155,6 +182,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
155182
};
156183
}
157184

185+
/**
186+
* Completely re-renders all widgets.
187+
*
188+
* @param view
189+
*/
158190
renderWidgets(view: EditorView): RangeSet<Decoration> | undefined {
159191
const currentFile = Cm6_Util.getCurrentFile(view);
160192
if (!currentFile) {
@@ -192,6 +224,14 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
192224
return Decoration.set(widgets, true);
193225
}
194226

227+
/**
228+
* Renders a singe widget of the given widget type at a given node.
229+
*
230+
* @param node
231+
* @param widgetType
232+
* @param content
233+
* @param currentFile
234+
*/
195235
renderWidget(
196236
node: SyntaxNode,
197237
widgetType: MBWidgetType,
@@ -214,6 +254,10 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
214254
}).range(node.from - 1, node.to + 1);
215255
}
216256

257+
/**
258+
* Triggered by codemirror when the view plugin is destroyed.
259+
* Unloads all widgets.
260+
*/
217261
destroy(): void {
218262
this.component.unload();
219263
}

0 commit comments

Comments
 (0)