generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
361dbb7
commit 5eb5c72
Showing
25 changed files
with
270 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NewAbstractInputField } from '../../NewAbstractInputField'; | ||
import { isLiteral, MBLiteral, stringifyLiteral } from '../../../../utils/Utils'; | ||
import { InputFieldMDRC } from '../../../../renderChildren/InputFieldMDRC'; | ||
import { SvelteComponent } from 'svelte'; | ||
import SelectComponent from './SelectComponent.svelte'; | ||
import { OptionInputFieldArgument } from '../../../../inputFieldArguments/arguments/OptionInputFieldArgument'; | ||
import { InputFieldArgumentType } from '../../../InputFieldConfigs'; | ||
|
||
export class Select extends NewAbstractInputField<MBLiteral, MBLiteral> { | ||
options: OptionInputFieldArgument[]; | ||
|
||
constructor(renderChild: InputFieldMDRC) { | ||
super(renderChild); | ||
|
||
this.options = this.renderChild.getArguments(InputFieldArgumentType.OPTION) as OptionInputFieldArgument[]; | ||
} | ||
|
||
protected filterValue(value: any): MBLiteral | undefined { | ||
return isLiteral(value) ? value : undefined; | ||
} | ||
|
||
protected getFallbackDefaultValue(): MBLiteral { | ||
return null; | ||
} | ||
|
||
protected getSvelteComponent(): typeof SvelteComponent { | ||
return SelectComponent; | ||
} | ||
|
||
protected rawMapValue(value: MBLiteral): MBLiteral { | ||
return value; | ||
} | ||
|
||
protected rawReverseMapValue(value: MBLiteral): MBLiteral | undefined { | ||
return value; | ||
} | ||
|
||
protected getMountArgs(): Record<string, any> { | ||
return { | ||
options: this.options, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script lang="ts"> | ||
import {MBLiteral, stringifyLiteral} from '../../../../utils/Utils'; | ||
import {OptionInputFieldArgument} from '../../../../inputFieldArguments/arguments/OptionInputFieldArgument'; | ||
export let value: MBLiteral; | ||
export let options: OptionInputFieldArgument[]; | ||
export let onValueChange: (value: MBLiteral) => void; | ||
export function setValue(v: MBLiteral): void { | ||
value = v; | ||
} | ||
function selectOption(option: MBLiteral) { | ||
value = option; | ||
onValueChange(value); | ||
} | ||
function selectOptionOnKey(event: KeyboardEvent, option: MBLiteral) { | ||
if (event.key === ' ') { | ||
selectOption(option); | ||
} | ||
} | ||
</script> | ||
|
||
{#each options as option} | ||
<div | ||
class="mb-select-input-element" | ||
class:is-selected={option.value === value} | ||
role="button" | ||
tabindex="0" | ||
on:click={() => selectOption(option.value)} | ||
on:keypress={(event) => selectOptionOnKey(event, option.value)} | ||
> | ||
{option.name} | ||
</div> | ||
{/each} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { NewAbstractInputField } from '../../NewAbstractInputField'; | ||
import { InputFieldMDRC } from '../../../../renderChildren/InputFieldMDRC'; | ||
import { isLiteral } from '../../../../utils/Utils'; | ||
import { SvelteComponent } from 'svelte'; | ||
import TextAreaComponent from './TextAreaComponent.svelte'; | ||
import { InputFieldArgumentType } from '../../../InputFieldConfigs'; | ||
|
||
export class TextArea extends NewAbstractInputField<string, string> { | ||
constructor(renderChild: InputFieldMDRC) { | ||
super(renderChild); | ||
} | ||
|
||
protected filterValue(value: any): string | undefined { | ||
return isLiteral(value) ? value?.toString() : undefined; | ||
} | ||
|
||
protected getFallbackDefaultValue(): string { | ||
return ''; | ||
} | ||
|
||
protected getSvelteComponent(): typeof SvelteComponent { | ||
return TextAreaComponent; | ||
} | ||
|
||
protected rawReverseMapValue(value: string): string | undefined { | ||
return value; | ||
} | ||
|
||
protected rawMapValue(value: string): string { | ||
return value; | ||
} | ||
|
||
protected getMountArgs(): Record<string, any> { | ||
return { | ||
placeholder: this.renderChild.getArgument(InputFieldArgumentType.PLACEHOLDER)?.value ?? 'Text', | ||
}; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/inputFields/_new/fields/TextArea/TextAreaComponent.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
export let value: string; | ||
export let placeholder: string; | ||
export let onValueChange: (value: string) => void; | ||
export function setValue(v: string): void { | ||
value = v; | ||
} | ||
</script> | ||
|
||
<textarea tabindex="0" placeholder={placeholder} bind:value={value} on:input={() => onValueChange(value)}></textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.