Skip to content

Commit 4787f2a

Browse files
committed
fix #234
1 parent 7906e81 commit 4787f2a

File tree

16 files changed

+194
-86
lines changed

16 files changed

+194
-86
lines changed

exampleVault/Input Fields/Progress Bar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
progress1: -6
3-
progress2: 0.2
3+
progress2: 0.5
44
progress3: 2
5-
progress4: 3.6
5+
progress4: 2.6
66
---
77

88
```meta-bind

exampleVault/Input Fields/Suggester.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
suggest: option 2
2+
suggest: option 1
33
fileSuggest: "[[Other/Example Notes/Example Note with Embeds.md|Example Note with Embeds]]"
44
fileSuggest2: "[[Example Note with Embeds]]"
55
fileSuggest3: Example Note with Embeds
@@ -16,6 +16,16 @@ showcase
1616
):suggest]
1717
```
1818

19+
```meta-bind
20+
INPUT[suggester(
21+
option(option 1),
22+
option(option 2),
23+
option(option 3),
24+
allowOther,
25+
showcase
26+
):suggest]
27+
```
28+
1929
### Suggester with Dataview
2030

2131
Note, that this will error, if dataview is not enabled.

packages/core/src/api/InternalAPI.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ButtonBuilderModal,
1919
type ButtonBuilderModalOptions,
2020
} from 'packages/core/src/modals/modalContents/ButtonBuilderModal';
21-
import { SvelteModal } from 'packages/core/src/modals/modalContents/SvelteModal';
21+
import { SvelteModalContent } from 'packages/core/src/modals/modalContents/SvelteModalContent';
2222
import DatePickerInput from 'packages/core/src/fields/inputFields/fields/DatePicker/DatePicker.svelte';
2323
import ImageSuggesterModalComponent from 'packages/core/src/modals/modalContents/ImageSuggesterModalComponent.svelte';
2424
import type { Moment } from 'moment';
@@ -27,6 +27,7 @@ import ErrorIndicatorComponent from 'packages/core/src/utils/errors/ErrorIndicat
2727
import { SuggesterSelectModal } from 'packages/core/src/modals/selectModalContents/SuggesterSelectModal';
2828
import { type IFuzzySearch } from 'packages/core/src/utils/IFuzzySearch';
2929
import { type ContextMenuItemDefinition, type IContextMenu } from 'packages/core/src/utils/IContextMenu';
30+
import TextPromptModalContent from 'packages/core/src/modals/modalContents/TextPromptModalContent.svelte';
3031

