@vueuse/shared 6.3.2 → 6.5.3

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,6 +1,5 @@
1
1
  import * as vue_demi from 'vue-demi';
2
2
  import { Ref, WatchOptions, WatchSource, ComputedRef, WatchCallback, WatchStopHandle, ShallowUnwrapRef as ShallowUnwrapRef$1, UnwrapRef, ToRefs } from 'vue-demi';
3
- import { Pausable as Pausable$1 } from '@vueuse/core';
4
3
 
5
4
  declare const isClient: boolean;
6
5
  declare const isDef: <T = any>(val?: T | undefined) => val is T;
@@ -29,6 +28,13 @@ declare type Fn = () => void;
29
28
  * ```
30
29
  */
31
30
  declare type MaybeRef<T> = T | Ref<T>;
31
+ /**
32
+ * A ref that allow to set null or undefined
33
+ */
34
+ declare type RemoveableRef<T> = Omit<Ref<T>, 'value'> & {
35
+ get value(): T;
36
+ set value(value: T | null | undefined);
37
+ };
32
38
  /**
33
39
  * Make all the nested attributes of an object or array to MaybeRef<T>
34
40
  *
@@ -106,6 +112,11 @@ interface FunctionWrapperOptions<Args extends any[] = any[], This = any> {
106
112
  }
107
113
  declare type EventFilter<Args extends any[] = any[], This = any> = (invoke: Fn, options: FunctionWrapperOptions<Args, This>) => void;
108
114
  interface ConfigurableEventFilter {
115
+ /**
116
+ * Filter for if events should to be received.
117
+ *
118
+ * @see https://vueuse.org/guide/config.html#event-filters
119
+ */
109
120
  eventFilter?: EventFilter;
110
121
  }
111
122
  /**
@@ -124,8 +135,9 @@ declare function debounceFilter(ms: MaybeRef<number>): EventFilter<any[], any>;
124
135
  *
125
136
  * @param ms
126
137
  * @param [trailing=true]
138
+ * @param [leading=true]
127
139
  */
128
- declare function throttleFilter(ms: MaybeRef<number>, trailing?: boolean): EventFilter<any[], any>;
140
+ declare function throttleFilter(ms: MaybeRef<number>, trailing?: boolean, leading?: boolean): EventFilter<any[], any>;
129
141
  /**
130
142
  * EventFilter that gives extra controls to pause and resume the filter
131
143
  *
@@ -562,7 +574,7 @@ interface IntervalOptions<Controls extends boolean> {
562
574
  declare function useInterval(interval?: number, options?: IntervalOptions<false>): Ref<number>;
563
575
  declare function useInterval(interval: number, options: IntervalOptions<true>): {
564
576
  counter: Ref<number>;
565
- } & Pausable$1;
577
+ } & Pausable;
566
578
 
567
579
  interface IntervalFnOptions {
568
580
  /**
@@ -603,9 +615,12 @@ declare function useLastChanged(source: WatchSource, options: UseLastChangedOpti
603
615
  * Throttle execution of a function. Especially useful for rate limiting
604
616
  * execution of handlers on events like resize and scroll.
605
617
  *
618
+ * @param value Ref value to be watched with throttle effect
606
619
  * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
620
+ * @param [trailing=true] if true, update the value again after the delay time is up
621
+ * @param [leading=true] if true, update the value on the leading edge of the ms timeout
607
622
  */
608
- declare function useThrottle<T>(value: Ref<T>, delay?: number): Ref<T>;
623
+ declare function useThrottle<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
609
624
 
610
625
  /**
611
626
  * Throttle execution of a function. Especially useful for rate limiting
@@ -615,9 +630,13 @@ declare function useThrottle<T>(value: Ref<T>, delay?: number): Ref<T>;
615
630
  * to `callback` when the throttled-function is executed.
616
631
  * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
617
632
  *
633
+ * @param [trailing=true] if true, call fn again after the time is up
634
+ *
635
+ * @param [leading=true] if true, call fn on the leading edge of the ms timeout
636
+ *
618
637
  * @return A new, throttled, function.
619
638
  */
620
- declare function useThrottleFn<T extends FunctionArgs>(fn: T, ms?: MaybeRef<number>, trailing?: boolean): T;
639
+ declare function useThrottleFn<T extends FunctionArgs>(fn: T, ms?: MaybeRef<number>, trailing?: boolean, leading?: boolean): T;
621
640
 
622
641
  interface TimeoutFnOptions {
623
642
  /**
@@ -665,6 +684,21 @@ declare function useTimeout(interval: number, options: TimeoutOptions<true>): {
665
684
  declare function useToggle(value: Ref<boolean>): (value?: boolean) => boolean;
666
685
  declare function useToggle(initialValue?: boolean): [Ref<boolean>, (value?: boolean) => boolean];
667
686
 
687
+ interface WatchAtMostOptions<Immediate> extends WatchWithFilterOptions<Immediate> {
688
+ count: MaybeRef<number>;
689
+ }
690
+ interface WatchAtMostReturn {
691
+ stop: WatchStopHandle;
692
+ count: Ref<number>;
693
+ }
694
+ declare function watchAtMost<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
695
+ declare function watchAtMost<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
696
+ declare function watchAtMost<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
697
+
698
+ 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;
699
+ 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;
700
+ 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;
701
+
668
702
  /**
669
703
  * Shorthand for watching value to be truthy
670
704
  *
@@ -672,4 +706,4 @@ declare function useToggle(initialValue?: boolean): [Ref<boolean>, (value?: bool
672
706
  */
673
707
  declare function whenever<T>(source: WatchSource<T>, cb: WatchCallback, options?: WatchOptions): vue_demi.WatchStopHandle;
674
708
 
675
- export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseLastChangedOptions, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchWithFilter, whenever };
709
+ export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseLastChangedOptions, WatchAtMostOptions, WatchAtMostReturn, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };