@reactive-vscode/vueuse 0.2.14 → 0.2.16

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
@@ -5,7 +5,7 @@ function computedWithControl(source, fn) {
5
5
  let v = void 0;
6
6
  let track;
7
7
  let trigger;
8
- const dirty = reactivity.ref(true);
8
+ const dirty = reactivity.shallowRef(true);
9
9
  const update = () => {
10
10
  dirty.value = true;
11
11
  trigger();
@@ -79,6 +79,13 @@ function createGlobalState(stateFactory) {
79
79
  return state;
80
80
  };
81
81
  }
82
+ function createRef(value, deep) {
83
+ if (deep === true) {
84
+ return reactivity.ref(value);
85
+ } else {
86
+ return reactivity.shallowRef(value);
87
+ }
88
+ }
82
89
  function createSharedComposable(composable) {
83
90
  let subscribers = 0;
84
91
  let state;
@@ -346,8 +353,11 @@ function throttleFilter(...args) {
346
353
  };
347
354
  return filter;
348
355
  }
349
- function pausableFilter(extendFilter = bypassFilter) {
350
- const isActive = reactivity.ref(true);
356
+ function pausableFilter(extendFilter = bypassFilter, options = {}) {
357
+ const {
358
+ initialState = "active"
359
+ } = options;
360
+ const isActive = toRef(initialState === "active");
351
361
  function pause() {
352
362
  isActive.value = false;
353
363
  }
@@ -595,9 +605,10 @@ function watchWithFilter(source, cb, options = {}) {
595
605
  function watchPausable(source, cb, options = {}) {
596
606
  const {
597
607
  eventFilter: filter,
608
+ initialState = "active",
598
609
  ...watchOptions
599
610
  } = options;
600
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
611
+ const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
601
612
  const stop = watchWithFilter(
602
613
  source,
603
614
  cb,
@@ -652,10 +663,10 @@ function syncRefs(source, targets, options = {}) {
652
663
  deep = false,
653
664
  immediate = true
654
665
  } = options;
655
- targets = toArray(targets);
666
+ const targetsArray = toArray(targets);
656
667
  return reactivity.watch(
657
668
  source,
658
- (newValue) => targets.forEach((target) => target.value = newValue),
669
+ (newValue) => targetsArray.forEach((target) => target.value = newValue),
659
670
  { flush, deep, immediate }
660
671
  );
661
672
  }
@@ -930,7 +941,7 @@ function useArrayUnique(list, compareFn) {
930
941
  }
931
942
  function useCounter(initialValue = 0, options = {}) {
932
943
  let _initialValue = reactivity.unref(initialValue);
933
- const count = reactivity.ref(initialValue);
944
+ const count = reactivity.shallowRef(initialValue);
934
945
  const {
935
946
  max = Number.POSITIVE_INFINITY,
936
947
  min = Number.NEGATIVE_INFINITY
@@ -946,7 +957,7 @@ function useCounter(initialValue = 0, options = {}) {
946
957
  return { count, inc, dec, get: get2, set: set2, reset };
947
958
  }
948
959
  const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
949
- const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
960
+ const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
950
961
  function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
951
962
  let m = hours < 12 ? "AM" : "PM";
952
963
  if (hasPeriod)
@@ -969,6 +980,10 @@ function formatDate(date, formatStr, options = {}) {
969
980
  const milliseconds = date.getMilliseconds();
970
981
  const day = date.getDay();
971
982
  const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
983
+ const stripTimeZone = (dateString) => {
984
+ var _a2;
985
+ return (_a2 = dateString.split(" ")[1]) != null ? _a2 : "";
986
+ };
972
987
  const matches = {
973
988
  Yo: () => formatOrdinal(years),
974
989
  YY: () => String(years).slice(-2),
@@ -1001,7 +1016,11 @@ function formatDate(date, formatStr, options = {}) {
1001
1016
  A: () => meridiem(hours, minutes),
1002
1017
  AA: () => meridiem(hours, minutes, false, true),
1003
1018
  a: () => meridiem(hours, minutes, true),
1004
- aa: () => meridiem(hours, minutes, true, true)
1019
+ aa: () => meridiem(hours, minutes, true, true),
1020
+ z: () => stripTimeZone(date.toLocaleDateString(reactivity.toValue(options.locales), { timeZoneName: "shortOffset" })),
1021
+ zz: () => stripTimeZone(date.toLocaleDateString(reactivity.toValue(options.locales), { timeZoneName: "shortOffset" })),
1022
+ zzz: () => stripTimeZone(date.toLocaleDateString(reactivity.toValue(options.locales), { timeZoneName: "shortOffset" })),
1023
+ zzzz: () => stripTimeZone(date.toLocaleDateString(reactivity.toValue(options.locales), { timeZoneName: "longOffset" }))
1005
1024
  };
1006
1025
  return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1007
1026
  var _a2, _b;
@@ -1034,7 +1053,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1034
1053
  immediateCallback = false
1035
1054
  } = options;
1036
1055
  let timer = null;
1037
- const isActive = reactivity.ref(false);
1056
+ const isActive = reactivity.shallowRef(false);
1038
1057
  function clean() {
1039
1058
  if (timer) {
1040
1059
  clearInterval(timer);
@@ -1078,7 +1097,7 @@ function useInterval(interval = 1e3, options = {}) {
1078
1097
  immediate = true,
1079
1098
  callback
1080
1099
  } = options;
1081
- const counter = reactivity.ref(0);
1100
+ const counter = reactivity.shallowRef(0);
1082
1101
  const update = () => counter.value += 1;
1083
1102
  const reset = () => {
1084
1103
  counter.value = 0;
@@ -1103,7 +1122,7 @@ function useInterval(interval = 1e3, options = {}) {
1103
1122
  }
1104
1123
  function useLastChanged(source, options = {}) {
1105
1124
  var _a;
1106
- const ms = reactivity.ref((_a = options.initialValue) != null ? _a : null);
1125
+ const ms = reactivity.shallowRef((_a = options.initialValue) != null ? _a : null);
1107
1126
  reactivity.watch(
1108
1127
  source,
1109
1128
  () => ms.value = timestamp(),
@@ -1113,9 +1132,10 @@ function useLastChanged(source, options = {}) {
1113
1132
  }
1114
1133
  function useTimeoutFn(cb, interval, options = {}) {
1115
1134
  const {
1116
- immediate = true
1135
+ immediate = true,
1136
+ immediateCallback = false
1117
1137
  } = options;
1118
- const isPending = reactivity.ref(false);
1138
+ const isPending = reactivity.shallowRef(false);
1119
1139
  let timer = null;
1120
1140
  function clear() {
1121
1141
  if (timer) {
@@ -1128,6 +1148,8 @@ function useTimeoutFn(cb, interval, options = {}) {
1128
1148
  clear();
1129
1149
  }
1130
1150
  function start(...args) {
1151
+ if (immediateCallback)
1152
+ cb();
1131
1153
  clear();
1132
1154
  isPending.value = true;
1133
1155
  timer = setTimeout(() => {
@@ -1194,7 +1216,7 @@ function useToggle(initialValue = false, options = {}) {
1194
1216
  falsyValue = false
1195
1217
  } = options;
1196
1218
  const valueIsRef = reactivity.isRef(initialValue);
1197
- const _value = reactivity.ref(initialValue);
1219
+ const _value = reactivity.shallowRef(initialValue);
1198
1220
  function toggle(value) {
1199
1221
  if (arguments.length) {
1200
1222
  _value.value = value;
@@ -1211,7 +1233,7 @@ function useToggle(initialValue = false, options = {}) {
1211
1233
  return [_value, toggle];
1212
1234
  }
1213
1235
  function watchArray(source, cb, options) {
1214
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : reactivity.toValue(source)];
1236
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : reactivity.toValue(source)];
1215
1237
  return reactivity.watch(source, (newList, _, onCleanup) => {
1216
1238
  const oldListRemains = Array.from({ length: oldList.length });
1217
1239
  const added = [];
@@ -1237,7 +1259,7 @@ function watchAtMost(source, cb, options) {
1237
1259
  count,
1238
1260
  ...watchOptions
1239
1261
  } = options;
1240
- const current = reactivity.ref(0);
1262
+ const current = reactivity.shallowRef(0);
1241
1263
  const stop = watchWithFilter(
1242
1264
  source,
1243
1265
  (...args) => {
@@ -1288,7 +1310,7 @@ function watchIgnorable(source, cb, options = {}) {
1288
1310
  let ignorePrevAsyncUpdates;
1289
1311
  let stop;
1290
1312
  if (watchOptions.flush === "sync") {
1291
- const ignore = reactivity.ref(false);
1313
+ const ignore = reactivity.shallowRef(false);
1292
1314
  ignorePrevAsyncUpdates = () => {
1293
1315
  };
1294
1316
  ignoreUpdates = (updater) => {
@@ -1306,8 +1328,8 @@ function watchIgnorable(source, cb, options = {}) {
1306
1328
  );
1307
1329
  } else {
1308
1330
  const disposables = [];
1309
- const ignoreCounter = reactivity.ref(0);
1310
- const syncCounter = reactivity.ref(0);
1331
+ const ignoreCounter = reactivity.shallowRef(0);
1332
+ const syncCounter = reactivity.shallowRef(0);
1311
1333
  ignorePrevAsyncUpdates = () => {
1312
1334
  ignoreCounter.value = syncCounter.value;
1313
1335
  };
@@ -1450,7 +1472,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1450
1472
  shallow = true,
1451
1473
  onError = noop
1452
1474
  } = options;
1453
- const started = reactivity.ref(!lazy);
1475
+ const started = reactivity.shallowRef(!lazy);
1454
1476
  const current = shallow ? reactivity.shallowRef(initialState) : reactivity.ref(initialState);
1455
1477
  let counter = 0;
1456
1478
  reactivity.watchEffect(async (onInvalidate) => {
@@ -1551,7 +1573,7 @@ function useEventListener(...args) {
1551
1573
  return stop;
1552
1574
  }
1553
1575
  function useMounted() {
1554
- const isMounted = reactivity.ref(false);
1576
+ const isMounted = reactivity.shallowRef(false);
1555
1577
  return isMounted;
1556
1578
  }
1557
1579
  function useSupported(callback) {
@@ -1565,9 +1587,10 @@ function useRafFn(fn, options = {}) {
1565
1587
  const {
1566
1588
  immediate = true,
1567
1589
  fpsLimit = void 0,
1568
- window: window2 = defaultWindow
1590
+ window: window2 = defaultWindow,
1591
+ once = false
1569
1592
  } = options;
1570
- const isActive = reactivity.ref(false);
1593
+ const isActive = reactivity.shallowRef(false);
1571
1594
  const intervalLimit = reactivity.computed(() => {
1572
1595
  return fpsLimit ? 1e3 / reactivity.toValue(fpsLimit) : null;
1573
1596
  });
@@ -1585,6 +1608,11 @@ function useRafFn(fn, options = {}) {
1585
1608
  }
1586
1609
  previousFrameTimestamp = timestamp2;
1587
1610
  fn({ delta, timestamp: timestamp2 });
1611
+ if (once) {
1612
+ isActive.value = false;
1613
+ rafId = null;
1614
+ return;
1615
+ }
1588
1616
  rafId = window2.requestAnimationFrame(loop);
1589
1617
  }
1590
1618
  function resume() {
@@ -1625,7 +1653,7 @@ function useAsyncQueue(tasks, options) {
1625
1653
  };
1626
1654
  const initialResult = Array.from(Array.from({ length: tasks.length }), () => ({ state: promiseState.pending, data: null }));
1627
1655
  const result = reactivity.reactive(initialResult);
1628
- const activeIndex = reactivity.ref(-1);
1656
+ const activeIndex = reactivity.shallowRef(-1);
1629
1657
  if (!tasks || tasks.length === 0) {
1630
1658
  onFinished();
1631
1659
  return {
@@ -1693,8 +1721,8 @@ function useAsyncState(promise, initialState, options) {
1693
1721
  throwError
1694
1722
  } = options != null ? options : {};
1695
1723
  const state = shallow ? reactivity.shallowRef(initialState) : reactivity.ref(initialState);
1696
- const isReady = reactivity.ref(false);
1697
- const isLoading = reactivity.ref(false);
1724
+ const isReady = reactivity.shallowRef(false);
1725
+ const isLoading = reactivity.shallowRef(false);
1698
1726
  const error = reactivity.shallowRef(void 0);
1699
1727
  async function execute(delay2 = 0, ...args) {
1700
1728
  if (resetOnExecute)
@@ -1762,8 +1790,8 @@ function getDefaultSerialization(target) {
1762
1790
  return defaults.object;
1763
1791
  }
1764
1792
  function useBase64(target, options) {
1765
- const base64 = reactivity.ref("");
1766
- const promise = reactivity.ref();
1793
+ const base64 = reactivity.shallowRef("");
1794
+ const promise = reactivity.shallowRef();
1767
1795
  function execute() {
1768
1796
  if (!isClient)
1769
1797
  return;
@@ -1845,7 +1873,7 @@ function useBroadcastChannel(options) {
1845
1873
  window: window2 = defaultWindow
1846
1874
  } = options;
1847
1875
  const isSupported = useSupported(() => window2 && "BroadcastChannel" in window2);
1848
- const isClosed = reactivity.ref(false);
1876
+ const isClosed = reactivity.shallowRef(false);
1849
1877
  const channel = reactivity.ref();
1850
1878
  const data = reactivity.ref();
1851
1879
  const error = reactivity.shallowRef(null);
@@ -1889,8 +1917,9 @@ function useBroadcastChannel(options) {
1889
1917
  isClosed
1890
1918
  };
1891
1919
  }
1892
- function useCached(refValue, comparator = (a, b) => a === b, watchOptions) {
1893
- const cachedValue = reactivity.ref(refValue.value);
1920
+ function useCached(refValue, comparator = (a, b) => a === b, options) {
1921
+ const { deepRefs = true, ...watchOptions } = options || {};
1922
+ const cachedValue = createRef(refValue.value, deepRefs);
1894
1923
  reactivity.watch(() => refValue.value, (value) => {
1895
1924
  if (!comparator(value, cachedValue.value))
1896
1925
  cachedValue.value = value;
@@ -1902,7 +1931,7 @@ function cloneFnJSON(source) {
1902
1931
  }
1903
1932
  function useCloned(source, options = {}) {
1904
1933
  const cloned = reactivity.ref({});
1905
- const isModified = reactivity.ref(false);
1934
+ const isModified = reactivity.shallowRef(false);
1906
1935
  let _lastSync = false;
1907
1936
  const {
1908
1937
  manual,
@@ -2185,7 +2214,13 @@ function headersToObject(headers) {
2185
2214
  function combineCallbacks(combination, ...callbacks) {
2186
2215
  if (combination === "overwrite") {
2187
2216
  return async (ctx) => {
2188
- const callback = callbacks[callbacks.length - 1];
2217
+ let callback;
2218
+ for (let i = callbacks.length - 1; i >= 0; i--) {
2219
+ if (callbacks[i] != null) {
2220
+ callback = callbacks[i];
2221
+ break;
2222
+ }
2223
+ }
2189
2224
  if (callback)
2190
2225
  return { ...ctx, ...await callback(ctx) };
2191
2226
  return ctx;
@@ -2278,10 +2313,10 @@ function useFetch(url, ...args) {
2278
2313
  const responseEvent = createEventHook();
2279
2314
  const errorEvent = createEventHook();
2280
2315
  const finallyEvent = createEventHook();
2281
- const isFinished = reactivity.ref(false);
2282
- const isFetching = reactivity.ref(false);
2283
- const aborted = reactivity.ref(false);
2284
- const statusCode = reactivity.ref(null);
2316
+ const isFinished = reactivity.shallowRef(false);
2317
+ const isFetching = reactivity.shallowRef(false);
2318
+ const aborted = reactivity.shallowRef(false);
2319
+ const statusCode = reactivity.shallowRef(null);
2285
2320
  const response = reactivity.shallowRef(null);
2286
2321
  const error = reactivity.shallowRef(null);
2287
2322
  const data = reactivity.shallowRef(initialData || null);
@@ -2515,8 +2550,8 @@ function useIdle(timeout = oneMinute, options = {}) {
2515
2550
  window: window2 = defaultWindow,
2516
2551
  eventFilter = throttleFilter(50)
2517
2552
  } = options;
2518
- const idle = reactivity.ref(initialState);
2519
- const lastActive = reactivity.ref(timestamp());
2553
+ const idle = reactivity.shallowRef(initialState);
2554
+ const lastActive = reactivity.shallowRef(timestamp());
2520
2555
  let timer;
2521
2556
  const reset = () => {
2522
2557
  idle.value = false;
@@ -2567,7 +2602,7 @@ function useNow(options = {}) {
2567
2602
  }
2568
2603
  }
2569
2604
  function useObjectUrl(object) {
2570
- const url = reactivity.ref();
2605
+ const url = reactivity.shallowRef();
2571
2606
  const release = () => {
2572
2607
  if (url.value)
2573
2608
  URL.revokeObjectURL(url.value);
@@ -2866,10 +2901,11 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
2866
2901
  }
2867
2902
  function useTimeoutPoll(fn, interval, options = {}) {
2868
2903
  const {
2869
- immediate = true
2904
+ immediate = true,
2905
+ immediateCallback = false
2870
2906
  } = options;
2871
- const { start } = useTimeoutFn(loop, interval, { immediate: false });
2872
- const isActive = reactivity.ref(false);
2907
+ const { start } = useTimeoutFn(loop, interval, { immediate });
2908
+ const isActive = reactivity.shallowRef(false);
2873
2909
  async function loop() {
2874
2910
  if (!isActive.value)
2875
2911
  return;
@@ -2879,7 +2915,9 @@ function useTimeoutPoll(fn, interval, options = {}) {
2879
2915
  function resume() {
2880
2916
  if (!isActive.value) {
2881
2917
  isActive.value = true;
2882
- loop();
2918
+ if (immediateCallback)
2919
+ fn();
2920
+ start();
2883
2921
  }
2884
2922
  }
2885
2923
  function pause() {
@@ -2902,7 +2940,7 @@ function useTimestamp(options = {}) {
2902
2940
  interval = "requestAnimationFrame",
2903
2941
  callback
2904
2942
  } = options;
2905
- const ts = reactivity.ref(timestamp() + offset);
2943
+ const ts = reactivity.shallowRef(timestamp() + offset);
2906
2944
  const update = () => ts.value = timestamp() + offset;
2907
2945
  const cb = callback ? () => {
2908
2946
  update();
@@ -3037,7 +3075,7 @@ function useWebSocket(url, options = {}) {
3037
3075
  protocols = []
3038
3076
  } = options;
3039
3077
  const data = reactivity.ref(null);
3040
- const status = reactivity.ref("CLOSED");
3078
+ const status = reactivity.shallowRef("CLOSED");
3041
3079
  const wsRef = reactivity.ref();
3042
3080
  const urlRef = toRef(url);
3043
3081
  let heartbeatPause;
@@ -3099,6 +3137,8 @@ function useWebSocket(url, options = {}) {
3099
3137
  };
3100
3138
  ws.onclose = (ev) => {
3101
3139
  status.value = "CLOSED";
3140
+ resetHeartbeat();
3141
+ heartbeatPause == null ? void 0 : heartbeatPause();
3102
3142
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3103
3143
  if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
3104
3144
  const {
@@ -3106,11 +3146,10 @@ function useWebSocket(url, options = {}) {
3106
3146
  delay = 1e3,
3107
3147
  onFailed
3108
3148
  } = resolveNestedOptions(options.autoReconnect);
3109
- if (typeof retries === "number" && (retries < 0 || retried < retries)) {
3149
+ const checkRetires = typeof retries === "function" ? retries : () => typeof retries === "number" && (retries < 0 || retried < retries);
3150
+ if (checkRetires(retried)) {
3110
3151
  retried += 1;
3111
3152
  retryTimeout = setTimeout(_init, delay);
3112
- } else if (typeof retries === "function" && retries()) {
3113
- retryTimeout = setTimeout(_init, delay);
3114
3153
  } else {
3115
3154
  onFailed == null ? void 0 : onFailed();
3116
3155
  }
@@ -3221,9 +3260,9 @@ function useWebWorkerFn(fn, options = {}) {
3221
3260
  window: window2 = defaultWindow
3222
3261
  } = options;
3223
3262
  const worker = reactivity.ref();
3224
- const workerStatus = reactivity.ref("PENDING");
3263
+ const workerStatus = reactivity.shallowRef("PENDING");
3225
3264
  const promise = reactivity.ref({});
3226
- const timeoutId = reactivity.ref();
3265
+ const timeoutId = reactivity.shallowRef();
3227
3266
  const workerTerminate = (status = "PENDING") => {
3228
3267
  if (worker.value && worker.value._url && window2) {
3229
3268
  worker.value.terminate();
package/dist/index.d.ts CHANGED
@@ -115,7 +115,7 @@ export declare const bypassFilter: EventFilter;
115
115
 
116
116
  declare type Callback<T> = IsAny<T> extends true ? (...param: any) => void : ([
117
117
  T
118
- ] extends [void] ? (...param: unknown[]) => void : (...param: [T, ...unknown[]]) => void);
118
+ ] extends [void] ? (...param: unknown[]) => void : [T] extends [any[]] ? (...param: T) => void : (...param: [T, ...unknown[]]) => void);
119
119
 
120
120
  export declare const camelize: (str: string) => string;
121
121
 
@@ -163,6 +163,15 @@ export declare interface ComputedWithControlRefExtra {
163
163
  trigger: () => void;
164
164
  }
165
165
 
166
+ declare interface ConfigurableDeepRefs<D extends boolean> {
167
+ /**
168
+ * Return deep refs instead of shallow refs.
169
+ *
170
+ * @default true - will be changed to `false` by default in the next major
171
+ */
172
+ deepRefs?: D;
173
+ }
174
+
166
175
  export declare interface ConfigurableEventFilter {
167
176
  /**
168
177
  * Filter for if events should to be received.
@@ -361,7 +370,7 @@ export declare type EventHookOn<T = any> = (fn: Callback<T>) => {
361
370
  off: () => void;
362
371
  };
363
372
 
364
- export declare type EventHookTrigger<T = any> = (...param: IsAny<T> extends true ? unknown[] : [T, ...unknown[]]) => Promise<unknown[]>;
373
+ export declare type EventHookTrigger<T = any> = (...param: Parameters<Callback<T>>) => Promise<unknown[]>;
365
374
 
366
375
  /**
367
376
  * Overload 1: Unwrap set to false
@@ -569,7 +578,7 @@ export declare interface Pausable {
569
578
  /**
570
579
  * A ref indicate whether a pausable instance is active
571
580
  */
572
- isActive: Readonly<Ref<boolean>>;
581
+ isActive: Readonly<ShallowRef<boolean>>;
573
582
  /**
574
583
  * Temporary pause the effect from executing
575
584
  */
@@ -584,12 +593,21 @@ export declare interface Pausable {
584
593
  * EventFilter that gives extra controls to pause and resume the filter
585
594
  *
586
595
  * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
587
- *
596
+ * @param options Options to configure the filter
588
597
  */
589
- export declare function pausableFilter(extendFilter?: EventFilter): Pausable & {
598
+ export declare function pausableFilter(extendFilter?: EventFilter, options?: PausableFilterOptions): Pausable & {
590
599
  eventFilter: EventFilter;
591
600
  };
592
601
 
602
+ declare interface PausableFilterOptions {
603
+ /**
604
+ * The initial state
605
+ *
606
+ * @default 'active'
607
+ */
608
+ initialState?: 'active' | 'paused';
609
+ }
610
+
593
611
  declare type PostMessage = typeof Worker.prototype['postMessage'];
594
612
 
595
613
  export declare function promiseTimeout(ms: number, throwOnTimeout?: boolean, reason?: string): Promise<void>;
@@ -647,7 +665,7 @@ export declare interface ReactifyOptions<T extends boolean> {
647
665
  /**
648
666
  * Computed reactive object.
649
667
  */
650
- export declare function reactiveComputed<T extends object>(fn: () => T): UnwrapNestedRefs<T>;
668
+ export declare function reactiveComputed<T extends object>(fn: ComputedGetter<T>): UnwrapNestedRefs<T>;
651
669
 
652
670
  export declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
653
671
 
@@ -754,6 +772,8 @@ export declare function set<T>(ref: Ref<T>, value: T): void;
754
772
 
755
773
  export declare function set<O extends object, K extends keyof O>(target: O, key: K, value: O[K]): void;
756
774
 
775
+ declare type ShallowOrDeepRef<T = any, D extends boolean = false> = D extends true ? Ref<T> : ShallowRef<T>;
776
+
757
777
  export declare type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T;
758
778
 
759
779
  export declare interface SingletonPromiseReturn<T> {
@@ -1219,7 +1239,7 @@ export declare interface UseAsyncQueueResult<T> {
1219
1239
  }
1220
1240
 
1221
1241
  export declare interface UseAsyncQueueReturn<T> {
1222
- activeIndex: Ref<number>;
1242
+ activeIndex: ShallowRef<number>;
1223
1243
  result: T;
1224
1244
  }
1225
1245
 
@@ -1296,15 +1316,15 @@ export declare interface UseAsyncStateReturnBase<Data, Params extends any[], Sha
1296
1316
  execute: (delay?: number, ...args: Params) => Promise<Data>;
1297
1317
  }
1298
1318
 
1299
- export declare function useBase64(target: MaybeRefOrGetter<string>, options?: UseBase64Options): UseBase64Return;
1319
+ export declare function useBase64(target: MaybeRefOrGetter<string | undefined>, options?: UseBase64Options): UseBase64Return;
1300
1320
 
1301
- export declare function useBase64(target: MaybeRefOrGetter<Blob>, options?: UseBase64Options): UseBase64Return;
1321
+ export declare function useBase64(target: MaybeRefOrGetter<Blob | undefined>, options?: UseBase64Options): UseBase64Return;
1302
1322
 
1303
- export declare function useBase64(target: MaybeRefOrGetter<ArrayBuffer>, options?: UseBase64Options): UseBase64Return;
1323
+ export declare function useBase64(target: MaybeRefOrGetter<ArrayBuffer | undefined>, options?: UseBase64Options): UseBase64Return;
1304
1324
 
1305
- export declare function useBase64(target: MaybeRefOrGetter<HTMLCanvasElement>, options?: ToDataURLOptions): UseBase64Return;
1325
+ export declare function useBase64(target: MaybeRefOrGetter<HTMLCanvasElement | undefined>, options?: ToDataURLOptions): UseBase64Return;
1306
1326
 
1307
- export declare function useBase64(target: MaybeRefOrGetter<HTMLImageElement>, options?: ToDataURLOptions): UseBase64Return;
1327
+ export declare function useBase64(target: MaybeRefOrGetter<HTMLImageElement | undefined>, options?: ToDataURLOptions): UseBase64Return;
1308
1328
 
1309
1329
  export declare function useBase64<T extends Record<string, unknown>>(target: MaybeRefOrGetter<T>, options?: UseBase64ObjectOptions<T>): UseBase64Return;
1310
1330
 
@@ -1328,8 +1348,8 @@ declare interface UseBase64Options {
1328
1348
  }
1329
1349
 
1330
1350
  export declare interface UseBase64Return {
1331
- base64: Ref<string>;
1332
- promise: Ref<Promise<string>>;
1351
+ base64: ShallowRef<string>;
1352
+ promise: ShallowRef<Promise<string>>;
1333
1353
  execute: () => Promise<string>;
1334
1354
  }
1335
1355
 
@@ -1356,8 +1376,8 @@ export declare interface UseBroadcastChannelReturn<D, P> {
1356
1376
  data: Ref<D>;
1357
1377
  post: (data: P) => void;
1358
1378
  close: () => void;
1359
- error: Ref<Event | null>;
1360
- isClosed: Ref<boolean>;
1379
+ error: ShallowRef<Event | null>;
1380
+ isClosed: ShallowRef<boolean>;
1361
1381
  }
1362
1382
 
1363
1383
  /**
@@ -1395,7 +1415,12 @@ declare function useBrowserLocation(options?: ConfigurableWindow): Ref<{
1395
1415
 
1396
1416
  export declare type UseBrowserLocationReturn = ReturnType<typeof useBrowserLocation>;
1397
1417
 
1398
- export declare function useCached<T>(refValue: Ref<T>, comparator?: (a: T, b: T) => boolean, watchOptions?: WatchOptions): Ref<T>;
1418
+ export declare function useCached<T, D extends boolean = true>(refValue: Ref<T>, comparator?: (a: T, b: T) => boolean, options?: UseCachedOptions<D>): UseCachedReturn<T, D>;
1419
+
1420
+ declare interface UseCachedOptions<D extends boolean = true> extends ConfigurableDeepRefs<D>, WatchOptions {
1421
+ }
1422
+
1423
+ declare type UseCachedReturn<T = any, D extends boolean = true> = ShallowOrDeepRef<T, D>;
1399
1424
 
1400
1425
  export declare function useCloned<T>(source: MaybeRefOrGetter<T>, options?: UseClonedOptions): UseClonedReturn<T>;
1401
1426
 
@@ -1437,7 +1462,7 @@ export declare interface UseClonedReturn<T> {
1437
1462
  * @param options
1438
1463
  */
1439
1464
  export declare function useCounter(initialValue?: MaybeRef<number>, options?: UseCounterOptions): {
1440
- count: vue.Ref<number, MaybeRef<number>>;
1465
+ count: vue.Ref<number, number> | vue.ShallowRef<number, number> | vue.WritableComputedRef<number, number>;
1441
1466
  inc: (delta?: number) => number;
1442
1467
  dec: (delta?: number) => number;
1443
1468
  get: () => number;
@@ -1474,8 +1499,8 @@ export declare interface UseCycleListOptions<T> {
1474
1499
  }
1475
1500
 
1476
1501
  export declare interface UseCycleListReturn<T> {
1477
- state: Ref<T>;
1478
- index: Ref<number>;
1502
+ state: ShallowRef<T>;
1503
+ index: WritableComputedRef<number>;
1479
1504
  next: (n?: number) => T;
1480
1505
  prev: (n?: number) => T;
1481
1506
  /**
@@ -1628,27 +1653,27 @@ export declare interface UseFetchReturn<T> {
1628
1653
  /**
1629
1654
  * Indicates if the fetch request has finished
1630
1655
  */
1631
- isFinished: Readonly<Ref<boolean>>;
1656
+ isFinished: Readonly<ShallowRef<boolean>>;
1632
1657
  /**
1633
1658
  * The statusCode of the HTTP fetch response
1634
1659
  */
1635
- statusCode: Ref<number | null>;
1660
+ statusCode: ShallowRef<number | null>;
1636
1661
  /**
1637
1662
  * The raw response of the fetch response
1638
1663
  */
1639
- response: Ref<Response | null>;
1664
+ response: ShallowRef<Response | null>;
1640
1665
  /**
1641
1666
  * Any fetch errors that may have occurred
1642
1667
  */
1643
- error: Ref<any>;
1668
+ error: ShallowRef<any>;
1644
1669
  /**
1645
1670
  * The fetch response body on success, may either be JSON or text
1646
1671
  */
1647
- data: Ref<T | null>;
1672
+ data: ShallowRef<T | null>;
1648
1673
  /**
1649
1674
  * Indicates if the request is currently being fetched.
1650
1675
  */
1651
- isFetching: Readonly<Ref<boolean>>;
1676
+ isFetching: Readonly<ShallowRef<boolean>>;
1652
1677
  /**
1653
1678
  * Indicates if the fetch request is able to be aborted
1654
1679
  */
@@ -1656,7 +1681,7 @@ export declare interface UseFetchReturn<T> {
1656
1681
  /**
1657
1682
  * Indicates if the fetch request was aborted
1658
1683
  */
1659
- aborted: Ref<boolean>;
1684
+ aborted: ShallowRef<boolean>;
1660
1685
  /**
1661
1686
  * Abort the fetch request
1662
1687
  */
@@ -1723,8 +1748,8 @@ declare interface UseIdleOptions extends ConfigurableWindow, ConfigurableEventFi
1723
1748
  }
1724
1749
 
1725
1750
  declare interface UseIdleReturn {
1726
- idle: Ref<boolean>;
1727
- lastActive: Ref<number>;
1751
+ idle: ShallowRef<boolean>;
1752
+ lastActive: ShallowRef<number>;
1728
1753
  reset: () => void;
1729
1754
  }
1730
1755
 
@@ -1735,12 +1760,12 @@ declare interface UseIdleReturn {
1735
1760
  * @param interval
1736
1761
  * @param options
1737
1762
  */
1738
- export declare function useInterval(interval?: MaybeRefOrGetter<number>, options?: UseIntervalOptions<false>): Ref<number>;
1763
+ export declare function useInterval(interval?: MaybeRefOrGetter<number>, options?: UseIntervalOptions<false>): ShallowRef<number>;
1739
1764
 
1740
1765
  export declare function useInterval(interval: MaybeRefOrGetter<number>, options: UseIntervalOptions<true>): UseIntervalControls & Pausable;
1741
1766
 
1742
1767
  export declare interface UseIntervalControls {
1743
- counter: Ref<number>;
1768
+ counter: ShallowRef<number>;
1744
1769
  reset: () => void;
1745
1770
  }
1746
1771
 
@@ -1792,9 +1817,9 @@ export declare interface UseIntervalOptions<Controls extends boolean> {
1792
1817
  *
1793
1818
  * @see https://vueuse.org/useLastChanged
1794
1819
  */
1795
- export declare function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): Ref<number | null>;
1820
+ export declare function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): ShallowRef<number | null>;
1796
1821
 
1797
- export declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): Ref<number>;
1822
+ export declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): ShallowRef<number>;
1798
1823
 
1799
1824
  export declare interface UseLastChangedOptions<Immediate extends boolean, InitialValue extends number | null | undefined = undefined> extends WatchOptions<Immediate> {
1800
1825
  initialValue?: InitialValue;
@@ -1973,9 +1998,9 @@ export declare interface UseOffsetPaginationReturn {
1973
1998
  *
1974
1999
  * @see {@link https://vueuse.org/usePrevious}
1975
2000
  */
1976
- export declare function usePrevious<T>(value: MaybeRefOrGetter<T>): Readonly<Ref<T | undefined>>;
2001
+ export declare function usePrevious<T>(value: MaybeRefOrGetter<T>): Readonly<ShallowRef<T | undefined>>;
1977
2002
 
1978
- export declare function usePrevious<T>(value: MaybeRefOrGetter<T>, initialValue: T): Readonly<Ref<T>>;
2003
+ export declare function usePrevious<T>(value: MaybeRefOrGetter<T>, initialValue: T): Readonly<ShallowRef<T>>;
1979
2004
 
1980
2005
  /**
1981
2006
  * Track the change history of a ref, also provides undo and redo functionality.
@@ -2160,7 +2185,7 @@ declare function useTextareaAutosize(options?: UseTextareaAutosizeOptions): {
2160
2185
  triggerResize: () => void;
2161
2186
  };
2162
2187
 
2163
- export declare interface UseTextareaAutosizeOptions {
2188
+ export declare interface UseTextareaAutosizeOptions extends ConfigurableWindow {
2164
2189
  /** Textarea element to autosize. */
2165
2190
  element?: MaybeRef<HTMLTextAreaElement | undefined>;
2166
2191
  /** Textarea content. */
@@ -2283,11 +2308,17 @@ export declare function useTimeoutFn<CallbackFn extends AnyFn>(cb: CallbackFn, i
2283
2308
 
2284
2309
  export declare interface UseTimeoutFnOptions {
2285
2310
  /**
2286
- * Start the timer immediate after calling this function
2311
+ * Start the timer immediately
2287
2312
  *
2288
2313
  * @default true
2289
2314
  */
2290
2315
  immediate?: boolean;
2316
+ /**
2317
+ * Execute the callback immediately after calling `start`
2318
+ *
2319
+ * @default false
2320
+ */
2321
+ immediateCallback?: boolean;
2291
2322
  }
2292
2323
 
2293
2324
  export declare interface UseTimeoutOptions<Controls extends boolean> extends UseTimeoutFnOptions {
@@ -2311,10 +2342,10 @@ export declare function useTimeoutPoll(fn: () => Awaitable<void>, interval: Mayb
2311
2342
  * @see https://vueuse.org/useTimestamp
2312
2343
  * @param options
2313
2344
  */
2314
- export declare function useTimestamp(options?: UseTimestampOptions<false>): Ref<number>;
2345
+ export declare function useTimestamp(options?: UseTimestampOptions<false>): ShallowRef<number>;
2315
2346
 
2316
2347
  export declare function useTimestamp(options: UseTimestampOptions<true>): {
2317
- timestamp: Ref<number>;
2348
+ timestamp: ShallowRef<number>;
2318
2349
  } & Pausable;
2319
2350
 
2320
2351
  export declare interface UseTimestampOptions<Controls extends boolean> {
@@ -2352,7 +2383,7 @@ export declare type UseTimestampReturn = ReturnType<typeof useTimestamp>;
2352
2383
 
2353
2384
  export declare function useToggle<Truthy, Falsy, T = Truthy | Falsy>(initialValue: Ref<T>, options?: UseToggleOptions<Truthy, Falsy>): (value?: T) => T;
2354
2385
 
2355
- export declare function useToggle<Truthy = true, Falsy = false, T = Truthy | Falsy>(initialValue?: T, options?: UseToggleOptions<Truthy, Falsy>): [Ref<T>, (value?: T) => T];
2386
+ export declare function useToggle<Truthy = true, Falsy = false, T = Truthy | Falsy>(initialValue?: T, options?: UseToggleOptions<Truthy, Falsy>): [ShallowRef<T>, (value?: T) => T];
2356
2387
 
2357
2388
  export declare interface UseToggleOptions<Truthy, Falsy> {
2358
2389
  truthyValue?: MaybeRefOrGetter<Truthy>;
@@ -2485,7 +2516,7 @@ export declare interface UseWebSocketOptions {
2485
2516
  *
2486
2517
  * @default -1
2487
2518
  */
2488
- retries?: number | (() => boolean);
2519
+ retries?: number | ((retried: number) => boolean);
2489
2520
  /**
2490
2521
  * Delay for reconnect, in milliseconds
2491
2522
  *
@@ -2533,7 +2564,7 @@ export declare interface UseWebSocketReturn<T> {
2533
2564
  * The current websocket status, can be only one of:
2534
2565
  * 'OPEN', 'CONNECTING', 'CLOSED'
2535
2566
  */
2536
- status: Ref<WebSocketStatus>;
2567
+ status: ShallowRef<WebSocketStatus>;
2537
2568
  /**
2538
2569
  * Closes the websocket connection gracefully.
2539
2570
  */
@@ -2565,7 +2596,7 @@ export declare interface UseWebSocketReturn<T> {
2565
2596
  */
2566
2597
  export declare function useWebWorkerFn<T extends (...fnArgs: any[]) => any>(fn: T, options?: UseWebWorkerOptions): {
2567
2598
  workerFn: (...fnArgs: Parameters<T>) => Promise<ReturnType<T>>;
2568
- workerStatus: vue.Ref<WebWorkerStatus, WebWorkerStatus>;
2599
+ workerStatus: vue.ShallowRef<WebWorkerStatus, WebWorkerStatus>;
2569
2600
  workerTerminate: (status?: WebWorkerStatus) => void;
2570
2601
  };
2571
2602
 
@@ -2614,7 +2645,7 @@ export declare interface WatchAtMostOptions<Immediate> extends WatchWithFilterOp
2614
2645
 
2615
2646
  export declare interface WatchAtMostReturn {
2616
2647
  stop: WatchStopHandle;
2617
- count: Ref<number>;
2648
+ count: ShallowRef<number>;
2618
2649
  }
2619
2650
 
2620
2651
  declare function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
@@ -2659,14 +2690,16 @@ export declare function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Im
2659
2690
 
2660
2691
  export declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): WatchStopHandle;
2661
2692
 
2662
- declare function watchPausable<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
2693
+ declare function watchPausable<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchPausableOptions<Immediate>): WatchPausableReturn;
2663
2694
 
2664
- declare function watchPausable<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
2695
+ declare function watchPausable<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchPausableOptions<Immediate>): WatchPausableReturn;
2665
2696
 
2666
- declare function watchPausable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
2697
+ declare function watchPausable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchPausableOptions<Immediate>): WatchPausableReturn;
2667
2698
  export { watchPausable as pausableWatch }
2668
2699
  export { watchPausable }
2669
2700
 
2701
+ declare type WatchPausableOptions<Immediate> = WatchWithFilterOptions<Immediate> & PausableFilterOptions;
2702
+
2670
2703
  export declare interface WatchPausableReturn extends Pausable {
2671
2704
  stop: WatchStopHandle;
2672
2705
  }
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, toValue as toValue$1, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, nextTick, isReactive, shallowRef, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
1
+ import { shallowRef, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, toValue as toValue$1, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, ref, nextTick, isReactive, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
2
2
  function computedWithControl(source, fn) {
3
3
  let v = void 0;
4
4
  let track;
5
5
  let trigger;
6
- const dirty = ref(true);
6
+ const dirty = shallowRef(true);
7
7
  const update = () => {
8
8
  dirty.value = true;
9
9
  trigger();
@@ -77,6 +77,13 @@ function createGlobalState(stateFactory) {
77
77
  return state;
78
78
  };
79
79
  }
80
+ function createRef(value, deep) {
81
+ if (deep === true) {
82
+ return ref(value);
83
+ } else {
84
+ return shallowRef(value);
85
+ }
86
+ }
80
87
  function createSharedComposable(composable) {
81
88
  let subscribers = 0;
82
89
  let state;
@@ -344,8 +351,11 @@ function throttleFilter(...args) {
344
351
  };
345
352
  return filter;
346
353
  }
347
- function pausableFilter(extendFilter = bypassFilter) {
348
- const isActive = ref(true);
354
+ function pausableFilter(extendFilter = bypassFilter, options = {}) {
355
+ const {
356
+ initialState = "active"
357
+ } = options;
358
+ const isActive = toRef(initialState === "active");
349
359
  function pause() {
350
360
  isActive.value = false;
351
361
  }
@@ -593,9 +603,10 @@ function watchWithFilter(source, cb, options = {}) {
593
603
  function watchPausable(source, cb, options = {}) {
594
604
  const {
595
605
  eventFilter: filter,
606
+ initialState = "active",
596
607
  ...watchOptions
597
608
  } = options;
598
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
609
+ const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
599
610
  const stop = watchWithFilter(
600
611
  source,
601
612
  cb,
@@ -650,10 +661,10 @@ function syncRefs(source, targets, options = {}) {
650
661
  deep = false,
651
662
  immediate = true
652
663
  } = options;
653
- targets = toArray(targets);
664
+ const targetsArray = toArray(targets);
654
665
  return watch(
655
666
  source,
656
- (newValue) => targets.forEach((target) => target.value = newValue),
667
+ (newValue) => targetsArray.forEach((target) => target.value = newValue),
657
668
  { flush, deep, immediate }
658
669
  );
659
670
  }
@@ -928,7 +939,7 @@ function useArrayUnique(list, compareFn) {
928
939
  }
929
940
  function useCounter(initialValue = 0, options = {}) {
930
941
  let _initialValue = unref(initialValue);
931
- const count = ref(initialValue);
942
+ const count = shallowRef(initialValue);
932
943
  const {
933
944
  max = Number.POSITIVE_INFINITY,
934
945
  min = Number.NEGATIVE_INFINITY
@@ -944,7 +955,7 @@ function useCounter(initialValue = 0, options = {}) {
944
955
  return { count, inc, dec, get: get2, set: set2, reset };
945
956
  }
946
957
  const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
947
- const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
958
+ const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
948
959
  function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
949
960
  let m = hours < 12 ? "AM" : "PM";
950
961
  if (hasPeriod)
@@ -967,6 +978,10 @@ function formatDate(date, formatStr, options = {}) {
967
978
  const milliseconds = date.getMilliseconds();
968
979
  const day = date.getDay();
969
980
  const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
981
+ const stripTimeZone = (dateString) => {
982
+ var _a2;
983
+ return (_a2 = dateString.split(" ")[1]) != null ? _a2 : "";
984
+ };
970
985
  const matches = {
971
986
  Yo: () => formatOrdinal(years),
972
987
  YY: () => String(years).slice(-2),
@@ -999,7 +1014,11 @@ function formatDate(date, formatStr, options = {}) {
999
1014
  A: () => meridiem(hours, minutes),
1000
1015
  AA: () => meridiem(hours, minutes, false, true),
1001
1016
  a: () => meridiem(hours, minutes, true),
1002
- aa: () => meridiem(hours, minutes, true, true)
1017
+ aa: () => meridiem(hours, minutes, true, true),
1018
+ z: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1019
+ zz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1020
+ zzz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1021
+ zzzz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "longOffset" }))
1003
1022
  };
1004
1023
  return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1005
1024
  var _a2, _b;
@@ -1032,7 +1051,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1032
1051
  immediateCallback = false
1033
1052
  } = options;
1034
1053
  let timer = null;
1035
- const isActive = ref(false);
1054
+ const isActive = shallowRef(false);
1036
1055
  function clean() {
1037
1056
  if (timer) {
1038
1057
  clearInterval(timer);
@@ -1076,7 +1095,7 @@ function useInterval(interval = 1e3, options = {}) {
1076
1095
  immediate = true,
1077
1096
  callback
1078
1097
  } = options;
1079
- const counter = ref(0);
1098
+ const counter = shallowRef(0);
1080
1099
  const update = () => counter.value += 1;
1081
1100
  const reset = () => {
1082
1101
  counter.value = 0;
@@ -1101,7 +1120,7 @@ function useInterval(interval = 1e3, options = {}) {
1101
1120
  }
1102
1121
  function useLastChanged(source, options = {}) {
1103
1122
  var _a;
1104
- const ms = ref((_a = options.initialValue) != null ? _a : null);
1123
+ const ms = shallowRef((_a = options.initialValue) != null ? _a : null);
1105
1124
  watch(
1106
1125
  source,
1107
1126
  () => ms.value = timestamp(),
@@ -1111,9 +1130,10 @@ function useLastChanged(source, options = {}) {
1111
1130
  }
1112
1131
  function useTimeoutFn(cb, interval, options = {}) {
1113
1132
  const {
1114
- immediate = true
1133
+ immediate = true,
1134
+ immediateCallback = false
1115
1135
  } = options;
1116
- const isPending = ref(false);
1136
+ const isPending = shallowRef(false);
1117
1137
  let timer = null;
1118
1138
  function clear() {
1119
1139
  if (timer) {
@@ -1126,6 +1146,8 @@ function useTimeoutFn(cb, interval, options = {}) {
1126
1146
  clear();
1127
1147
  }
1128
1148
  function start(...args) {
1149
+ if (immediateCallback)
1150
+ cb();
1129
1151
  clear();
1130
1152
  isPending.value = true;
1131
1153
  timer = setTimeout(() => {
@@ -1192,7 +1214,7 @@ function useToggle(initialValue = false, options = {}) {
1192
1214
  falsyValue = false
1193
1215
  } = options;
1194
1216
  const valueIsRef = isRef(initialValue);
1195
- const _value = ref(initialValue);
1217
+ const _value = shallowRef(initialValue);
1196
1218
  function toggle(value) {
1197
1219
  if (arguments.length) {
1198
1220
  _value.value = value;
@@ -1209,7 +1231,7 @@ function useToggle(initialValue = false, options = {}) {
1209
1231
  return [_value, toggle];
1210
1232
  }
1211
1233
  function watchArray(source, cb, options) {
1212
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
1234
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : toValue$1(source)];
1213
1235
  return watch(source, (newList, _, onCleanup) => {
1214
1236
  const oldListRemains = Array.from({ length: oldList.length });
1215
1237
  const added = [];
@@ -1235,7 +1257,7 @@ function watchAtMost(source, cb, options) {
1235
1257
  count,
1236
1258
  ...watchOptions
1237
1259
  } = options;
1238
- const current = ref(0);
1260
+ const current = shallowRef(0);
1239
1261
  const stop = watchWithFilter(
1240
1262
  source,
1241
1263
  (...args) => {
@@ -1286,7 +1308,7 @@ function watchIgnorable(source, cb, options = {}) {
1286
1308
  let ignorePrevAsyncUpdates;
1287
1309
  let stop;
1288
1310
  if (watchOptions.flush === "sync") {
1289
- const ignore = ref(false);
1311
+ const ignore = shallowRef(false);
1290
1312
  ignorePrevAsyncUpdates = () => {
1291
1313
  };
1292
1314
  ignoreUpdates = (updater) => {
@@ -1304,8 +1326,8 @@ function watchIgnorable(source, cb, options = {}) {
1304
1326
  );
1305
1327
  } else {
1306
1328
  const disposables = [];
1307
- const ignoreCounter = ref(0);
1308
- const syncCounter = ref(0);
1329
+ const ignoreCounter = shallowRef(0);
1330
+ const syncCounter = shallowRef(0);
1309
1331
  ignorePrevAsyncUpdates = () => {
1310
1332
  ignoreCounter.value = syncCounter.value;
1311
1333
  };
@@ -1448,7 +1470,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1448
1470
  shallow = true,
1449
1471
  onError = noop
1450
1472
  } = options;
1451
- const started = ref(!lazy);
1473
+ const started = shallowRef(!lazy);
1452
1474
  const current = shallow ? shallowRef(initialState) : ref(initialState);
1453
1475
  let counter = 0;
1454
1476
  watchEffect(async (onInvalidate) => {
@@ -1549,7 +1571,7 @@ function useEventListener(...args) {
1549
1571
  return stop;
1550
1572
  }
1551
1573
  function useMounted() {
1552
- const isMounted = ref(false);
1574
+ const isMounted = shallowRef(false);
1553
1575
  return isMounted;
1554
1576
  }
1555
1577
  function useSupported(callback) {
@@ -1563,9 +1585,10 @@ function useRafFn(fn, options = {}) {
1563
1585
  const {
1564
1586
  immediate = true,
1565
1587
  fpsLimit = void 0,
1566
- window: window2 = defaultWindow
1588
+ window: window2 = defaultWindow,
1589
+ once = false
1567
1590
  } = options;
1568
- const isActive = ref(false);
1591
+ const isActive = shallowRef(false);
1569
1592
  const intervalLimit = computed(() => {
1570
1593
  return fpsLimit ? 1e3 / toValue$1(fpsLimit) : null;
1571
1594
  });
@@ -1583,6 +1606,11 @@ function useRafFn(fn, options = {}) {
1583
1606
  }
1584
1607
  previousFrameTimestamp = timestamp2;
1585
1608
  fn({ delta, timestamp: timestamp2 });
1609
+ if (once) {
1610
+ isActive.value = false;
1611
+ rafId = null;
1612
+ return;
1613
+ }
1586
1614
  rafId = window2.requestAnimationFrame(loop);
1587
1615
  }
1588
1616
  function resume() {
@@ -1623,7 +1651,7 @@ function useAsyncQueue(tasks, options) {
1623
1651
  };
1624
1652
  const initialResult = Array.from(Array.from({ length: tasks.length }), () => ({ state: promiseState.pending, data: null }));
1625
1653
  const result = reactive(initialResult);
1626
- const activeIndex = ref(-1);
1654
+ const activeIndex = shallowRef(-1);
1627
1655
  if (!tasks || tasks.length === 0) {
1628
1656
  onFinished();
1629
1657
  return {
@@ -1691,8 +1719,8 @@ function useAsyncState(promise, initialState, options) {
1691
1719
  throwError
1692
1720
  } = options != null ? options : {};
1693
1721
  const state = shallow ? shallowRef(initialState) : ref(initialState);
1694
- const isReady = ref(false);
1695
- const isLoading = ref(false);
1722
+ const isReady = shallowRef(false);
1723
+ const isLoading = shallowRef(false);
1696
1724
  const error = shallowRef(void 0);
1697
1725
  async function execute(delay2 = 0, ...args) {
1698
1726
  if (resetOnExecute)
@@ -1760,8 +1788,8 @@ function getDefaultSerialization(target) {
1760
1788
  return defaults.object;
1761
1789
  }
1762
1790
  function useBase64(target, options) {
1763
- const base64 = ref("");
1764
- const promise = ref();
1791
+ const base64 = shallowRef("");
1792
+ const promise = shallowRef();
1765
1793
  function execute() {
1766
1794
  if (!isClient)
1767
1795
  return;
@@ -1843,7 +1871,7 @@ function useBroadcastChannel(options) {
1843
1871
  window: window2 = defaultWindow
1844
1872
  } = options;
1845
1873
  const isSupported = useSupported(() => window2 && "BroadcastChannel" in window2);
1846
- const isClosed = ref(false);
1874
+ const isClosed = shallowRef(false);
1847
1875
  const channel = ref();
1848
1876
  const data = ref();
1849
1877
  const error = shallowRef(null);
@@ -1887,8 +1915,9 @@ function useBroadcastChannel(options) {
1887
1915
  isClosed
1888
1916
  };
1889
1917
  }
1890
- function useCached(refValue, comparator = (a, b) => a === b, watchOptions) {
1891
- const cachedValue = ref(refValue.value);
1918
+ function useCached(refValue, comparator = (a, b) => a === b, options) {
1919
+ const { deepRefs = true, ...watchOptions } = options || {};
1920
+ const cachedValue = createRef(refValue.value, deepRefs);
1892
1921
  watch(() => refValue.value, (value) => {
1893
1922
  if (!comparator(value, cachedValue.value))
1894
1923
  cachedValue.value = value;
@@ -1900,7 +1929,7 @@ function cloneFnJSON(source) {
1900
1929
  }
1901
1930
  function useCloned(source, options = {}) {
1902
1931
  const cloned = ref({});
1903
- const isModified = ref(false);
1932
+ const isModified = shallowRef(false);
1904
1933
  let _lastSync = false;
1905
1934
  const {
1906
1935
  manual,
@@ -2183,7 +2212,13 @@ function headersToObject(headers) {
2183
2212
  function combineCallbacks(combination, ...callbacks) {
2184
2213
  if (combination === "overwrite") {
2185
2214
  return async (ctx) => {
2186
- const callback = callbacks[callbacks.length - 1];
2215
+ let callback;
2216
+ for (let i = callbacks.length - 1; i >= 0; i--) {
2217
+ if (callbacks[i] != null) {
2218
+ callback = callbacks[i];
2219
+ break;
2220
+ }
2221
+ }
2187
2222
  if (callback)
2188
2223
  return { ...ctx, ...await callback(ctx) };
2189
2224
  return ctx;
@@ -2276,10 +2311,10 @@ function useFetch(url, ...args) {
2276
2311
  const responseEvent = createEventHook();
2277
2312
  const errorEvent = createEventHook();
2278
2313
  const finallyEvent = createEventHook();
2279
- const isFinished = ref(false);
2280
- const isFetching = ref(false);
2281
- const aborted = ref(false);
2282
- const statusCode = ref(null);
2314
+ const isFinished = shallowRef(false);
2315
+ const isFetching = shallowRef(false);
2316
+ const aborted = shallowRef(false);
2317
+ const statusCode = shallowRef(null);
2283
2318
  const response = shallowRef(null);
2284
2319
  const error = shallowRef(null);
2285
2320
  const data = shallowRef(initialData || null);
@@ -2513,8 +2548,8 @@ function useIdle(timeout = oneMinute, options = {}) {
2513
2548
  window: window2 = defaultWindow,
2514
2549
  eventFilter = throttleFilter(50)
2515
2550
  } = options;
2516
- const idle = ref(initialState);
2517
- const lastActive = ref(timestamp());
2551
+ const idle = shallowRef(initialState);
2552
+ const lastActive = shallowRef(timestamp());
2518
2553
  let timer;
2519
2554
  const reset = () => {
2520
2555
  idle.value = false;
@@ -2565,7 +2600,7 @@ function useNow(options = {}) {
2565
2600
  }
2566
2601
  }
2567
2602
  function useObjectUrl(object) {
2568
- const url = ref();
2603
+ const url = shallowRef();
2569
2604
  const release = () => {
2570
2605
  if (url.value)
2571
2606
  URL.revokeObjectURL(url.value);
@@ -2864,10 +2899,11 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
2864
2899
  }
2865
2900
  function useTimeoutPoll(fn, interval, options = {}) {
2866
2901
  const {
2867
- immediate = true
2902
+ immediate = true,
2903
+ immediateCallback = false
2868
2904
  } = options;
2869
- const { start } = useTimeoutFn(loop, interval, { immediate: false });
2870
- const isActive = ref(false);
2905
+ const { start } = useTimeoutFn(loop, interval, { immediate });
2906
+ const isActive = shallowRef(false);
2871
2907
  async function loop() {
2872
2908
  if (!isActive.value)
2873
2909
  return;
@@ -2877,7 +2913,9 @@ function useTimeoutPoll(fn, interval, options = {}) {
2877
2913
  function resume() {
2878
2914
  if (!isActive.value) {
2879
2915
  isActive.value = true;
2880
- loop();
2916
+ if (immediateCallback)
2917
+ fn();
2918
+ start();
2881
2919
  }
2882
2920
  }
2883
2921
  function pause() {
@@ -2900,7 +2938,7 @@ function useTimestamp(options = {}) {
2900
2938
  interval = "requestAnimationFrame",
2901
2939
  callback
2902
2940
  } = options;
2903
- const ts = ref(timestamp() + offset);
2941
+ const ts = shallowRef(timestamp() + offset);
2904
2942
  const update = () => ts.value = timestamp() + offset;
2905
2943
  const cb = callback ? () => {
2906
2944
  update();
@@ -3035,7 +3073,7 @@ function useWebSocket(url, options = {}) {
3035
3073
  protocols = []
3036
3074
  } = options;
3037
3075
  const data = ref(null);
3038
- const status = ref("CLOSED");
3076
+ const status = shallowRef("CLOSED");
3039
3077
  const wsRef = ref();
3040
3078
  const urlRef = toRef(url);
3041
3079
  let heartbeatPause;
@@ -3097,6 +3135,8 @@ function useWebSocket(url, options = {}) {
3097
3135
  };
3098
3136
  ws.onclose = (ev) => {
3099
3137
  status.value = "CLOSED";
3138
+ resetHeartbeat();
3139
+ heartbeatPause == null ? void 0 : heartbeatPause();
3100
3140
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3101
3141
  if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
3102
3142
  const {
@@ -3104,11 +3144,10 @@ function useWebSocket(url, options = {}) {
3104
3144
  delay = 1e3,
3105
3145
  onFailed
3106
3146
  } = resolveNestedOptions(options.autoReconnect);
3107
- if (typeof retries === "number" && (retries < 0 || retried < retries)) {
3147
+ const checkRetires = typeof retries === "function" ? retries : () => typeof retries === "number" && (retries < 0 || retried < retries);
3148
+ if (checkRetires(retried)) {
3108
3149
  retried += 1;
3109
3150
  retryTimeout = setTimeout(_init, delay);
3110
- } else if (typeof retries === "function" && retries()) {
3111
- retryTimeout = setTimeout(_init, delay);
3112
3151
  } else {
3113
3152
  onFailed == null ? void 0 : onFailed();
3114
3153
  }
@@ -3219,9 +3258,9 @@ function useWebWorkerFn(fn, options = {}) {
3219
3258
  window: window2 = defaultWindow
3220
3259
  } = options;
3221
3260
  const worker = ref();
3222
- const workerStatus = ref("PENDING");
3261
+ const workerStatus = shallowRef("PENDING");
3223
3262
  const promise = ref({});
3224
- const timeoutId = ref();
3263
+ const timeoutId = shallowRef();
3225
3264
  const workerTerminate = (status = "PENDING") => {
3226
3265
  if (worker.value && worker.value._url && window2) {
3227
3266
  worker.value.terminate();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reactive-vscode/vueuse",
3
3
  "type": "module",
4
- "version": "0.2.14",
4
+ "version": "0.2.16",
5
5
  "description": "Useful VueUse utilities for VSCode extension development",
6
6
  "author": "_Kerman <kermanx@qq.com>",
7
7
  "license": "MIT",
@@ -33,14 +33,14 @@
33
33
  "tsconfig.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@reactive-vscode/reactivity": "0.2.14"
36
+ "@reactive-vscode/reactivity": "0.2.16"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^20.17.16",
40
- "@vueuse/core": "^12.5.0",
41
- "typescript": "^5.7.3",
42
- "vite": "^5.4.14",
43
- "vite-plugin-dts": "^4.5.0"
39
+ "@types/node": "^20.17.45",
40
+ "@vueuse/core": "^12.8.2",
41
+ "typescript": "^5.8.3",
42
+ "vite": "^5.4.19",
43
+ "vite-plugin-dts": "^4.5.3"
44
44
  },
45
45
  "scripts": {
46
46
  "typecheck": "tsc --noEmit",