Skip to content

Commit

Permalink
feat: tabs for the form builder interface
Browse files Browse the repository at this point in the history
feat: interactive template editor

feat: create new note from form using templates

feat: generic input suggester interface

feat: UI for creating notes from forms

create new notes from forms using templates associated to each form
  • Loading branch information
danielo515 committed Dec 15, 2023
1 parent 0dee888 commit 019ab6f
Show file tree
Hide file tree
Showing 28 changed files with 1,078 additions and 316 deletions.
10 changes: 8 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": ["@typescript-eslint", "fp-ts", "@stylistic"],
"plugins": [
"@typescript-eslint",
"fp-ts",
"@stylistic",
"newline-function-call"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
Expand All @@ -20,6 +25,7 @@
"@typescript-eslint/no-empty-function": "off",
"arrow-parens": ["error", "always"],
"fp-ts/no-lib-imports": "error",
"@stylistic/function-call-argument-newline": ["error", "consistent"]
"@stylistic/function-call-argument-newline": ["error", "consistent"],
"newline-function-call/function-call-argument-newline": ["error"]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
with:
cache: "npm"

- run: npm install
- run: npm ci
- name: Build and Test
run: npm run build && npm run test
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ https://github.com/danielo515/obsidian-modal-form/assets/2270425/542974aa-c58b-4
- Define forms using a simple JSON format
- Create and manage a collection of forms, each identified by a unique name
- User interface for creating new forms
- Create new notes directly from the form using templates
- Template editor has a nice UI for creating templates
- Many input types
- number
- date
Expand All @@ -33,6 +35,8 @@ https://github.com/danielo515/obsidian-modal-form/assets/2270425/542974aa-c58b-4
- list of notes from a folder

![example form](media/example.png)
![templates](media/templates-v1.gif)

## Why this plugin?

Obsidian is a great tool for taking notes, but it is also a nice for managing data.
Expand Down
Binary file added media/templates-v1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 33 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"esbuild": "0.17.3",
"esbuild-svelte": "^0.8.0",
"eslint-plugin-fp-ts": "^0.3.2",
"eslint-plugin-newline-function-call": "^1.0.0",
"jest": "^29.7.0",
"obsidian": "^1.4.11",
"prettier": "^3.0.3",
Expand All @@ -43,7 +44,8 @@
"dependencies": {
"fp-ts": "^2.16.1",
"fuse.js": "^6.6.2",
"parser-ts": "^0.7.0",
"type-fest": "^4.6.0",
"valibot": "^0.19.0"
}
}
}
2 changes: 2 additions & 0 deletions src/core/formDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MigrationError,
} from "./formDefinitionSchema";
import { A, O, pipe } from "@std";
import { ParsedTemplate } from "./template/templateParser";
//=========== Types derived from schemas
type selectFromNotes = Output<typeof SelectFromNotesSchema>;
type inputSlider = Output<typeof InputSliderSchema>;
Expand Down Expand Up @@ -71,6 +72,7 @@ export type FieldDefinition = Output<typeof FieldDefinitionSchema>;
* FormDefinition is an already valid form, ready to be used in the form modal.
*/
export type FormDefinition = Output<typeof FormDefinitionLatestSchema>;
export type FormWithTemplate = FormDefinition & { template: ParsedTemplate }

export type FormOptions = {
values?: Record<string, unknown>;
Expand Down
11 changes: 9 additions & 2 deletions src/core/formDefinitionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "valibot";
import { AllFieldTypes, FormDefinition } from "./formDefinition";
import { findFieldErrors } from "./findInputDefinitionSchema";
import { ParsedTemplateSchema } from "./template/templateSchema";

/**
* Here are the core logic around the main domain of the plugin,
Expand Down Expand Up @@ -72,7 +73,7 @@ export const InputDataviewSourceSchema = object({
type: literal("dataview"),
query: nonEmptyString("dataview query"),
});
export const InputBasicSchema = object({ type: InputBasicTypeSchema, });
export const InputBasicSchema = object({ type: InputBasicTypeSchema });
export const InputSelectFixedSchema = object({
type: literal("select"),
source: literal("fixed"),
Expand Down Expand Up @@ -176,6 +177,12 @@ const FormDefinitionV1Schema = merge([
object({
version: literal("1"),
fields: FieldListSchema,
template: optional(
object({
createCommand: boolean(),
parsedTemplate: ParsedTemplateSchema,
}),
),
}),
]);
// This is the latest schema.
Expand Down Expand Up @@ -221,7 +228,7 @@ export class InvalidData {
constructor(
public data: unknown,
readonly error: ValiError,
) { }
) {}
toString(): string {
return `InvalidData: ${this.error.issues
.map((issue) => issue.message)
Expand Down
6 changes: 4 additions & 2 deletions src/core/objectSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const PickOmitSchema = object({

function picKeys(obj: Record<string, unknown>) {
return (keys: NonEmptyArray<string>) =>
pipe(obj,
pipe(
obj,
filterWithIndex((k) => keys.includes(k))
);
}
function omitKeys(obj: Record<string, unknown>) {
return (keys: NonEmptyArray<string>) =>
pipe(obj,
pipe(
obj,
filterWithIndex((k) => !keys.includes(k))
);
}
Expand Down
Loading

0 comments on commit 019ab6f

Please sign in to comment.