@reactive-vscode/vueuse 0.2.4 → 0.2.5

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/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ComputedGetter } from '@reactive-vscode/reactivity';
2
2
  import { ComputedRef } from '@reactive-vscode/reactivity';
3
- import { MaybeRef as MaybeRef_2 } from '@reactive-vscode/reactivity';
4
3
  import { Ref } from '@reactive-vscode/reactivity';
5
4
  import { ShallowRef } from '@reactive-vscode/reactivity';
6
5
  import { ShallowUnwrapRef as ShallowUnwrapRef_2 } from '@reactive-vscode/reactivity';
@@ -8,7 +7,7 @@ import { ToRef } from '@reactive-vscode/reactivity';
8
7
  import { ToRefs } from '@reactive-vscode/reactivity';
9
8
  import { UnwrapNestedRefs } from '@reactive-vscode/reactivity';
10
9
  import { UnwrapRef } from '@reactive-vscode/reactivity';
11
- import * as vue_demi from '@reactive-vscode/reactivity';
10
+ import * as vue from '@reactive-vscode/reactivity';
12
11
  import { WatchCallback } from '@reactive-vscode/reactivity';
13
12
  import { WatchOptions } from '@reactive-vscode/reactivity';
14
13
  import { WatchSource } from '@reactive-vscode/reactivity';
@@ -87,6 +86,21 @@ export declare interface BeforeFetchContext {
87
86
  cancel: Fn;
88
87
  }
89
88
 
89
+ declare interface BrowserLocationState {
90
+ readonly trigger: string;
91
+ readonly state?: any;
92
+ readonly length?: number;
93
+ readonly origin?: string;
94
+ hash?: string;
95
+ host?: string;
96
+ hostname?: string;
97
+ href?: string;
98
+ pathname?: string;
99
+ port?: string;
100
+ protocol?: string;
101
+ search?: string;
102
+ }
103
+
90
104
  export declare const bypassFilter: EventFilter;
91
105
 
92
106
  /**
@@ -94,9 +108,9 @@ export declare const bypassFilter: EventFilter;
94
108
  * https://github.com/vuejs/vue-apollo/blob/v4/packages/vue-apollo-composable/src/util/useEventHook.ts
95
109
  */
96
110
 
97
- declare type Callback<T> = IsAny<T> extends true ? (param: any) => void : ([
111
+ declare type Callback<T> = IsAny<T> extends true ? (...param: any) => void : ([
98
112
  T
99
- ] extends [void] ? () => void : (param: T) => void);
113
+ ] extends [void] ? (...param: unknown[]) => void : (...param: [T, ...unknown[]]) => void);
100
114
 
101
115
  export declare const camelize: (str: string) => string;
102
116
 
@@ -116,7 +130,9 @@ declare type Combination = 'overwrite' | 'chain';
116
130
  * @param initialState The initial state, used until the first evaluation finishes
117
131
  * @param optionsOrRef Additional options or a ref passed to receive the updates of the async evaluation
118
132
  */
119
- declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState?: T, optionsOrRef?: Ref<boolean> | AsyncComputedOptions): Ref<T>;
133
+ declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState: T, optionsOrRef?: Ref<boolean> | AsyncComputedOptions): Ref<T>;
134
+
135
+ declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState?: undefined, optionsOrRef?: Ref<boolean> | AsyncComputedOptions): Ref<T | undefined>;
120
136
  export { computedAsync as asyncComputed }
121
137
  export { computedAsync }
122
138
 
@@ -339,7 +355,7 @@ export declare type EventHookOn<T = any> = (fn: Callback<T>) => {
339
355
  off: () => void;
340
356
  };
341
357
 
342
- export declare type EventHookTrigger<T = any> = (param?: T) => Promise<unknown[]>;
358
+ export declare type EventHookTrigger<T = any> = (...param: IsAny<T> extends true ? unknown[] : [T, ...unknown[]]) => Promise<unknown[]>;
343
359
 
