Skip to content

Commit 5279544

Browse files
committed
better input field data handling
1 parent 929f93f commit 5279544

40 files changed

+783
-548
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"no-prototype-builtins": "off",
1717
"@typescript-eslint/no-empty-function": "off",
1818
"@typescript-eslint/no-inferrable-types": "off",
19-
"@typescript-eslint/no-explicit-any": "off",
19+
"@typescript-eslint/no-explicit-any": ["warn"],
2020
"@typescript-eslint/explicit-function-return-type": ["warn"]
2121
}
2222
}

CHANGELOG.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
# 0.5.1
44

55
Minor Changes
6-
- added a setting to disable JS View Fields
76

7+
- added a setting to disable JS View Fields
88

99
# 0.5.0
1010

1111
New Features
12-
- Live Preview support (thanks to koala on discord for helping me with this)
13-
- Obsidian Publish support (docs page coming soon, thanks to Sigrunixia on discord for letting me test on her publish account)
14-
- View Fields, a way to reactively display your metadata using mathjs
15-
- Inline Select input field (more or less a dropdown select)
16-
- Progress Bar input field (a bigger full note width slider)
17-
- On and Off Value arguments for the Toggle input field (specify custom on and off values for the toggle)
18-
- new error handling system that supports warnings
12+
13+
- Live Preview support (thanks to koala on discord for helping me with this)
14+
- Obsidian Publish support (docs page coming soon, thanks to Sigrunixia on discord for letting me test on her publish account)
15+
- View Fields, a way to reactively display your metadata using mathjs
16+
- Inline Select input field (more or less a dropdown select)
17+
- Progress Bar input field (a bigger full note width slider)
18+
- On and Off Value arguments for the Toggle input field (specify custom on and off values for the toggle)
19+
- new error handling system that supports warnings
1920

2021
Minor Changes
21-
- added timed cache retention to the plugins on demand metadata cache
22+
23+
- added timed cache retention to the plugins on demand metadata cache
2224

2325
Bug Fixes
24-
- fixed a bug with the metadata cache needlessly updating the frontmatter
25-
- fixed some mistakes in the docs
26+
27+
- fixed a bug with the metadata cache needlessly updating the frontmatter
28+
- fixed some mistakes in the docs
2629

2730
# 0.4.X
2831

exampleVault/Input Fields/Date and Time.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
time: 14:12
3-
date2: 2023-06-07
3+
date2: null
44
date1: 2023-06-08
55
---
66

exampleVault/Input Fields/Number.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
number: 100
2+
number: 1234
33
---
44

55
```meta-bind

exampleVault/Input Fields/Progress Bar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
progress1: -7
2+
progress1: 1
33
---
44

55
```meta-bind

exampleVault/Input Fields/Select and Multi Select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ select: 1
33
multiSelect:
44
- option 1
55
- option 3
6-
select2: 1
6+
select2: null
77
---
88

99
### Select

exampleVault/Test.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
---
22
frequency: "[[high]]"
3+
toggle: false
4+
needs: Text
5+
date: Saturday, July 8th 2023
6+
text: asdasddas
37
---
48

59

