@reactive-vscode/vueuse 0.4.1 → 1.0.0-beta.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/dist/index.js CHANGED
@@ -1,8 +1,19 @@
1
- import { customRef, toValue, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, readonly, toRefs as toRefs$1, reactive, toRef as toRef$1, getCurrentScope, onScopeDispose, shallowRef, nextTick, isReactive, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
2
- import { toRef, toValue as toValue2, toValue as toValue3 } from "@reactive-vscode/reactivity";
1
+ import { customRef, toValue, shallowRef, watchEffect, readonly, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, getCurrentScope, hasInjectionContext, inject, provide, toRefs as toRefs$1, reactive, toRef as toRef$1, onBeforeMount, nextTick, onBeforeUnmount, onScopeDispose, onUnmounted, isReactive, isReadonly, markRaw } from "@reactive-vscode/reactivity";
3
2
  function getCurrentInstance() {
4
3
  return null;
5
4
  }
5
+ function computedEager(fn, options) {
6
+ var _options$flush;
7
+ const result = shallowRef();
8
+ watchEffect(() => {
9
+ result.value = fn();
10
+ }, {
11
+ ...options,
12
+ flush: (_options$flush = options === null || options === void 0 ? void 0 : options.flush) !== null && _options$flush !== void 0 ? _options$flush : "sync"
13
+ });
14
+ return readonly(result);
15
+ }
16
+ const eagerComputed = computedEager;
6
17
  function computedWithControl(source, fn, options = {}) {
7
18
  let v = void 0;
8
19
  let track;
@@ -38,6 +49,7 @@ function computedWithControl(source, fn, options = {}) {
38
49
  result.trigger = update;
39
50
  return result;
40
51
  }
52
+ const controlledComputed = computedWithControl;
41
53
  function tryOnScopeDispose(fn, failSilently) {
42
54
  if (getCurrentScope()) {
43
55
  onScopeDispose(fn, failSilently);
@@ -83,6 +95,38 @@ function createGlobalState(stateFactory) {
83
95
  return state;
84
96
  });
85
97
  }
98
+ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
99
+ const injectLocal = /* @__NO_SIDE_EFFECTS__ */ (...args) => {
100
+ var _getCurrentInstance;
101
+ const key = args[0];
102
+ const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
103
+ const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
104
+ if (owner == null && !hasInjectionContext()) throw new Error("injectLocal must be called in setup");
105
+ if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)) return localProvidedStateMap.get(owner)[key];
106
+ return inject(...args);
107
+ };
108
+ function provideLocal(key, value) {
109
+ var _getCurrentInstance;
110
+ const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
111
+ const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
112
+ if (owner == null) throw new Error("provideLocal must be called in setup");
113
+ if (!localProvidedStateMap.has(owner)) localProvidedStateMap.set(owner, /* @__PURE__ */ Object.create(null));
114
+ const localProvidedState = localProvidedStateMap.get(owner);
115
+ localProvidedState[key] = value;
116
+ return provide(key, value);
117
+ }
118
+ // @__NO_SIDE_EFFECTS__
119
+ function createInjectionState(composable, options) {
120
+ const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
121
+ const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
122
+ const useProvidingState = (...args) => {
123
+ const state = composable(...args);
124
+ provideLocal(key, state);
125
+ return state;
126
+ };
127
+ const useInjectedState = () => /* @__PURE__ */ injectLocal(key, defaultValue);
128
+ return [useProvidingState, useInjectedState];
129
+ }
86
130
  // @__NO_SIDE_EFFECTS__
