Skip to content

Commit 5eb5c72

Browse files
committed
the fixing part 1
1 parent 361dbb7 commit 5eb5c72

25 files changed

+270
-256
lines changed

exampleVault/Input Fields/Select and Multi Select.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
select: 2
2+
select: 1
33
multiSelect:
44
- option 1
55
- option 3
6-
select2: 1
6+
select2: false
7+
select3: 3
78
---
89

910
### Select
@@ -25,6 +26,16 @@ showcase
2526
):select2]
2627
```
2728

29+
```meta-bind
30+
INPUT[select(
31+
option(1, option 1),
32+
option(2, option 2),
33+
option(3, option 3),
34+
option(3, option 3),
35+
option(2, option 2),
36+
showcase
37+
):select3]
38+
```
2839

2940
### Multi Select
3041
```meta-bind

src/api/IAPI.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ export interface IAPI {
1212
readonly inputFieldParser: InputFieldDeclarationParser;
1313
readonly viewFieldParser: ViewFieldDeclarationParser;
1414
readonly bindTargetParser: BindTargetParser;
15-
16-
readonly inputFieldFactory: NewInputFieldFactory;
1715
}

src/cm6/Cm6_Widgets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class ViewFieldWidget extends MarkdownRenderChildWidget<ViewFieldMDRC> {
5050

5151
export class InputFieldWidget extends MarkdownRenderChildWidget<InputFieldMDRC> {
5252
public createRenderChild(container: HTMLElement, component: Component): InputFieldMDRC | ExcludedMDRC {
53-
return this.plugin.api.createInputFieldFromString(this.content, RenderChildType.INLINE, this.filePath, container, component);
53+
return this.plugin.api.createInputFieldFromString(this.content, RenderChildType.INLINE, this.filePath, container, component, undefined);
5454
}
5555
}
5656

src/frontmatterDisplay/CmPlugin.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/frontmatterDisplay/FrontmatterDisplay.svelte

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/frontmatterDisplay/FrontmatterWidget.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/frontmatterDisplay/custom_overlay.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/inputFields/_new/NewInputFieldFactory.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { IPlugin } from '../../IPlugin';
55
import { Toggle } from './fields/Toggle/Toggle';
66
import { Text } from './fields/Text/Text';
77
import { Slider } from './fields/Slider/Slider';
8+
import { TextArea } from './fields/TextArea/TextArea';
9+
import { Select } from './fields/Select/Select';
810

9-
export type NewInputField = Toggle | Slider | Text;
11+
export type NewInputField = Toggle | Slider | Text | TextArea | Select;
1012

1113
export class NewInputFieldFactory {
1214
plugin: IPlugin;
@@ -26,6 +28,12 @@ export class NewInputFieldFactory {
2628
return new Slider(renderChild);
2729
} else if (type === InputFieldType.TEXT) {
2830
return new Text(renderChild);
31+
} else if (type === InputFieldType.TEXT_AREA) {
32+
return new TextArea(renderChild);
33+
} else if (type === InputFieldType.TEXT_AREA_DEPRECATED) {
34+
return new TextArea(renderChild);
35+
} else if (type === InputFieldType.SELECT) {
36+
return new Select(renderChild);
2937
}
3038

3139
return undefined;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { NewAbstractInputField } from '../../NewAbstractInputField';
2+
import { isLiteral, MBLiteral, stringifyLiteral } from '../../../../utils/Utils';
3+
import { InputFieldMDRC } from '../../../../renderChildren/InputFieldMDRC';
4+
import { SvelteComponent } from 'svelte';
5+
import SelectComponent from './SelectComponent.svelte';
6+
import { OptionInputFieldArgument } from '../../../../inputFieldArguments/arguments/OptionInputFieldArgument';
7+
import { InputFieldArgumentType } from '../../../InputFieldConfigs';
8+
9+
export class Select extends NewAbstractInputField<MBLiteral, MBLiteral> {
10+
options: OptionInputFieldArgument[];
11+
12+
constructor(renderChild: InputFieldMDRC) {
13+
super(renderChild);
14+
15+
this.options = this.renderChild.getArguments(InputFieldArgumentType.OPTION) as OptionInputFieldArgument[];
16+
}
17+
18+
protected filterValue(value: any): MBLiteral | undefined {
19+
return isLiteral(value) ? value : undefined;
20+
}
21+
22+
protected getFallbackDefaultValue(): MBLiteral {
23+
return null;
24+
}
25+
26+
protected getSvelteComponent(): typeof SvelteComponent {
27+
return SelectComponent;
28+
}
29+
30+
protected rawMapValue(value: MBLiteral): MBLiteral {
31+
return value;
32+
}
33+
34+
protected rawReverseMapValue(value: MBLiteral): MBLiteral | undefined {
35+
return value;
36+
}
37+
38+
protected getMountArgs(): Record<string, any> {
39+
return {
40+
options: this.options,
41+
};
42+
}
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script lang="ts">
2+
import {MBLiteral, stringifyLiteral} from '../../../../utils/Utils';
3+
import {OptionInputFieldArgument} from '../../../../inputFieldArguments/arguments/OptionInputFieldArgument';
4+
5+
export let value: MBLiteral;
6+
export let options: OptionInputFieldArgument[];
7+
export let onValueChange: (value: MBLiteral) => void;
8+
9+
export function setValue(v: MBLiteral): void {
10+
value = v;
11+
}
12+
13+
function selectOption(option: MBLiteral) {
14+
value = option;
15+
onValueChange(value);
16+
}
17+
18+
function selectOptionOnKey(event: KeyboardEvent, option: MBLiteral) {
19+
if (event.key === ' ') {
20+
selectOption(option);
21+
}
22+
}
23+
</script>
24+
25+
{#each options as option}
26+
<div
27+
class="mb-select-input-element"
28+
class:is-selected={option.value === value}
29+
role="button"
30+
tabindex="0"
31+
on:click={() => selectOption(option.value)}
32+
on:keypress={(event) => selectOptionOnKey(event, option.value)}
33+
>
34+
{option.name}
35+
</div>
36+
{/each}

0 commit comments

Comments
 (0)