index.d.mts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import * as vue from 'vue';
  2. import { ComponentPropsOptions, ExtractPropTypes, VNodeChild, VNode, PropType, Ref } from 'vue';
  3. type SlotsToProps<U extends RawSlots, T = MakeInternalSlots<U>> = {
  4. $children?: (VNodeChild | (T extends {
  5. default: infer V;
  6. } ? V : {}) | {
  7. [K in keyof T]?: T[K];
  8. });
  9. 'v-slots'?: {
  10. [K in keyof T]?: T[K] | false;
  11. };
  12. } & {
  13. [K in keyof T as `v-slot:${K & string}`]?: T[K] | false;
  14. };
  15. type RawSlots = Record<string, unknown>;
  16. type Slot<T> = [T] extends [never] ? () => VNodeChild : (arg: T) => VNodeChild;
  17. type VueSlot<T> = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[];
  18. type MakeInternalSlots<T extends RawSlots> = {
  19. [K in keyof T]: Slot<T[K]>;
  20. };
  21. type MakeSlots<T extends RawSlots> = {
  22. [K in keyof T]: VueSlot<T[K]>;
  23. };
  24. type GenericProps<Props, Slots extends Record<string, unknown>> = {
  25. $props: Props & SlotsToProps<Slots>;
  26. $slots: MakeSlots<Slots>;
  27. };
  28. interface FilterPropsOptions<PropsOptions extends Readonly<ComponentPropsOptions>, Props = ExtractPropTypes<PropsOptions>> {
  29. filterProps<T extends Partial<Props>, U extends Exclude<keyof Props, Exclude<keyof Props, keyof T>>>(props: T): Partial<Pick<T, U>>;
  30. }
  31. type MaybeRef<T> = T | Ref<T>;
  32. type EventProp<T extends any[] = any[], F = (...args: T) => void> = F;
  33. declare const EventProp: <T extends any[] = any[]>() => PropType<EventProp<T>>;
  34. type ValidationResult = string | boolean;
  35. type ValidationRule = ValidationResult | PromiseLike<ValidationResult> | ((value: any) => ValidationResult) | ((value: any) => PromiseLike<ValidationResult>);
  36. type ValidateOnValue = 'blur' | 'input' | 'submit' | 'invalid-input';
  37. type ValidateOn = ValidateOnValue | `${ValidateOnValue} lazy` | `${ValidateOnValue} eager` | `lazy ${ValidateOnValue}` | `eager ${ValidateOnValue}` | 'lazy' | 'eager';
  38. interface ValidationProps {
  39. disabled: boolean | null;
  40. error: boolean;
  41. errorMessages: string | readonly string[] | null;
  42. focused: boolean;
  43. maxErrors: string | number;
  44. name: string | undefined;
  45. label: string | undefined;
  46. readonly: boolean | null;
  47. rules: readonly ValidationRule[];
  48. modelValue: any;
  49. 'onUpdate:modelValue': EventProp | undefined;
  50. validateOn?: ValidateOn;
  51. validationValue: any;
  52. }
  53. declare function useValidation(props: ValidationProps, name?: string, id?: MaybeRef<string | number>): {
  54. errorMessages: vue.ComputedRef<string[]>;
  55. isDirty: vue.ComputedRef<boolean>;
  56. isDisabled: vue.ComputedRef<boolean>;
  57. isReadonly: vue.ComputedRef<boolean>;
  58. isPristine: vue.ShallowRef<boolean>;
  59. isValid: vue.ComputedRef<boolean | null>;
  60. isValidating: vue.ShallowRef<boolean>;
  61. reset: () => Promise<void>;
  62. resetValidation: () => Promise<void>;
  63. validate: (silent?: boolean) => Promise<string[]>;
  64. validationClasses: vue.ComputedRef<{
  65. [x: string]: boolean;
  66. }>;
  67. };
  68. type VValidationSlots = {
  69. default: ReturnType<typeof useValidation>;
  70. };
  71. declare const VValidation: {
  72. new (...args: any[]): vue.CreateComponentPublicInstance<{
  73. error: boolean;
  74. disabled: boolean | null;
  75. readonly: boolean | null;
  76. focused: boolean;
  77. errorMessages: string | readonly string[] | null;
  78. maxErrors: string | number;
  79. rules: readonly ValidationRule[];
  80. } & {
  81. name?: string | undefined;
  82. label?: string | undefined;
  83. 'onUpdate:focused'?: ((args_0: boolean) => void) | undefined;
  84. validateOn?: ("eager" | "lazy" | ("input" | "blur" | "submit" | "invalid-input") | "input lazy" | "blur lazy" | "submit lazy" | "invalid-input lazy" | "input eager" | "blur eager" | "submit eager" | "invalid-input eager" | "lazy input" | "lazy blur" | "lazy submit" | "lazy invalid-input" | "eager input" | "eager blur" | "eager submit" | "eager invalid-input") | undefined;
  85. validationValue?: any;
  86. } & {}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
  87. [key: string]: any;
  88. }>[] | undefined, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Omit<{
  89. 'update:modelValue': (value: any) => true;
  90. }, "$children" | "v-slots" | "v-slot:default" | "modelValue" | "update:modelValue">, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps & {
  91. error: boolean;
  92. disabled: boolean | null;
  93. readonly: boolean | null;
  94. focused: boolean;
  95. errorMessages: string | readonly string[] | null;
  96. maxErrors: string | number;
  97. rules: readonly ValidationRule[];
  98. } & {
  99. name?: string | undefined;
  100. label?: string | undefined;
  101. 'onUpdate:focused'?: ((args_0: boolean) => void) | undefined;
  102. validateOn?: ("eager" | "lazy" | ("input" | "blur" | "submit" | "invalid-input") | "input lazy" | "blur lazy" | "submit lazy" | "invalid-input lazy" | "input eager" | "blur eager" | "submit eager" | "invalid-input eager" | "lazy input" | "lazy blur" | "lazy submit" | "lazy invalid-input" | "eager input" | "eager blur" | "eager submit" | "eager invalid-input") | undefined;
  103. validationValue?: any;
  104. } & {}, {
  105. error: boolean;
  106. disabled: boolean | null;
  107. readonly: boolean | null;
  108. focused: boolean;
  109. errorMessages: string | readonly string[] | null;
  110. maxErrors: string | number;
  111. rules: readonly ValidationRule[];
  112. }, true, {}, vue.SlotsType<Partial<{
  113. default: (arg: {
  114. errorMessages: vue.ComputedRef<string[]>;
  115. isDirty: vue.ComputedRef<boolean>;
  116. isDisabled: vue.ComputedRef<boolean>;
  117. isReadonly: vue.ComputedRef<boolean>;
  118. isPristine: vue.ShallowRef<boolean>;
  119. isValid: vue.ComputedRef<boolean | null>;
  120. isValidating: vue.ShallowRef<boolean>;
  121. reset: () => Promise<void>;
  122. resetValidation: () => Promise<void>;
  123. validate: (silent?: boolean) => Promise<string[]>;
  124. validationClasses: vue.ComputedRef<{
  125. [x: string]: boolean;
  126. }>;
  127. }) => vue.VNode[];
  128. }>>, {
  129. P: {};
  130. B: {};
  131. D: {};
  132. C: {};
  133. M: {};
  134. Defaults: {};
  135. }, {
  136. error: boolean;
  137. disabled: boolean | null;
  138. readonly: boolean | null;
  139. focused: boolean;
  140. errorMessages: string | readonly string[] | null;
  141. maxErrors: string | number;
  142. rules: readonly ValidationRule[];
  143. } & {
  144. name?: string | undefined;
  145. label?: string | undefined;
  146. 'onUpdate:focused'?: ((args_0: boolean) => void) | undefined;
  147. validateOn?: ("eager" | "lazy" | ("input" | "blur" | "submit" | "invalid-input") | "input lazy" | "blur lazy" | "submit lazy" | "invalid-input lazy" | "input eager" | "blur eager" | "submit eager" | "invalid-input eager" | "lazy input" | "lazy blur" | "lazy submit" | "lazy invalid-input" | "eager input" | "eager blur" | "eager submit" | "eager invalid-input") | undefined;
  148. validationValue?: any;
  149. } & {}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
  150. [key: string]: any;
  151. }>[] | undefined, {}, {}, {}, {
  152. error: boolean;
  153. disabled: boolean | null;
  154. readonly: boolean | null;
  155. focused: boolean;
  156. errorMessages: string | readonly string[] | null;
  157. maxErrors: string | number;
  158. rules: readonly ValidationRule[];
  159. }>;
  160. __isFragment?: never;
  161. __isTeleport?: never;
  162. __isSuspense?: never;
  163. } & vue.ComponentOptionsBase<{
  164. error: boolean;
  165. disabled: boolean | null;
  166. readonly: boolean | null;
  167. focused: boolean;
  168. errorMessages: string | readonly string[] | null;
  169. maxErrors: string | number;
  170. rules: readonly ValidationRule[];
  171. } & {
  172. name?: string | undefined;
  173. label?: string | undefined;
  174. 'onUpdate:focused'?: ((args_0: boolean) => void) | undefined;
  175. validateOn?: ("eager" | "lazy" | ("input" | "blur" | "submit" | "invalid-input") | "input lazy" | "blur lazy" | "submit lazy" | "invalid-input lazy" | "input eager" | "blur eager" | "submit eager" | "invalid-input eager" | "lazy input" | "lazy blur" | "lazy submit" | "lazy invalid-input" | "eager input" | "eager blur" | "eager submit" | "eager invalid-input") | undefined;
  176. validationValue?: any;
  177. } & {}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
  178. [key: string]: any;
  179. }>[] | undefined, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Omit<{
  180. 'update:modelValue': (value: any) => true;
  181. }, "$children" | "v-slots" | "v-slot:default" | "modelValue" | "update:modelValue">, string, {
  182. error: boolean;
  183. disabled: boolean | null;
  184. readonly: boolean | null;
  185. focused: boolean;
  186. errorMessages: string | readonly string[] | null;
  187. maxErrors: string | number;
  188. rules: readonly ValidationRule[];
  189. }, {}, string, vue.SlotsType<Partial<{
  190. default: (arg: {
  191. errorMessages: vue.ComputedRef<string[]>;
  192. isDirty: vue.ComputedRef<boolean>;
  193. isDisabled: vue.ComputedRef<boolean>;
  194. isReadonly: vue.ComputedRef<boolean>;
  195. isPristine: vue.ShallowRef<boolean>;
  196. isValid: vue.ComputedRef<boolean | null>;
  197. isValidating: vue.ShallowRef<boolean>;
  198. reset: () => Promise<void>;
  199. resetValidation: () => Promise<void>;
  200. validate: (silent?: boolean) => Promise<string[]>;
  201. validationClasses: vue.ComputedRef<{
  202. [x: string]: boolean;
  203. }>;
  204. }) => vue.VNode[];
  205. }>>> & vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps & (new <T>(props: {
  206. modelValue?: T | null;
  207. "onUpdate:modelValue"?: (value: T | null) => void;
  208. }, slots: VValidationSlots) => GenericProps<typeof props, typeof slots>) & FilterPropsOptions<{
  209. focused: BooleanConstructor;
  210. 'onUpdate:focused': vue.PropType<(args_0: boolean) => void>;
  211. disabled: {
  212. type: vue.PropType<boolean | null>;
  213. default: null;
  214. };
  215. error: BooleanConstructor;
  216. errorMessages: {
  217. type: vue.PropType<string | readonly string[] | null>;
  218. default: () => never[];
  219. };
  220. maxErrors: {
  221. type: (StringConstructor | NumberConstructor)[];
  222. default: number;
  223. };
  224. name: StringConstructor;
  225. label: StringConstructor;
  226. readonly: {
  227. type: vue.PropType<boolean | null>;
  228. default: null;
  229. };
  230. rules: {
  231. type: vue.PropType<readonly ValidationRule[]>;
  232. default: () => never[];
  233. };
  234. modelValue: null;
  235. validateOn: vue.PropType<ValidationProps["validateOn"]>;
  236. validationValue: null;
  237. }, vue.ExtractPropTypes<{
  238. focused: BooleanConstructor;
  239. 'onUpdate:focused': vue.PropType<(args_0: boolean) => void>;
  240. disabled: {
  241. type: vue.PropType<boolean | null>;
  242. default: null;
  243. };
  244. error: BooleanConstructor;
  245. errorMessages: {
  246. type: vue.PropType<string | readonly string[] | null>;
  247. default: () => never[];
  248. };
  249. maxErrors: {
  250. type: (StringConstructor | NumberConstructor)[];
  251. default: number;
  252. };
  253. name: StringConstructor;
  254. label: StringConstructor;
  255. readonly: {
  256. type: vue.PropType<boolean | null>;
  257. default: null;
  258. };
  259. rules: {
  260. type: vue.PropType<readonly ValidationRule[]>;
  261. default: () => never[];
  262. };
  263. modelValue: null;
  264. validateOn: vue.PropType<ValidationProps["validateOn"]>;
  265. validationValue: null;
  266. }>>;
  267. type VValidation = InstanceType<typeof VValidation>;
  268. export { VValidation };