@vueuse/shared 8.7.4 → 8.8.1

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,16 +1,21 @@
1
1
  import * as vue_demi from 'vue-demi';
2
- import { WatchOptionsBase, Ref, WatchSource, ComputedRef, ShallowUnwrapRef as ShallowUnwrapRef$1, WatchOptions, UnwrapRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue-demi';
2
+ import { WatchOptionsBase, Ref, ComputedRef, WritableComputedRef, WatchSource, ComputedGetter, WritableComputedOptions, ShallowUnwrapRef as ShallowUnwrapRef$1, WatchOptions, UnwrapRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue-demi';
3
3
  import { MaybeRef as MaybeRef$1 } from '@vueuse/shared';
4
4
 
5
5
  declare function computedEager<T>(fn: () => T, options?: WatchOptionsBase): Readonly<Ref<T>>;
6
6
 
7
- /**
8
- * Explicitly define the deps of computed.
9
- *
10
- * @param source
11
- * @param fn
12
- */
13
- declare function computedWithControl<T, S>(source: WatchSource<S>, fn: () => T): ComputedRef<T>;
7
+ interface ComputedWithControlRefExtra {
8
+ /**
9
+ * Force update the computed value.
10
+ */
11
+ trigger(): void;
12
+ }
13
+ interface ComputedRefWithControl<T> extends ComputedRef<T>, ComputedWithControlRefExtra {
14
+ }
15
+ interface WritableComputedRefWithControl<T> extends WritableComputedRef<T>, ComputedWithControlRefExtra {
16
+ }
17
+ declare function computedWithControl<T, S>(source: WatchSource<S> | WatchSource<S>[], fn: ComputedGetter<T>): ComputedRefWithControl<T>;
18
+ declare function computedWithControl<T, S>(source: WatchSource<S> | WatchSource<S>[], fn: WritableComputedOptions<T>): WritableComputedRefWithControl<T>;
14
19
 
15
20
  /**
16
21
  * The source code for this function was inspired by vue-apollo's `useEventHook` util
@@ -100,14 +105,6 @@ declare const isIOS: boolean | "";
100
105
  * Any function
101
106
  */
102
107
  declare type Fn = () => void;
103
- /**
104
- * Maybe it's a ref, or not.
105
- *
106
- * ```ts
107
- * type MaybeRef<T> = T | Ref<T>
108
- * ```
109
- */
110
- declare type MaybeRef<T> = T | Ref<T>;
111
108
  /**
112
109
  * A ref that allow to set null or undefined
113
110
  */
@@ -119,6 +116,22 @@ declare type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
119
116
  * @deprecated Use `RemovableRef`
120
117
  */
121
118
  declare type RemoveableRef<T> = RemovableRef<T>;
119
+ /**
120
+ * Maybe it's a ref, or a plain value
121
+ *
122
+ * ```ts
123
+ * type MaybeRef<T> = T | Ref<T>
124
+ * ```
125
+ */
126
+ declare type MaybeRef<T> = T | Ref<T>;
127
+ /**
128
+ * Maybe it's a ref, or a getter function
129
+ *
130
+ * ```ts
131
+ * type MaybeRef<T> = T | Ref<T>
132
+ * ```
133
+ */
134
+ declare type MaybeComputedRef<T> = T extends Function ? never : (() => T) | MaybeRef<T>;
122
135
  /**
123
136
  * Make all the nested attributes of an object or array to MaybeRef<T>
124
137
  *
@@ -365,14 +378,14 @@ declare function reactiveComputed<T extends {}>(fn: () => T): T;
365
378
  *
366
379
  * @see https://vueuse.js.org/reactiveOmit
367
380
  */
368
- declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
381
+ declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
369
382
 
370
383
  /**
371
384
  * Reactively pick fields from a reactive object
372
385
  *
373
386
  * @see https://vueuse.js.org/reactivePick
374
387
  */
375
- declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): {
388
+ declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): {
376
389
  [S in K]: UnwrapRef<T[S]>;
377
390
  };
378
391
 
@@ -444,6 +457,17 @@ declare function refWithControl<T>(initial: T, options?: ControlledRefOptions<T>
444
457
  */
445
458
  declare const controlledRef: typeof refWithControl;
446
459
 
460
+ /**
461
+ * Normalize value/ref/getter to `ref` or `computed`.
462
+ */
463
+ declare function resolveRef<T>(r: MaybeComputedRef<T>): ComputedRef<T>;
464
+ declare function resolveRef<T>(r: MaybeRef<T>): Ref<T>;
465
+
466
+ /**
467
+ * Normalize value/ref/getter to `ref` or `computed`.
468
+ */
469
+ declare function resolveUnref<T>(r: MaybeComputedRef<T>): T;
470
+
447
471
  declare function set<T>(ref: Ref<T>, value: T): void;
448
472
  declare function set<O extends object, K extends keyof O>(target: O, key: K, value: O[K]): void;
449
473
 
@@ -822,6 +846,16 @@ declare function watchThrottled<T extends Readonly<WatchSource<unknown>[]>, Imme
822
846
  declare function watchThrottled<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle;
823
847
  declare function watchThrottled<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle;
824
848
 
849
+ interface WatchTriggerableReturn<FnReturnT = void> extends WatchIgnorableReturn {
850
+ /** Execute `WatchCallback` immediately */
851
+ trigger: () => FnReturnT;
852
+ }
853
+ declare type OnCleanup = (cleanupFn: () => void) => void;
854
+ declare type WatchTriggerableCallback<V = any, OV = any, R = void> = (value: V, oldValue: OV, onCleanup: OnCleanup) => R;
855
+ declare function watchTriggerable<T extends Readonly<WatchSource<unknown>[]>, FnReturnT>(sources: [...T], cb: WatchTriggerableCallback<MapSources<T>, MapOldSources<T, true>, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
856
+ declare function watchTriggerable<T, FnReturnT>(source: WatchSource<T>, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
857
+ declare function watchTriggerable<T extends object, FnReturnT>(source: T, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
858
+
825
859
  /**
826
860
  * Shorthand for watching value to be truthy
827
861
  *
@@ -829,4 +863,4 @@ declare function watchThrottled<T extends object, Immediate extends Readonly<boo
829
863
  */
830
864
  declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
831
865
 
832
- export { Awaitable, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, Reactify, ReactifyNested, ReactifyObjectOptions, RemovableRef, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, Stoppable, SyncRefOptions, SyncRefsOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseCounterOptions, UseDateFormatReturn, UseLastChangedOptions, UseToggleOptions, WatchAtMostOptions, WatchAtMostReturn, WatchDebouncedOptions, WatchIgnorableReturn, WatchPausableReturn, WatchThrottledOptions, WatchWithFilterOptions, __onlyVue3, logicAnd as and, 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, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isIOS, isNumber, isObject, isString, isWindow, logicAnd, logicNot, logicOr, makeDestructurable, noop, normalizeDate, logicNot as not, now, objectPick, logicOr as or, pausableFilter, watchPausable as pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchDebounced, watchIgnorable, watchOnce, watchPausable, watchThrottled, watchWithFilter, whenever };
866
+ export { Awaitable, ComputedRefWithControl, ComputedWithControlRefExtra, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeComputedRef, MaybeRef, Pausable, Reactify, ReactifyNested, ReactifyObjectOptions, RemovableRef, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, Stoppable, SyncRefOptions, SyncRefsOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseCounterOptions, UseDateFormatReturn, UseLastChangedOptions, UseToggleOptions, WatchAtMostOptions, WatchAtMostReturn, WatchDebouncedOptions, WatchIgnorableReturn, WatchPausableReturn, WatchThrottledOptions, WatchTriggerableCallback, WatchTriggerableReturn, WatchWithFilterOptions, WritableComputedRefWithControl, __onlyVue3, logicAnd as and, 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, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isIOS, isNumber, isObject, isString, isWindow, logicAnd, logicNot, logicOr, makeDestructurable, noop, normalizeDate, logicNot as not, now, objectPick, logicOr as or, 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, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchDebounced, watchIgnorable, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };