@inertiajs/svelte 2.3.13 → 2.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  <script>import {
2
+ config,
2
3
  formDataToObject,
3
4
  FormComponentResetSymbol,
4
5
  resetFormFields,
@@ -37,7 +38,7 @@ export let resetOnSuccess = false;
37
38
  export let setDefaultsOnSuccess = false;
38
39
  export let validateFiles = false;
39
40
  export let validationTimeout = 1500;
40
- export let withAllErrors = false;
41
+ export let withAllErrors = null;
41
42
  const getTransformedData = () => {
42
43
  const [_url, data] = getUrlAndData();
43
44
  return transform(data);
@@ -49,7 +50,7 @@ const form = useForm({}).withPrecognition(
49
50
  if (validateFiles) {
50
51
  form.validateFiles();
51
52
  }
52
- if (withAllErrors) {
53
+ if (withAllErrors ?? config.get("form.withAllErrors")) {
53
54
  form.withAllErrors();
54
55
  }
55
56
  form.transform(getTransformedData);
@@ -156,8 +157,8 @@ export function defaults() {
156
157
  defaultData = getFormData();
157
158
  isDirty = false;
158
159
  }
159
- export function validate(field, config) {
160
- return form.validate(...UseFormUtils.mergeHeadersForValidation(field, config, headers));
160
+ export function validate(field, config2) {
161
+ return form.validate(...UseFormUtils.mergeHeadersForValidation(field, config2, headers));
161
162
  }
162
163
  export function valid(field) {
163
164
  return form.valid(field);
@@ -28,7 +28,7 @@ declare const __propDef: {
28
28
  setDefaultsOnSuccess?: boolean | undefined;
29
29
  validateFiles?: boolean | undefined;
30
30
  validationTimeout?: number | undefined;
31
- withAllErrors?: boolean | undefined;
31
+ withAllErrors?: boolean | null | undefined;
32
32
  getFormData?: ((submitter?: HTMLElement | null) => FormData) | undefined;
33
33
  getData?: ((submitter?: HTMLElement | null) => Record<string, FormDataConvertible>) | undefined;
34
34
  submit?: ((submitter?: HTMLElement | null) => void) | undefined;
package/dist/useForm.d.ts CHANGED
@@ -54,12 +54,12 @@ export interface InertiaFormValidationProps<TForm extends object> {
54
54
  export type InertiaForm<TForm extends object> = InertiaFormProps<TForm> & TForm;
55
55
  export type InertiaPrecognitiveForm<TForm extends object> = InertiaForm<TForm> & InertiaFormValidationProps<TForm>;
56
56
  type ReservedFormKeys = keyof InertiaFormProps<any>;
57
- type ValidateFormData<T> = string extends keyof T ? T : {
57
+ type ValidateFormData<T> = {
58
58
  [K in keyof T]: K extends ReservedFormKeys ? ['Error: This field name is reserved by useForm:', K] : T[K];
59
59
  };
60
- export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
61
- export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
62
- export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
63
- export default function useForm<TForm extends FormDataType<TForm>>(data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
60
+ export default function useForm<TForm extends FormDataType<TForm> & ValidateFormData<TForm>>(method: Method | (() => Method), url: string | (() => string), data: TForm | (() => TForm)): InertiaPrecognitiveFormStore<TForm>;
61
+ export default function useForm<TForm extends FormDataType<TForm> & ValidateFormData<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: TForm | (() => TForm)): InertiaPrecognitiveFormStore<TForm>;
62
+ export default function useForm<TForm extends FormDataType<TForm> & ValidateFormData<TForm>>(rememberKey: string, data: TForm | (() => TForm)): InertiaFormStore<TForm>;
63
+ export default function useForm<TForm extends FormDataType<TForm> & ValidateFormData<TForm>>(data: TForm | (() => TForm)): InertiaFormStore<TForm>;
64
64
  export default function useForm<TForm extends FormDataType<TForm>>(): InertiaFormStore<TForm>;
65
65
  export {};
package/dist/useForm.js CHANGED
@@ -41,7 +41,7 @@ export default function useForm(...args) {
41
41
  const withPrecognition = (...args) => {
42
42
  precognitionEndpoint = UseFormUtils.createWayfinderCallback(...args);
43
43
  const formWithPrecognition = () => getStore(store);
44
- let withAllErrors = false;
44
+ let withAllErrors = null;
45
45
  if (!validatorRef) {
46
46
  const validator = createValidator((client) => {
47
47
  const { method, url } = precognitionEndpoint();
@@ -61,7 +61,9 @@ export default function useForm(...args) {
61
61
  setFormState('__touched', validator.touched());
62
62
  })
63
63
  .on('errorsChanged', () => {
64
- const validationErrors = withAllErrors ? validator.errors() : toSimpleValidationErrors(validator.errors());
64
+ const validationErrors = (withAllErrors ?? config.get('form.withAllErrors'))
65
+ ? validator.errors()
66
+ : toSimpleValidationErrors(validator.errors());
65
67
  setFormState('errors', {});
66
68
  formWithPrecognition().setError(validationErrors);
67
69
  setFormState('__valid', validator.valid());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "2.3.13",
3
+ "version": "2.3.14",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -55,7 +55,7 @@
55
55
  "@types/lodash-es": "^4.17.12",
56
56
  "laravel-precognition": "^1.0.1",
57
57
  "lodash-es": "^4.17.23",
58
- "@inertiajs/core": "2.3.13"
58
+ "@inertiajs/core": "2.3.14"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",