344
360
  /**
345
361
  * Overload 1: Unwrap set to false
@@ -478,15 +494,15 @@ export declare type IsAny<T> = IfAny<T, true, false>;
478
494
 
479
495
  export declare const isDef: <T = any>(val?: T) => val is T;
480
496
 
481
- export declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
482
-
483
497
  export declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
484
498
 
499
+ export declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
500
+
485
501
  export declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
486
502
 
487
503
  export declare const isObject: (val: any) => val is object;
488
504
 
489
- export declare function makeDestructurable<T extends Record<string, unknown>, const A extends readonly any[]>(obj: T, arr: A): T & A;
505
+ export declare function makeDestructurable<T extends Record<string, unknown>, A extends readonly any[]>(obj: T, arr: A): T & A;
490
506
 
491
507
  export declare type MapOldSources<T, Immediate> = {
492
508
  [K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : never;
@@ -501,22 +517,14 @@ export declare type MapSources<T> = {
501
517
  };
502
518
 
503
519
  /**
504
- * Maybe it's a ref, or a plain value
505
- *
506
- * ```ts
507
- * type MaybeRef<T> = T | Ref<T>
508
- * ```
520
+ * Maybe it's a ref, or a plain value.
509
521
  */
510
- declare type MaybeRef<T> = T | Ref<T>;
522
+ declare type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
511
523
 
512
524
  /**
513
- * Maybe it's a ref, or a plain value, or a getter function
514
- *
515
- * ```ts
516
- * type MaybeRefOrGetter<T> = (() => T) | T | Ref<T> | ComputedRef<T>
517
- * ```
525
+ * Maybe it's a ref, or a plain value, or a getter function.
518
526
  */
519
- declare type MaybeRefOrGetter<T> = MaybeRef<T> | (() => T);
527
+ declare type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);
520
528
 
521
529
  export declare type MultiWatchSources = (WatchSource<unknown> | object)[];
522
530
 
@@ -539,7 +547,7 @@ export declare const notNullish: <T = any>(val?: T | null | undefined) => val is
539
547
 
540
548
  export declare const now: () => number;
541
549
 
542
- export declare function objectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
550
+ export declare function objectEntries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
543
551
 
544
552
  /**
545
553
  * Create a new subset object by omit giving keys
@@ -698,7 +706,7 @@ export declare function refDefault<T>(source: Ref<T | undefined | null>, default
698
706
  * @param [trailing] if true, update the value again after the delay time is up
699
707
  * @param [leading] if true, update the value on the leading edge of the ms timeout
700
708
  */
701
- declare function refThrottled<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
709
+ declare function refThrottled<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T, T>;
702
710
  export { refThrottled }
703
711
  export { refThrottled as throttledRef }
704
712
  export { refThrottled as useThrottle }
@@ -706,14 +714,14 @@ export { refThrottled as useThrottle }
706
714
  /**
707
715
  * Fine-grained controls over ref and its reactivity.
708
716
  */
709
- export declare function refWithControl<T>(initial: T, options?: ControlledRefOptions<T>): vue_demi.ShallowUnwrapRef<{
717
+ export declare function refWithControl<T>(initial: T, options?: ControlledRefOptions<T>): vue.ShallowUnwrapRef<{
710
718
  get: (tracking?: boolean) => T;
711
719
  set: (value: T, triggering?: boolean) => void;
712
720
  untrackedGet: () => T;
713
721
  silentSet: (v: T) => void;
714
722
  peek: () => T;
715
723
  lay: (v: T) => void;
716
- }> & vue_demi.Ref<T>;
724
+ }> & vue.Ref<T, T>;
717
725
 
718
726
  /**
719
727
  * A ref that allow to set null or undefined
@@ -823,7 +831,7 @@ export declare type SyncRefOptions<L, R, D extends Direction> = ConfigurableFlus
823
831
  * @param source source ref
824
832
  * @param targets
825
833
  */
