Skip to content

Commit 075b3c1

Browse files
authored
Merge pull request #54 from x0k/deprecate-use-form
Deprecate use form
2 parents a7ae90a + 8b969e9 commit 075b3c1

File tree

64 files changed

+445
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+445
-370
lines changed

.changeset/cool-snails-eat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@sjsf/sveltekit": patch
3+
"playground": patch
4+
"docs": patch
5+
---
6+
7+
Migrate to `createForm3`

.changeset/ten-experts-compete.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@sjsf/form": minor
3+
---
4+
5+
Add `createForm3` function
6+
7+
## Migration
8+
9+
- Replace `useForm2` with `createForm3`.
10+
- If custom form is used it should call `setFormContext(form.context)` before using `FormContent` and `SubmitButton` components.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ npm install @sjsf/form @sjsf/ajv8-validator ajv@8
1818

1919
```svelte
2020
<script lang="ts">
21-
import { useForm2, SimpleForm, type Schema } from '@sjsf/form';
21+
import { createForm3, SimpleForm, type Schema } from '@sjsf/form';
2222
import { translation } from '@sjsf/form/translations/en';
2323
import { theme } from '@sjsf/form/basic-theme';
24-
import { createValidator } from "@sjsf/ajv8-validator";
24+
import { createValidator2 } from "@sjsf/ajv8-validator";
2525
26-
const validator = createValidator();
26+
const validator = createValidator2();
2727
2828
const schema: Schema = {
2929
type: 'object',
@@ -40,7 +40,7 @@ npm install @sjsf/form @sjsf/ajv8-validator ajv@8
4040
required: ["name"]
4141
}
4242
43-
const form = useForm2({
43+
const form = createForm3({
4444
...theme,
4545
schema,
4646
validator,
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import type { ErrorObject } from "ajv";
2-
import { useForm2, type FormAPI, type UseFormOptions2 } from "@sjsf/form";
2+
import { type FormInternals, type FormState, type FormOptions, createForm3 } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme } from "@sjsf/form/basic-theme";
55
import { createValidator2 } from "@sjsf/ajv8-validator";
66

77
type Defaults = "widgets" | "components" | "validator" | "translation";
88

9-
export type CustomOptions<T, E> = Omit<UseFormOptions2<T, E>, Defaults> &
10-
Partial<Pick<UseFormOptions2<T, E>, Defaults>>;
9+
export type CustomOptions<T, E> = Omit<FormOptions<T, E>, Defaults> &
10+
Partial<Pick<FormOptions<T, E>, Defaults>>;
1111

12-
export function useCustomForm<T, E = ErrorObject>(
12+
export function createCustomForm<T, E = ErrorObject>(
1313
options: CustomOptions<T, E>
14-
): FormAPI<T, E> {
14+
): FormState<T, E> & FormInternals {
1515
const validator = createValidator2();
16-
const defaults: Pick<UseFormOptions2<T, ErrorObject>, Defaults> = {
16+
const defaults: Pick<FormOptions<T, ErrorObject>, Defaults> = {
1717
...theme,
1818
validator,
1919
translation,
2020
};
21-
return useForm2(
21+
return createForm3(
2222
new Proxy(options, {
2323
get(target, p, receiver) {
2424
if (!(p in target)) {
2525
return defaults[p as Defaults];
2626
}
2727
return Reflect.get(target, p, receiver);
2828
},
29-
}) as UseFormOptions2<T, E>
29+
}) as FormOptions<T, E>
3030
);
3131
}

apps/docs/src/content/docs/_with-basic.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script lang="ts">
2-
import { useForm2, SimpleForm } from "@sjsf/form";
2+
import { createForm3, SimpleForm } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme } from "@sjsf/form/basic-theme";
55
66
import { schema, uiSchema, initialValue } from "./_schema";
77
import { validator } from "./_validator";
88
import { onSubmit } from './_on-submit';
99
10-
const form = useForm2({
10+
const form = createForm3({
1111
...theme,
1212
initialValue,
1313
schema,

apps/docs/src/content/docs/_with-daisyui.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { SimpleForm, useForm2 } from "@sjsf/form";
2+
import { SimpleForm, createForm3 } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme } from "@sjsf/daisyui-theme";
55
@@ -11,7 +11,7 @@
1111
1212
const astro = useAstro();
1313
14-
const form = useForm2({
14+
const form = createForm3({
1515
...theme,
1616
initialValue,
1717
schema,

apps/docs/src/content/docs/_with-flowbite.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { SimpleForm, useForm2 } from "@sjsf/form";
2+
import { SimpleForm, createForm3 } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme } from "@sjsf/flowbite-theme";
55
@@ -11,7 +11,7 @@
1111
1212
const astro = useAstro();
1313
14-
const form = useForm2({
14+
const form = createForm3({
1515
...theme,
1616
initialValue,
1717
schema,

apps/docs/src/content/docs/_with-shadcn.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { SimpleForm, useForm2 } from "@sjsf/form";
2+
import { SimpleForm, createForm3 } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
55
import { components } from "@sjsf/shadcn-theme/default";
@@ -12,7 +12,7 @@
1212
1313
const astro = useAstro();
1414
15-
const form = useForm2({
15+
const form = createForm3({
1616
...theme,
1717
initialValue,
1818
schema,

apps/docs/src/content/docs/_with-skeleton.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { SimpleForm, useForm2 } from "@sjsf/form";
2+
import { SimpleForm, createForm3 } from "@sjsf/form";
33
import { translation } from "@sjsf/form/translations/en";
44
import { theme } from "@sjsf/skeleton-theme";
55
@@ -11,7 +11,7 @@
1111
1212
const astro = useAstro();
1313
14-
const form = useForm2({
14+
const form = createForm3({
1515
...theme,
1616
initialValue,
1717
schema,

apps/docs/src/content/docs/advanced/_custom-form.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" generics="T">
2-
import { type Schema, type UiSchemaRoot, FormContent, SubmitButton } from '@sjsf/form'
2+
import { type Schema, type UiSchemaRoot, FormContent, setFromContext, SubmitButton } from '@sjsf/form'
33
4-
import { useCustomForm } from '@/components/custom-form'
4+
import { createCustomForm } from '@/components/custom-form'
55
66
interface Props {
77
schema: Schema
@@ -12,12 +12,13 @@
1212
1313
const { schema, uiSchema, initialValue, onSubmit }: Props = $props()
1414
15-
const form = useCustomForm({
15+
const form = createCustomForm({
1616
schema,
1717
uiSchema,
1818
initialValue,
1919
onSubmit,
2020
})
21+
setFromContext(form.context)
2122
</script>
2223

2324
<form use:form.enhance style="display: flex; flex-direction: column; gap: 1rem">

0 commit comments

Comments
 (0)