From b5b9528f92ca8dbc9f6a35884f269075ec522306 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Fri, 20 Oct 2023 23:37:28 +0200 Subject: [PATCH 01/11] feat: scroll to new fields in the editor --- src/views/FormBuilder.svelte | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/views/FormBuilder.svelte b/src/views/FormBuilder.svelte index 480f91e2..d9d8665b 100644 --- a/src/views/FormBuilder.svelte +++ b/src/views/FormBuilder.svelte @@ -26,6 +26,7 @@ $: isValid = isValidFormDefinition(definition); $: errors = validateFields(definition.fields); + $: activeFieldIndex = 0; function folderField(element: HTMLElement, index: number) { const field = definition.fields[index]; @@ -45,6 +46,18 @@ }); } + function scrollWhenActive(element: HTMLElement, index: number) { + function update() { + if (index === activeFieldIndex) { + element.scrollIntoView({ behavior: "smooth", block: "center" }); + } + } + update(); + return { + update, + }; + } + function findFreeName(fieldIndex: number): string { const field = definition.fields[fieldIndex]; let name = field.name; @@ -130,7 +143,8 @@ input: { type: "text" }, }, ]; - onChange(); + // onChange(); + activeFieldIndex = definition.fields.length - 1; }}>Add more fields {/each} @@ -187,7 +199,7 @@ {@const delete_id = `delete_${index}`}
From 0c4b077092fa08440930c89fafc32db02da8579a Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Sun, 22 Oct 2023 13:51:23 +0200 Subject: [PATCH 11/11] fix: accept empty option values for now --- src/core/formDefinition.ts | 2 +- src/views/EditFormView.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/formDefinition.ts b/src/core/formDefinition.ts index 3aa733b9..b02d8147 100644 --- a/src/core/formDefinition.ts +++ b/src/core/formDefinition.ts @@ -32,7 +32,7 @@ const InputSelectFixedSchema = object({ type: literal("select"), source: literal("fixed"), options: array(object({ - value: nonEmptyString('Value of a select option'), label: string() + value: string([toTrimmed()]), label: string() })) }); diff --git a/src/views/EditFormView.ts b/src/views/EditFormView.ts index 2b179559..7fecc2b2 100644 --- a/src/views/EditFormView.ts +++ b/src/views/EditFormView.ts @@ -46,7 +46,6 @@ export class EditFormView extends ItemView { target: this.containerEl, props: { definition: this.formState, - app: this.app, onChange: () => { console.log(this.formState) this.app.workspace.requestSaveLayout()