826
- export declare function syncRefs<T>(source: WatchSource<T>, targets: Ref<T> | Ref<T>[], options?: SyncRefsOptions): vue_demi.WatchStopHandle;
834
+ export declare function syncRefs<T>(source: WatchSource<T>, targets: Ref<T> | Ref<T>[], options?: SyncRefsOptions): vue.WatchHandle;
827
835
 
828
836
  export declare interface SyncRefsOptions extends ConfigurableFlushSync {
829
837
  /**
@@ -1036,7 +1044,9 @@ export declare function useArrayEvery<T>(list: MaybeRefOrGetter<MaybeRefOrGetter
1036
1044
  *
1037
1045
  * @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
1038
1046
  */
1039
- export declare function useArrayFilter<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => boolean): ComputedRef<T[]>;
1047
+ export declare function useArrayFilter<T, S extends T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => element is S): ComputedRef<S[]>;
1048
+
1049
+ export declare function useArrayFilter<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => unknown): ComputedRef<T[]>;
1040
1050
 
1041
1051
  /**
1042
1052
  * Reactive `Array.find`
@@ -1348,6 +1358,19 @@ declare function useBrowserLocation(options?: ConfigurableWindow): Ref<{
1348
1358
  port?: string | undefined;
1349
1359
  protocol?: string | undefined;
1350
1360
  search?: string | undefined;
1361
+ }, BrowserLocationState | {
1362
+ readonly trigger: string;
1363
+ readonly state?: any;
1364
+ readonly length?: number | undefined;
1365
+ readonly origin?: string | undefined;
1366
+ hash?: string | undefined;
1367
+ host?: string | undefined;
1368
+ hostname?: string | undefined;
1369
+ href?: string | undefined;
1370
+ pathname?: string | undefined;
1371
+ port?: string | undefined;
1372
+ protocol?: string | undefined;
1373
+ search?: string | undefined;
1351
1374
  }>;
1352
1375
 
1353
1376
  export declare type UseBrowserLocationReturn = ReturnType<typeof useBrowserLocation>;
@@ -1389,8 +1412,8 @@ export declare interface UseClonedReturn<T> {
1389
1412
  * @param [initialValue]
1390
1413
  * @param options
1391
1414
  */
