@vueuse/integrations 10.2.1 → 10.3.0

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