Skip to content

Commit

Permalink
feat: ability to open template builder form UI
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed May 30, 2024
1 parent e3e3249 commit c6663ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
18 changes: 13 additions & 5 deletions src/views/ManageForms.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts">
import * as Separated from "fp-ts/Separated";
import { FormDefinition } from "src/core/formDefinition";
import KeyValue from "./components/KeyValue.svelte";
import Button from "./components/Button.svelte";
import { MigrationError } from "src/core/formDefinitionSchema";
import * as Separated from "fp-ts/Separated";
import { Readable } from "svelte/store";
import Button from "./components/Button.svelte";
import KeyValue from "./components/KeyValue.svelte";
export let createNewForm: () => void;
export let deleteForm: (formName: string) => void;
export let duplicateForm: (formName: string) => void;
export let editForm: (formName: string) => void;
export let copyFormToClipboard: (form: FormDefinition) => void;
export let openInTemplateBuilder: (form: FormDefinition) => void;
export let openImportFormModal: () => void;
export let forms: Readable<FormDefinition[]>;
Expand All @@ -34,6 +35,10 @@
console.log(`Copying ${form.name}`);
copyFormToClipboard(form);
}
function handleOpenInTemplateBuilder(form: FormDefinition) {
console.log(`Opening ${form.name} in template builder`);
openInTemplateBuilder(form);
}
</script>

<div class="header">
Expand Down Expand Up @@ -62,8 +67,8 @@
>{Array.isArray(value)
? value.length
: typeof value === "object"
? !!value
: value}</span
? !!value
: value}</span
>
</KeyValue>
{/if}
Expand Down Expand Up @@ -92,6 +97,9 @@
<button on:click={() => handleDuplicateForm(form)}>
<span>Duplicate</span>
</button>
<button on:click={() => handleOpenInTemplateBuilder(form)}>
<span>Open in template editor</span>
</button>
<Button
tooltip={`Copy ${form.name} to clipboard`}
icon="clipboard-copy"
Expand Down
9 changes: 6 additions & 3 deletions src/views/ManageFormsView.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FormDefinition } from "src/core/formDefinition";
import ManageForms from "./ManageForms.svelte";
import ModalFormPlugin from "../main";
import { ItemView, Notice, WorkspaceLeaf } from "obsidian";
import { FormDefinition } from "src/core/formDefinition";
import { formsStore, invalidFormsStore, settingsStore } from "src/store/store";
import ModalFormPlugin from "../main";
import ManageForms from "./ManageForms.svelte";

export const MANAGE_FORMS_VIEW = "modal-form-manage-forms-view";

Expand Down Expand Up @@ -56,6 +56,9 @@ export class ManageFormsView extends ItemView {
openImportFormModal: () => {
this.plugin.openImportFormModal();
},
openInTemplateBuilder: (formDefinition: FormDefinition) => {
this.plugin.openTemplateBuilder({ formDefinition });
},
},
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/views/components/TemplateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ function compileFrontmatter(fields: FieldOption[]) {
return "";
}
if (frontmatterFields.length === fields.length) {
return `tR + = result.asFrontmatterString();`;
return `tR += result.asFrontmatterString();`;
}
return `tR + = result.asFrontmatterString({ pick: ${JSON.stringify(
return `tR += result.asFrontmatterString({ pick: ${JSON.stringify(
frontmatterFields,
null,
16,
Expand Down Expand Up @@ -69,8 +69,8 @@ function compileTemplaterTemplate(formName: string) {
fieldsToOmit.map((x) => x.name),
)}`,
` ${compileFrontmatter(fieldsToInclude)} `,
`%>`,
`<% "---" %>`,
`-%>`,
`<% "---" -%>`,
].join("\n");
};
}
Expand Down

0 comments on commit c6663ff

Please sign in to comment.