@inertiajs/svelte
Advanced tools
| import type { FormComponentRef } from '@inertiajs/core'; | ||
| import type { Readable } from 'svelte/store'; | ||
| export declare const FormContextKey: unique symbol; | ||
| export declare function useFormContext(): Readable<FormComponentRef> | undefined; |
| import { getContext } from 'svelte'; | ||
| export const FormContextKey = Symbol('InertiaFormContext'); | ||
| export function useFormContext() { | ||
| return getContext(FormContextKey); | ||
| } |
@@ -10,3 +10,5 @@ <script>import { | ||
| import { isEqual } from "lodash-es"; | ||
| import { onMount } from "svelte"; | ||
| import { onMount, setContext } from "svelte"; | ||
| import { writable } from "svelte/store"; | ||
| import { FormContextKey } from "./formContext"; | ||
| import useForm from "../useForm"; | ||
@@ -185,2 +187,29 @@ const noop = () => void 0; | ||
| $: slotErrors = $form.errors; | ||
| const formContextStore = writable(void 0); | ||
| $: formContextStore.set({ | ||
| errors: $form.errors, | ||
| hasErrors: $form.hasErrors, | ||
| processing: $form.processing, | ||
| progress: $form.progress, | ||
| wasSuccessful: $form.wasSuccessful, | ||
| recentlySuccessful: $form.recentlySuccessful, | ||
| isDirty, | ||
| clearErrors, | ||
| resetAndClearErrors, | ||
| setError, | ||
| reset, | ||
| submit, | ||
| defaults, | ||
| getData, | ||
| getFormData, | ||
| // Precognition | ||
| validator, | ||
| validate, | ||
| touch, | ||
| validating: $form.validating, | ||
| valid, | ||
| invalid, | ||
| touched | ||
| }); | ||
| setContext(FormContextKey, formContextStore); | ||
| </script> | ||
@@ -187,0 +216,0 @@ |
+1
-0
@@ -5,2 +5,3 @@ export { progress, router } from '@inertiajs/core'; | ||
| export { default as Form } from './components/Form.svelte'; | ||
| export { useFormContext } from './components/formContext'; | ||
| export { default as InfiniteScroll } from './components/InfiniteScroll.svelte'; | ||
@@ -7,0 +8,0 @@ export { default as Link } from './components/Link.svelte'; |
+1
-0
@@ -6,2 +6,3 @@ import { config as coreConfig } from '@inertiajs/core'; | ||
| export { default as Form } from './components/Form.svelte'; | ||
| export { useFormContext } from './components/formContext'; | ||
| export { default as InfiniteScroll } from './components/InfiniteScroll.svelte'; | ||
@@ -8,0 +9,0 @@ export { default as Link } from './components/Link.svelte'; |
+2
-2
| { | ||
| "name": "@inertiajs/svelte", | ||
| "version": "2.3.8", | ||
| "version": "2.3.9", | ||
| "license": "MIT", | ||
@@ -58,3 +58,3 @@ "description": "The Svelte adapter for Inertia.js", | ||
| "lodash-es": "^4.17.21", | ||
| "@inertiajs/core": "2.3.8" | ||
| "@inertiajs/core": "2.3.9" | ||
| }, | ||
@@ -61,0 +61,0 @@ "scripts": { |
77408
1.55%39
5.41%1196
0.93%+ Added
- Removed
Updated