1392
- export declare function useCounter(initialValue?: MaybeRef_2<number>, options?: UseCounterOptions): {
1393
- count: vue_demi.Ref<number>;
1415
+ export declare function useCounter(initialValue?: MaybeRef<number>, options?: UseCounterOptions): {
1416
+ count: vue.Ref<number, MaybeRef<number>>;
1394
1417
  inc: (delta?: number) => number;
1395
1418
  dec: (delta?: number) => number;
1396
1419
  get: () => number;
@@ -1445,7 +1468,7 @@ export declare interface UseCycleListReturn<T> {
1445
1468
  * @param formatStr - The combination of tokens to format the date
1446
1469
  * @param options - UseDateFormatOptions
1447
1470
  */
1448
- export declare function useDateFormat(date: MaybeRefOrGetter<DateLike>, formatStr?: MaybeRefOrGetter<string>, options?: UseDateFormatOptions): vue_demi.ComputedRef<string>;
1471
+ export declare function useDateFormat(date: MaybeRefOrGetter<DateLike>, formatStr?: MaybeRefOrGetter<string>, options?: UseDateFormatOptions): vue.ComputedRef<string>;
1449
1472
 
1450
1473
  export declare interface UseDateFormatOptions {
1451
1474
  /**
@@ -1453,7 +1476,7 @@ export declare interface UseDateFormatOptions {
1453
1476
  *
1454
1477
  * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
1455
1478
  */
1456
- locales?: Intl.LocalesArgument;
1479
+ locales?: MaybeRefOrGetter<Intl.LocalesArgument>;
1457
1480
  /**
1458
1481
  * A custom function to re-modify the way to display meridiem
1459
1482
  *
@@ -1878,7 +1901,7 @@ export declare type UseNowReturn = ReturnType<typeof useNow>;
1878
1901
  * @see https://vueuse.org/useObjectUrl
1879
1902
  * @param object
1880
1903
  */
1881
- export declare function useObjectUrl(object: MaybeRefOrGetter<Blob | MediaSource | null | undefined>): Readonly<vue_demi.Ref<string | undefined>>;
1904
+ export declare function useObjectUrl(object: MaybeRefOrGetter<Blob | MediaSource | null | undefined>): Readonly<vue.Ref<string | undefined, string | undefined>>;
1882
1905
 
1883
1906
  export declare function useOffsetPagination(options: Omit<UseOffsetPaginationOptions, 'total'>): UseOffsetPaginationInfinityPageReturn;
1884
1907
 
@@ -2022,7 +2045,7 @@ export declare interface UseRefHistoryReturn<Raw, Serialized> extends UseManualR
2022
2045
  * @param options
2023
2046
  */
2024
2047
  declare function useShare(shareOptions?: MaybeRefOrGetter<UseShareOptions>, options?: ConfigurableNavigator): {
2025
- isSupported: vue_demi.ComputedRef<boolean>;
2048
+ isSupported: vue.ComputedRef<boolean>;
2026
2049
  share: (overrideOptions?: MaybeRefOrGetter<UseShareOptions>) => Promise<void>;
2027
2050
  };
2028
2051
 
@@ -2112,8 +2135,8 @@ export declare interface UseStepperReturn<StepName, Steps, Step> {
2112
2135
  }
2113
2136
 
2114
2137
  declare function useTextareaAutosize(options?: UseTextareaAutosizeOptions): {
2115
- textarea: vue_demi.Ref<HTMLTextAreaElement>;
2116
- input: vue_demi.Ref<string>;
2138
+ textarea: vue.Ref<HTMLTextAreaElement, HTMLTextAreaElement>;
2139
+ input: vue.Ref<string, string>;
2117
2140
  triggerResize: () => void;
2118
2141
  };
2119
2142
 
@@ -2127,7 +2150,7 @@ export declare interface UseTextareaAutosizeOptions {
2127
2150
  /** Function called when the textarea size changes. */
2128
2151
  onResize?: () => void;
2129
2152
  /** Specify style target to apply the height based on textarea content. If not provided it will use textarea it self. */
2130
- styleTarget?: MaybeRef<HTMLElement>;
2153
+ styleTarget?: MaybeRef<HTMLElement | undefined>;
2131
2154
  /** Specify the style property that will be used to manipulate height. Can be `height | minHeight`. Default value is `height`. */
2132
2155
  styleProp?: 'height' | 'minHeight';
2133
2156
  }
@@ -2403,6 +2426,10 @@ export declare interface UseWebSocketOptions {
2403
2426
  * @default 'ping'
2404
2427
  */
2405
2428
  message?: string | ArrayBuffer | Blob;
2429
+ /**
2430
+ * Response message for the heartbeat, if undefined the message will be used
2431
+ */
2432
+ responseMessage?: string | ArrayBuffer | Blob;
2406
2433
  /**
2407
2434
  * Interval, in milliseconds
2408
2435
  *
@@ -2503,7 +2530,7 @@ export declare interface UseWebSocketReturn<T> {
2503
2530
  */
2504
2531
  export declare function useWebWorkerFn<T extends (...fnArgs: any[]) => any>(fn: T, options?: UseWebWorkerOptions): {
2505
2532
  workerFn: (...fnArgs: Parameters<T>) => Promise<ReturnType<T>>;
2506
- workerStatus: vue_demi.Ref<WebWorkerStatus>;
2533
+ workerStatus: vue.Ref<WebWorkerStatus, WebWorkerStatus>;
2507
2534
  workerTerminate: (status?: WebWorkerStatus) => void;
2508
2535
  };
2509
2536
 
@@ -2538,7 +2565,7 @@ export declare interface UseWebWorkerReturn<Data = any> {
2538
2565
  *
2539
2566
  * @see https://vueuse.org/watchArray
2540
2567
  */
2541
- export declare function watchArray<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T[]> | T[], cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>, options?: WatchOptions<Immediate>): vue_demi.WatchStopHandle;
2568
+ export declare function watchArray<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T[]> | T[], cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>, options?: WatchOptions<Immediate>): vue.WatchHandle;
2542
2569
 
2543
2570
  export declare type WatchArrayCallback<V = any, OV = any> = (value: V, oldValue: OV, added: V, removed: OV, onCleanup: (cleanupFn: () => void) => void) => any;
2544
2571
 
@@ -2567,7 +2594,7 @@ export declare interface WatchDebouncedOptions<Immediate> extends WatchOptions<I
2567
2594
  debounce?: MaybeRefOrGetter<number>;
2568
2595
  }
2569
2596
 
2570
- export declare function watchDeep<T extends Readonly<MultiWatchSources>, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
2597
+ export declare function watchDeep<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
2571
2598
 
2572
2599
  export declare function watchDeep<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
2573
2600
 
@@ -2587,7 +2614,7 @@ export declare interface WatchIgnorableReturn {
2587
2614
  stop: WatchStopHandle;
2588
2615
  }
2589
2616
 
2590
- export declare function watchImmediate<T extends Readonly<MultiWatchSources>>(source: T, cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
2617
+ export declare function watchImmediate<T extends Readonly<WatchSource<unknown>[]>>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
2591
2618
 
2592
2619
  export declare function watchImmediate<T>(source: WatchSource<T>, cb: WatchCallback<T, T | undefined>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
2593
2620
 
@@ -2654,7 +2681,7 @@ export declare type WebWorkerStatus = 'PENDING' | 'SUCCESS' | 'RUNNING' | 'ERROR
2654
2681
  *
2655
2682
  * @see https://vueuse.org/whenever
2656
2683
  */
2657
- export declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WheneverOptions): vue_demi.WatchStopHandle;
2684
+ export declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WheneverOptions): vue.WatchHandle;
2658
2685
 
2659
2686
  export declare interface WheneverOptions extends WatchOptions {
2660
2687
  /**
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ function computedWithControl(source, fn) {
17
17
  return {
18
18
  get() {
19
19
  if (dirty.value) {
20
- v = get2();
20
+ v = get2(v);
21
21
  dirty.value = false;
22
22
  }
23
23
  track();
@@ -87,7 +87,7 @@ function createSharedComposable(composable) {
87
87
  };
88
88
  return (...args) => {
89
89
  subscribers += 1;
90
- if (!state) {
90
+ if (!scope) {
91
91
  scope = effectScope(true);
92
92
  state = scope.run(() => composable(...args));
93
93
  }
@@ -699,7 +699,10 @@ function createUntil(r, isNot = false) {
699
699
  r,
700
700
  (v) => {
701
701
  if (condition(v) !== isNot) {
702
- stop == null ? void 0 : stop();
702
+ if (stop)
703
+ stop();
704
+ else
705
+ nextTick(() => stop == null ? void 0 : stop());
703
706
  resolve(v);
704
707
  }
705
708
  },
@@ -728,7 +731,10 @@ function createUntil(r, isNot = false) {
728
731
  [r, value],
729
732
  ([v1, v2]) => {
730
733
  if (isNot !== (v1 === v2)) {
731
- stop == null ? void 0 : stop();
734
+ if (stop)
735
+ stop();
736
+ else
737
+ nextTick(() => stop == null ? void 0 : stop());
732
738
  resolve(v1);
733
739
  }
734
740
  },
@@ -955,8 +961,8 @@ function formatDate(date, formatStr, options = {}) {
955
961
  M: () => month + 1,
956
962
  Mo: () => formatOrdinal(month + 1),
957
963
  MM: () => `${month + 1}`.padStart(2, "0"),
958
- MMM: () => date.toLocaleDateString(options.locales, { month: "short" }),
959
- MMMM: () => date.toLocaleDateString(options.locales, { month: "long" }),
964
+ MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
965
+ MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
960
966
  D: () => String(days),
961
967
  Do: () => formatOrdinal(days),
962
968
  DD: () => `${days}`.padStart(2, "0"),
@@ -974,9 +980,9 @@ function formatDate(date, formatStr, options = {}) {
974
980
  ss: () => `${seconds}`.padStart(2, "0"),
975
981
  SSS: () => `${milliseconds}`.padStart(3, "0"),
976
982
  d: () => day,
977
- dd: () => date.toLocaleDateString(options.locales, { weekday: "narrow" }),
978
- ddd: () => date.toLocaleDateString(options.locales, { weekday: "short" }),
979
- dddd: () => date.toLocaleDateString(options.locales, { weekday: "long" }),
983
+ dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
984
+ ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
985
+ dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
980
986
  A: () => meridiem(hours, minutes),
981
987
  AA: () => meridiem(hours, minutes, false, true),
982
988
  a: () => meridiem(hours, minutes, true),
@@ -1473,12 +1479,12 @@ function createUnrefFn(fn) {
1473
1479
  return fn.apply(this, args.map((i) => toValue(i)));
1474
1480
  };
1475
1481
  }
1482
+ const defaultWindow = isClient ? window : void 0;
1476
1483
  function unrefElement(elRef) {
1477
1484
  var _a;
1478
1485
  const plain = toValue(elRef);
1479
1486
  return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
1480
1487
  }
1481
- const defaultWindow = isClient ? window : void 0;
1482
1488
  function useEventListener(...args) {
1483
1489
  let target;
1484
1490
  let events2;
@@ -1626,7 +1632,8 @@ function useAsyncQueue(tasks, options) {
1626
1632
  }
1627
1633
  const done = curr(prevRes).then((currentRes) => {
1628
1634
  updateResult(promiseState.fulfilled, currentRes);
1629
- activeIndex.value === tasks.length - 1 && onFinished();
1635
+ if (activeIndex.value === tasks.length - 1)
1636
+ onFinished();
1630
1637
  return currentRes;
1631
1638
  });
1632
1639
  if (!signal)
@@ -3014,6 +3021,7 @@ function useWebSocket(url, options = {}) {
3014
3021
  status.value = "CONNECTING";
3015
3022
  ws.onopen = () => {
3016
3023
  status.value = "OPEN";
3024
+ retried = 0;
3017
3025
  onConnected == null ? void 0 : onConnected(ws);
3018
3026
  heartbeatResume == null ? void 0 : heartbeatResume();
3019
3027
  _sendBuffer();
@@ -3021,19 +3029,20 @@ function useWebSocket(url, options = {}) {
3021
3029
  ws.onclose = (ev) => {
3022
3030
  status.value = "CLOSED";
3023
3031
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3024
- if (!explicitlyClosed && options.autoReconnect) {
3032
+ if (!explicitlyClosed && options.autoReconnect && ws === wsRef.value) {
3025
3033
  const {
3026
3034
  retries = -1,
3027
3035
  delay = 1e3,
3028
3036
  onFailed
3029
3037
  } = resolveNestedOptions(options.autoReconnect);
3030
- retried += 1;
3031
- if (typeof retries === "number" && (retries < 0 || retried < retries))
3038
+ if (typeof retries === "number" && (retries < 0 || retried < retries)) {
3039
+ retried += 1;
3032
3040
  setTimeout(_init, delay);
3033
- else if (typeof retries === "function" && retries())
3041
+ } else if (typeof retries === "function" && retries()) {
3034
3042
  setTimeout(_init, delay);
3035
- else
3043
+ } else {
3036
3044
  onFailed == null ? void 0 : onFailed();
3045
+ }
3037
3046
  }
3038
3047
  };
3039
3048
  ws.onerror = (e) => {
@@ -3043,9 +3052,10 @@ function useWebSocket(url, options = {}) {
3043
3052
  if (options.heartbeat) {
3044
3053
  resetHeartbeat();
3045
3054
  const {
3046
- message = DEFAULT_PING_MESSAGE
3055
+ message = DEFAULT_PING_MESSAGE,
3056
+ responseMessage = message
3047
3057
  } = resolveNestedOptions(options.heartbeat);
3048
- if (e.data === message)
3058
+ if (e.data === responseMessage)
3049
3059
  return;
3050
3060
  }
3051
3061
  data.value = e.data;
@@ -3099,16 +3109,6 @@ function useWebSocket(url, options = {}) {
3099
3109
  ws: wsRef
3100
3110
  };
3101
3111
  }
3102
- function jobRunner(userFunc) {
3103
- return (e) => {
3104
- const userFuncArgs = e.data[0];
3105
- return Promise.resolve(userFunc.apply(void 0, userFuncArgs)).then((result) => {
3106
- postMessage(["SUCCESS", result]);
3107
- }).catch((error) => {
3108
- postMessage(["ERROR", error]);
3109
- });
3110
- };
3111
- }
3112
3112
  function depsParser(deps, localDeps) {
3113
3113
  if (deps.length === 0 && localDeps.length === 0)
3114
3114
  return "";
@@ -3125,6 +3125,16 @@ function depsParser(deps, localDeps) {
3125
3125
  const importString = `importScripts(${depsString});`;
3126
3126
  return `${depsString.trim() === "" ? "" : importString} ${depsFunctionString}`;
3127
3127
  }
3128
+ function jobRunner(userFunc) {
3129
+ return (e) => {
3130
+ const userFuncArgs = e.data[0];
3131
+ return Promise.resolve(userFunc.apply(void 0, userFuncArgs)).then((result) => {
3132
+ postMessage(["SUCCESS", result]);
3133
+ }).catch((error) => {
3134
+ postMessage(["ERROR", error]);
3135
+ });
3136
+ };
3137
+ }
3128
3138
  function createWorkerBlobUrl(fn, deps, localDeps) {
3129
3139
  const blobCode = `${depsParser(deps, localDeps)}; onmessage=(${jobRunner})(${fn})`;
3130
3140
  const blob = new Blob([blobCode], { type: "text/javascript" });
@@ -3190,11 +3200,12 @@ function useWebWorkerFn(fn, options = {}) {
3190
3200
  return newWorker;
3191
3201
  };
3192
3202
  const callWorker = (...fnArgs) => new Promise((resolve, reject) => {
3203
+ var _a;
3193
3204
  promise.value = {
3194
3205
  resolve,
3195
3206
  reject
3196
3207
  };
3197
- worker.value && worker.value.postMessage([[...fnArgs]]);
3208
+ (_a = worker.value) == null ? void 0 : _a.postMessage([[...fnArgs]]);
3198
3209
  workerStatus.value = "RUNNING";
3199
3210
  });
3200
3211
  const workerFn = (...fnArgs) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reactive-vscode/vueuse",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "description": "Useful VueUse utilities for VSCode extension development",
6
6
  "author": "_Kerman <kermanx@qq.com>",
7
7
  "license": "MIT",
@@ -32,14 +32,14 @@
32
32
  "tsconfig.json"
33
33
  ],
34
34
  "dependencies": {
35
- "@reactive-vscode/reactivity": "0.2.4"
35
+ "@reactive-vscode/reactivity": "0.2.5"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "^20.14.2",
39
- "@vueuse/core": "^10.10.0",
40
- "typescript": "^5.4.5",
41
- "vite": "^5.2.12",
42
- "vite-plugin-dts": "^3.9.1"
38
+ "@types/node": "^20.16.10",
39
+ "@vueuse/core": "^11.1.0",
40
+ "typescript": "^5.6.2",
41
+ "vite": "^5.4.8",
42
+ "vite-plugin-dts": "^4.2.1"
43
43
  },
44
44
  "scripts": {
45
45
  "typecheck": "tsc --noEmit",