Skip to content

Commit febaaae

Browse files
committed
fix #108; fix #106
1 parent b652e7a commit febaaae

26 files changed

+185
-102
lines changed

exampleVault/Input Fields/Select and Multi Select.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
select: "1"
2+
select: 1
33
multiSelect:
44
- option 1
55
- option 3
6+
select2: 1
67
---
78

89
### Select
@@ -15,6 +16,16 @@ showcase
1516
):select]
1617
```
1718

19+
```meta-bind
20+
INPUT[select(
21+
option(1, option 1),
22+
option(false, option 2),
23+
option(null, option 3),
24+
showcase
25+
):select2]
26+
```
27+
28+
1829
### Multi Select
1930
```meta-bind
2031
INPUT[multi_select(

exampleVault/Test.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
frequency: "[[high]]"
3+
---
4+
5+
6+
`INPUT[suggester(option([[low]]), option([[medium]]), option([[high]])):frequency]`

exampleVault/View Fields/Advanced Example/Note 3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
added:
3-
- "5"
4-
- "4"
3+
- "3"
54
removed:
65
- "4"
6+
aliases: []
77
---
88

99
# Added

exampleVault/examples.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
---
2-
slider1: 4
3-
nested:
4-
object: test
2+
slider1: 5
53
suggest: test
64
toggle1: false
75
Domestic_tasks:

src/inputFieldArguments/InputFieldArgumentContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AbstractInputFieldArgument } from './AbstractInputFieldArgument';
22
import { InputFieldArgumentType } from '../parsers/InputFieldDeclarationParser';
3-
import { ErrorLevel, MetaBindInternalError, MetaBindParsingError } from '../utils/errors/MetaBindErrors';
3+
import { ErrorLevel, MetaBindParsingError } from '../utils/errors/MetaBindErrors';
44

55
export class InputFieldArgumentContainer {
66
arguments: AbstractInputFieldArgument[] = [];
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import { AbstractInputFieldArgument } from '../AbstractInputFieldArgument';
22
import { InputFieldArgumentType, InputFieldType } from '../../parsers/InputFieldDeclarationParser';
3+
import { MBLiteral, parseLiteral } from '../../utils/Utils';
34

45
export class OffValueInputFieldArgument extends AbstractInputFieldArgument {
56
identifier: InputFieldArgumentType = InputFieldArgumentType.OFF_VALUE;
67
allowedInputFields: InputFieldType[] = [InputFieldType.TOGGLE];
7-
value: string | number | boolean = false;
8+
value: MBLiteral = false;
89
requiresValue: boolean = true;
910
allowMultiple: boolean = false;
1011

1112
parseValue(valueStr: string): void {
12-
if (valueStr === 'true') {
13-
this.value = true;
14-
} else if (valueStr === 'false') {
15-
this.value = false;
16-
} else {
17-
const parsedNumber = Number.parseFloat(valueStr);
18-
this.value = !Number.isNaN(parsedNumber) ? parsedNumber : valueStr;
19-
}
13+
this.value = parseLiteral(valueStr);
2014
}
2115
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import { AbstractInputFieldArgument } from '../AbstractInputFieldArgument';
22
import { InputFieldArgumentType, InputFieldType } from '../../parsers/InputFieldDeclarationParser';
3+
import { MBLiteral, parseLiteral } from '../../utils/Utils';
34

45
export class OnValueInputFieldArgument extends AbstractInputFieldArgument {
56
identifier: InputFieldArgumentType = InputFieldArgumentType.ON_VALUE;
67
allowedInputFields: InputFieldType[] = [InputFieldType.TOGGLE];
7-
value: string | boolean | number = true;
8+
value: MBLiteral = true;
89
requiresValue: boolean = true;
910
allowMultiple: boolean = false;
1011

1112
parseValue(valueStr: string): void {
12-
if (valueStr === 'true') {
13-
this.value = true;
14-
} else if (valueStr === 'false') {
15-
this.value = false;
16-
} else {
17-
const parsedNumber = Number.parseFloat(valueStr);
18-
this.value = !Number.isNaN(parsedNumber) ? parsedNumber : valueStr;
19-
}
13+
this.value = parseLiteral(valueStr);
2014
}
2115
}

src/inputFieldArguments/arguments/OptionInputFieldArgument.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AbstractInputFieldArgument } from '../AbstractInputFieldArgument';
22
import { InputFieldArgumentType, InputFieldType } from '../../parsers/InputFieldDeclarationParser';
33
import { ErrorLevel, MetaBindArgumentError } from '../../utils/errors/MetaBindErrors';
4+
import { MBLiteral, parseLiteral } from '../../utils/Utils';
45

56
export class OptionInputFieldArgument extends AbstractInputFieldArgument {
67
identifier: InputFieldArgumentType = InputFieldArgumentType.OPTION;
@@ -11,7 +12,7 @@ export class OptionInputFieldArgument extends AbstractInputFieldArgument {
1112
InputFieldType.IMAGE_SUGGESTER,
1213
InputFieldType.INLINE_SELECT,
1314
];
14-
value: string = '';
15+
value: MBLiteral = '';
1516
name: string = '';
1617
requiresValue: boolean = true;
1718
allowMultiple: boolean = true;
@@ -20,10 +21,10 @@ export class OptionInputFieldArgument extends AbstractInputFieldArgument {
2021
const valueParts: string[] = valueStr.split(',').map(x => x.trim());
2122

2223
if (valueParts.length === 1) {
23-
this.value = valueParts[0];
24+
this.value = parseLiteral(valueParts[0]);
2425
this.name = valueParts[0];
2526
} else if (valueParts.length === 2) {
26-
this.value = valueParts[0];
27+
this.value = parseLiteral(valueParts[0]);
2728
this.name = valueParts[1];
2829
} else {
2930
throw new MetaBindArgumentError(ErrorLevel.WARNING, 'failed to parse option argument value', 'expected there to be either one or two comma seperated values');

src/inputFields/fields/ImageSuggest/ImageSuggestInputField.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AbstractInputField } from '../../AbstractInputField';
22
import ImageSuggestInput from './ImageSuggestInput.svelte';
3-
import { ErrorLevel, MetaBindArgumentError, MetaBindInternalError, MetaBindPublishError } from '../../../utils/errors/MetaBindErrors';
3+
import { ErrorLevel, MetaBindArgumentError, MetaBindInternalError } from '../../../utils/errors/MetaBindErrors';
44
import { InputFieldArgumentType } from '../../../parsers/InputFieldDeclarationParser';
55
import { Notice, TFile, TFolder } from 'obsidian';
66
import { ImageSuggestModal } from './ImageSuggestModal';
77
import { OptionQueryInputFieldArgument } from '../../../inputFieldArguments/arguments/OptionQueryInputFieldArgument';
88
import { OptionInputFieldArgument } from '../../../inputFieldArguments/arguments/OptionInputFieldArgument';
99
import { InputFieldMDRC } from '../../../renderChildren/InputFieldMDRC';
10-
import MetaBindPlugin from '../../../main';
10+
import { stringifyLiteral } from '../../../utils/Utils';
1111

1212
export class ImageSuggestInputField extends AbstractInputField {
1313
static allowInline: boolean = false;
@@ -106,10 +106,19 @@ export class ImageSuggestInputField extends AbstractInputField {
106106
}
107107
}
108108

109-
const imagePaths: OptionInputFieldArgument[] = this.renderChild.getArguments(InputFieldArgumentType.OPTION);
109+
const imagePaths: OptionInputFieldArgument[] = this.renderChild.getArguments(InputFieldArgumentType.OPTION) as OptionInputFieldArgument[];
110110

111111
for (const imagePath of imagePaths) {
112-
const imageFile = this.renderChild.plugin.app.vault.getAbstractFileByPath(imagePath.value);
112+
const imagePathString = stringifyLiteral(imagePath.value);
113+
114+
if (!imagePathString) {
115+
const error = new MetaBindArgumentError(ErrorLevel.ERROR, 'failed to get suggest options', `expected suggest option ${imagePath.value} to be truthy`);
116+
new Notice(`meta-bind | ${error.message}`);
117+
console.warn(error);
118+
continue;
119+
}
120+
121+
const imageFile = this.renderChild.plugin.app.vault.getAbstractFileByPath(imagePathString);
113122

114123
if (!imageFile) {
115124
const error = new MetaBindArgumentError(
@@ -144,7 +153,7 @@ export class ImageSuggestInputField extends AbstractInputField {
144153
continue;
145154
}
146155

147-
images.push(imagePath.value);
156+
images.push(imagePathString);
148157
}
149158

150159
this.options = images;

src/inputFields/fields/InlineSelectInputField.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ErrorLevel, MetaBindInternalError, MetaBindValueError } from '../../uti
44
import { InputFieldMDRC } from '../../renderChildren/InputFieldMDRC';
55
import { InputFieldArgumentType } from '../../parsers/InputFieldDeclarationParser';
66
import { OptionInputFieldArgument } from '../../inputFieldArguments/arguments/OptionInputFieldArgument';
7+
import { MBLiteral, parseLiteral, stringifyLiteral } from '../../utils/Utils';
78

89
export class InlineSelectInputField extends AbstractInputField {
910
static allowBlock: boolean = false;
@@ -16,21 +17,21 @@ export class InlineSelectInputField extends AbstractInputField {
1617
this.options = inputFieldMDRC.getArguments(InputFieldArgumentType.OPTION) as OptionInputFieldArgument[];
1718
}
1819

19-
getValue(): string | undefined {
20+
getValue(): MBLiteral {
2021
if (!this.selectComponent) {
2122
return undefined;
2223
}
2324

24-
return this.selectComponent.getValue();
25+
return parseLiteral(this.selectComponent.getValue());
2526
}
2627

27-
setValue(value: any): void {
28+
setValue(value: MBLiteral): void {
2829
if (!this.selectComponent) {
2930
return;
3031
}
3132

32-
if (value != null && typeof value == 'string') {
33-
this.selectComponent.setValue(value);
33+
if (typeof value !== 'object') {
34+
this.selectComponent.setValue(stringifyLiteral(value));
3435
} else {
3536
console.warn(new MetaBindValueError(ErrorLevel.WARNING, 'failed to set value', `invalid value '${value}' at inlineSelectInputField ${this.renderChild.uuid}`));
3637
this.selectComponent.setValue('');
@@ -58,7 +59,7 @@ export class InlineSelectInputField extends AbstractInputField {
5859

5960
const component = new DropdownComponent(container);
6061
for (const option of this.options) {
61-
component.addOption(option.value, option.name);
62+
component.addOption(stringifyLiteral(option.value), option.name);
6263
}
6364
component.setValue(this.renderChild.getInitialValue());
6465
component.onChange(this.onValueChange);

0 commit comments

Comments
 (0)