maz-ui 5.0.0-beta.47 → 5.0.0-beta.48

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,5 +1,5 @@
1
1
  import { useFreezeValue } from "../composables/useFreezeValue.js";
2
- import { getCurrentInstance, inject, nextTick } from "vue";
2
+ import { getCurrentInstance, inject, nextTick, toRaw } from "vue";
3
3
  import { isEqual } from "@maz-ui/utils/helpers/isEqual";
4
4
  import { debounceId } from "@maz-ui/utils/helpers/debounceId";
5
5
  import { throttleId } from "@maz-ui/utils/helpers/throttleId";
@@ -15,21 +15,15 @@ var CONFIG = {
15
15
  function isEmptyValue(value) {
16
16
  return value == null || value === "";
17
17
  }
18
- var storeValidbot = {};
19
- async function getValibotValidationMethod(methodName) {
20
- if (storeValidbot[methodName]) return storeValidbot[methodName];
21
- let valibot = await import("valibot");
22
- return storeValidbot[methodName] = valibot[methodName], valibot[methodName];
23
- }
24
- async function getValidationSchema(formSchema) {
25
- return (await getValibotValidationMethod("objectAsync"))(formSchema);
26
- }
27
18
  async function getFieldValidationResult(name, schema, value) {
28
- let fieldSchema = await getValidationSchema(schema);
29
- let result = await (await getValibotValidationMethod("safeParseAsync"))(fieldSchema.entries[name], value ?? "");
19
+ let result = await toRaw(schema[name])["~standard"].validate(value ?? "");
20
+ let isValid = !result.issues;
30
21
  return {
31
- result,
32
- isValid: result.success
22
+ result: {
23
+ ...result,
24
+ success: isValid
25
+ },
26
+ isValid
33
27
  };
34
28
  }
35
29
  async function setFieldValidationState({ name, fieldState, schema, payload, setError = !0, setErrorIfInvalidAndNotEmpty = !1 }) {
@@ -48,7 +42,7 @@ async function setFieldValidationState({ name, fieldState, schema, payload, setE
48
42
  "blur",
49
43
  "progressive"
50
44
  ].includes(fieldState.mode);
51
- (shouldSetError || shouldPreserveError) && (fieldState.error = !isValid), fieldState.errors = result.issues ?? [], fieldState.validated = !0;
45
+ (shouldSetError || shouldPreserveError) && (fieldState.error = !isValid), fieldState.errors = result.issues ? [...result.issues] : [], fieldState.validated = !0;
52
46
  } finally {
53
47
  fieldState.validating = !1;
54
48
  }
@@ -6,7 +6,7 @@ export * from './useDrag';
6
6
  export * from './useDropzone';
7
7
  export * from './useFormField';
8
8
  export * from './useFormValidator';
9
- export type { FieldsStates, FieldState, FormFieldOptions, FormSchema, FormValidatorOptions, InferOutputSchemaFormValidator, InferSchemaFormValidator } from './useFormValidator/types';
9
+ export type { FieldsStates, FieldState, FormFieldOptions, FormSchema, FormValidatorOptions, InferOutputSchemaFormValidator, InferSchemaFormValidator, StandardSchemaV1, Validation, ValidationIssue, ValidationIssues } from './useFormValidator/types';
10
10
  export * from './useFreezeValue';
11
11
  export type { GlobalizableProps, MazComponentName, MazUiDefaultsOptions } from './useGlobalConfig';
12
12
  export * from './useIdleTimeout';
@@ -1,7 +1,7 @@
1
1
  import { BaseFormPayload, ExtractModelKey, FormFieldOptions, FormSchema } from './useFormValidator/types';
2
2
  export declare function useFormField<FieldType, Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(name: ModelKey, options?: FormFieldOptions<Model, ModelKey, FieldType>): {
3
3
  hasError: import('vue').ComputedRef<boolean>;
4
- errors: import('vue').ComputedRef<import('./useFormValidator/types').ValidationIssues>;
4
+ errors: import('vue').ComputedRef<import('.').ValidationIssues>;
5
5
  errorMessage: import('vue').ComputedRef<Record<ModelKey, string | undefined>[ModelKey]>;
6
6
  isValid: import('vue').ComputedRef<boolean>;
7
7
  isDirty: import('vue').ComputedRef<boolean>;
@@ -1,4 +1,4 @@
1
- import { _ as setFieldValidationState, f as hasModeIncludes, i as removeEventFromInteractiveElements, n as findInteractiveElements, o as fieldHasValidation, p as updateFieldState, r as getValidationEvents, s as getContext, t as addEventToInteractiveElements, u as handleFieldBlur } from "../chunks/dom-events.CuYg9JPf.js";
1
+ import { _ as setFieldValidationState, f as hasModeIncludes, i as removeEventFromInteractiveElements, n as findInteractiveElements, o as fieldHasValidation, p as updateFieldState, r as getValidationEvents, s as getContext, t as addEventToInteractiveElements, u as handleFieldBlur } from "../chunks/dom-events.Sq75viWa.js";
2
2
  import { useFreezeValue } from "./useFreezeValue.js";
3
3
  import { computed, onUnmounted, unref, watch } from "vue";
4
4
  import { isClient } from "@maz-ui/utils/helpers/isClient";
@@ -1,8 +1,42 @@
1
- import { BaseIssue, BaseSchema, BaseSchemaAsync, InferInput, InferIssue, InferOutput, objectAsync } from 'valibot';
2
1
  import { ComponentInternalInstance, InjectionKey, Ref, TemplateRef } from 'vue';
3
2
  import { getValidateFunction } from './validation';
4
- export type Validation = BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
5
- export type ValidationIssues = InferIssue<Validation>[];
3
+ /**
4
+ * Standard Schema interface (https://standardschema.dev)
5
+ * Implemented by Valibot, Zod, ArkType, Effect Schema and many others
6
+ */
7
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
8
+ readonly '~standard': StandardSchemaV1Props<Input, Output>;
9
+ }
10
+ export interface StandardSchemaV1Props<Input = unknown, Output = Input> {
11
+ readonly version: 1;
12
+ readonly vendor: string;
13
+ readonly validate: (value: unknown) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>;
14
+ readonly types?: StandardSchemaV1Types<Input, Output> | undefined;
15
+ }
16
+ export type StandardSchemaV1Result<Output> = StandardSchemaV1SuccessResult<Output> | StandardSchemaV1FailureResult;
17
+ export interface StandardSchemaV1SuccessResult<Output> {
18
+ readonly value: Output;
19
+ readonly issues?: undefined;
20
+ }
21
+ export interface StandardSchemaV1FailureResult {
22
+ readonly issues: ReadonlyArray<StandardSchemaV1Issue>;
23
+ }
24
+ export interface StandardSchemaV1Issue {
25
+ readonly message: string;
26
+ readonly path?: ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | undefined;
27
+ }
28
+ export interface StandardSchemaV1PathSegment {
29
+ readonly key: PropertyKey;
30
+ }
31
+ export interface StandardSchemaV1Types<Input = unknown, Output = Input> {
32
+ readonly input: Input;
33
+ readonly output: Output;
34
+ }
35
+ export type Validation = StandardSchemaV1;
36
+ export type ValidationIssue = StandardSchemaV1Issue;
37
+ export type ValidationIssues = ValidationIssue[];
38
+ export type InferValidationInput<T> = T extends StandardSchemaV1 ? NonNullable<T['~standard']['types']>['input'] : never;
39
+ export type InferValidationOutput<T> = T extends StandardSchemaV1 ? NonNullable<T['~standard']['types']>['output'] : never;
6
40
  export type ExtractModelKey<T> = Extract<keyof T, string>;
7
41
  export type FormSchema<Model extends BaseFormPayload> = {
8
42
  [K in Extract<keyof Model, string> as Model[K] extends Required<Model>[K] ? K : never]: Validation;
@@ -102,5 +136,40 @@ export interface FormFieldOptions<Model extends BaseFormPayload, ModelKey extend
102
136
  */
103
137
  formIdentifier?: string | symbol;
104
138
  }
105
- export type InferSchemaFormValidator<T> = T extends Ref<infer U> ? U extends FormSchema<BaseFormPayload> ? Partial<InferInput<ReturnType<typeof objectAsync<U>>>> : never : T extends (...args: any[]) => FormSchema<BaseFormPayload> ? Partial<InferInput<ReturnType<typeof objectAsync<ReturnType<T>>>>> : T extends FormSchema<BaseFormPayload> ? Partial<InferInput<ReturnType<typeof objectAsync<T>>>> : never;
106
- export type InferOutputSchemaFormValidator<T> = T extends Ref<infer U> ? U extends FormSchema<BaseFormPayload> ? InferOutput<ReturnType<typeof objectAsync<U>>> : never : T extends (...args: any[]) => FormSchema<BaseFormPayload> ? InferOutput<ReturnType<typeof objectAsync<ReturnType<T>>>> : T extends FormSchema<BaseFormPayload> ? InferOutput<ReturnType<typeof objectAsync<T>>> : never;
139
+ type Simplify<T> = {
140
+ [K in keyof T]: T[K];
141
+ } & {};
142
+ type IsOptionalOutputKey<TSchema> = TSchema extends {
143
+ readonly kind: 'schema';
144
+ readonly type: string;
145
+ } ? TSchema extends {
146
+ readonly type: 'optional' | 'exact_optional' | 'nullish';
147
+ readonly default: infer TDefault;
148
+ } ? undefined extends TDefault ? true : false : false : unknown extends InferValidationOutput<TSchema> ? false : undefined extends InferValidationOutput<TSchema> ? true : false;
149
+ type IsReadonlyOutputKey<TSchema> = TSchema extends {
150
+ readonly pipe: readonly (infer TItem)[];
151
+ } ? [Extract<TItem, {
152
+ readonly kind: 'transformation';
153
+ readonly type: 'readonly';
154
+ }>] extends [never] ? false : true : false;
155
+ type OptionalOutputKeys<TSchema> = {
156
+ [K in keyof TSchema]: IsOptionalOutputKey<TSchema[K]> extends true ? K : never;
157
+ }[keyof TSchema];
158
+ type ReadonlyOutputKeys<TSchema> = {
159
+ [K in keyof TSchema]: IsReadonlyOutputKey<TSchema[K]> extends true ? K : never;
160
+ }[keyof TSchema];
161
+ export type InferFormSchemaInput<TSchema> = Simplify<{
162
+ -readonly [K in keyof TSchema]?: InferValidationInput<TSchema[K]>;
163
+ }>;
164
+ export type InferFormSchemaOutput<TSchema> = Simplify<{
165
+ -readonly [K in Exclude<keyof TSchema, OptionalOutputKeys<TSchema> | ReadonlyOutputKeys<TSchema>>]: InferValidationOutput<TSchema[K]>;
166
+ } & {
167
+ -readonly [K in Exclude<OptionalOutputKeys<TSchema>, ReadonlyOutputKeys<TSchema>>]?: InferValidationOutput<TSchema[K]>;
168
+ } & {
169
+ readonly [K in Exclude<ReadonlyOutputKeys<TSchema>, OptionalOutputKeys<TSchema>>]: InferValidationOutput<TSchema[K]>;
170
+ } & {
171
+ readonly [K in Extract<ReadonlyOutputKeys<TSchema>, OptionalOutputKeys<TSchema>>]?: InferValidationOutput<TSchema[K]>;
172
+ }>;
173
+ export type InferSchemaFormValidator<T> = T extends Ref<infer U> ? U extends FormSchema<BaseFormPayload> ? InferFormSchemaInput<U> : never : T extends (...args: any[]) => FormSchema<BaseFormPayload> ? InferFormSchemaInput<ReturnType<T>> : T extends FormSchema<BaseFormPayload> ? InferFormSchemaInput<T> : never;
174
+ export type InferOutputSchemaFormValidator<T> = T extends Ref<infer U> ? U extends FormSchema<BaseFormPayload> ? InferFormSchemaOutput<U> : never : T extends (...args: any[]) => FormSchema<BaseFormPayload> ? InferFormSchemaOutput<ReturnType<T>> : T extends FormSchema<BaseFormPayload> ? InferFormSchemaOutput<T> : never;
175
+ export {};
@@ -1,9 +1,14 @@
1
1
  import { BaseFormPayload, ExtractModelKey, FieldsStates, FieldState, FormSchema, StrictOptions, ValidationIssues } from './types';
2
2
  export declare function isEmptyValue(value: unknown): value is null | undefined | '';
3
- export declare function getValibotValidationMethod<MethodName extends keyof typeof import('valibot')>(methodName: MethodName): Promise<(typeof import('valibot'))[MethodName]>;
4
- export declare function getValidationSchema<Model extends BaseFormPayload>(formSchema: FormSchema<Model>): Promise<import('valibot').ObjectSchemaAsync<FormSchema<Model>, undefined>>;
5
3
  export declare function getFieldValidationResult<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>>(name: ModelKey, schema: FormSchema<Model>, value: Model[ModelKey]): Promise<{
6
- result: import('valibot').SafeParseResult<FormSchema<Model>[ModelKey]>;
4
+ result: {
5
+ success: boolean;
6
+ issues: ReadonlyArray<import('./types').StandardSchemaV1Issue>;
7
+ } | {
8
+ success: boolean;
9
+ value: unknown;
10
+ issues?: undefined;
11
+ };
7
12
  isValid: boolean;
8
13
  }>;
9
14
  export declare function setFieldValidationState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>>({ name, fieldState, schema, payload, setError, setErrorIfInvalidAndNotEmpty, }: {
@@ -1,4 +1,4 @@
1
- import { a as scrollToError, c as getFieldsStates, d as handleFieldInput, f as hasModeIncludes, g as getFieldsErrors, h as getErrorMessages, l as getInstance, m as updateFieldsStates, v as validateForm, y as CONFIG } from "../chunks/dom-events.CuYg9JPf.js";
1
+ import { a as scrollToError, c as getFieldsStates, d as handleFieldInput, f as hasModeIncludes, g as getFieldsErrors, h as getErrorMessages, l as getInstance, m as updateFieldsStates, v as validateForm, y as CONFIG } from "../chunks/dom-events.Sq75viWa.js";
2
2
  import { computed, nextTick, provide, ref, toValue, watch } from "vue";
3
3
  //#region src/composables/useFormValidator.ts
4
4
  function createValidationProcessor(fieldsToValidate, fieldsStates, payload, internalSchema, isSubmitted) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "maz-ui",
3
3
  "type": "module",
4
- "version": "5.0.0-beta.47",
4
+ "version": "5.0.0-beta.48",
5
5
  "description": "A standalone components library for Vue.Js 3 & Nuxt.Js 3",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -153,14 +153,20 @@
153
153
  "node": ">= 18.0.0"
154
154
  },
155
155
  "peerDependencies": {
156
+ "arktype": ">=2.0.0 <3.0.0",
156
157
  "nuxt": ">=3.4.0 <5.0.0",
157
158
  "shiki": ">=4.0.0",
158
159
  "unplugin-auto-import": ">=19.0.0 <22.0.0",
159
160
  "unplugin-vue-components": ">=28.0.0 <33.0.0",
161
+ "valibot": ">=1.0.0 <2.0.0",
160
162
  "vue": ">=3.5.0 <4.0.0",
161
- "vue-router": ">=4.0.0 <6.0.0"
163
+ "vue-router": ">=4.0.0 <6.0.0",
164
+ "zod": ">=3.24.0 <5.0.0"
162
165
  },
163
166
  "peerDependenciesMeta": {
167
+ "arktype": {
168
+ "optional": true
169
+ },
164
170
  "nuxt": {
165
171
  "optional": true
166
172
  },
@@ -173,8 +179,14 @@
173
179
  "unplugin-vue-components": {
174
180
  "optional": true
175
181
  },
182
+ "valibot": {
183
+ "optional": true
184
+ },
176
185
  "vue-router": {
177
186
  "optional": true
187
+ },
188
+ "zod": {
189
+ "optional": true
178
190
  }
179
191
  },
180
192
  "dependencies": {
@@ -188,8 +200,7 @@
188
200
  "dayjs": "^1.11.23",
189
201
  "dompurify": "^3.4.16",
190
202
  "libphonenumber-js": "^1.13.14",
191
- "marked": "^18.0.14",
192
- "valibot": "^1.5.0"
203
+ "marked": "^18.0.14"
193
204
  },
194
205
  "devDependencies": {
195
206
  "@maz-ui/eslint-config": "5.0.0-beta.47",
@@ -210,8 +221,10 @@
210
221
  "tailwindcss": "^4.3.3",
211
222
  "unplugin-auto-import": "^21.1.0",
212
223
  "unplugin-vue-components": "^32.0.0",
224
+ "valibot": "^1.5.0",
213
225
  "vitest-axe": "^0.1.0",
214
- "vue-router": "^5.3.1"
226
+ "vue-router": "^5.3.1",
227
+ "zod": "^4.6.5"
215
228
  },
216
229
  "lint-staged": {
217
230
  "*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix",