From fa5987a93ae7ef7bc6aea60f6273bbcb6e78fcc1 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Wed, 11 Oct 2023 10:33:57 +0200 Subject: [PATCH] fix: make multi-select static work fixes #63 --- src/FormModal.ts | 2 +- src/core/formDefinition.ts | 8 +- src/exampleModalDefinition.ts | 2 +- src/views/FormBuilder.svelte | 773 +++++++++++++++++----------------- 4 files changed, 388 insertions(+), 397 deletions(-) diff --git a/src/FormModal.ts b/src/FormModal.ts index c25555cd..76605a7e 100644 --- a/src/FormModal.ts +++ b/src/FormModal.ts @@ -132,7 +132,7 @@ export class FormModal extends Modal { { this.formResult[definition.name] = this.formResult[definition.name] || [] const options = fieldInput.source == 'fixed' - ? fieldInput.options + ? fieldInput.multi_select_options : get_tfiles_from_folder(fieldInput.folder, this.app).map(file => file.basename); this.svelteComponents.push(new MultiSelect({ target: fieldBase.controlEl, diff --git a/src/core/formDefinition.ts b/src/core/formDefinition.ts index 0371b49c..6795a0e8 100644 --- a/src/core/formDefinition.ts +++ b/src/core/formDefinition.ts @@ -26,7 +26,7 @@ type inputSelectFixed = { options: { value: string; label: string }[]; } type basicInput = { type: FieldType }; -type multiselect = { type: 'multiselect', source: 'notes', folder: string } | { type: 'multiselect', source: 'fixed', options: string[] } +type multiselect = { type: 'multiselect', source: 'notes', folder: string } | { type: 'multiselect', source: 'fixed', multi_select_options: string[] } type inputType = | basicInput | inputNoteFromFolder @@ -120,6 +120,7 @@ export type EditableInput = { min?: number; max?: number; options?: { value: string; label: string }[]; + multi_select_options?: string[]; query?: string; }; @@ -145,7 +146,10 @@ export function isMultiSelect(input: unknown): input is multiselect { return isObject(input) && input.type === 'multiselect' && ( - (input.source === 'notes' && typeof input.folder === 'string') || (input.source === 'fixed' && Array.isArray(input.options)) + (input.source === 'notes' && typeof input.folder === 'string') + || ( + input.source === 'fixed' && Array.isArray(input.multi_select_options) && input.multi_select_options.every((option: unknown) => typeof option === 'string') + ) ) } diff --git a/src/exampleModalDefinition.ts b/src/exampleModalDefinition.ts index a7917fbd..a42b4a36 100644 --- a/src/exampleModalDefinition.ts +++ b/src/exampleModalDefinition.ts @@ -49,7 +49,7 @@ export const exampleModalDefinition: FormDefinition = { name: "multi_example_2", label: "Multi select fixed", description: "Allows to pick many notes from a fixed list", - input: { type: "multiselect", source: "fixed", options: ['Android', 'iOS', 'Windows', 'MacOS', 'Linux', 'Solaris', 'MS2'] }, + input: { type: "multiselect", source: "fixed", multi_select_options: ['Android', 'iOS', 'Windows', 'MacOS', 'Linux', 'Solaris', 'MS2'] }, }, { name: "best_fried", diff --git a/src/views/FormBuilder.svelte b/src/views/FormBuilder.svelte index ccf14051..42050b96 100644 --- a/src/views/FormBuilder.svelte +++ b/src/views/FormBuilder.svelte @@ -1,413 +1,400 @@ + {/each} + + {:else if field.input.source === "notes"} + +
+ +
+ {/if} + {:else if field.input.type === "slider"} + {@const min_id = `min_${index}`} + {@const max_id = `max_${index}`} +
+ + +
+
+ + +
+ {:else if field.input.type === "note"} + +
+ +
+ {:else if field.input.type === "dataview"} + + {/if} + +
+ +
+
+ {/each} + {:else} + No fields yet + {/if} + +