@vueuse/shared 9.13.0 → 10.0.0-beta.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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue_demi from 'vue-demi';
2
- import { WatchOptionsBase, Ref, ComputedRef, WritableComputedRef, WatchSource, ComputedGetter, WritableComputedOptions, ShallowUnwrapRef as ShallowUnwrapRef$1, WatchOptions, UnwrapRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue-demi';
2
+ import { WatchOptionsBase, Ref, ComputedRef, WritableComputedRef, WatchSource, ComputedGetter, WritableComputedOptions, WatchOptions, ShallowUnwrapRef as ShallowUnwrapRef$1, UnwrapRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue-demi';
3
3
 
4
4
  declare function computedEager<T>(fn: () => T, options?: WatchOptionsBase): Readonly<Ref<T>>;
5
5
 
@@ -20,7 +20,7 @@ type EventHookOn<T = any> = (fn: (param: T) => void) => {
20
20
  off: () => void;
21
21
  };
22
22
  type EventHookOff<T = any> = (fn: (param: T) => void) => void;
23
- type EventHookTrigger<T = any> = (param: T) => void;
23
+ type EventHookTrigger<T = any> = (param: T) => Promise<unknown[]>;
24
24
  interface EventHook<T = any> {
25
25
  on: EventHookOn<T>;
26
26
  off: EventHookOff<T>;
@@ -33,53 +33,6 @@ interface EventHook<T = any> {
33
33
  */
34
34
  declare function createEventHook<T = any>(): EventHook<T>;
35
35
 
36
- type CreateGlobalStateReturn<T> = () => T;
37
- /**
38
- * Keep states in the global scope to be reusable across Vue instances.
39
- *
40
- * @see https://vueuse.org/createGlobalState
41
- * @param stateFactory A factory function to create the state
42
- */
43
- declare function createGlobalState<T>(stateFactory: () => T): CreateGlobalStateReturn<T>;
44
-
45
- /**
46
- * Create global state that can be injected into components.
47
- *
48
- * @see https://vueuse.org/createInjectionState
49
- *
50
- */
51
- declare function createInjectionState<Arguments extends Array<any>, Return>(composable: (...args: Arguments) => Return): readonly [useProvidingState: (...args: Arguments) => Return, useInjectedState: () => Return | undefined];
52
-
53
- /**
54
- * Make a composable function usable with multiple Vue instances.
55
- *
56
- * @see https://vueuse.org/createSharedComposable
57
- */
58
- declare function createSharedComposable<Fn extends ((...args: any[]) => any)>(composable: Fn): Fn;
59
-
60
- interface ExtendRefOptions<Unwrap extends boolean = boolean> {
61
- /**
62
- * Is the extends properties enumerable
63
- *
64
- * @default false
65
- */
66
- enumerable?: boolean;
67
- /**
68
- * Unwrap for Ref properties
69
- *
70
- * @default true
71
- */
72
- unwrap?: Unwrap;
73
- }
74
- /**
75
- * Overload 1: Unwrap set to false
76
- */
77
- declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options?: Options): ShallowUnwrapRef$1<Extend> & R;
78
- /**
79
- * Overload 2: Unwrap unset or set to true
80
- */
81
- declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions>(ref: R, extend: Extend, options?: Options): Extend & R;
82
-
83
36
  declare const isClient: boolean;
84
37
  declare const isDef: <T = any>(val?: T | undefined) => val is T;
85
38
  declare const assert: (condition: boolean, ...infos: any[]) => void;
@@ -112,10 +65,6 @@ type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
112
65
  get value(): T;
113
66
  set value(value: T | null | undefined);
114
67
  };
115
- /**
116
- * @deprecated Use `RemovableRef`
117
- */
118
- type RemoveableRef<T> = RemovableRef<T>;
119
68
  /**
120
69
  * Maybe it's a ref, or a plain value
121
70
  *
@@ -189,10 +138,6 @@ interface Stoppable<StartFnArgs extends any[] = any[]> {
189
138
  */
190
139
  start: (...args: StartFnArgs) => void;
191
140
  }
192
- /**
193
- * @deprecated Use `Stoppable`
194
- */
195
- type Stopable = Stoppable;
196
141
  interface ConfigurableFlush {
197
142
  /**
198
143
  * Timing for monitoring changes, refer to WatchOptions for more details
@@ -324,6 +269,53 @@ declare function increaseWithUnit(target: string | number, delta: number): strin
324
269
  * @category Object
325
270
  */
326
271
  declare function objectPick<O extends object, T extends keyof O>(obj: O, keys: T[], omitUndefined?: boolean): Pick<O, T>;
272
+ declare function objectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
273
+
274
+ /**
275
+ * Keep states in the global scope to be reusable across Vue instances.
276
+ *
277
+ * @see https://vueuse.org/createGlobalState
278
+ * @param stateFactory A factory function to create the state
279
+ */
280
+ declare function createGlobalState<Fn extends AnyFn>(stateFactory: Fn): Fn;
281
+
282
+ /**
283
+ * Create global state that can be injected into components.
284
+ *
285
+ * @see https://vueuse.org/createInjectionState
286
+ *
287
+ */
288
+ declare function createInjectionState<Arguments extends Array<any>, Return>(composable: (...args: Arguments) => Return): readonly [useProvidingState: (...args: Arguments) => Return, useInjectedState: () => Return | undefined];
289
+
290
+ /**
291
+ * Make a composable function usable with multiple Vue instances.
292
+ *
293
+ * @see https://vueuse.org/createSharedComposable
294
+ */
295
+ declare function createSharedComposable<Fn extends AnyFn>(composable: Fn): Fn;
296
+
297
+ interface ExtendRefOptions<Unwrap extends boolean = boolean> {
298
+ /**
299
+ * Is the extends properties enumerable
300
+ *
301
+ * @default false
302
+ */
303
+ enumerable?: boolean;
304
+ /**
305
+ * Unwrap for Ref properties
306
+ *
307
+ * @default true
308
+ */
309
+ unwrap?: Unwrap;
310
+ }
311
+ /**
312
+ * Overload 1: Unwrap set to false
313
+ */
314
+ declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options?: Options): ShallowUnwrapRef$1<Extend> & R;
315
+ /**
316
+ * Overload 2: Unwrap unset or set to true
317
+ */
318
+ declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions>(ref: R, extend: Extend, options?: Options): Extend & R;
327
319
 
328
320
  /**
329
321
  * Shorthand for accessing `ref.value`
@@ -358,7 +350,7 @@ interface ReactifyOptions<T extends boolean> {
358
350
  declare function reactify<T extends Function, K extends boolean = true>(fn: T, options?: ReactifyOptions<K>): Reactified<T, K>;
359
351
 
360
352
  type ReactifyNested<T, Keys extends keyof T = keyof T, S extends boolean = true> = {
361
- [K in Keys]: T[K] extends (...args: any[]) => any ? Reactified<T[K], S> : T[K];
353
+ [K in Keys]: T[K] extends AnyFn ? Reactified<T[K], S> : T[K];
362
354
  };
363
355
  interface ReactifyObjectOptions<T extends boolean> extends ReactifyOptions<T> {
364
356
  /**
@@ -650,6 +642,9 @@ interface UntilArrayInstance<T> extends UntilBaseInstance<T> {
650
642
  declare function until<T extends unknown[]>(r: WatchSource<T> | MaybeComputedRef<T>): UntilArrayInstance<T>;
651
643
  declare function until<T>(r: WatchSource<T> | MaybeComputedRef<T>): UntilValueInstance<T>;
652
644
 
645
+ declare function useArrayDifference<T>(list: MaybeComputedRef<T[]>, values: MaybeComputedRef<T[]>, key?: keyof T): ComputedRef<T[]>;
646
+ declare function useArrayDifference<T>(list: MaybeComputedRef<T[]>, values: MaybeComputedRef<T[]>, compareFn?: (value: T, othVal: T) => boolean): ComputedRef<T[]>;
647
+
653
648
  /**
654
649
  * Reactive `Array.every`
655
650
  *
@@ -705,6 +700,15 @@ declare function useArrayFindIndex<T>(list: MaybeComputedRef<MaybeComputedRef<T>
705
700
  */
706
701
  declare function useArrayFindLast<T>(list: MaybeComputedRef<MaybeComputedRef<T>[]>, fn: (element: T, index: number, array: MaybeComputedRef<T>[]) => boolean): ComputedRef<T | undefined>;
707
702
 
703
+ type UseArrayIncludesComparatorFn<T, V> = ((element: T, value: V, index: number, array: MaybeComputedRef<T>[]) => boolean);
704
+ interface UseArrayIncludesOptions<T, V> {
705
+ fromIndex?: number;
706
+ comparator?: UseArrayIncludesComparatorFn<T, V> | keyof T;
707
+ }
708
+ declare function useArrayIncludes<T, V = any>(list: MaybeComputedRef<MaybeComputedRef<T>[]>, value: MaybeComputedRef<V>, comparator?: UseArrayIncludesComparatorFn<T, V>): ComputedRef<boolean>;
709
+ declare function useArrayIncludes<T, V = any>(list: MaybeComputedRef<MaybeComputedRef<T>[]>, value: MaybeComputedRef<V>, comparator?: keyof T): ComputedRef<boolean>;
710
+ declare function useArrayIncludes<T, V = any>(list: MaybeComputedRef<MaybeComputedRef<T>[]>, value: MaybeComputedRef<V>, options?: UseArrayIncludesOptions<T, V>): ComputedRef<boolean>;
711
+
708
712
  /**
709
713
  * Reactive `Array.join`
710
714
  *
@@ -928,7 +932,7 @@ interface UseTimeoutFnOptions {
928
932
  * @param interval
929
933
  * @param options
930
934
  */
931
- declare function useTimeoutFn<CallbackFn extends (...args: any[]) => any>(cb: CallbackFn, interval: MaybeComputedRef<number>, options?: UseTimeoutFnOptions): Stoppable<Parameters<CallbackFn> | []>;
935
+ declare function useTimeoutFn<CallbackFn extends AnyFn>(cb: CallbackFn, interval: MaybeComputedRef<number>, options?: UseTimeoutFnOptions): Stoppable<Parameters<CallbackFn> | []>;
932
936
 
933
937
  interface UseTimeoutOptions<Controls extends boolean> extends UseTimeoutFnOptions {
934
938
  /**
@@ -1023,6 +1027,13 @@ declare function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Imme
1023
1027
  declare function watchDebounced<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
1024
1028
  declare function watchDebounced<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
1025
1029
 
1030
+ /**
1031
+ * Shorthand for watching value with {deep: true}
1032
+ *
1033
+ * @see https://vueuse.org/watchDeep
1034
+ */
1035
+ declare function watchDeep<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
1036
+
1026
1037
  type IgnoredUpdater = (updater: () => void) => void;
1027
1038
  interface WatchIgnorableReturn {
1028
1039
  ignoreUpdates: IgnoredUpdater;
@@ -1033,6 +1044,13 @@ declare function watchIgnorable<T extends Readonly<WatchSource<unknown>[]>, Imme
1033
1044
  declare function watchIgnorable<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchIgnorableReturn;
1034
1045
  declare function watchIgnorable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchIgnorableReturn;
1035
1046
 
1047
+ /**
1048
+ * Shorthand for watching value with {immediate: true}
1049
+ *
1050
+ * @see https://vueuse.org/watchImmediate
1051
+ */
1052
+ declare function watchImmediate<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
1053
+
1036
1054
  declare function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchOptions<Immediate>): void;
1037
1055
  declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): void;
1038
1056
 
@@ -1069,4 +1087,4 @@ declare function watchTriggerable<T extends object, FnReturnT>(source: T, cb: Wa
1069
1087
  */
1070
1088
  declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
1071
1089
 
1072
- export { AnyFn, ArgumentsType, Arrayable, Awaitable, ComputedRefWithControl, ComputedWithControlRefExtra, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater, MapOldSources, MapSources, MaybeComputedRef, MaybeReadonlyRef, MaybeRef, Pausable, PromisifyFn, Reactified, ReactifyNested, ReactifyObjectOptions, ReactifyOptions, RemovableRef, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, Stoppable, SyncRefOptions, SyncRefsOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseArrayReducer, UseCounterOptions, UseDateFormatOptions, UseDateFormatReturn, UseIntervalControls, UseIntervalFnOptions, UseIntervalOptions, UseLastChangedOptions, UseTimeoutFnOptions, UseTimeoutOptions, UseToNumberOptions, UseToggleOptions, WatchArrayCallback, WatchAtMostOptions, WatchAtMostReturn, WatchDebouncedOptions, WatchIgnorableReturn, WatchPausableReturn, WatchThrottledOptions, WatchTriggerableCallback, WatchTriggerableReturn, WatchWithFilterOptions, WritableComputedRefWithControl, __onlyVue27Plus, __onlyVue3, assert, refAutoReset as autoResetRef, bypassFilter, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, directiveHooks, computedEager as eagerComputed, extendRef, formatDate, get, hasOwn, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isIOS, isNumber, isObject, isString, isWindow, makeDestructurable, noop, normalizeDate, now, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchIgnorable, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
1090
+ export { AnyFn, ArgumentsType, Arrayable, Awaitable, ComputedRefWithControl, ComputedWithControlRefExtra, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater, MapOldSources, MapSources, MaybeComputedRef, MaybeReadonlyRef, MaybeRef, Pausable, PromisifyFn, Reactified, ReactifyNested, ReactifyObjectOptions, ReactifyOptions, RemovableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stoppable, SyncRefOptions, SyncRefsOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseArrayIncludesComparatorFn, UseArrayIncludesOptions, UseArrayReducer, UseCounterOptions, UseDateFormatOptions, UseDateFormatReturn, UseIntervalControls, UseIntervalFnOptions, UseIntervalOptions, UseLastChangedOptions, UseTimeoutFnOptions, UseTimeoutOptions, UseToNumberOptions, UseToggleOptions, WatchArrayCallback, WatchAtMostOptions, WatchAtMostReturn, WatchDebouncedOptions, WatchIgnorableReturn, WatchPausableReturn, WatchThrottledOptions, WatchTriggerableCallback, WatchTriggerableReturn, WatchWithFilterOptions, WritableComputedRefWithControl, __onlyVue27Plus, __onlyVue3, assert, refAutoReset as autoResetRef, bypassFilter, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, directiveHooks, computedEager as eagerComputed, extendRef, formatDate, get, hasOwn, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isIOS, isNumber, isObject, isString, isWindow, makeDestructurable, noop, normalizeDate, now, objectEntries, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };