Skip to content

Commit b251a21

Browse files
committed
placeholder argument
1 parent ca187e1 commit b251a21

19 files changed

+277
-128
lines changed

CHANGELOG.md

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

3+
# 0.6.0 - UNRELEASED
4+
5+
New Features
6+
7+
- `list` input field
8+
- `defaultValue` input field argument
9+
- lets you define a custom default value for an input field
10+
- works on any input field
11+
- `placeholder` input field argument
12+
- lets you define a placeholder value to be displayed in the input field, if no value is set
13+
- works on the following input fields `text`, `textArea`, `number` and `list`
14+
15+
Changes
16+
17+
- new parser for input fields, view fields and bind targets
18+
- input fields now display way better error messages
19+
- i tried not to introduce breaking changes, but some might have slipped through
20+
- this is also why the update took so long
21+
- new API to create input field using code (e.g. using dataviewJS or [JS Engine](https://github.com/mProjectsCode/obsidian-js-engine-plugin))
22+
- this is a breaking change
23+
24+
Bug Fixes
25+
26+
- fixed a bug with the metadata cache when the frontmatter was invalid
27+
- fixed a bug with view fields that caused an error when referencing metadata from another file
28+
329
# 0.5.1
430

531
Minor Changes

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"jest": "^29.6.1",
3636
"jest-environment-jsdom": "^28.1.1",
3737
"obsidian": "latest",
38-
"obsidian-dataview": "latest",
38+
"obsidian-dataview": "0.5.56",
3939
"prettier": "2.7.1",
4040
"svelte": "^4.2.0",
4141
"svelte-preprocess": "^5.0.4",
@@ -45,7 +45,7 @@
4545
},
4646
"dependencies": {
4747
"@codemirror/language": "https://github.com/lishid/cm-language",
48-
"@lemons_dev/parsinom": "^0.0.6",
48+
"@lemons_dev/parsinom": "^0.0.8",
4949
"@opd-libs/opd-metadata-lib": "0.0.4",
5050
"@opd-libs/opd-utils-lib": "0.0.2",
5151
"@popperjs/core": "^2.11.8",

src/inputFieldArguments/InputFieldArgumentFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ShowcaseInputFieldArgument } from './arguments/ShowcaseInputFieldArgume
1212
import { OffValueInputFieldArgument } from './arguments/OffValueInputFieldArgument';
1313
import { OnValueInputFieldArgument } from './arguments/OnValueInputFieldArgument';
1414
import { DefaultValueInputFieldArgument } from './arguments/DefaultValueInputFieldArgument';
15+
import { PlaceholderInputFieldArgument } from './arguments/PlaceholderInputFieldArgument';
1516

1617
export class InputFieldArgumentFactory {
1718
static createInputFieldArgument(argumentIdentifier: string): AbstractInputFieldArgument {
@@ -37,6 +38,8 @@ export class InputFieldArgumentFactory {
3738
return new OnValueInputFieldArgument();
3839
} else if (argumentIdentifier === InputFieldArgumentType.DEFAULT_VALUE) {
3940
return new DefaultValueInputFieldArgument();
41+
} else if (argumentIdentifier === InputFieldArgumentType.PLACEHOLDER) {
42+
return new PlaceholderInputFieldArgument();
4043
} else {
4144
throw new MetaBindParsingError(ErrorLevel.ERROR, 'can not crate input field argument', `unknown argument '${argumentIdentifier}'`);
4245
}

src/inputFieldArguments/arguments/OptionInputFieldArgument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AbstractInputFieldArgument } from '../AbstractInputFieldArgument';
22
import { InputFieldArgumentType, InputFieldType } from '../../parsers/InputFieldDeclarationParser';
3-
import { ErrorLevel, MetaBindArgumentError } from '../../utils/errors/MetaBindErrors';
43
import { MBLiteral, parseLiteral } from '../../utils/Utils';
54
import { ParsingResultNode } from '../../parsers/newInputFieldParser/InputFieldDeclarationValidator';
65

76
export class OptionInputFieldArgument extends AbstractInputFieldArgument {
87
identifier: InputFieldArgumentType = InputFieldArgumentType.OPTION;
98
allowedInputFields: InputFieldType[] = [
109
InputFieldType.SELECT,
10+
InputFieldType.MULTI_SELECT_DEPRECATED,
1111
InputFieldType.MULTI_SELECT,
1212
InputFieldType.SUGGESTER,
1313
InputFieldType.IMAGE_SUGGESTER,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AbstractInputFieldArgument } from '../AbstractInputFieldArgument';
2+
import { InputFieldArgumentType, InputFieldType } from '../../parsers/InputFieldDeclarationParser';
3+
import { ParsingResultNode } from '../../parsers/newInputFieldParser/InputFieldDeclarationValidator';
4+
5+
export class PlaceholderInputFieldArgument extends AbstractInputFieldArgument {
6+
identifier: InputFieldArgumentType = InputFieldArgumentType.PLACEHOLDER;
7+
allowedInputFields: InputFieldType[] = [
8+
InputFieldType.TEXT,
9+
InputFieldType.TEXT_AREA,
10+
InputFieldType.TEXT_AREA_DEPRECATED,
11+
InputFieldType.NUMBER,
12+
InputFieldType.LIST,
13+
];
14+
value: string = '';
15+
valueLengthMin: number = 1;
16+
valueLengthMax: number = 1;
17+
allowMultiple: boolean = true;
18+
19+
_parseValue(value: ParsingResultNode[]): void {
20+
this.value = value[0].value;
21+
}
22+
}

src/inputFields/InputFieldConfigs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const InputFieldConfigs: Record<InputFieldType, InputFieldConfig> = {
2222
allowInBlock: true,
2323
allowInline: true,
2424
},
25+
[InputFieldType.TEXT_AREA_DEPRECATED]: {
26+
type: InputFieldType.TEXT_AREA_DEPRECATED,
27+
allowInBlock: true,
28+
allowInline: true,
29+
},
2530
[InputFieldType.TEXT_AREA]: {
2631
type: InputFieldType.TEXT_AREA,
2732
allowInBlock: true,
@@ -32,6 +37,11 @@ export const InputFieldConfigs: Record<InputFieldType, InputFieldConfig> = {
3237
allowInBlock: true,
3338
allowInline: false,
3439
},
40+
[InputFieldType.MULTI_SELECT_DEPRECATED]: {
41+
type: InputFieldType.MULTI_SELECT_DEPRECATED,
42+
allowInBlock: true,
43+
allowInline: false,
44+
},
3545
[InputFieldType.MULTI_SELECT]: {
3646
type: InputFieldType.MULTI_SELECT,
3747
allowInBlock: true,
@@ -47,6 +57,11 @@ export const InputFieldConfigs: Record<InputFieldType, InputFieldConfig> = {
4757
allowInBlock: true,
4858
allowInline: true,
4959
},
60+
[InputFieldType.DATE_PICKER_DEPRECATED]: {
61+
type: InputFieldType.DATE_PICKER_DEPRECATED,
62+
allowInBlock: true,
63+
allowInline: true,
64+
},
5065
[InputFieldType.DATE_PICKER]: {
5166
type: InputFieldType.DATE_PICKER,
5267
allowInBlock: true,

src/inputFields/InputFieldFactory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,22 @@ export class InputFieldFactory {
3636
return new SliderInputField(args.inputFieldMDRC);
3737
} else if (inputFieldType === InputFieldType.TEXT) {
3838
return new TextInputField(args.inputFieldMDRC);
39+
} else if (inputFieldType === InputFieldType.TEXT_AREA_DEPRECATED) {
40+
return new TextAreaInputField(args.inputFieldMDRC);
3941
} else if (inputFieldType === InputFieldType.TEXT_AREA) {
4042
return new TextAreaInputField(args.inputFieldMDRC);
4143
} else if (inputFieldType === InputFieldType.SELECT) {
4244
return new SelectInputField(args.inputFieldMDRC);
45+
} else if (inputFieldType === InputFieldType.MULTI_SELECT_DEPRECATED) {
46+
return new MultiSelectInputField(args.inputFieldMDRC);
4347
} else if (inputFieldType === InputFieldType.MULTI_SELECT) {
4448
return new MultiSelectInputField(args.inputFieldMDRC);
4549
} else if (inputFieldType === InputFieldType.DATE) {
4650
return new DateInputField(args.inputFieldMDRC);
4751
} else if (inputFieldType === InputFieldType.TIME) {
4852
return new TimeInputField(args.inputFieldMDRC);
53+
} else if (inputFieldType === InputFieldType.DATE_PICKER_DEPRECATED) {
54+
return new DatePickerInputField(args.inputFieldMDRC);
4955
} else if (inputFieldType === InputFieldType.DATE_PICKER) {
5056
return new DatePickerInputField(args.inputFieldMDRC);
5157
} else if (inputFieldType === InputFieldType.NUMBER) {

src/inputFields/fields/ImageSuggest/ImageCard.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
44
export let image: string;
55
export let onSelect: (item: string) => void;
6+
7+
function keySelect(event: KeyboardEvent, image: string): void {
8+
if (event.key === ' ') {
9+
onSelect(image);
10+
}
11+
}
612
</script>
713

814
<style>
@@ -21,7 +27,7 @@
2127
}
2228
</style>
2329

24-
<div class="image-card" on:click={() => onSelect(image)}>
30+
<div class="image-card" on:click={() => onSelect(image)} on:keydown={(event) => keySelect(event, image)} role="button" tabindex=0>
2531
<img class="image-card-image" src={imagePathToUri(image)} alt={image}/>
2632
<span class="image-card-text">{image}</span>
2733
</div>

src/inputFields/fields/List/ListInput.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import {ListInputField} from './ListInputField';
33
import Icon from '../../../utils/Icon.svelte';
44
import {Button, TextInput} from 'obsidian-svelte';
5+
import {InputFieldArgumentType} from '../../../parsers/InputFieldDeclarationParser';
56
67
export let value: string[] = [];
78
export let onValueChange: (value: any) => void;
89
export let listInput: ListInputField;
910
1011
let addValue: string = '';
1112
13+
let placeholder = listInput.renderChild.getArgument(InputFieldArgumentType.PLACEHOLDER);
14+
1215
export function updateValue(v: string[]) {
1316
value = v;
1417
}
@@ -44,7 +47,7 @@
4447
{/each}
4548
</div>
4649
<div class="mb-list-input">
47-
<TextInput bind:value={addValue} placeholder="add entry..." width="100%"></TextInput>
50+
<TextInput bind:value={addValue} placeholder="{placeholder?.value ?? 'add entry...'}" width="100%"></TextInput>
4851
<Button on:click={() => add()} disabled="{!addValue}">
4952
<Icon iconName="plus"/>
5053
</Button>

0 commit comments

Comments
 (0)