3132
export interface ErrorIndicatorProps {
3233
errorCollection: ErrorCollection;
@@ -46,6 +47,14 @@ export interface ModalOptions {
4647
classes?: string[];
4748
}
4849

50+
export interface TextPromptModalOptions extends ModalOptions {
51+
value: string;
52+
subTitle: string;
53+
multiline: boolean;
54+
onSubmit: (value: string) => void;
55+
onCancel: () => void;
56+
}
57+
4958
export abstract class InternalAPI<Plugin extends IPlugin> {
5059
plugin: Plugin;
5160

@@ -241,7 +250,7 @@ export abstract class InternalAPI<Plugin extends IPlugin> {
241250

242251
openImageSuggesterModal(inputField: ImageSuggesterIPF, selectCallback: (selected: string) => void): void {
243252
this.createModal(
244-
new SvelteModal((modal, targetEl) => {
253+
new SvelteModalContent((modal, targetEl) => {
245254
return new ImageSuggesterModalComponent({
246255
target: targetEl,
247256
props: {
@@ -263,7 +272,7 @@ export abstract class InternalAPI<Plugin extends IPlugin> {
263272

264273
openDatePickerModal(inputField: DatePickerIPF): void {
265274
this.createModal(
266-
new SvelteModal((modal, targetEl) => {
275+
new SvelteModalContent((modal, targetEl) => {
267276
return new DatePickerInput({
268277
target: targetEl,
269278
props: {
@@ -281,20 +290,33 @@ export abstract class InternalAPI<Plugin extends IPlugin> {
281290
).open();
282291
}
283292

284-
openTextPromptModal(
285-
_value: string,
286-
_title: string,
287-
_subTitle: string,
288-
_description: string,
289-
_onSubmit: (value: string) => void,
290-
_onCancel: () => void,
291-
): void {
292-
throw new Error('Method not implemented.');
293+
openTextPromptModal(options: TextPromptModalOptions): void {
294+
this.createModal(
295+
new SvelteModalContent((modal, targetEl) => {
296+
return new TextPromptModalContent({
297+
target: targetEl,
298+
props: {
299+
options: {
300+
...options,
301+
onSubmit: (value: string): void => {
302+
options.onSubmit(value);
303+
modal.closeModal();
304+
},
305+
onCancel: (): void => {
306+
options.onCancel();
307+
modal.closeModal();
308+
},
309+
},
310+
},
311+
});
312+
}),
313+
options,
314+
).open();
293315
}
294316

295317
openErrorCollectionViewModal(settings: ErrorIndicatorProps): void {
296318
this.createModal(
297-
new SvelteModal((_modal, targetEl) => {
319+
new SvelteModalContent((_modal, targetEl) => {
298320
return new ErrorCollectionComponent({
299321
target: targetEl,
300322
props: {

packages/core/src/fields/fieldArguments/inputFieldArguments/arguments/AllowOtherInputFieldArgument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export class AllowOtherInputFieldArgument extends AbstractInputFieldArgument {
1010
}
1111

1212
public getConfig(): InputFieldArgumentConfig {
13-
return InputFieldArgumentConfigs.multiLine;
13+
return InputFieldArgumentConfigs.allowOther;
1414
}
1515
}

packages/core/src/fields/inputFields/fields/InlineList/InlineListComponent.svelte

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,17 @@
6767
name: 'Edit',
6868
icon: 'pencil',
6969
onclick: () => {
70-
// TODO: this needs the text prompt modal
71-
plugin.internal.openTextPromptModal(
72-
stringifyLiteral(value[index]),
73-
'Edit List Item',
74-
'Edit the value of this list item.',
75-
'',
76-
v => {
70+
plugin.internal.openTextPromptModal({
71+
title: 'Meta Bind List',
72+
subTitle: 'Edit the value of a list item.',
73+
value: stringifyLiteral(value[index]),
74+
multiline: false,
75+
onSubmit: (v: MBLiteral) => {
7776
value[index] = v;
7877
onValueChange(value);
7978
},
80-
() => {},
81-
);
79+
onCancel: () => {},
80+
});
8281
},
8382
});
8483

packages/core/src/fields/inputFields/fields/InlineList/InlineListIPF.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ export class InlineListIPF extends AbstractInputField<MBLiteral[], MBLiteral[]>
3232
}
3333

3434
openModal(): void {
35-
this.base.plugin.internal.openTextPromptModal(
36-
'',
37-
'Meta Bind List',
38-
'New List Element',
39-
'',
40-
(newElement: MBLiteral) => {
35+
this.base.plugin.internal.openTextPromptModal({
36+
title: 'Meta Bind List',
37+
subTitle: 'Create a new List Element.',
38+
value: '',
39+
multiline: false,
40+
onSubmit: (newElement: MBLiteral) => {
4141
const value = this.getInternalValue();
4242
value.push(newElement);
4343
this.setInternalValue(value);
4444
},
45-
() => {},
46-
);
45+
onCancel: () => {},
46+
});
4747
}
4848
}

packages/core/src/fields/inputFields/fields/InlineListSuggester/InlineListSuggesterIPF.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ export class InlineListSuggesterIPF extends AbstractInputField<MBLiteral[], MBLi
4343
}
4444

4545
openTextModal(): void {
46-
this.base.plugin.internal.openTextPromptModal(
47-
'',
48-
'Meta Bind List Suggester',
49-
'New List Element',
50-
'',
51-
(newElement: MBLiteral) => {
46+
this.base.plugin.internal.openTextPromptModal({
47+
title: 'Meta Bind List Suggester',
48+
subTitle: 'Create a new List Element.',
49+
value: '',
50+
multiline: false,
51+
onSubmit: (newElement: MBLiteral) => {
5252
const value = this.getInternalValue();
5353
value.push(newElement);
5454
this.setInternalValue(value);
5555
},
56-
() => {},
57-
);
56+
onCancel: () => {},
57+
});
5858
}
5959
}

packages/core/src/fields/inputFields/fields/List/ListComponent.svelte

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,17 @@
7777
name: 'Edit',
7878
icon: 'pencil',
7979
onclick: () => {
80-
// TODO: this needs the text prompt modal
81-
plugin.internal.openTextPromptModal(
82-
stringifyLiteral(value[index]),
83-
'Edit List Item',
84-
'Edit the value of this list item.',
85-
'',
86-
v => {
80+
plugin.internal.openTextPromptModal({
81+
title: 'Meta Bind List',
82+
subTitle: 'Edit the value of a list item.',
83+
value: stringifyLiteral(value[index]),
84+
multiline: multiLine,
85+
onSubmit: (v: MBLiteral) => {
8786
value[index] = v;
8887
onValueChange(value);
8988
},
90-
() => {},
91-
);
89+
onCancel: () => {},
90+
});
9291
},
9392
});
9493

packages/core/src/fields/inputFields/fields/ListSuggester/ListSuggesterComponent.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
export let value: MBLiteral[];
1212
export let showSuggester: () => void;
1313
export let showTextPrompt: () => void;
14-
export let allowsOther: boolean;
14+
export let allowOther: boolean;
1515
export let onValueChange: (value: MBLiteral[]) => void;
1616
1717
export function setValue(v: MBLiteral[]): void {
@@ -92,7 +92,7 @@
9292
</div>
9393
<div class="mb-list-input">
9494
<Button variant={ButtonStyleType.DEFAULT} on:click={() => showSuggester()}>Add new item</Button>
95-
{#if allowsOther}
95+
{#if allowOther}
9696
<Button variant={ButtonStyleType.DEFAULT} on:click={() => showTextPrompt()}>Add other item</Button>
9797
{/if}
9898
</div>

packages/core/src/fields/inputFields/fields/ListSuggester/ListSuggesterIPF.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ListSuggesterIPF extends AbstractInputField<MBLiteral[], MBLiteral[
3030
return {
3131
showSuggester: () => this.openModal(),
3232
showTextPrompt: () => this.openTextModal(),
33-
allowsOther: this.base.getArgument(InputFieldArgumentType.ALLOW_OTHER)?.value === true,
33+
allowOther: this.base.getArgument(InputFieldArgumentType.ALLOW_OTHER)?.value === true,
3434
};
3535
}
3636

@@ -43,17 +43,17 @@ export class ListSuggesterIPF extends AbstractInputField<MBLiteral[], MBLiteral[
4343
}
4444

4545
openTextModal(): void {
46-
this.base.plugin.internal.openTextPromptModal(
47-
'',
48-
'Meta Bind List Suggester',
49-
'New List Element',
50-
'',
51-
(newElement: MBLiteral) => {
46+
this.base.plugin.internal.openTextPromptModal({
47+
title: 'Meta Bind List Suggester',
48+
subTitle: 'Create a new List Element.',
49+
value: '',
50+
multiline: false,
51+
onSubmit: (newElement: MBLiteral) => {
5252
const value = this.getInternalValue();
5353
value.push(newElement);
5454
this.setInternalValue(value);
5555
},
56-
() => {},
57-
);
56+
onCancel: () => {},
57+
});
5858
}
5959
}

0 commit comments

Comments
 (0)