-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from x0k/next
Preparations for SvelteKit integration
- Loading branch information
Showing
67 changed files
with
1,591 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/ajv8-validator": patch | ||
--- | ||
|
||
Fix peer dependency specifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/skeleton-theme": patch | ||
--- | ||
|
||
Fix peer dependency specifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"docs": minor | ||
--- | ||
|
||
Add Zod integration guide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": minor | ||
--- | ||
|
||
Add `preventDataLoss` function for handling `beforeunload` event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/zod-integration": minor | ||
--- | ||
|
||
Add `@sjsf/zod-integration` package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@sjsf/form": patch | ||
--- | ||
|
||
Changed the value of `DEFAULT_ID_SEPARATOR` | ||
|
||
This change may be a BREAKING change for you if you code implicitly depends on this constant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/shadcn-theme": patch | ||
--- | ||
|
||
Fix peer dependency specifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"docs": minor | ||
--- | ||
|
||
Add `preventDataLoss` guide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": patch | ||
--- | ||
|
||
Remove forced `undefined` for `value` in `onSubmit` handler of the form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": minor | ||
--- | ||
|
||
Allow to pass multiple arguments to `mutation.run` method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": minor | ||
--- | ||
|
||
Add form option `pseudoIdSeparator` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/ajv8-validator": minor | ||
--- | ||
|
||
Add `createValidator` function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": patch | ||
--- | ||
|
||
Allow to pass a `Map` and `Array` to the `initialErrors` form option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/docs/src/content/docs/guides/_prevent-data-loss.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script lang="ts"> | ||
import { FormContent } from "@sjsf/form"; | ||
import { preventDataLoss } from "@sjsf/form/prevent-data-loss.svelte"; | ||
import { useCustomForm } from "@/components/custom-form"; | ||
const form = useCustomForm({ | ||
schema: { type: "string" }, | ||
}); | ||
preventDataLoss(form); | ||
</script> | ||
|
||
<FormContent bind:value={form.formValue} /> | ||
|
||
<button | ||
style="width: 100%; padding: 0.5rem;" | ||
onclick={() => { | ||
window.location.reload(); | ||
}} | ||
> | ||
Reload page | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ Usage: | |
Playground | ||
</LinkButton> | ||
|
||
### Radic icons | ||
### Radix icons | ||
|
||
Installation: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: Prevent data loss | ||
sidebar: | ||
order: 4 | ||
--- | ||
|
||
import { Code, Card } from '@astrojs/starlight/components' | ||
|
||
import Form from './_prevent-data-loss.svelte' | ||
import formCode from './_prevent-data-loss.svelte?raw' | ||
|
||
You can prevent data loss due to accidentally closing or reloading a tab by using | ||
the `preventDataLoss` function. | ||
|
||
## Example | ||
|
||
Try to change the value of the form and reload the page. | ||
|
||
<Code code={formCode} lang="svelte" /> | ||
|
||
<Card> | ||
<Form client:only="svelte" /> | ||
</Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import { ShadowHost } from '@/components/shadow' | ||
import Form from './_zod.svelte' | ||
--- | ||
|
||
<ShadowHost client:only="svelte"> | ||
<Form client:only="svelte" /> | ||
</ShadowHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script lang="ts"> | ||
import { SimpleForm, type Schema, type UiSchema } from "@sjsf/form"; | ||
import { createValidator } from "@sjsf/ajv8-validator"; | ||
import { withZod } from "@sjsf/zod-integration"; | ||
import { zodToJsonSchema } from "zod-to-json-schema"; | ||
import { z } from "zod"; | ||
import { useCustomForm } from "@/components/custom-form"; | ||
const schema = z.object({ | ||
id: z | ||
.string() | ||
.regex(new RegExp("\\d+"), "Must be a number") | ||
.min(8) | ||
.optional(), | ||
active: z.boolean().optional(), | ||
skills: z.array(z.string().min(5)).min(4).optional(), | ||
multipleChoicesList: z | ||
.array(z.enum(["foo", "bar", "fuzz"])) | ||
.max(2) | ||
.optional(), | ||
}); | ||
type Value = z.infer<typeof schema>; | ||
const uiSchema: UiSchema = { | ||
id: { | ||
"ui:options": { | ||
title: "Identifier", | ||
}, | ||
}, | ||
active: { | ||
"ui:options": { | ||
title: "Active", | ||
}, | ||
}, | ||
multipleChoicesList: { | ||
"ui:options": { | ||
title: "Pick max two items", | ||
}, | ||
}, | ||
}; | ||
const validator = withZod(createValidator(), { schema, uiSchema }); | ||
let value = $state<Value>(); | ||
const form = useCustomForm({ | ||
schema: zodToJsonSchema(schema) as Schema, | ||
uiSchema, | ||
validator, | ||
initialValue: { | ||
id: "Invalid", | ||
skills: ["karate", "budo", "aikido"], | ||
multipleChoicesList: ["foo", "bar", "fuzz"], | ||
}, | ||
onSubmit(data: Value) { | ||
value = data; | ||
}, | ||
}); | ||
</script> | ||
|
||
<SimpleForm | ||
{form} | ||
novalidate | ||
style="display: flex; flex-direction: column; gap: 1rem;" | ||
/> | ||
|
||
<pre>{JSON.stringify(value, null, 2)}</pre> |
Oops, something went wrong.