@vueuse/shared 8.7.3 → 8.8.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
@@ -10,7 +10,7 @@ declare function computedEager<T>(fn: () => T, options?: WatchOptionsBase): Read
10
10
  * @param source
11
11
  * @param fn
12
12
  */
13
- declare function computedWithControl<T, S>(source: WatchSource<S>, fn: () => T): ComputedRef<T>;
13
+ declare function computedWithControl<T, S>(source: WatchSource<S> | WatchSource<S>[], fn: () => T): ComputedRef<T>;
14
14
 
15
15
  /**
16
16
  * The source code for this function was inspired by vue-apollo's `useEventHook` util
@@ -100,14 +100,6 @@ declare const isIOS: boolean | "";
100
100
  * Any function
101
101
  */
102
102
  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
103
  /**
112
104
  * A ref that allow to set null or undefined
113
105
  */
@@ -119,6 +111,22 @@ declare type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
119
111
  * @deprecated Use `RemovableRef`
120
112
  */
121
113
  declare type RemoveableRef<T> = RemovableRef<T>;
114
+ /**
115
+ * Maybe it's a ref, or a plain value
116
+ *
117
+ * ```ts
118
+ * type MaybeRef<T> = T | Ref<T>
119
+ * ```
120
+ */
121
+ declare type MaybeRef<T> = T | Ref<T>;
122
+ /**
123
+ * Maybe it's a ref, or a getter function
124
+ *
125
+ * ```ts
126
+ * type MaybeRef<T> = T | Ref<T>
127
+ * ```
128
+ */
129
+ declare type MaybeComputedRef<T> = T extends Function ? never : (() => T) | MaybeRef<T>;
122
130
  /**
123
131
  * Make all the nested attributes of an object or array to MaybeRef<T>
124
132
  *
@@ -365,14 +373,14 @@ declare function reactiveComputed<T extends {}>(fn: () => T): T;
365
373
  *
366
374
  * @see https://vueuse.js.org/reactiveOmit
367
375
  */
368
- declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
376
+ declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
369
377
 
370
378
  /**
371
379
  * Reactively pick fields from a reactive object
372
380
  *
373
381
  * @see https://vueuse.js.org/reactivePick
374
382
  */
375
- declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): {
383
+ declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): {
376
384
  [S in K]: UnwrapRef<T[S]>;
377
385
  };
378
386
 
@@ -444,6 +452,17 @@ declare function refWithControl<T>(initial: T, options?: ControlledRefOptions<T>
444
452
  */
445
453
  declare const controlledRef: typeof refWithControl;
446
454
 
455
+ /**
456
+ * Normalize value/ref/getter to `ref` or `computed`.
457
+ */
458
+ declare function resolveRef<T>(r: MaybeComputedRef<T>): ComputedRef<T>;
459
+ declare function resolveRef<T>(r: MaybeRef<T>): Ref<T>;
460
+
461
+ /**
462
+ * Normalize value/ref/getter to `ref` or `computed`.
463
+ */
464
+ declare function resolveUnref<T>(r: MaybeComputedRef<T>): T;
465
+
447
466
  declare function set<T>(ref: Ref<T>, value: T): void;
448
467
  declare function set<O extends object, K extends keyof O>(target: O, key: K, value: O[K]): void;
449
468
 
@@ -822,6 +841,16 @@ declare function watchThrottled<T extends Readonly<WatchSource<unknown>[]>, Imme
822
841
  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
842
  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
843
 
844
+ interface WatchTriggerableReturn<FnReturnT = void> extends WatchIgnorableReturn {
845
+ /** Execute `WatchCallback` immediately */
846
+ trigger: () => FnReturnT;
847
+ }
848
+ declare type OnCleanup = (cleanupFn: () => void) => void;
849
+ declare type WatchTriggerableCallback<V = any, OV = any, R = void> = (value: V, oldValue: OV, onCleanup: OnCleanup) => R;
850
+ declare function watchTriggerable<T extends Readonly<WatchSource<unknown>[]>, FnReturnT>(sources: [...T], cb: WatchTriggerableCallback<MapSources<T>, MapOldSources<T, true>, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
851
+ declare function watchTriggerable<T, FnReturnT>(source: WatchSource<T>, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
852
+ declare function watchTriggerable<T extends object, FnReturnT>(source: T, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
853
+
825
854
  /**
826
855
  * Shorthand for watching value to be truthy
827
856
  *
@@ -829,4 +858,4 @@ declare function watchThrottled<T extends object, Immediate extends Readonly<boo
829
858
  */
830
859
  declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
831
860
 
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 };
861
+ 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, 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, __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 };