版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

396 строки
15 KiB

  1. import { MaybeComputedRef, MaybeRef, ConfigurableFlush, RemovableRef } from '@vueuse/shared';
  2. import { ValidateError, ValidateOption, Rules } from 'async-validator';
  3. import * as vue_demi from 'vue-demi';
  4. import { Ref, ShallowRef, WritableComputedRef, ComputedRef } from 'vue-demi';
  5. import { AxiosResponse, AxiosError, RawAxiosRequestConfig, AxiosInstance } from 'axios';
  6. import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase, Options } from 'change-case';
  7. import * as universal_cookie from 'universal-cookie';
  8. import universal_cookie__default from 'universal-cookie';
  9. import { IncomingMessage } from 'http';
  10. import { Options as Options$1, Drauu, Brush } from 'drauu';
  11. import { EventHookOn, MaybeComputedElementRef, Fn, MaybeElementRef } from '@vueuse/core';
  12. import { Options as Options$2, ActivateOptions, DeactivateOptions } from 'focus-trap';
  13. import Fuse from 'fuse.js';
  14. import { JwtPayload, JwtHeader } from 'jwt-decode';
  15. import nprogress, { NProgressOptions } from 'nprogress';
  16. import QRCode from 'qrcode';
  17. type AsyncValidatorError = Error & {
  18. errors: ValidateError[];
  19. fields: Record<string, ValidateError[]>;
  20. };
  21. interface UseAsyncValidatorReturn {
  22. pass: Ref<boolean>;
  23. errorInfo: Ref<AsyncValidatorError | null>;
  24. isFinished: Ref<boolean>;
  25. errors: Ref<AsyncValidatorError['errors'] | undefined>;
  26. errorFields: Ref<AsyncValidatorError['fields'] | undefined>;
  27. }
  28. interface UseAsyncValidatorOptions {
  29. /**
  30. * @see https://github.com/yiminghe/async-validator#options
  31. */
  32. validateOption?: ValidateOption;
  33. }
  34. /**
  35. * Wrapper for async-validator.
  36. *
  37. * @see https://vueuse.org/useAsyncValidator
  38. * @see https://github.com/yiminghe/async-validator
  39. */
  40. declare function useAsyncValidator(value: MaybeComputedRef<Record<string, any>>, rules: MaybeComputedRef<Rules>, options?: UseAsyncValidatorOptions): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>;
  41. interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
  42. /**
  43. * Axios Response
  44. */
  45. response: ShallowRef<R | undefined>;
  46. /**
  47. * Axios response data
  48. */
  49. data: Ref<T | undefined>;
  50. /**
  51. * Indicates if the request has finished
  52. */
  53. isFinished: Ref<boolean>;
  54. /**
  55. * Indicates if the request is currently loading
  56. */
  57. isLoading: Ref<boolean>;
  58. /**
  59. * Indicates if the request was canceled
  60. */
  61. isAborted: Ref<boolean>;
  62. /**
  63. * Any errors that may have occurred
  64. */
  65. error: ShallowRef<AxiosError<T, D> | undefined>;
  66. /**
  67. * Aborts the current request
  68. */
  69. abort: (message?: string | undefined) => void;
  70. /**
  71. * isFinished alias
  72. * @deprecated use `isFinished` instead
  73. */
  74. finished: Ref<boolean>;
  75. /**
  76. * isLoading alias
  77. * @deprecated use `isLoading` instead
  78. */
  79. loading: Ref<boolean>;
  80. /**
  81. * isAborted alias
  82. * @deprecated use `isAborted` instead
  83. */
  84. aborted: Ref<boolean>;
  85. /**
  86. * abort alias
  87. */
  88. cancel: (message?: string | undefined) => void;
  89. /**
  90. * isAborted alias
  91. * @deprecated use `isCanceled` instead
  92. */
  93. canceled: Ref<boolean>;
  94. /**
  95. * isAborted alias
  96. */
  97. isCanceled: Ref<boolean>;
  98. }
  99. interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
  100. /**
  101. * Manually call the axios request
  102. */
  103. execute: (url?: string | RawAxiosRequestConfig<D>, config?: RawAxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
  104. }
  105. interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
  106. /**
  107. * Manually call the axios request
  108. */
  109. execute: (url: string, config?: RawAxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  110. }
  111. interface UseAxiosOptions<T = any> {
  112. /**
  113. * Will automatically run axios request when `useAxios` is used
  114. *
  115. */
  116. immediate?: boolean;
  117. /**
  118. * Use shallowRef.
  119. *
  120. * @default true
  121. */
  122. shallow?: boolean;
  123. /**
  124. * Callback when error is caught.
  125. */
  126. onError?: (e: unknown) => void;
  127. /**
  128. * Callback when success is caught.
  129. */
  130. onSuccess?: (data: T) => void;
  131. }
  132. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
  133. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
  134. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: RawAxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
  135. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  136. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  137. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  138. declare const changeCase_camelCase: typeof camelCase;
  139. declare const changeCase_capitalCase: typeof capitalCase;
  140. declare const changeCase_constantCase: typeof constantCase;
  141. declare const changeCase_dotCase: typeof dotCase;
  142. declare const changeCase_headerCase: typeof headerCase;
  143. declare const changeCase_noCase: typeof noCase;
  144. declare const changeCase_paramCase: typeof paramCase;
  145. declare const changeCase_pascalCase: typeof pascalCase;
  146. declare const changeCase_pathCase: typeof pathCase;
  147. declare const changeCase_sentenceCase: typeof sentenceCase;
  148. declare const changeCase_snakeCase: typeof snakeCase;
  149. declare namespace changeCase {
  150. export {
  151. changeCase_camelCase as camelCase,
  152. changeCase_capitalCase as capitalCase,
  153. changeCase_constantCase as constantCase,
  154. changeCase_dotCase as dotCase,
  155. changeCase_headerCase as headerCase,
  156. changeCase_noCase as noCase,
  157. changeCase_paramCase as paramCase,
  158. changeCase_pascalCase as pascalCase,
  159. changeCase_pathCase as pathCase,
  160. changeCase_sentenceCase as sentenceCase,
  161. changeCase_snakeCase as snakeCase,
  162. };
  163. }
  164. type ChangeCaseType = keyof typeof changeCase;
  165. declare function useChangeCase(input: MaybeRef<string>, type: ChangeCaseType, options?: Options | undefined): WritableComputedRef<string>;
  166. declare function useChangeCase(input: MaybeComputedRef<string>, type: ChangeCaseType, options?: Options | undefined): ComputedRef<string>;
  167. /**
  168. * Creates a new {@link useCookies} function
  169. * @param {Object} req - incoming http request (for SSR)
  170. * @see https://github.com/reactivestack/cookies/tree/master/packages/universal-cookie universal-cookie
  171. * @description Creates universal-cookie instance using request (default is window.document.cookie) and returns {@link useCookies} function with provided universal-cookie instance
  172. */
  173. declare function createCookies(req?: IncomingMessage): (dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
  174. doNotParse?: boolean | undefined;
  175. autoUpdateDependencies?: boolean | undefined;
  176. }) => {
  177. /**
  178. * Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
  179. */
  180. get: <T = any>(name: string, options?: universal_cookie.CookieGetOptions | undefined) => T;
  181. /**
  182. * Reactive get all cookies
  183. */
  184. getAll: <T_1 = any>(options?: universal_cookie.CookieGetOptions | undefined) => T_1;
  185. set: (name: string, value: any, options?: universal_cookie.CookieSetOptions | undefined) => void;
  186. remove: (name: string, options?: universal_cookie.CookieSetOptions | undefined) => void;
  187. addChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  188. removeChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  189. };
  190. /**
  191. * Reactive methods to work with cookies (use {@link createCookies} method instead if you are using SSR)
  192. * @param {string[]|null|undefined} dependencies - array of watching cookie's names. Pass empty array if don't want to watch cookies changes.
  193. * @param {Object} options
  194. * @param {boolean} options.doNotParse - don't try parse value as JSON
  195. * @param {boolean} options.autoUpdateDependencies - automatically update watching dependencies
  196. * @param {Object} cookies - universal-cookie instance
  197. */
  198. declare function useCookies(dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
  199. doNotParse?: boolean | undefined;
  200. autoUpdateDependencies?: boolean | undefined;
  201. }, cookies?: universal_cookie__default): {
  202. /**
  203. * Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
  204. */
  205. get: <T = any>(name: string, options?: universal_cookie.CookieGetOptions | undefined) => T;
  206. /**
  207. * Reactive get all cookies
  208. */
  209. getAll: <T_1 = any>(options?: universal_cookie.CookieGetOptions | undefined) => T_1;
  210. set: (name: string, value: any, options?: universal_cookie.CookieSetOptions | undefined) => void;
  211. remove: (name: string, options?: universal_cookie.CookieSetOptions | undefined) => void;
  212. addChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  213. removeChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  214. };
  215. type UseDrauuOptions = Omit<Options$1, 'el'>;
  216. interface UseDrauuReturn {
  217. drauuInstance: Ref<Drauu | undefined>;
  218. load: (svg: string) => void;
  219. dump: () => string | undefined;
  220. clear: () => void;
  221. cancel: () => void;
  222. undo: () => boolean | undefined;
  223. redo: () => boolean | undefined;
  224. canUndo: Ref<boolean>;
  225. canRedo: Ref<boolean>;
  226. brush: Ref<Brush>;
  227. onChanged: EventHookOn;
  228. onCommitted: EventHookOn;
  229. onStart: EventHookOn;
  230. onEnd: EventHookOn;
  231. onCanceled: EventHookOn;
  232. }
  233. /**
  234. * Reactive drauu
  235. *
  236. * @see https://vueuse.org/useDrauu
  237. * @param target The target svg element
  238. * @param options Drauu Options
  239. */
  240. declare function useDrauu(target: MaybeComputedElementRef, options?: UseDrauuOptions): UseDrauuReturn;
  241. interface UseFocusTrapOptions extends Options$2 {
  242. /**
  243. * Immediately activate the trap
  244. */
  245. immediate?: boolean;
  246. }
  247. interface UseFocusTrapReturn {
  248. /**
  249. * Indicates if the focus trap is currently active
  250. */
  251. hasFocus: Ref<boolean>;
  252. /**
  253. * Indicates if the focus trap is currently paused
  254. */
  255. isPaused: Ref<boolean>;
  256. /**
  257. * Activate the focus trap
  258. *
  259. * @see https://github.com/focus-trap/focus-trap#trapactivateactivateoptions
  260. * @param opts Activate focus trap options
  261. */
  262. activate: (opts?: ActivateOptions) => void;
  263. /**
  264. * Deactivate the focus trap
  265. *
  266. * @see https://github.com/focus-trap/focus-trap#trapdeactivatedeactivateoptions
  267. * @param opts Deactivate focus trap options
  268. */
  269. deactivate: (opts?: DeactivateOptions) => void;
  270. /**
  271. * Pause the focus trap
  272. *
  273. * @see https://github.com/focus-trap/focus-trap#trappause
  274. */
  275. pause: Fn;
  276. /**
  277. * Unpauses the focus trap
  278. *
  279. * @see https://github.com/focus-trap/focus-trap#trapunpause
  280. */
  281. unpause: Fn;
  282. }
  283. /**
  284. * Reactive focus-trap
  285. *
  286. * @see https://vueuse.org/useFocusTrap
  287. * @param target The target element to trap focus within
  288. * @param options Focus trap options
  289. * @param autoFocus Focus trap automatically when mounted
  290. */
  291. declare function useFocusTrap(target: MaybeElementRef, options?: UseFocusTrapOptions): UseFocusTrapReturn;
  292. type FuseOptions<T> = Fuse.IFuseOptions<T>;
  293. interface UseFuseOptions<T> {
  294. fuseOptions?: FuseOptions<T>;
  295. resultLimit?: number;
  296. matchAllWhenSearchEmpty?: boolean;
  297. }
  298. declare function useFuse<DataItem>(search: MaybeComputedRef<string>, data: MaybeComputedRef<DataItem[]>, options?: MaybeComputedRef<UseFuseOptions<DataItem>>): {
  299. fuse: vue_demi.Ref<{
  300. search: <R = DataItem>(pattern: string | Fuse.Expression, options?: Fuse.FuseSearchOptions | undefined) => Fuse.FuseResult<R>[];
  301. setCollection: (docs: readonly DataItem[], index?: Fuse.FuseIndex<DataItem> | undefined) => void;
  302. add: (doc: DataItem) => void;
  303. remove: (predicate: (doc: DataItem, idx: number) => boolean) => DataItem[];
  304. removeAt: (idx: number) => void;
  305. getIndex: () => Fuse.FuseIndex<DataItem>;
  306. }>;
  307. results: ComputedRef<Fuse.FuseResult<DataItem>[]>;
  308. };
  309. type UseFuseReturn = ReturnType<typeof useFuse>;
  310. interface UseIDBOptions extends ConfigurableFlush {
  311. /**
  312. * Watch for deep changes
  313. *
  314. * @default true
  315. */
  316. deep?: boolean;
  317. /**
  318. * On error callback
  319. *
  320. * Default log error to `console.error`
  321. */
  322. onError?: (error: unknown) => void;
  323. /**
  324. * Use shallow ref as reference
  325. *
  326. * @default false
  327. */
  328. shallow?: boolean;
  329. }
  330. /**
  331. *
  332. * @param key
  333. * @param initialValue
  334. * @param options
  335. */
  336. declare function useIDBKeyval<T>(key: IDBValidKey, initialValue: MaybeComputedRef<T>, options?: UseIDBOptions): RemovableRef<T>;
  337. interface UseJwtOptions<Fallback> {
  338. /**
  339. * Value returned when encounter error on decoding
  340. *
  341. * @default null
  342. */
  343. fallbackValue?: Fallback;
  344. /**
  345. * Error callback for decoding
  346. */
  347. onError?: (error: unknown) => void;
  348. }
  349. interface UseJwtReturn<Payload, Header, Fallback> {
  350. header: ComputedRef<Header | Fallback>;
  351. payload: ComputedRef<Payload | Fallback>;
  352. }
  353. /**
  354. * Reactive decoded jwt token.
  355. *
  356. * @see https://vueuse.org/useJwt
  357. * @param jwt
  358. */
  359. declare function useJwt<Payload extends object = JwtPayload, Header extends object = JwtHeader, Fallback = null>(encodedJwt: MaybeComputedRef<string>, options?: UseJwtOptions<Fallback>): UseJwtReturn<Payload, Header, Fallback>;
  360. type UseNProgressOptions = Partial<NProgressOptions>;
  361. /**
  362. * Reactive progress bar.
  363. *
  364. * @see https://vueuse.org/useNProgress
  365. */
  366. declare function useNProgress(currentProgress?: MaybeComputedRef<number | null | undefined>, options?: UseNProgressOptions): {
  367. isLoading: vue_demi.WritableComputedRef<boolean>;
  368. progress: vue_demi.Ref<number | (() => number | null | undefined) | null | undefined>;
  369. start: () => nprogress.NProgress;
  370. done: (force?: boolean | undefined) => nprogress.NProgress;
  371. remove: () => void;
  372. };
  373. type UseNProgressReturn = ReturnType<typeof useNProgress>;
  374. /**
  375. * Wrapper for qrcode.
  376. *
  377. * @see https://vueuse.org/useQRCode
  378. * @param text
  379. * @param options
  380. */
  381. declare function useQRCode(text: MaybeComputedRef<string>, options?: QRCode.QRCodeToDataURLOptions): vue_demi.Ref<string>;
  382. export { AsyncValidatorError, ChangeCaseType, EasyUseAxiosReturn, FuseOptions, StrictUseAxiosReturn, UseAsyncValidatorOptions, UseAsyncValidatorReturn, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, UseIDBOptions, UseJwtOptions, UseJwtReturn, UseNProgressOptions, UseNProgressReturn, createCookies, useAsyncValidator, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useIDBKeyval, useJwt, useNProgress, useQRCode };