diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..07d11491 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "prettier-plugin-svelte" + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f7ea842a..e985825c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-modal-form", - "version": "1.21.0", + "version": "1.22.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-modal-form", - "version": "1.21.0", + "version": "1.22.1", "license": "MIT", "dependencies": { "fp-ts": "^2.16.1", @@ -25,6 +25,8 @@ "esbuild-svelte": "^0.8.0", "jest": "^29.7.0", "obsidian": "^1.4.11", + "prettier": "^3.0.3", + "prettier-plugin-svelte": "^3.0.3", "svelte": "^4.2.0", "svelte-check": "^3.5.2", "svelte-preprocess": "^5.0.4", @@ -4940,6 +4942,31 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-plugin-svelte": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-3.0.3.tgz", + "integrity": "sha512-dLhieh4obJEK1hnZ6koxF+tMUrZbV5YGvRpf2+OADyanjya5j0z1Llo8iGwiHmFWZVG/hLEw/AJD5chXd9r3XA==", + "dev": true, + "peerDependencies": { + "prettier": "^3.0.0", + "svelte": "^3.2.0 || ^4.0.0-next.0" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index 290eea66..86b6c888 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "esbuild-svelte": "^0.8.0", "jest": "^29.7.0", "obsidian": "^1.4.11", + "prettier": "^3.0.3", + "prettier-plugin-svelte": "^3.0.3", "svelte": "^4.2.0", "svelte-check": "^3.5.2", "svelte-preprocess": "^5.0.4", diff --git a/src/std/index.ts b/src/std/index.ts index 2d2a2cbf..7e316a5b 100644 --- a/src/std/index.ts +++ b/src/std/index.ts @@ -1,6 +1,6 @@ import { pipe as p } from "fp-ts/function"; import { partitionMap } from "fp-ts/Array"; -import { isLeft, isRight, tryCatchK, map, getOrElse } from "fp-ts/Either"; +import { isLeft, isRight, tryCatchK, map, getOrElse, right, left } from "fp-ts/Either"; import { ValiError, parse as parseV } from "valibot"; export const pipe = p @@ -11,6 +11,8 @@ export const A = { export const E = { isLeft, isRight, + left, + right, tryCatchK, getOrElse, map diff --git a/src/views/ManageForms.svelte b/src/views/ManageForms.svelte new file mode 100644 index 00000000..a63d4c68 --- /dev/null +++ b/src/views/ManageForms.svelte @@ -0,0 +1,135 @@ + + +

Manage forms

+ + + +
+ {#each forms as form} +
+

{form.name}

+
+ + + + +
+
+ {/each} +
+ + diff --git a/src/views/ManageFormsView.ts b/src/views/ManageFormsView.ts index 0224820a..56a8cbbb 100644 --- a/src/views/ManageFormsView.ts +++ b/src/views/ManageFormsView.ts @@ -1,6 +1,9 @@ -import { MigrationError } from "src/core/formDefinition"; +import { FormDefinition, MigrationError } from "src/core/formDefinition"; +import ManageForms from './ManageForms.svelte' import ModalFormPlugin from "../main"; +import * as A from 'fp-ts/Array' import { ItemView, Notice, Setting, WorkspaceLeaf } from "obsidian"; +import { E, pipe } from "@std"; export const MANAGE_FORMS_VIEW = "modal-form-manage-forms-view"; @@ -9,6 +12,7 @@ export const MANAGE_FORMS_VIEW = "modal-form-manage-forms-view"; * Manage existing forms and create new ones */ export class ManageFormsView extends ItemView { + component!: ManageForms; constructor(readonly leaf: WorkspaceLeaf, readonly plugin: ModalFormPlugin) { super(leaf); this.icon = "documents"; @@ -26,9 +30,40 @@ export class ManageFormsView extends ItemView { // console.log('On open manage forms'); const container = this.containerEl.children[1] || this.containerEl.createDiv(); container.empty(); - container.createEl("h3", { text: "Manage forms" }); - this.renderControls(container.createDiv()); - await this.renderForms(container.createDiv()); + + const settings = await this.plugin.getSettings(); + const allForms = settings.formDefinitions; + const { left: invalidForms, right: forms } = pipe( + allForms, + A.partitionMap((form) => { + if (form instanceof MigrationError) { + return E.left(form); + } else { + return E.right(form); + } + })); + this.component = new ManageForms({ + target: container, + props: { + forms, + invalidForms, + createNewForm: () => { + this.plugin.createNewForm(); + }, + editForm: (formName: string) => { + this.plugin.editForm(formName); + }, + deleteForm: (formName: string) => { + this.plugin.deleteForm(formName); + }, + duplicateForm: (form: FormDefinition) => { + this.plugin.duplicateForm(form); + } + } + }) + // container.createEl("h3", { text: "Manage forms" }); + // this.renderControls(container.createDiv()); + // await this.renderForms(container.createDiv()); } renderControls(root: HTMLElement) { @@ -94,6 +129,7 @@ export class ManageFormsView extends ItemView { } async onClose() { + this.component.$destroy(); } }