@reactive-vscode/vueuse 0.2.8 → 0.2.9

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.cjs CHANGED
@@ -569,10 +569,8 @@ function set(...args) {
569
569
  ref.value = value;
570
570
  }
571
571
  if (args.length === 3) {
572
- {
573
- const [target, key, value] = args;
574
- target[key] = value;
575
- }
572
+ const [target, key, value] = args;
573
+ target[key] = value;
576
574
  }
577
575
  }
578
576
  function watchWithFilter(source, cb, options = {}) {
@@ -893,7 +891,7 @@ function useArrayReduce(list, reducer, ...args) {
893
891
  const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
894
892
  return reactivity.computed(() => {
895
893
  const resolved = toValue(list);
896
- return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
894
+ return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
897
895
  });
898
896
  }
899
897
  function useArraySome(list, fn) {
@@ -1040,7 +1038,8 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1040
1038
  if (immediateCallback)
1041
1039
  cb();
1042
1040
  clean();
1043
- timer = setInterval(cb, intervalValue);
1041
+ if (isActive.value)
1042
+ timer = setInterval(cb, intervalValue);
1044
1043
  }
1045
1044
  if (immediate && isClient)
1046
1045
  resume();
@@ -2285,7 +2284,8 @@ function useFetch(url, ...args) {
2285
2284
  if (config.payload) {
2286
2285
  const headers = headersToObject(defaultFetchOptions.headers);
2287
2286
  const payload = toValue(config.payload);
2288
- if (!config.payloadType && payload && Object.getPrototypeOf(payload) === Object.prototype && !(payload instanceof FormData))
2287
+ const proto = Object.getPrototypeOf(payload);
2288
+ if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
2289
2289
  config.payloadType = "json";
2290
2290
  if (config.payloadType)
2291
2291
  headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
@@ -2428,7 +2428,7 @@ function useFetch(url, ...args) {
2428
2428
  }
2429
2429
  function waitUntilFinished() {
2430
2430
  return new Promise((resolve, reject) => {
2431
- until(isFinished).toBe(true).then(() => resolve(shell)).catch((error2) => reject(error2));
2431
+ until(isFinished).toBe(true).then(() => resolve(shell)).catch(reject);
2432
2432
  });
2433
2433
  }
2434
2434
  function setType(type) {
@@ -2455,8 +2455,12 @@ function useFetch(url, ...args) {
2455
2455
  };
2456
2456
  }
2457
2457
  function joinPaths(start, end) {
2458
- if (!start.endsWith("/") && !end.startsWith("/"))
2458
+ if (!start.endsWith("/") && !end.startsWith("/")) {
2459
2459
  return `${start}/${end}`;
2460
+ }
2461
+ if (start.endsWith("/") && end.startsWith("/")) {
2462
+ return `${start.slice(0, -1)}${end}`;
2463
+ }
2460
2464
  return `${start}${end}`;
2461
2465
  }
2462
2466
  const defaultEvents$1 = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"];
@@ -2899,8 +2903,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
2899
2903
  const hash = window2.location.hash || "#";
2900
2904
  const index = hash.indexOf("?");
2901
2905
  if (index > 0)
2902
- return `${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2903
- return `${hash}${stringified ? `?${stringified}` : ""}`;
2906
+ return `${window2.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2907
+ return `${window2.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
2904
2908
  }
2905
2909
  function read() {
2906
2910
  return new URLSearchParams(getRawParams());
@@ -3031,7 +3035,7 @@ function useWebSocket(url, options = {}) {
3031
3035
  ws.onclose = (ev) => {
3032
3036
  status.value = "CLOSED";
3033
3037
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3034
- if (!explicitlyClosed && options.autoReconnect && ws === wsRef.value) {
3038
+ if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
3035
3039
  const {
3036
3040
  retries = -1,
3037
3041
  delay = 1e3,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { ComputedGetter } from '@reactive-vscode/reactivity';
2
2
  import { ComputedRef } from '@reactive-vscode/reactivity';
3
+ import { MaybeRef } from '@reactive-vscode/reactivity';
4
+ import { MaybeRefOrGetter } from '@reactive-vscode/reactivity';
3
5
  import { Ref } from '@reactive-vscode/reactivity';
4
6
  import { ShallowRef } from '@reactive-vscode/reactivity';
5
7
  import { ShallowUnwrapRef as ShallowUnwrapRef_2 } from '@reactive-vscode/reactivity';
@@ -516,16 +518,6 @@ export declare type MapSources<T> = {
516
518
  [K in keyof T]: T[K] extends WatchSource<infer V> ? V : never;
517
519
  };
518
520
 
519
- /**
520
- * Maybe it's a ref, or a plain value.
521
- */
522
- declare type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
523
-
524
- /**
525
- * Maybe it's a ref, or a plain value, or a getter function.
526
- */
527
- declare type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);
528
-
529
521
  export declare type MultiWatchSources = (WatchSource<unknown> | object)[];
530
522
 
531
523
  export declare type Mutable<T> = {
@@ -1839,11 +1831,11 @@ export declare interface UseManualRefHistoryReturn<Raw, Serialized> {
1839
1831
  /**
1840
1832
  * A ref representing if undo is possible (non empty undoStack)
1841
1833
  */
1842
- canUndo: Ref<boolean>;
1834
+ canUndo: ComputedRef<boolean>;
1843
1835
  /**
1844
1836
  * A ref representing if redo is possible (non empty redoStack)
1845
1837
  */
1846
- canRedo: Ref<boolean>;
1838
+ canRedo: ComputedRef<boolean>;
1847
1839
  /**
1848
1840
  * Undo changes
1849
1841
  */
package/dist/index.js CHANGED
@@ -567,10 +567,8 @@ function set(...args) {
567
567
  ref2.value = value;
568
568
  }
569
569
  if (args.length === 3) {
570
- {
571
- const [target, key, value] = args;
572
- target[key] = value;
573
- }
570
+ const [target, key, value] = args;
571
+ target[key] = value;
574
572
  }
575
573
  }
576
574
  function watchWithFilter(source, cb, options = {}) {
@@ -891,7 +889,7 @@ function useArrayReduce(list, reducer, ...args) {
891
889
  const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
892
890
  return computed(() => {
893
891
  const resolved = toValue(list);
894
- return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
892
+ return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
895
893
  });
896
894
  }
897
895
  function useArraySome(list, fn) {
@@ -1038,7 +1036,8 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1038
1036
  if (immediateCallback)
1039
1037
  cb();
1040
1038
  clean();
1041
- timer = setInterval(cb, intervalValue);
1039
+ if (isActive.value)
1040
+ timer = setInterval(cb, intervalValue);
1042
1041
  }
1043
1042
  if (immediate && isClient)
1044
1043
  resume();
@@ -2283,7 +2282,8 @@ function useFetch(url, ...args) {
2283
2282
  if (config.payload) {
2284
2283
  const headers = headersToObject(defaultFetchOptions.headers);
2285
2284
  const payload = toValue(config.payload);
2286
- if (!config.payloadType && payload && Object.getPrototypeOf(payload) === Object.prototype && !(payload instanceof FormData))
2285
+ const proto = Object.getPrototypeOf(payload);
2286
+ if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
2287
2287
  config.payloadType = "json";
2288
2288
  if (config.payloadType)
2289
2289
  headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
@@ -2426,7 +2426,7 @@ function useFetch(url, ...args) {
2426
2426
  }
2427
2427
  function waitUntilFinished() {
2428
2428
  return new Promise((resolve, reject) => {
2429
- until(isFinished).toBe(true).then(() => resolve(shell)).catch((error2) => reject(error2));
2429
+ until(isFinished).toBe(true).then(() => resolve(shell)).catch(reject);
2430
2430
  });
2431
2431
  }
2432
2432
  function setType(type) {
@@ -2453,8 +2453,12 @@ function useFetch(url, ...args) {
2453
2453
  };
2454
2454
  }
2455
2455
  function joinPaths(start, end) {
2456
- if (!start.endsWith("/") && !end.startsWith("/"))
2456
+ if (!start.endsWith("/") && !end.startsWith("/")) {
2457
2457
  return `${start}/${end}`;
2458
+ }
2459
+ if (start.endsWith("/") && end.startsWith("/")) {
2460
+ return `${start.slice(0, -1)}${end}`;
2461
+ }
2458
2462
  return `${start}${end}`;
2459
2463
  }
2460
2464
  const defaultEvents$1 = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"];
@@ -2897,8 +2901,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
2897
2901
  const hash = window2.location.hash || "#";
2898
2902
  const index = hash.indexOf("?");
2899
2903
  if (index > 0)
2900
- return `${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2901
- return `${hash}${stringified ? `?${stringified}` : ""}`;
2904
+ return `${window2.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2905
+ return `${window2.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
2902
2906
  }
2903
2907
  function read() {
2904
2908
  return new URLSearchParams(getRawParams());
@@ -3029,7 +3033,7 @@ function useWebSocket(url, options = {}) {
3029
3033
  ws.onclose = (ev) => {
3030
3034
  status.value = "CLOSED";
3031
3035
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3032
- if (!explicitlyClosed && options.autoReconnect && ws === wsRef.value) {
3036
+ if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
3033
3037
  const {
3034
3038
  retries = -1,
3035
3039
  delay = 1e3,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reactive-vscode/vueuse",
3
3
  "type": "module",
4
- "version": "0.2.8",
4
+ "version": "0.2.9",
5
5
  "description": "Useful VueUse utilities for VSCode extension development",
6
6
  "author": "_Kerman <kermanx@qq.com>",
7
7
  "license": "MIT",
@@ -33,13 +33,13 @@
33
33
  "tsconfig.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@reactive-vscode/reactivity": "0.2.8"
36
+ "@reactive-vscode/reactivity": "0.2.9"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^20.17.0",
40
- "@vueuse/core": "^11.1.0",
41
- "typescript": "^5.6.3",
42
- "vite": "^5.4.10",
39
+ "@types/node": "^20.17.7",
40
+ "@vueuse/core": "^12.0.0-beta.1",
41
+ "typescript": "^5.7.2",
42
+ "vite": "^5.4.11",
43
43
  "vite-plugin-dts": "^4.3.0"
44
44
  },
45
45
  "scripts": {