Skip to content

Commit c1fadad

Browse files
committed
Date picker alignRight argument
1 parent a5cfc7e commit c1fadad

File tree

9 files changed

+113
-60
lines changed

9 files changed

+113
-60
lines changed

exampleVault/.obsidian/plugins/obsidian-meta-bind-plugin/main.js

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

exampleVault/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ option(option d)
121121
):other note#multi-select]
122122
```
123123

124-
Lorem ipsum dolor sit amet, `INPUT[date():other note#date]` consectetur adipiscing elit. Pellentesque sit amet porttitor arcu. Quisque scelerisque dolor augue, et posuere nulla bibendum nec. `INPUT[date():other note#date]` Curabitur sed rhoncus nisl. Maecenas nisi justo, viverra vel tempus vel, hendrerit at metus. `INPUT[date_picker:other note#date]` asdasd asdasdasd
124+
Lorem ipsum dolor sit amet, `INPUT[date():other note#date]` consectetur adipiscing elit. Pellentesque sit amet porttitor arcu. Quisque scelerisque dolor augue, et posuere nulla bibendum nec. `INPUT[date():other note#date]` Curabitur sed rhoncus nisl. Maecenas nisi justo, viverra vel tempus vel, hendrerit at metus. `INPUT[date_picker():other note#date]` asdasd asdasdasd
125125

126126
asdasd
127127

exampleVault/other note.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: asdasds sdf sasdfnosdijn sdaskdjasbokbfosdasdasdasd asd asdasda f
3-
select: option b
2+
title: asdasds sdf sasdfnosdijn sdaskdjasbokbfosdasdasdasd asd asd
3+
select: option a
44
multi-select:
5-
- option b
5+
- option a
66
- option c
7-
date: Monday, June 4th 2029
7+
date: Wednesday, June 6th 2029
88
time: 19:20
99
---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {AbstractInputFieldArgument} from './AbstractInputFieldArgument';
2+
import {InputFieldArgumentType, InputFieldType} from '../parsers/InputFieldDeclarationParser';
3+
4+
export class AlignRightInputFieldArgument extends AbstractInputFieldArgument {
5+
identifier: InputFieldArgumentType = InputFieldArgumentType.ALIGN_RIGHT;
6+
allowedInputFields: InputFieldType[] = [
7+
InputFieldType.DATE_PICKER,
8+
];
9+
value: boolean = true;
10+
requiresValue: boolean = false;
11+
allowMultiple: boolean = false;
12+
13+
parseValue(valueStr: string): void {
14+
this.value = (valueStr.toLowerCase() === 'true');
15+
}
16+
}

src/inputFieldArguments/InputFieldArgumentFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {MinValueInputFieldArgument} from "./MinValueInputFieldArgument";
66
import {MaxValueInputFieldArgument} from "./MaxValueInputFieldArgument";
77
import {OptionInputFieldArgument} from "./OptionInputFieldArgument";
88
import {TitleInputFieldArgument} from "./TitleInputFieldArgument";
9+
import {AlignRightInputFieldArgument} from './AlignRightInputFieldArgument';
910

1011

1112
export class InputFieldArgumentFactory {
@@ -22,6 +23,8 @@ export class InputFieldArgumentFactory {
2223
return new OptionInputFieldArgument();
2324
} else if (argumentIdentifier === InputFieldArgumentType.TITLE) {
2425
return new TitleInputFieldArgument();
26+
} else if (argumentIdentifier === InputFieldArgumentType.ALIGN_RIGHT) {
27+
return new AlignRightInputFieldArgument();
2528
} else {
2629
throw new MetaBindParsingError(`unknown argument \'${argumentIdentifier}\'`);
2730
}

src/inputFields/DatePicker/DatePicker.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
export let dateFormat: string = 'dddd, MMMM Do YYYY';
1313
export let dateChangeCallback: (date: Moment) => void;
1414
15+
export let alignRight: boolean;
16+
1517
let date: number;
1618
let month: number;
1719
let year: number;
@@ -68,7 +70,6 @@
6870
.date-picker {
6971
position: absolute;
7072
top: 35px;
71-
left: 0;
7273
display: inline-block;
7374
background: var(--background-secondary);
7475
border-radius: var(--meta-bind-plugin-border-radius);
@@ -134,7 +135,7 @@
134135
</div>
135136
{#if showDatePicker}
136137
<div class="date-picker-close-layer" on:click={() => showDatePicker = false}></div>
137-
<div class="date-picker">
138+
<div class="date-picker" style="{alignRight ? 'left: auto; right: 0;' : 'right: auto; left: 0;'}">
138139
<div class="date-picker-header">
139140
<button class="month-switch-button" on:click={prevMonth}>Prev</button>
140141
<div class="date-picker-header-text">

src/inputFields/DatePicker/DatePickerInputField.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {InputFieldMarkdownRenderChild} from '../../InputFieldMarkdownRenderChild';
22
import {AbstractInputField} from '../AbstractInputField';
3-
import {MetaBindInternalError} from '../../utils/Utils';
3+
import {isTruthy, MetaBindInternalError} from '../../utils/Utils';
44
import DatePicker from './DatePicker.svelte';
55
import {moment} from 'obsidian';
66
import {DateParser} from '../../parsers/DateParser';
7+
import {InputFieldArgumentType} from '../../parsers/InputFieldDeclarationParser';
78

89
export class DatePickerInputField extends AbstractInputField {
910
container: HTMLDivElement | undefined;
@@ -68,6 +69,7 @@ export class DatePickerInputField extends AbstractInputField {
6869
this.component = new DatePicker({
6970
target: container,
7071
props: {
72+
alignRight: this.inputFieldMarkdownRenderChild.getArgument(InputFieldArgumentType.ALIGN_RIGHT)?.value,
7173
selectedDate: this.date,
7274
dateFormat: this.inputFieldMarkdownRenderChild.plugin.settings.preferredDateFormat,
7375
dateChangeCallback: (date: moment.Moment) => this.datePickerValueChanged(date),

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export default class MetaBindPlugin extends Plugin {
3838
context.addChild(new InputFieldMarkdownRenderChild(
3939
codeBlock,
4040
InputFieldMarkdownRenderChildType.INLINE_CODE_BLOCK,
41-
text, this,
41+
text,
42+
this,
4243
context.sourcePath,
4344
this.markDownInputFieldIndex,
4445
));

src/parsers/InputFieldDeclarationParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum InputFieldArgumentType {
2424
MAX_VALUE = 'maxValue',
2525
OPTION = 'option',
2626
TITLE = 'title',
27+
ALIGN_RIGHT = 'alignRight',
2728

2829
INVALID = 'invalid',
2930
}
@@ -106,9 +107,9 @@ export class InputFieldDeclarationParser {
106107

107108

108109
if (useTemplate) {
109-
console.log(templateName);
110+
// console.log(templateName);
110111
const template = InputFieldDeclarationParser.templates.filter(x => x.identifier === templateName).first()?.template;
111-
console.log(template);
112+
// console.log(template);
112113
if (template) {
113114
inputFieldDeclaration.bindTarget = inputFieldDeclaration.bindTarget || template.bindTarget;
114115
inputFieldDeclaration.isBound = inputFieldDeclaration.isBound || template.isBound;

0 commit comments

Comments
 (0)