diff --git a/.changeset/mean-bugs-end.md b/.changeset/mean-bugs-end.md new file mode 100644 index 00000000..4906dc77 --- /dev/null +++ b/.changeset/mean-bugs-end.md @@ -0,0 +1,5 @@ +--- +"@sjsf/form": minor +--- + +Implement `useForm` API, Add `FormContent` and `SubmitButton` components diff --git a/.github/workflows/deploy-pages.yaml b/.github/workflows/deploy-pages.yaml new file mode 100644 index 00000000..89070db2 --- /dev/null +++ b/.github/workflows/deploy-pages.yaml @@ -0,0 +1,54 @@ +name: Deploy to GitHub Pages +on: + release: + types: [published] + +permissions: + id-token: write + contents: write + pages: write + +jobs: + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Checkout code repository + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + - name: Install dependencies + run: pnpm install + + - name: Cache turbo build setup + uses: actions/cache@v4 + with: + path: .turbo + key: ${{ runner.os }}-turbo-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-turbo- + + - name: Build + run: pnpm run build --filter="./apps/*" + + - name: Merge apps build outputs + run: mv apps/playground/dist apps/docs/dist/playground + + - name: Upload Pages Artifact + uses: actions/upload-pages-artifact@v3 + with: + path: "apps/docs/dist/" + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/version-and-publish.yaml similarity index 65% rename from .github/workflows/release.yml rename to .github/workflows/version-and-publish.yaml index db603e7d..1fcf83de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/version-and-publish.yaml @@ -1,4 +1,4 @@ -name: Release +name: Version and Publish on: push: branches: @@ -10,7 +10,6 @@ permissions: id-token: write contents: write pull-requests: write - pages: write jobs: version: @@ -41,9 +40,9 @@ jobs: ${{ runner.os }}-turbo- - name: Build - run: pnpm run ci:build + run: pnpm run ci:build --filter="@sjsf/*" - - name: create and publish versions + - name: Create and publish versions uses: changesets/action@v1 with: version: pnpm ci:version @@ -53,23 +52,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Merge apps build outputs - run: mv apps/playground/dist apps/docs/dist/playground - - - name: Upload Pages Artifact - uses: actions/upload-pages-artifact@v3 - with: - path: "apps/docs/dist/" - - deploy: - needs: version - runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 - diff --git a/README.md b/README.md index fb7d239f..0ec1e285 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ npm install @sjsf/form @sjsf/ajv8-validator ajv@8 ```svelte -
+ required: ["name"] + } + + const form = useForm({ + ...theme, + schema, + validator, + translation, + onSubmit: console.log, + }) + + +{JSON.stringify(value, null, 2)}+
{JSON.stringify(form.value, null, 2)}diff --git a/apps/docs/src/content/docs/_with-daisyui.svelte b/apps/docs/src/content/docs/_with-daisyui.svelte index e3900c86..c07d0a4f 100644 --- a/apps/docs/src/content/docs/_with-daisyui.svelte +++ b/apps/docs/src/content/docs/_with-daisyui.svelte @@ -1,28 +1,30 @@ - -
{JSON.stringify(value, null, 2)}+
{JSON.stringify(form.value, null, 2)}diff --git a/apps/docs/src/content/docs/_with-flowbite.svelte b/apps/docs/src/content/docs/_with-flowbite.svelte index 038a9d3e..95d3b64f 100644 --- a/apps/docs/src/content/docs/_with-flowbite.svelte +++ b/apps/docs/src/content/docs/_with-flowbite.svelte @@ -1,27 +1,25 @@ - +
{JSON.stringify(value, null, 2)}+
{JSON.stringify(form.value, null, 2)}diff --git a/apps/docs/src/content/docs/_with-shadcn.svelte b/apps/docs/src/content/docs/_with-shadcn.svelte index 7684fb87..f3a4dc3b 100644 --- a/apps/docs/src/content/docs/_with-shadcn.svelte +++ b/apps/docs/src/content/docs/_with-shadcn.svelte @@ -1,30 +1,28 @@ - +
{JSON.stringify(value, null, 2)}+
{JSON.stringify(form.value, null, 2)}diff --git a/apps/docs/src/content/docs/_with-skeleton.svelte b/apps/docs/src/content/docs/_with-skeleton.svelte index d421fc83..46b313ab 100644 --- a/apps/docs/src/content/docs/_with-skeleton.svelte +++ b/apps/docs/src/content/docs/_with-skeleton.svelte @@ -1,29 +1,30 @@ - -
{JSON.stringify(value, null, 2)}+
{JSON.stringify(form.value, null, 2)}diff --git a/apps/docs/src/content/docs/guides/custom-form.mdx b/apps/docs/src/content/docs/advanced/custom-form.mdx similarity index 51% rename from apps/docs/src/content/docs/guides/custom-form.mdx rename to apps/docs/src/content/docs/advanced/custom-form.mdx index 2f9d706d..7119729e 100644 --- a/apps/docs/src/content/docs/guides/custom-form.mdx +++ b/apps/docs/src/content/docs/advanced/custom-form.mdx @@ -1,14 +1,14 @@ --- title: Custom form sidebar: - order: 4 + order: 0 --- import { Code } from '@astrojs/starlight/components'; -import customFormCode from '@/components/custom-form.svelte?raw'; +import customFormCode from '@/components/custom-form.ts?raw'; Even with a simple setup, resulting code is very verbose. -Therefore, after choosing a theme, validator and translation, it is convenient to create a custom component. +Therefore, after choosing a theme, validator and translation, it is convenient to create a wrapper around the `useForm`. -
+
diff --git a/apps/docs/src/content/docs/advanced/custom-validation.mdx b/apps/docs/src/content/docs/advanced/custom-validation.mdx
index 1dc428c6..3353524e 100644
--- a/apps/docs/src/content/docs/advanced/custom-validation.mdx
+++ b/apps/docs/src/content/docs/advanced/custom-validation.mdx
@@ -1,7 +1,7 @@
---
title: Custom validation
sidebar:
- order: 2
+ order: 1
---
## Errors transformation and custom validation
diff --git a/apps/docs/src/content/docs/advanced/custom-widgets.mdx b/apps/docs/src/content/docs/advanced/custom-widgets.mdx
index 21a922b9..f614450e 100644
--- a/apps/docs/src/content/docs/advanced/custom-widgets.mdx
+++ b/apps/docs/src/content/docs/advanced/custom-widgets.mdx
@@ -1,7 +1,7 @@
---
title: Custom widgets
sidebar:
- order: 3
+ order: 2
---
## Example
diff --git a/apps/docs/src/content/docs/advanced/form-base.mdx b/apps/docs/src/content/docs/advanced/form-base.mdx
deleted file mode 100644
index 1850f8cc..00000000
--- a/apps/docs/src/content/docs/advanced/form-base.mdx
+++ /dev/null
@@ -1,57 +0,0 @@
----
-title: Form base
-sidebar:
- order: 0
----
-
-By default `Form` will calculate default value for provided `schema` and current `value` on each `schema` change.
-
-```typescript
-$effect(() => {
- schema;
- value = untrack(() => getDefaultFormState(
- validator,
- schema,
- value
- ));
-});
-```
-
-While this behavior is convenient it has some drawbacks:
-
-- Empty form on initial render when `value` is `undefined`
-- Additional render after defaults calculation
-- This behavior may not be desirable in some cases
-
-To prevent this behavior, you can use `FormBase` component,
-which provides the same interface as `Form`.
-
-:::note
-
-You should calculate initial value by yourself.
-
-:::
-
-```svelte
-
-
-