diff --git a/main.ts b/main.ts index b25b4f63..266010ec 100644 --- a/main.ts +++ b/main.ts @@ -21,7 +21,7 @@ const DEFAULT_SETTINGS: ModalFormSettings = { // Define functions and properties you want to make available to other plugins, or templater templates, etc interface PublicAPI { exampleForm(): Promise; - openForm(name: string): Promise; + openForm(formReference: string | FormDefinition): Promise } // This is the plugin entrypoint export default class ModalFormPlugin extends Plugin { diff --git a/src/views/EditFormView.ts b/src/views/EditFormView.ts index fdd40fc1..5845374a 100644 --- a/src/views/EditFormView.ts +++ b/src/views/EditFormView.ts @@ -56,7 +56,10 @@ export class EditFormView extends ItemView { }, onCancel: () => { this.plugin.closeEditForm() - } + }, + onPreview: (formDefinition) => { + this.plugin.api.openForm(formDefinition) + }, } }); } diff --git a/src/views/FormBuilder.svelte b/src/views/FormBuilder.svelte index b64ba2fb..dde23b7b 100644 --- a/src/views/FormBuilder.svelte +++ b/src/views/FormBuilder.svelte @@ -22,6 +22,7 @@ export let onChange: () => void; export let onSubmit: (formDefinition: FormDefinition) => void; export let onCancel: () => void; + export let onPreview: (formDefinition: FormDefinition) => void; $: isValid = isValidFormDefinition(definition); @@ -83,6 +84,10 @@ if (!isValidFormDefinition(definition)) return; onSubmit(definition); }; + const handlePreview = () => { + if (!isValidFormDefinition(definition)) return; + onPreview(definition); + };