6-
`INPUT[suggester(option([[low]]), option([[medium]]), option([[high]])):frequency]`
10+
`--INPUT[suggester(option([[low]]), option([[medium]]), option([[high]])):frequency]`
11+
12+
```dataviewjs
13+
const setFilter = "" ;
14+
let filter = "Need | "
15+
const pages = await dv.pages()
16+
let list = []
17+
18+
for (let items of pages) {
19+
list.push('option(' + items.file.name + ')')
20+
}
21+
22+
// This is the Mermaid configuration.
23+
const codeblock = "INPUT[suggester(";
24+
const backticks = "`";
25+
26+
console.log(`${filter}${backticks}${codeblock}${list}):needs]${backticks}`);
27+
28+
await dv.paragraph(`${filter}${backticks}${codeblock}${list}):needs]${backticks}`);
29+
```
30+
31+
```dataviewjs
32+
const setFilter = "" ;
33+
let filter = "Need | "
34+
const pages = await dv.pages()
35+
let list = []
36+
37+
for (let items of pages) {
38+
list.push('option(' + items.file.name + ')')
39+
}
40+
41+
// This is the Mermaid configuration.
42+
const codeblock = "INPUT[text:text]";
43+
const backticks = "`";
44+
45+
console.log(`${filter}${backticks}${codeblock}${backticks}`);
46+
47+
await dv.paragraph(`${filter}${backticks}${codeblock}${backticks}`);
48+
```

exampleVault/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slider1: 5
2+
slider1: 6
33
suggest: test
44
toggle1: false
55
Domestic_tasks:

exampleVault/other note.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
tags: test
3-
title: test
3+
title: test test
44
select: option b
5-
date: Tuesday, January 10th 2023
5+
date: Thursday, July 20th 2023
66
time: 19:20
77
multi-select:
88
- option a
9+
- option b
910
- option c
1011
---
1112

src/inputFields/AbstractInputField.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
11
import { InputFieldMDRC } from '../renderChildren/InputFieldMDRC';
2+
import { MBExtendedLiteral } from '../utils/Utils';
3+
import { ComputedSignal } from '../utils/Signal';
24

3-
export abstract class AbstractInputField {
4-
static allowBlock: boolean = true;
5-
static allowInline: boolean = true;
5+
export type GetInputFieldType<T extends AbstractInputField<any>> = T extends AbstractInputField<infer R> ? R : unknown;
6+
7+
export abstract class AbstractInputField<T extends MBExtendedLiteral> {
68
renderChild: InputFieldMDRC;
7-
onValueChange: (value: any) => void | Promise<void>;
9+
filteredWriteSignal: ComputedSignal<MBExtendedLiteral | undefined, T>;
10+
onValueChange: (value: T | undefined) => void;
811

912
constructor(inputFieldMDRC: InputFieldMDRC) {
1013
this.renderChild = inputFieldMDRC;
1114

12-
this.onValueChange = (value: any): void => {
15+
this.onValueChange = (value: T | undefined) => {
1316
console.debug(`meta-bind | input field on value change`, value);
1417
this.renderChild.readSignal.set(value);
1518
};
1619

17-
this.renderChild.writeSignal.registerListener({
18-
callback: (value: any) => {
20+
this.filteredWriteSignal = new ComputedSignal<MBExtendedLiteral | undefined, T>(this.renderChild.writeSignal, (value: MBExtendedLiteral | undefined) => {
21+
return this.filterValue(value);
22+
});
23+
24+
this.filteredWriteSignal.registerListener({
25+
callback: (value: T): void => {
1926
if (!this.isEqualValue(value)) {
20-
this.setValue(value);
27+
this.updateDisplayValue(value);
2128
}
2229
},
2330
});
2431
}
2532

33+
getInitialValue(): T {
34+
return this.filteredWriteSignal.get();
35+
}
36+
37+
isEqualValue(value: T | undefined): boolean {
38+
return this.getValue() === value;
39+
}
40+
2641
/**
2742
* Returns the current content of the input field
2843
*/
29-
abstract getValue(): any;
44+
abstract getValue(): T | undefined;
3045

3146
/**
32-
* Sets the value on this input field, overriding the current content
47+
* Maps an extended literal to the value for the input field
3348
*
3449
* @param value
3550
*/
36-
abstract setValue(value: any): void;
51+
abstract filterValue(value: MBExtendedLiteral | undefined): T;
3752

38-
/**
39-
* Checks if the value is the same as the value of this input field
40-
*
41-
* @param value
42-
*/
43-
abstract isEqualValue(value: any): boolean;
53+
abstract updateDisplayValue(value: T): void;
4454

4555
/**
4656
* Returns the default value of this input field
4757
*/
48-
abstract getDefaultValue(): any;
58+
abstract getDefaultValue(): T;
4959

5060
/**
5161
* Returns the HTML element this input field is wrapped in

0 commit comments

Comments
 (0)