87
131
  function createRef(value, deep) {
88
132
  if (deep === true) return ref(value);
@@ -108,7 +152,7 @@ const rand = (min, max) => {
108
152
  return Math.floor(Math.random() * (max - min + 1)) + min;
109
153
  };
110
154
  const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
111
- function toRef2(...args) {
155
+ function toRef(...args) {
112
156
  if (args.length !== 1) return toRef$1(...args);
113
157
  const r = args[0];
114
158
  return typeof r === "function" ? readonly(customRef(() => ({
@@ -220,7 +264,7 @@ function throttleFilter(...args) {
220
264
  }
221
265
  function pausableFilter(extendFilter = bypassFilter, options = {}) {
222
266
  const { initialState = "active" } = options;
223
- const isActive = toRef2(initialState === "active");
267
+ const isActive = toRef(initialState === "active");
224
268
  function pause() {
225
269
  isActive.value = false;
226
270
  }
@@ -274,6 +318,9 @@ function increaseWithUnit(target, delta) {
274
318
  if (Number.isNaN(result)) return target;
275
319
  return result + unit;
276
320
  }
321
+ function pxValue(px) {
322
+ return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
323
+ }
277
324
  function objectPick(obj, keys, omitUndefined = false) {
278
325
  return keys.reduce((n, k) => {
279
326
  if (k in obj) {
@@ -382,6 +429,7 @@ function reactify(fn, options) {
382
429
  return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
383
430
  };
384
431
  }
432
+ const createReactiveFn = reactify;
385
433
  // @__NO_SIDE_EFFECTS__
386
434
  function reactifyObject(obj, optionsOrKeys = {}) {
387
435
  let keys = [];
@@ -437,7 +485,7 @@ function reactiveOmit(obj, ...keys) {
437
485
  function reactivePick(obj, ...keys) {
438
486
  const flatKeys = keys.flat();
439
487
  const predicate = flatKeys[0];
440
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef2(obj, k)])));
488
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
441
489
  }
442
490
  function refAutoReset(defaultValue, afterMs = 1e4) {
443
491
  return customRef((track, trigger) => {
@@ -464,6 +512,7 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
464
512
  };
465
513
  });
466
514
  }
515
+ const autoResetRef = refAutoReset;
467
516
  // @__NO_SIDE_EFFECTS__
468
517
  function useDebounceFn(fn, ms = 200, options = {}) {
469
518
  return createFilterWrapper(debounceFilter(ms, options), fn);
@@ -476,6 +525,8 @@ function refDebounced(value, ms = 200, options = {}) {
476
525
  watch(value, () => updater());
477
526
  return shallowReadonly(debounced);
478
527
  }
528
+ const debouncedRef = refDebounced;
529
+ const useDebounce = refDebounced;
479
530
  // @__NO_SIDE_EFFECTS__
480
531
  function refDefault(source, defaultValue) {
481
532
  return computed({
@@ -488,6 +539,29 @@ function refDefault(source, defaultValue) {
488
539
  }
489
540
  });
490
541
  }
542
+ function refManualReset(defaultValue) {
543
+ let value = toValue(defaultValue);
544
+ let trigger;
545
+ const reset = () => {
546
+ value = toValue(defaultValue);
547
+ trigger();
548
+ };
549
+ const refValue = customRef((track, _trigger) => {
550
+ trigger = _trigger;
551
+ return {
552
+ get() {
553
+ track();
554
+ return value;
555
+ },
556
+ set(newValue) {
557
+ value = newValue;
558
+ trigger();
559
+ }
560
+ };
561
+ });
562
+ refValue.reset = reset;
563
+ return refValue;
564
+ }
491
565
  // @__NO_SIDE_EFFECTS__
492
566
  function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
493
567
  return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
@@ -501,6 +575,8 @@ function refThrottled(value, delay = 200, trailing = true, leading = true) {
501
575
  watch(value, () => updater());
502
576
  return throttled;
503
577
  }
578
+ const throttledRef = refThrottled;
579
+ const useThrottle = refThrottled;
504
580
  // @__NO_SIDE_EFFECTS__
505
581
  function refWithControl(initial, options = {}) {
506
582
  let source = initial;
@@ -636,11 +712,22 @@ function toRefs(objectRef, options = {}) {
636
712
  }));
637
713
  return result;
638
714
  }
715
+ function tryOnBeforeMount(fn, sync = true, target) {
716
+ if (getLifeCycleTarget(target)) onBeforeMount(fn, target);
717
+ else if (sync) fn();
718
+ else nextTick(fn);
719
+ }
720
+ function tryOnBeforeUnmount(fn, target) {
721
+ if (getLifeCycleTarget(target)) onBeforeUnmount(fn, target);
722
+ }
639
723
  function tryOnMounted(fn, sync = true, target) {
640
724
  if (getLifeCycleTarget(target)) ;
641
725
  else if (sync) fn();
642
726
  else nextTick(fn);
643
727
  }
728
+ function tryOnUnmounted(fn, target) {
729
+ if (getLifeCycleTarget(target)) onUnmounted(fn, target);
730
+ }
644
731
  function createUntil(r, isNot = false) {
645
732
  function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
646
733
  let stop = null;
@@ -1129,6 +1216,7 @@ function watchDebounced(source, cb, options = {}) {
1129
1216
  eventFilter: debounceFilter(debounce, { maxWait })
1130
1217
  });
1131
1218
  }
1219
+ const debouncedWatch = watchDebounced;
1132
1220
  function watchDeep(source, cb, options) {
1133
1221
  return watch(source, cb, {
1134
1222
  ...options,
@@ -1188,6 +1276,7 @@ function watchIgnorable(source, cb, options = {}) {
1188
1276
  ignorePrevAsyncUpdates
1189
1277
  };
1190
1278
  }
1279
+ const ignorableWatch = watchIgnorable;
1191
1280
  function watchImmediate(source, cb, options) {
1192
1281
  return watch(source, cb, {
1193
1282
  ...options,
@@ -1207,6 +1296,7 @@ function watchThrottled(source, cb, options = {}) {
1207
1296
  eventFilter: throttleFilter(throttle, trailing, leading)
1208
1297
  });
1209
1298
  }
1299
+ const throttledWatch = watchThrottled;
1210
1300
  function watchTriggerable(source, cb, options = {}) {
1211
1301
  let cleanupFn;
1212
1302
  function onEffect() {
@@ -1294,6 +1384,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1294
1384
  });
1295
1385
  else return current;
1296
1386
  }
1387
+ const asyncComputed = computedAsync;
1297
1388
  // @__NO_SIDE_EFFECTS__
1298
1389
  function createUnrefFn(fn) {
1299
1390
  return function(...args) {
@@ -1307,11 +1398,6 @@ function unrefElement(elRef) {
1307
1398
  return (_$el = plain === null || plain === void 0 ? void 0 : plain.$el) !== null && _$el !== void 0 ? _$el : plain;
1308
1399
  }
1309
1400
  function useEventListener(...args) {
1310
- const cleanups = [];
1311
- const cleanup = () => {
1312
- cleanups.forEach((fn) => fn());
1313
- cleanups.length = 0;
1314
- };
1315
1401
  const register = (el, event, listener, options) => {
1316
1402
  el.addEventListener(event, listener, options);
1317
1403
  return () => el.removeEventListener(event, listener, options);
@@ -1320,7 +1406,7 @@ function useEventListener(...args) {
1320
1406
  const test = toArray(toValue(args[0])).filter((e) => e != null);
1321
1407
  return test.every((e) => typeof e !== "string") ? test : void 0;
1322
1408
  });
1323
- const stopWatch = watchImmediate(() => {
1409
+ return watchImmediate(() => {
1324
1410
  var _firstParamTargets$va, _firstParamTargets$va2;
1325
1411
  return [
1326
1412
  (_firstParamTargets$va = (_firstParamTargets$va2 = firstParamTargets.value) === null || _firstParamTargets$va2 === void 0 ? void 0 : _firstParamTargets$va2.map((e) => unrefElement(e))) !== null && _firstParamTargets$va !== void 0 ? _firstParamTargets$va : [defaultWindow].filter((e) => e != null),
@@ -1328,18 +1414,14 @@ function useEventListener(...args) {
1328
1414
  toArray(unref(firstParamTargets.value ? args[2] : args[1])),
1329
1415
  toValue(firstParamTargets.value ? args[3] : args[2])
1330
1416
  ];
1331
- }, ([raw_targets, raw_events, raw_listeners, raw_options]) => {
1332
- cleanup();
1417
+ }, ([raw_targets, raw_events, raw_listeners, raw_options], _, onCleanup) => {
1333
1418
  if (!(raw_targets === null || raw_targets === void 0 ? void 0 : raw_targets.length) || !(raw_events === null || raw_events === void 0 ? void 0 : raw_events.length) || !(raw_listeners === null || raw_listeners === void 0 ? void 0 : raw_listeners.length)) return;
1334
1419
  const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
1335
- cleanups.push(...raw_targets.flatMap((el) => raw_events.flatMap((event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone)))));
1420
+ const cleanups = raw_targets.flatMap((el) => raw_events.flatMap((event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))));
1421
+ onCleanup(() => {
1422
+ cleanups.forEach((fn) => fn());
1423
+ });
1336
1424
  }, { flush: "post" });
1337
- const stop = () => {
1338
- stopWatch();
1339
- cleanup();
1340
- };
1341
- tryOnScopeDispose(cleanup);
1342
- return stop;
1343
1425
  }
1344
1426
  // @__NO_SIDE_EFFECTS__
1345
1427
  function useMounted() {
@@ -1454,6 +1536,7 @@ function useAsyncQueue(tasks, options) {
1454
1536
  }
1455
1537
  updateResult(promiseState.rejected, e);
1456
1538
  onError();
1539
+ if (activeIndex.value === tasks.length - 1) onFinished();
1457
1540
  return e;
1458
1541
  });
1459
1542
  }, Promise.resolve());
@@ -1687,7 +1770,7 @@ function useCloned(source, options = {}) {
1687
1770
  }
1688
1771
  function useCycleList(list, options) {
1689
1772
  const state = shallowRef(getInitialValue());
1690
- const listRef = toRef2(list);
1773
+ const listRef = toRef(list);
1691
1774
  const index = computed({
1692
1775
  get() {
1693
1776
  var _options$fallbackInde;
@@ -2115,8 +2198,8 @@ function useFetch(url, ...args) {
2115
2198
  finallyEvent.trigger(null);
2116
2199
  });
2117
2200
  };
2118
- const refetch = toRef2(options.refetch);
2119
- watch([refetch, toRef2(url)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
2201
+ const refetch = toRef(options.refetch);
2202
+ watch([refetch, toRef(url)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
2120
2203
  const shell = {
2121
2204
  isFinished: readonly(isFinished),
2122
2205
  isFetching: readonly(isFetching),
@@ -2150,7 +2233,7 @@ function useFetch(url, ...args) {
2150
2233
  config.method = method;
2151
2234
  config.payload = payload;
2152
2235
  config.payloadType = payloadType;
2153
- if (isRef(config.payload)) watch([refetch, toRef2(config.payload)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
2236
+ if (isRef(config.payload)) watch([refetch, toRef(config.payload)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
2154
2237
  return {
2155
2238
  ...shell,
2156
2239
  then(onFulfilled, onRejected) {
@@ -2322,7 +2405,7 @@ function useOffsetPagination(options) {
2322
2405
  }
2323
2406
  function usePrevious(value, initialValue) {
2324
2407
  const previous = shallowRef(initialValue);
2325
- watch(toRef2(value), (_, oldValue) => {
2408
+ watch(toRef(value), (_, oldValue) => {
2326
2409
  previous.value = oldValue;
2327
2410
  }, { flush: "sync" });
2328
2411
  return readonly(previous);
@@ -2646,7 +2729,7 @@ function useWebSocket(url, options = {}) {
2646
2729
  const data = ref(null);
2647
2730
  const status = shallowRef("CLOSED");
2648
2731
  const wsRef = ref();
2649
- const urlRef = toRef2(url);
2732
+ const urlRef = toRef(url);
2650
2733
  let heartbeatPause;
2651
2734
  let heartbeatResume;
2652
2735
  let explicitlyClosed = false;
@@ -2709,7 +2792,8 @@ function useWebSocket(url, options = {}) {
2709
2792
  const { retries = -1, delay = 1e3, onFailed } = resolveNestedOptions(options.autoReconnect);
2710
2793
  if ((typeof retries === "function" ? retries : () => typeof retries === "number" && (retries < 0 || retried < retries))(retried)) {
2711
2794
  retried += 1;
2712
- retryTimeout = setTimeout(_init, delay);
2795
+ const delayTime = typeof delay === "function" ? delay(retried) : delay;
2796
+ retryTimeout = setTimeout(_init, delayTime);
2713
2797
  } else onFailed === null || onFailed === void 0 || onFailed();
2714
2798
  }
2715
2799
  };
@@ -2863,28 +2947,32 @@ function useWebWorkerFn(fn, options = {}) {
2863
2947
  }
2864
2948
  export {
2865
2949
  assert,
2866
- computedAsync as asyncComputed,
2867
- refAutoReset as autoResetRef,
2950
+ asyncComputed,
2951
+ autoResetRef,
2868
2952
  bypassFilter,
2869
2953
  camelize,
2870
2954
  clamp,
2871
2955
  cloneFnJSON,
2872
2956
  computedAsync,
2957
+ computedEager,
2873
2958
  computedWithControl,
2874
2959
  containsProp,
2875
- computedWithControl as controlledComputed,
2960
+ controlledComputed,
2876
2961
  controlledRef,
2877
2962
  createEventHook,
2878
2963
  createFetch,
2879
2964
  createFilterWrapper,
2880
2965
  createGlobalState,
2881
- reactify as createReactiveFn,
2966
+ createInjectionState,
2967
+ createReactiveFn,
2968
+ createRef,
2882
2969
  createSharedComposable,
2883
2970
  createSingletonPromise,
2884
2971
  createUnrefFn,
2885
2972
  debounceFilter,
2886
- refDebounced as debouncedRef,
2887
- watchDebounced as debouncedWatch,
2973
+ debouncedRef,
2974
+ debouncedWatch,
2975
+ eagerComputed,
2888
2976
  extendRef,
2889
2977
  formatDate,
2890
2978
  formatTimeAgo,
@@ -2893,8 +2981,9 @@ export {
2893
2981
  hasOwn,
2894
2982
  hyphenate,
2895
2983
  identity,
2896
- watchIgnorable as ignorableWatch,
2984
+ ignorableWatch,
2897
2985
  increaseWithUnit,
2986
+ injectLocal,
2898
2987
  invoke,
2899
2988
  isDef,
2900
2989
  isDefined,
@@ -2908,8 +2997,10 @@ export {
2908
2997
  objectOmit,
2909
2998
  objectPick,
2910
2999
  pausableFilter,
2911
- watchPausable as pausableWatch,
3000
+ pausableWatch,
2912
3001
  promiseTimeout,
3002
+ provideLocal,
3003
+ pxValue,
2913
3004
  rand,
2914
3005
  reactify,
2915
3006
  reactifyObject,
@@ -2919,21 +3010,25 @@ export {
2919
3010
  refAutoReset,
2920
3011
  refDebounced,
2921
3012
  refDefault,
3013
+ refManualReset,
2922
3014
  refThrottled,
2923
3015
  refWithControl,
2924
- toRef as resolveRef,
2925
- toValue2 as resolveUnref,
2926
3016
  set,
2927
3017
  syncRef,
2928
3018
  syncRefs,
2929
3019
  throttleFilter,
2930
- refThrottled as throttledRef,
2931
- watchThrottled as throttledWatch,
3020
+ throttledRef,
3021
+ throttledWatch,
3022
+ timestamp,
3023
+ toArray,
2932
3024
  toReactive,
2933
- toRef2 as toRef,
3025
+ toRef,
2934
3026
  toRefs,
2935
- toValue3 as toValue,
3027
+ tryOnBeforeMount,
3028
+ tryOnBeforeUnmount,
3029
+ tryOnMounted,
2936
3030
  tryOnScopeDispose,
3031
+ tryOnUnmounted,
2937
3032
  until,
2938
3033
  useArrayDifference,
2939
3034
  useArrayEvery,
@@ -2956,7 +3051,7 @@ export {
2956
3051
  useCounter,
2957
3052
  useCycleList,
2958
3053
  useDateFormat,
2959
- refDebounced as useDebounce,
3054
+ useDebounce,
2960
3055
  useDebounceFn,
2961
3056
  useDebouncedRefHistory,
2962
3057
  useEventBus,
@@ -2973,7 +3068,7 @@ export {
2973
3068
  useRefHistory,
2974
3069
  useSorted,
2975
3070
  useStepper,
2976
- refThrottled as useThrottle,
3071
+ useThrottle,
2977
3072
  useThrottleFn,
2978
3073
  useThrottledRefHistory,
2979
3074
  useTimeAgo,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reactive-vscode/vueuse",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "1.0.0-beta.1",
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.4.1"
36
+ "@reactive-vscode/reactivity": "1.0.0-beta.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^24.9.2",
40
- "@vueuse/core": "^14.0.0",
39
+ "@types/node": "^25.0.3",
40
+ "@vueuse/core": "^14.1.0",
41
41
  "typescript": "^5.9.3",
42
- "vite": "^7.1.12",
42
+ "vite": "^7.3.0",
43
43
  "vite-plugin-dts": "^4.5.4"
44
44
  },
45
45
  "scripts": {