Skip to content

Commit

Permalink
feat(input): new input folder suggester
Browse files Browse the repository at this point in the history
fixes #148
  • Loading branch information
danielo515 committed Dec 8, 2023
1 parent e7949ad commit 2102619
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/FormModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { A, E, pipe, throttle } from "@std";
import { log_error, log_notice } from "./utils/Log";
import { FieldValue, FormEngine, makeFormEngine } from "./store/formStore";
import { Writable } from "svelte/store";
import { FolderSuggest } from "./suggesters/suggestFolder";

export type SubmitFn = (formResult: FormResult) => void;

Expand Down Expand Up @@ -154,6 +155,15 @@ export class FormModal extends Modal {
subToErrors(element.inputEl);
element.onChange(fieldStore.value.set);
});
case "folder":
return fieldBase.addText((element) => {
new FolderSuggest(
element.inputEl,
this.app,
);
subToErrors(element.inputEl);
element.onChange(fieldStore.value.set);
});
case "slider":
return fieldBase.addSlider((slider) => {
slider.setLimits(fieldInput.min, fieldInput.max, 1);
Expand Down
1 change: 1 addition & 0 deletions src/core/formDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const FieldTypeReadable: Record<AllFieldTypes, string> = {
textarea: "Text area",
toggle: "Toggle",
note: "Note",
folder: "Folder",
slider: "Slider",
select: "Select",
dataview: "Dataview",
Expand Down
6 changes: 6 additions & 0 deletions src/core/formDefinitionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export const InputNoteFromFolderSchema = object({
type: literal("note"),
folder: nonEmptyString("folder name"),
});
export const InputFolderSchema = object({
type: literal("folder"),
// TODO: allow exclude option
});
export const InputDataviewSourceSchema = object({
type: literal("dataview"),
query: nonEmptyString("dataview query"),
Expand Down Expand Up @@ -102,6 +106,7 @@ export const MultiselectSchema = union([
export const InputTypeSchema = union([
InputBasicSchema,
InputNoteFromFolderSchema,
InputFolderSchema,
InputSliderSchema,
InputTagSchema,
SelectFromNotesSchema,
Expand All @@ -123,6 +128,7 @@ export const InputTypeToParserMap: Record<
textarea: parseC(InputBasicSchema),
toggle: parseC(InputBasicSchema),
note: parseC(InputNoteFromFolderSchema),
folder: parseC(InputFolderSchema),
slider: parseC(InputSliderSchema),
tag: parseC(InputTagSchema),
select: trySchemas([SelectFromNotesSchema, InputSelectFixedSchema]),
Expand Down
5 changes: 5 additions & 0 deletions src/exampleModalDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const exampleModalDefinition: FormDefinition = {
label: "Favorite book",
description: "Pick one",
input: { type: "note", folder: "Books" },
}, {
name: "folder",
label: "The destination folder",
description: "It offers auto-completion to existing folders",
input: { type: "folder" },
},
{
name: "multi_example",
Expand Down

0 comments on commit 2102619

Please sign in to comment.