@reactive-vscode/vueuse 0.3.1 → 0.3.2
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 +185 -130
- package/dist/index.d.ts +208 -66
- package/dist/index.js +186 -131
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function computedWithControl(source, fn) {
|
|
1
|
+
import { toValue as toValue$1, customRef, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, readonly, toRefs as toRefs$1, toRef as toRef$1, reactive, getCurrentScope, onScopeDispose, shallowRef, nextTick, isReactive, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
|
|
2
|
+
function computedWithControl(source, fn, options = {}) {
|
|
3
3
|
let v = void 0;
|
|
4
4
|
let track;
|
|
5
5
|
let trigger;
|
|
6
|
-
|
|
6
|
+
let dirty = true;
|
|
7
7
|
const update = () => {
|
|
8
|
-
dirty
|
|
8
|
+
dirty = true;
|
|
9
9
|
trigger();
|
|
10
10
|
};
|
|
11
|
-
watch(source, update, { flush: "sync" });
|
|
11
|
+
watch(source, update, { flush: "sync", ...options });
|
|
12
12
|
const get2 = typeof fn === "function" ? fn : fn.get;
|
|
13
13
|
const set2 = typeof fn === "function" ? void 0 : fn.set;
|
|
14
14
|
const result = customRef((_track, _trigger) => {
|
|
@@ -16,9 +16,9 @@ function computedWithControl(source, fn) {
|
|
|
16
16
|
trigger = _trigger;
|
|
17
17
|
return {
|
|
18
18
|
get() {
|
|
19
|
-
if (dirty
|
|
19
|
+
if (dirty) {
|
|
20
20
|
v = get2(v);
|
|
21
|
-
dirty
|
|
21
|
+
dirty = false;
|
|
22
22
|
}
|
|
23
23
|
track();
|
|
24
24
|
return v;
|
|
@@ -28,8 +28,7 @@ function computedWithControl(source, fn) {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
|
-
|
|
32
|
-
result.trigger = update;
|
|
31
|
+
result.trigger = update;
|
|
33
32
|
return result;
|
|
34
33
|
}
|
|
35
34
|
function tryOnScopeDispose(fn) {
|
|
@@ -39,6 +38,7 @@ function tryOnScopeDispose(fn) {
|
|
|
39
38
|
}
|
|
40
39
|
return false;
|
|
41
40
|
}
|
|
41
|
+
// @__NO_SIDE_EFFECTS__
|
|
42
42
|
function createEventHook() {
|
|
43
43
|
const fns = /* @__PURE__ */ new Set();
|
|
44
44
|
const off = (fn) => {
|
|
@@ -65,6 +65,7 @@ function createEventHook() {
|
|
|
65
65
|
clear
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
// @__NO_SIDE_EFFECTS__
|
|
68
69
|
function createGlobalState(stateFactory) {
|
|
69
70
|
let initialized = false;
|
|
70
71
|
let state;
|
|
@@ -77,6 +78,7 @@ function createGlobalState(stateFactory) {
|
|
|
77
78
|
return state;
|
|
78
79
|
};
|
|
79
80
|
}
|
|
81
|
+
// @__NO_SIDE_EFFECTS__
|
|
80
82
|
function createRef(value, deep) {
|
|
81
83
|
if (deep === true) {
|
|
82
84
|
return ref(value);
|
|
@@ -84,6 +86,7 @@ function createRef(value, deep) {
|
|
|
84
86
|
return shallowRef(value);
|
|
85
87
|
}
|
|
86
88
|
}
|
|
89
|
+
// @__NO_SIDE_EFFECTS__
|
|
87
90
|
function createSharedComposable(composable) {
|
|
88
91
|
let subscribers = 0;
|
|
89
92
|
let state;
|
|
@@ -134,6 +137,7 @@ function get(obj, key) {
|
|
|
134
137
|
function isDefined(v) {
|
|
135
138
|
return unref(v) != null;
|
|
136
139
|
}
|
|
140
|
+
// @__NO_SIDE_EFFECTS__
|
|
137
141
|
function makeDestructurable(obj, arr) {
|
|
138
142
|
if (typeof Symbol !== "undefined") {
|
|
139
143
|
const clone = { ...obj };
|
|
@@ -154,12 +158,14 @@ function makeDestructurable(obj, arr) {
|
|
|
154
158
|
return Object.assign([...arr], obj);
|
|
155
159
|
}
|
|
156
160
|
}
|
|
161
|
+
// @__NO_SIDE_EFFECTS__
|
|
157
162
|
function reactify(fn, options) {
|
|
158
163
|
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue$1;
|
|
159
164
|
return function(...args) {
|
|
160
165
|
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
161
166
|
};
|
|
162
167
|
}
|
|
168
|
+
// @__NO_SIDE_EFFECTS__
|
|
163
169
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
164
170
|
let keys = [];
|
|
165
171
|
let options;
|
|
@@ -177,7 +183,7 @@ function reactifyObject(obj, optionsOrKeys = {}) {
|
|
|
177
183
|
const value = obj[key];
|
|
178
184
|
return [
|
|
179
185
|
key,
|
|
180
|
-
typeof value === "function" ? reactify(value.bind(obj), options) : value
|
|
186
|
+
typeof value === "function" ? /* @__PURE__ */ reactify(value.bind(obj), options) : value
|
|
181
187
|
];
|
|
182
188
|
})
|
|
183
189
|
);
|
|
@@ -243,6 +249,43 @@ const rand = (min, max) => {
|
|
|
243
249
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
244
250
|
};
|
|
245
251
|
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
252
|
+
function toRef(...args) {
|
|
253
|
+
if (args.length !== 1)
|
|
254
|
+
return toRef$1(...args);
|
|
255
|
+
const r = args[0];
|
|
256
|
+
return typeof r === "function" ? readonly(customRef(() => ({ get: r, set: noop }))) : ref(r);
|
|
257
|
+
}
|
|
258
|
+
const resolveRef = toRef;
|
|
259
|
+
function reactivePick(obj, ...keys) {
|
|
260
|
+
const flatKeys = keys.flat();
|
|
261
|
+
const predicate = flatKeys[0];
|
|
262
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue$1(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
263
|
+
}
|
|
264
|
+
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
265
|
+
return customRef((track, trigger) => {
|
|
266
|
+
let value = toValue$1(defaultValue);
|
|
267
|
+
let timer;
|
|
268
|
+
const resetAfter = () => setTimeout(() => {
|
|
269
|
+
value = toValue$1(defaultValue);
|
|
270
|
+
trigger();
|
|
271
|
+
}, toValue$1(afterMs));
|
|
272
|
+
tryOnScopeDispose(() => {
|
|
273
|
+
clearTimeout(timer);
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
get() {
|
|
277
|
+
track();
|
|
278
|
+
return value;
|
|
279
|
+
},
|
|
280
|
+
set(newValue) {
|
|
281
|
+
value = newValue;
|
|
282
|
+
trigger();
|
|
283
|
+
clearTimeout(timer);
|
|
284
|
+
timer = resetAfter();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
246
289
|
function createFilterWrapper(filter, fn) {
|
|
247
290
|
function wrapper(...args) {
|
|
248
291
|
return new Promise((resolve, reject) => {
|
|
@@ -272,7 +315,7 @@ function debounceFilter(ms, options = {}) {
|
|
|
272
315
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
273
316
|
if (maxTimer) {
|
|
274
317
|
_clearTimeout(maxTimer);
|
|
275
|
-
maxTimer =
|
|
318
|
+
maxTimer = void 0;
|
|
276
319
|
}
|
|
277
320
|
return Promise.resolve(invoke2());
|
|
278
321
|
}
|
|
@@ -283,14 +326,14 @@ function debounceFilter(ms, options = {}) {
|
|
|
283
326
|
maxTimer = setTimeout(() => {
|
|
284
327
|
if (timer)
|
|
285
328
|
_clearTimeout(timer);
|
|
286
|
-
maxTimer =
|
|
329
|
+
maxTimer = void 0;
|
|
287
330
|
resolve(lastInvoker());
|
|
288
331
|
}, maxDuration);
|
|
289
332
|
}
|
|
290
333
|
timer = setTimeout(() => {
|
|
291
334
|
if (maxTimer)
|
|
292
335
|
_clearTimeout(maxTimer);
|
|
293
|
-
maxTimer =
|
|
336
|
+
maxTimer = void 0;
|
|
294
337
|
resolve(invoke2());
|
|
295
338
|
}, duration);
|
|
296
339
|
});
|
|
@@ -368,19 +411,6 @@ function pausableFilter(extendFilter = bypassFilter, options = {}) {
|
|
|
368
411
|
};
|
|
369
412
|
return { isActive: readonly(isActive), pause, resume, eventFilter };
|
|
370
413
|
}
|
|
371
|
-
function cacheStringFunction(fn) {
|
|
372
|
-
const cache = /* @__PURE__ */ Object.create(null);
|
|
373
|
-
return (str) => {
|
|
374
|
-
const hit = cache[str];
|
|
375
|
-
return hit || (cache[str] = fn(str));
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
const hyphenateRE = /\B([A-Z])/g;
|
|
379
|
-
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
380
|
-
const camelizeRE = /-(\w)/g;
|
|
381
|
-
const camelize = cacheStringFunction((str) => {
|
|
382
|
-
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
383
|
-
});
|
|
384
414
|
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
385
415
|
return new Promise((resolve, reject) => {
|
|
386
416
|
if (throwOnTimeout)
|
|
@@ -441,49 +471,26 @@ function objectOmit(obj, keys, omitUndefined = false) {
|
|
|
441
471
|
function objectEntries(obj) {
|
|
442
472
|
return Object.entries(obj);
|
|
443
473
|
}
|
|
444
|
-
function getLifeCycleTarget(target) {
|
|
445
|
-
return target || null;
|
|
446
|
-
}
|
|
447
474
|
function toArray(value) {
|
|
448
475
|
return Array.isArray(value) ? value : [value];
|
|
449
476
|
}
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
const resolveRef = toRef;
|
|
457
|
-
function reactivePick(obj, ...keys) {
|
|
458
|
-
const flatKeys = keys.flat();
|
|
459
|
-
const predicate = flatKeys[0];
|
|
460
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue$1(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
477
|
+
function cacheStringFunction(fn) {
|
|
478
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
479
|
+
return (str) => {
|
|
480
|
+
const hit = cache[str];
|
|
481
|
+
return hit || (cache[str] = fn(str));
|
|
482
|
+
};
|
|
461
483
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
tryOnScopeDispose(() => {
|
|
471
|
-
clearTimeout(timer);
|
|
472
|
-
});
|
|
473
|
-
return {
|
|
474
|
-
get() {
|
|
475
|
-
track();
|
|
476
|
-
return value;
|
|
477
|
-
},
|
|
478
|
-
set(newValue) {
|
|
479
|
-
value = newValue;
|
|
480
|
-
trigger();
|
|
481
|
-
clearTimeout(timer);
|
|
482
|
-
timer = resetAfter();
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
});
|
|
484
|
+
const hyphenateRE = /\B([A-Z])/g;
|
|
485
|
+
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
486
|
+
const camelizeRE = /-(\w)/g;
|
|
487
|
+
const camelize = cacheStringFunction((str) => {
|
|
488
|
+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
489
|
+
});
|
|
490
|
+
function getLifeCycleTarget(target) {
|
|
491
|
+
return target || null;
|
|
486
492
|
}
|
|
493
|
+
// @__NO_SIDE_EFFECTS__
|
|
487
494
|
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
488
495
|
return createFilterWrapper(
|
|
489
496
|
debounceFilter(ms, options),
|
|
@@ -491,13 +498,14 @@ function useDebounceFn(fn, ms = 200, options = {}) {
|
|
|
491
498
|
);
|
|
492
499
|
}
|
|
493
500
|
function refDebounced(value, ms = 200, options = {}) {
|
|
494
|
-
const debounced = ref(value
|
|
495
|
-
const updater = useDebounceFn(() => {
|
|
501
|
+
const debounced = ref(toValue$1(value));
|
|
502
|
+
const updater = /* @__PURE__ */ useDebounceFn(() => {
|
|
496
503
|
debounced.value = value.value;
|
|
497
504
|
}, ms, options);
|
|
498
505
|
watch(value, () => updater());
|
|
499
|
-
return debounced;
|
|
506
|
+
return shallowReadonly(debounced);
|
|
500
507
|
}
|
|
508
|
+
// @__NO_SIDE_EFFECTS__
|
|
501
509
|
function refDefault(source, defaultValue) {
|
|
502
510
|
return computed({
|
|
503
511
|
get() {
|
|
@@ -509,6 +517,7 @@ function refDefault(source, defaultValue) {
|
|
|
509
517
|
}
|
|
510
518
|
});
|
|
511
519
|
}
|
|
520
|
+
// @__NO_SIDE_EFFECTS__
|
|
512
521
|
function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
|
|
513
522
|
return createFilterWrapper(
|
|
514
523
|
throttleFilter(ms, trailing, leading, rejectOnCancel),
|
|
@@ -518,13 +527,14 @@ function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnC
|
|
|
518
527
|
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
519
528
|
if (delay <= 0)
|
|
520
529
|
return value;
|
|
521
|
-
const throttled = ref(value
|
|
522
|
-
const updater = useThrottleFn(() => {
|
|
530
|
+
const throttled = ref(toValue$1(value));
|
|
531
|
+
const updater = /* @__PURE__ */ useThrottleFn(() => {
|
|
523
532
|
throttled.value = value.value;
|
|
524
533
|
}, delay, trailing, leading);
|
|
525
534
|
watch(value, () => updater());
|
|
526
535
|
return throttled;
|
|
527
536
|
}
|
|
537
|
+
// @__NO_SIDE_EFFECTS__
|
|
528
538
|
function refWithControl(initial, options = {}) {
|
|
529
539
|
let source = initial;
|
|
530
540
|
let track;
|
|
@@ -701,7 +711,10 @@ function toRefs(objectRef, options = {}) {
|
|
|
701
711
|
const toValue = toValue$1;
|
|
702
712
|
const resolveUnref = toValue$1;
|
|
703
713
|
function tryOnMounted(fn, sync = true, target) {
|
|
704
|
-
|
|
714
|
+
const instance = getLifeCycleTarget(target);
|
|
715
|
+
if (instance)
|
|
716
|
+
;
|
|
717
|
+
else if (sync)
|
|
705
718
|
fn();
|
|
706
719
|
else
|
|
707
720
|
nextTick(fn);
|
|
@@ -833,6 +846,7 @@ function until(r) {
|
|
|
833
846
|
function defaultComparator(value, othVal) {
|
|
834
847
|
return value === othVal;
|
|
835
848
|
}
|
|
849
|
+
// @__NO_SIDE_EFFECTS__
|
|
836
850
|
function useArrayDifference(...args) {
|
|
837
851
|
var _a, _b;
|
|
838
852
|
const list = args[0];
|
|
@@ -853,17 +867,21 @@ function useArrayDifference(...args) {
|
|
|
853
867
|
return diff1;
|
|
854
868
|
}
|
|
855
869
|
}
|
|
870
|
+
// @__NO_SIDE_EFFECTS__
|
|
856
871
|
function useArrayEvery(list, fn) {
|
|
857
872
|
return computed(() => toValue$1(list).every((element, index, array) => fn(toValue$1(element), index, array)));
|
|
858
873
|
}
|
|
874
|
+
// @__NO_SIDE_EFFECTS__
|
|
859
875
|
function useArrayFilter(list, fn) {
|
|
860
876
|
return computed(() => toValue$1(list).map((i) => toValue$1(i)).filter(fn));
|
|
861
877
|
}
|
|
878
|
+
// @__NO_SIDE_EFFECTS__
|
|
862
879
|
function useArrayFind(list, fn) {
|
|
863
880
|
return computed(() => toValue$1(
|
|
864
881
|
toValue$1(list).find((element, index, array) => fn(toValue$1(element), index, array))
|
|
865
882
|
));
|
|
866
883
|
}
|
|
884
|
+
// @__NO_SIDE_EFFECTS__
|
|
867
885
|
function useArrayFindIndex(list, fn) {
|
|
868
886
|
return computed(() => toValue$1(list).findIndex((element, index, array) => fn(toValue$1(element), index, array)));
|
|
869
887
|
}
|
|
@@ -875,6 +893,7 @@ function findLast(arr, cb) {
|
|
|
875
893
|
}
|
|
876
894
|
return void 0;
|
|
877
895
|
}
|
|
896
|
+
// @__NO_SIDE_EFFECTS__
|
|
878
897
|
function useArrayFindLast(list, fn) {
|
|
879
898
|
return computed(() => toValue$1(
|
|
880
899
|
!Array.prototype.findLast ? findLast(toValue$1(list), (element, index, array) => fn(toValue$1(element), index, array)) : toValue$1(list).findLast((element, index, array) => fn(toValue$1(element), index, array))
|
|
@@ -883,6 +902,7 @@ function useArrayFindLast(list, fn) {
|
|
|
883
902
|
function isArrayIncludesOptions(obj) {
|
|
884
903
|
return isObject(obj) && containsProp(obj, "formIndex", "comparator");
|
|
885
904
|
}
|
|
905
|
+
// @__NO_SIDE_EFFECTS__
|
|
886
906
|
function useArrayIncludes(...args) {
|
|
887
907
|
var _a;
|
|
888
908
|
const list = args[0];
|
|
@@ -905,12 +925,15 @@ function useArrayIncludes(...args) {
|
|
|
905
925
|
toValue$1(array)
|
|
906
926
|
)));
|
|
907
927
|
}
|
|
928
|
+
// @__NO_SIDE_EFFECTS__
|
|
908
929
|
function useArrayJoin(list, separator) {
|
|
909
930
|
return computed(() => toValue$1(list).map((i) => toValue$1(i)).join(toValue$1(separator)));
|
|
910
931
|
}
|
|
932
|
+
// @__NO_SIDE_EFFECTS__
|
|
911
933
|
function useArrayMap(list, fn) {
|
|
912
934
|
return computed(() => toValue$1(list).map((i) => toValue$1(i)).map(fn));
|
|
913
935
|
}
|
|
936
|
+
// @__NO_SIDE_EFFECTS__
|
|
914
937
|
function useArrayReduce(list, reducer, ...args) {
|
|
915
938
|
const reduceCallback = (sum, value, index) => reducer(toValue$1(sum), toValue$1(value), index);
|
|
916
939
|
return computed(() => {
|
|
@@ -918,6 +941,7 @@ function useArrayReduce(list, reducer, ...args) {
|
|
|
918
941
|
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue$1(args[0]()) : toValue$1(args[0])) : resolved.reduce(reduceCallback);
|
|
919
942
|
});
|
|
920
943
|
}
|
|
944
|
+
// @__NO_SIDE_EFFECTS__
|
|
921
945
|
function useArraySome(list, fn) {
|
|
922
946
|
return computed(() => toValue$1(list).some((element, index, array) => fn(toValue$1(element), index, array)));
|
|
923
947
|
}
|
|
@@ -931,6 +955,7 @@ function uniqueElementsBy(array, fn) {
|
|
|
931
955
|
return acc;
|
|
932
956
|
}, []);
|
|
933
957
|
}
|
|
958
|
+
// @__NO_SIDE_EFFECTS__
|
|
934
959
|
function useArrayUnique(list, compareFn) {
|
|
935
960
|
return computed(() => {
|
|
936
961
|
const resolvedList = toValue$1(list).map((element) => toValue$1(element));
|
|
@@ -952,7 +977,7 @@ function useCounter(initialValue = 0, options = {}) {
|
|
|
952
977
|
_initialValue = val;
|
|
953
978
|
return set2(val);
|
|
954
979
|
};
|
|
955
|
-
return { count, inc, dec, get: get2, set: set2, reset };
|
|
980
|
+
return { count: shallowReadonly(count), inc, dec, get: get2, set: set2, reset };
|
|
956
981
|
}
|
|
957
982
|
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
958
983
|
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;
|
|
@@ -1042,6 +1067,7 @@ function normalizeDate(date) {
|
|
|
1042
1067
|
}
|
|
1043
1068
|
return new Date(date);
|
|
1044
1069
|
}
|
|
1070
|
+
// @__NO_SIDE_EFFECTS__
|
|
1045
1071
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1046
1072
|
return computed(() => formatDate(normalizeDate(toValue$1(date)), toValue$1(formatStr), options));
|
|
1047
1073
|
}
|
|
@@ -1084,7 +1110,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1084
1110
|
}
|
|
1085
1111
|
tryOnScopeDispose(pause);
|
|
1086
1112
|
return {
|
|
1087
|
-
isActive,
|
|
1113
|
+
isActive: shallowReadonly(isActive),
|
|
1088
1114
|
pause,
|
|
1089
1115
|
resume
|
|
1090
1116
|
};
|
|
@@ -1110,12 +1136,12 @@ function useInterval(interval = 1e3, options = {}) {
|
|
|
1110
1136
|
);
|
|
1111
1137
|
if (exposeControls) {
|
|
1112
1138
|
return {
|
|
1113
|
-
counter,
|
|
1139
|
+
counter: shallowReadonly(counter),
|
|
1114
1140
|
reset,
|
|
1115
1141
|
...controls
|
|
1116
1142
|
};
|
|
1117
1143
|
} else {
|
|
1118
|
-
return counter;
|
|
1144
|
+
return shallowReadonly(counter);
|
|
1119
1145
|
}
|
|
1120
1146
|
}
|
|
1121
1147
|
function useLastChanged(source, options = {}) {
|
|
@@ -1126,7 +1152,7 @@ function useLastChanged(source, options = {}) {
|
|
|
1126
1152
|
() => ms.value = timestamp(),
|
|
1127
1153
|
options
|
|
1128
1154
|
);
|
|
1129
|
-
return ms;
|
|
1155
|
+
return shallowReadonly(ms);
|
|
1130
1156
|
}
|
|
1131
1157
|
function useTimeoutFn(cb, interval, options = {}) {
|
|
1132
1158
|
const {
|
|
@@ -1134,11 +1160,11 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1134
1160
|
immediateCallback = false
|
|
1135
1161
|
} = options;
|
|
1136
1162
|
const isPending = shallowRef(false);
|
|
1137
|
-
let timer
|
|
1163
|
+
let timer;
|
|
1138
1164
|
function clear() {
|
|
1139
1165
|
if (timer) {
|
|
1140
1166
|
clearTimeout(timer);
|
|
1141
|
-
timer =
|
|
1167
|
+
timer = void 0;
|
|
1142
1168
|
}
|
|
1143
1169
|
}
|
|
1144
1170
|
function stop() {
|
|
@@ -1152,7 +1178,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1152
1178
|
isPending.value = true;
|
|
1153
1179
|
timer = setTimeout(() => {
|
|
1154
1180
|
isPending.value = false;
|
|
1155
|
-
timer =
|
|
1181
|
+
timer = void 0;
|
|
1156
1182
|
cb(...args);
|
|
1157
1183
|
}, toValue$1(interval));
|
|
1158
1184
|
}
|
|
@@ -1163,7 +1189,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1163
1189
|
}
|
|
1164
1190
|
tryOnScopeDispose(stop);
|
|
1165
1191
|
return {
|
|
1166
|
-
isPending:
|
|
1192
|
+
isPending: shallowReadonly(isPending),
|
|
1167
1193
|
start,
|
|
1168
1194
|
stop
|
|
1169
1195
|
};
|
|
@@ -1188,6 +1214,7 @@ function useTimeout(interval = 1e3, options = {}) {
|
|
|
1188
1214
|
return ready;
|
|
1189
1215
|
}
|
|
1190
1216
|
}
|
|
1217
|
+
// @__NO_SIDE_EFFECTS__
|
|
1191
1218
|
function useToNumber(value, options = {}) {
|
|
1192
1219
|
const {
|
|
1193
1220
|
method = "parseFloat",
|
|
@@ -1205,9 +1232,11 @@ function useToNumber(value, options = {}) {
|
|
|
1205
1232
|
return resolved;
|
|
1206
1233
|
});
|
|
1207
1234
|
}
|
|
1235
|
+
// @__NO_SIDE_EFFECTS__
|
|
1208
1236
|
function useToString(value) {
|
|
1209
1237
|
return computed(() => `${toValue$1(value)}`);
|
|
1210
1238
|
}
|
|
1239
|
+
// @__NO_SIDE_EFFECTS__
|
|
1211
1240
|
function useToggle(initialValue = false, options = {}) {
|
|
1212
1241
|
const {
|
|
1213
1242
|
truthyValue = true,
|
|
@@ -1308,50 +1337,50 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1308
1337
|
let ignorePrevAsyncUpdates;
|
|
1309
1338
|
let stop;
|
|
1310
1339
|
if (watchOptions.flush === "sync") {
|
|
1311
|
-
|
|
1340
|
+
let ignore = false;
|
|
1312
1341
|
ignorePrevAsyncUpdates = () => {
|
|
1313
1342
|
};
|
|
1314
1343
|
ignoreUpdates = (updater) => {
|
|
1315
|
-
ignore
|
|
1344
|
+
ignore = true;
|
|
1316
1345
|
updater();
|
|
1317
|
-
ignore
|
|
1346
|
+
ignore = false;
|
|
1318
1347
|
};
|
|
1319
1348
|
stop = watch(
|
|
1320
1349
|
source,
|
|
1321
1350
|
(...args) => {
|
|
1322
|
-
if (!ignore
|
|
1351
|
+
if (!ignore)
|
|
1323
1352
|
filteredCb(...args);
|
|
1324
1353
|
},
|
|
1325
1354
|
watchOptions
|
|
1326
1355
|
);
|
|
1327
1356
|
} else {
|
|
1328
1357
|
const disposables = [];
|
|
1329
|
-
|
|
1330
|
-
|
|
1358
|
+
let ignoreCounter = 0;
|
|
1359
|
+
let syncCounter = 0;
|
|
1331
1360
|
ignorePrevAsyncUpdates = () => {
|
|
1332
|
-
ignoreCounter
|
|
1361
|
+
ignoreCounter = syncCounter;
|
|
1333
1362
|
};
|
|
1334
1363
|
disposables.push(
|
|
1335
1364
|
watch(
|
|
1336
1365
|
source,
|
|
1337
1366
|
() => {
|
|
1338
|
-
syncCounter
|
|
1367
|
+
syncCounter++;
|
|
1339
1368
|
},
|
|
1340
1369
|
{ ...watchOptions, flush: "sync" }
|
|
1341
1370
|
)
|
|
1342
1371
|
);
|
|
1343
1372
|
ignoreUpdates = (updater) => {
|
|
1344
|
-
const syncCounterPrev = syncCounter
|
|
1373
|
+
const syncCounterPrev = syncCounter;
|
|
1345
1374
|
updater();
|
|
1346
|
-
ignoreCounter
|
|
1375
|
+
ignoreCounter += syncCounter - syncCounterPrev;
|
|
1347
1376
|
};
|
|
1348
1377
|
disposables.push(
|
|
1349
1378
|
watch(
|
|
1350
1379
|
source,
|
|
1351
1380
|
(...args) => {
|
|
1352
|
-
const ignore = ignoreCounter
|
|
1353
|
-
ignoreCounter
|
|
1354
|
-
syncCounter
|
|
1381
|
+
const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
|
|
1382
|
+
ignoreCounter = 0;
|
|
1383
|
+
syncCounter = 0;
|
|
1355
1384
|
if (ignore)
|
|
1356
1385
|
return;
|
|
1357
1386
|
filteredCb(...args);
|
|
@@ -1376,11 +1405,14 @@ function watchImmediate(source, cb, options) {
|
|
|
1376
1405
|
);
|
|
1377
1406
|
}
|
|
1378
1407
|
function watchOnce(source, cb, options) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1408
|
+
return watch(
|
|
1409
|
+
source,
|
|
1410
|
+
cb,
|
|
1411
|
+
{
|
|
1412
|
+
...options,
|
|
1413
|
+
once: true
|
|
1414
|
+
}
|
|
1415
|
+
);
|
|
1384
1416
|
}
|
|
1385
1417
|
function watchThrottled(source, cb, options = {}) {
|
|
1386
1418
|
const {
|
|
@@ -1456,6 +1488,7 @@ function whenever(source, cb, options) {
|
|
|
1456
1488
|
return stop;
|
|
1457
1489
|
}
|
|
1458
1490
|
function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
1491
|
+
var _a;
|
|
1459
1492
|
let options;
|
|
1460
1493
|
if (isRef(optionsOrRef)) {
|
|
1461
1494
|
options = {
|
|
@@ -1466,9 +1499,10 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
|
1466
1499
|
}
|
|
1467
1500
|
const {
|
|
1468
1501
|
lazy = false,
|
|
1502
|
+
flush = "pre",
|
|
1469
1503
|
evaluating = void 0,
|
|
1470
1504
|
shallow = true,
|
|
1471
|
-
onError = noop
|
|
1505
|
+
onError = (_a = globalThis.reportError) != null ? _a : noop
|
|
1472
1506
|
} = options;
|
|
1473
1507
|
const started = shallowRef(!lazy);
|
|
1474
1508
|
const current = shallow ? shallowRef(initialState) : ref(initialState);
|
|
@@ -1502,7 +1536,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
|
1502
1536
|
evaluating.value = false;
|
|
1503
1537
|
hasFinished = true;
|
|
1504
1538
|
}
|
|
1505
|
-
});
|
|
1539
|
+
}, { flush });
|
|
1506
1540
|
if (lazy) {
|
|
1507
1541
|
return computed(() => {
|
|
1508
1542
|
started.value = true;
|
|
@@ -1512,6 +1546,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
|
1512
1546
|
return current;
|
|
1513
1547
|
}
|
|
1514
1548
|
}
|
|
1549
|
+
// @__NO_SIDE_EFFECTS__
|
|
1515
1550
|
function createUnrefFn(fn) {
|
|
1516
1551
|
return function(...args) {
|
|
1517
1552
|
return fn.apply(this, args.map((i) => toValue$1(i)));
|
|
@@ -1570,12 +1605,14 @@ function useEventListener(...args) {
|
|
|
1570
1605
|
tryOnScopeDispose(cleanup);
|
|
1571
1606
|
return stop;
|
|
1572
1607
|
}
|
|
1608
|
+
// @__NO_SIDE_EFFECTS__
|
|
1573
1609
|
function useMounted() {
|
|
1574
1610
|
const isMounted = shallowRef(false);
|
|
1575
1611
|
return isMounted;
|
|
1576
1612
|
}
|
|
1613
|
+
// @__NO_SIDE_EFFECTS__
|
|
1577
1614
|
function useSupported(callback) {
|
|
1578
|
-
const isMounted = useMounted();
|
|
1615
|
+
const isMounted = /* @__PURE__ */ useMounted();
|
|
1579
1616
|
return computed(() => {
|
|
1580
1617
|
isMounted.value;
|
|
1581
1618
|
return Boolean(callback());
|
|
@@ -1709,10 +1746,11 @@ function whenAborted(signal) {
|
|
|
1709
1746
|
});
|
|
1710
1747
|
}
|
|
1711
1748
|
function useAsyncState(promise, initialState, options) {
|
|
1749
|
+
var _a;
|
|
1712
1750
|
const {
|
|
1713
1751
|
immediate = true,
|
|
1714
1752
|
delay = 0,
|
|
1715
|
-
onError = noop,
|
|
1753
|
+
onError = (_a = globalThis.reportError) != null ? _a : noop,
|
|
1716
1754
|
onSuccess = noop,
|
|
1717
1755
|
resetOnExecute = true,
|
|
1718
1756
|
shallow = true,
|
|
@@ -1724,7 +1762,7 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1724
1762
|
const error = shallowRef(void 0);
|
|
1725
1763
|
async function execute(delay2 = 0, ...args) {
|
|
1726
1764
|
if (resetOnExecute)
|
|
1727
|
-
state.value = initialState;
|
|
1765
|
+
state.value = toValue$1(initialState);
|
|
1728
1766
|
error.value = void 0;
|
|
1729
1767
|
isReady.value = false;
|
|
1730
1768
|
isLoading.value = true;
|
|
@@ -1754,7 +1792,8 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1754
1792
|
isReady,
|
|
1755
1793
|
isLoading,
|
|
1756
1794
|
error,
|
|
1757
|
-
execute
|
|
1795
|
+
execute,
|
|
1796
|
+
executeImmediate: (...args) => execute(0, ...args)
|
|
1758
1797
|
};
|
|
1759
1798
|
function waitUntilIsLoaded() {
|
|
1760
1799
|
return new Promise((resolve, reject) => {
|
|
@@ -1870,7 +1909,7 @@ function useBroadcastChannel(options) {
|
|
|
1870
1909
|
name,
|
|
1871
1910
|
window: window2 = defaultWindow
|
|
1872
1911
|
} = options;
|
|
1873
|
-
const isSupported = useSupported(() => window2 && "BroadcastChannel" in window2);
|
|
1912
|
+
const isSupported = /* @__PURE__ */ useSupported(() => window2 && "BroadcastChannel" in window2);
|
|
1874
1913
|
const isClosed = shallowRef(false);
|
|
1875
1914
|
const channel = ref();
|
|
1876
1915
|
const data = ref();
|
|
@@ -1917,7 +1956,7 @@ function useBroadcastChannel(options) {
|
|
|
1917
1956
|
}
|
|
1918
1957
|
function useCached(refValue, comparator = (a, b) => a === b, options) {
|
|
1919
1958
|
const { deepRefs = true, ...watchOptions } = options || {};
|
|
1920
|
-
const cachedValue = createRef(refValue.value, deepRefs);
|
|
1959
|
+
const cachedValue = /* @__PURE__ */ createRef(refValue.value, deepRefs);
|
|
1921
1960
|
watch(() => refValue.value, (value) => {
|
|
1922
1961
|
if (!comparator(value, cachedValue.value))
|
|
1923
1962
|
cachedValue.value = value;
|
|
@@ -2093,7 +2132,8 @@ function useRefHistory(source, options = {}) {
|
|
|
2093
2132
|
const {
|
|
2094
2133
|
deep = false,
|
|
2095
2134
|
flush = "pre",
|
|
2096
|
-
eventFilter
|
|
2135
|
+
eventFilter,
|
|
2136
|
+
shouldCommit = () => true
|
|
2097
2137
|
} = options;
|
|
2098
2138
|
const {
|
|
2099
2139
|
eventFilter: composedFilter,
|
|
@@ -2101,6 +2141,7 @@ function useRefHistory(source, options = {}) {
|
|
|
2101
2141
|
resume: resumeTracking,
|
|
2102
2142
|
isActive: isTracking
|
|
2103
2143
|
} = pausableFilter(eventFilter);
|
|
2144
|
+
let lastRawValue = source.value;
|
|
2104
2145
|
const {
|
|
2105
2146
|
ignoreUpdates,
|
|
2106
2147
|
ignorePrevAsyncUpdates,
|
|
@@ -2114,12 +2155,16 @@ function useRefHistory(source, options = {}) {
|
|
|
2114
2155
|
ignorePrevAsyncUpdates();
|
|
2115
2156
|
ignoreUpdates(() => {
|
|
2116
2157
|
source2.value = value;
|
|
2158
|
+
lastRawValue = value;
|
|
2117
2159
|
});
|
|
2118
2160
|
}
|
|
2119
2161
|
const manualHistory = useManualRefHistory(source, { ...options, clone: options.clone || deep, setSource });
|
|
2120
2162
|
const { clear, commit: manualCommit } = manualHistory;
|
|
2121
2163
|
function commit() {
|
|
2122
2164
|
ignorePrevAsyncUpdates();
|
|
2165
|
+
if (!shouldCommit(lastRawValue, source.value))
|
|
2166
|
+
return;
|
|
2167
|
+
lastRawValue = source.value;
|
|
2123
2168
|
manualCommit();
|
|
2124
2169
|
}
|
|
2125
2170
|
function resume(commitNow) {
|
|
@@ -2158,6 +2203,7 @@ function useDebouncedRefHistory(source, options = {}) {
|
|
|
2158
2203
|
};
|
|
2159
2204
|
}
|
|
2160
2205
|
const events = /* @__PURE__ */ new Map();
|
|
2206
|
+
// @__NO_SIDE_EFFECTS__
|
|
2161
2207
|
function useEventBus(key) {
|
|
2162
2208
|
const scope = getCurrentScope();
|
|
2163
2209
|
function on(listener) {
|
|
@@ -2279,7 +2325,7 @@ function createFetch(config = {}) {
|
|
|
2279
2325
|
return useFactoryFetch;
|
|
2280
2326
|
}
|
|
2281
2327
|
function useFetch(url, ...args) {
|
|
2282
|
-
var _a;
|
|
2328
|
+
var _a, _b;
|
|
2283
2329
|
const supportsAbort = typeof AbortController === "function";
|
|
2284
2330
|
let fetchOptions = {};
|
|
2285
2331
|
let options = {
|
|
@@ -2304,13 +2350,13 @@ function useFetch(url, ...args) {
|
|
|
2304
2350
|
options = { ...options, ...args[1] };
|
|
2305
2351
|
}
|
|
2306
2352
|
const {
|
|
2307
|
-
fetch = (_a = defaultWindow) == null ? void 0 : _a.fetch,
|
|
2353
|
+
fetch = (_b = (_a = defaultWindow) == null ? void 0 : _a.fetch) != null ? _b : globalThis == null ? void 0 : globalThis.fetch,
|
|
2308
2354
|
initialData,
|
|
2309
2355
|
timeout
|
|
2310
2356
|
} = options;
|
|
2311
|
-
const responseEvent = createEventHook();
|
|
2312
|
-
const errorEvent = createEventHook();
|
|
2313
|
-
const finallyEvent = createEventHook();
|
|
2357
|
+
const responseEvent = /* @__PURE__ */ createEventHook();
|
|
2358
|
+
const errorEvent = /* @__PURE__ */ createEventHook();
|
|
2359
|
+
const finallyEvent = /* @__PURE__ */ createEventHook();
|
|
2314
2360
|
const isFinished = shallowRef(false);
|
|
2315
2361
|
const isFetching = shallowRef(false);
|
|
2316
2362
|
const aborted = shallowRef(false);
|
|
@@ -2321,9 +2367,9 @@ function useFetch(url, ...args) {
|
|
|
2321
2367
|
const canAbort = computed(() => supportsAbort && isFetching.value);
|
|
2322
2368
|
let controller;
|
|
2323
2369
|
let timer;
|
|
2324
|
-
const abort = () => {
|
|
2370
|
+
const abort = (reason) => {
|
|
2325
2371
|
if (supportsAbort) {
|
|
2326
|
-
controller == null ? void 0 : controller.abort();
|
|
2372
|
+
controller == null ? void 0 : controller.abort(reason);
|
|
2327
2373
|
controller = new AbortController();
|
|
2328
2374
|
controller.signal.onabort = () => aborted.value = true;
|
|
2329
2375
|
fetchOptions = {
|
|
@@ -2340,7 +2386,7 @@ function useFetch(url, ...args) {
|
|
|
2340
2386
|
timer = useTimeoutFn(abort, timeout, { immediate: false });
|
|
2341
2387
|
let executeCounter = 0;
|
|
2342
2388
|
const execute = async (throwOnFailed = false) => {
|
|
2343
|
-
var _a2,
|
|
2389
|
+
var _a2, _b2;
|
|
2344
2390
|
abort();
|
|
2345
2391
|
loading(true);
|
|
2346
2392
|
error.value = null;
|
|
@@ -2389,7 +2435,7 @@ function useFetch(url, ...args) {
|
|
|
2389
2435
|
...context.options,
|
|
2390
2436
|
headers: {
|
|
2391
2437
|
...headersToObject(defaultFetchOptions.headers),
|
|
2392
|
-
...headersToObject((
|
|
2438
|
+
...headersToObject((_b2 = context.options) == null ? void 0 : _b2.headers)
|
|
2393
2439
|
}
|
|
2394
2440
|
}
|
|
2395
2441
|
).then(async (fetchResponse) => {
|
|
@@ -2574,7 +2620,8 @@ function useIdle(timeout = oneMinute, options = {}) {
|
|
|
2574
2620
|
onEvent();
|
|
2575
2621
|
}, listenerOptions);
|
|
2576
2622
|
}
|
|
2577
|
-
|
|
2623
|
+
if (!initialState)
|
|
2624
|
+
reset();
|
|
2578
2625
|
}
|
|
2579
2626
|
return {
|
|
2580
2627
|
idle,
|
|
@@ -2582,14 +2629,16 @@ function useIdle(timeout = oneMinute, options = {}) {
|
|
|
2582
2629
|
reset
|
|
2583
2630
|
};
|
|
2584
2631
|
}
|
|
2632
|
+
// @__NO_SIDE_EFFECTS__
|
|
2585
2633
|
function useNow(options = {}) {
|
|
2586
2634
|
const {
|
|
2587
2635
|
controls: exposeControls = false,
|
|
2588
|
-
interval = "requestAnimationFrame"
|
|
2636
|
+
interval = "requestAnimationFrame",
|
|
2637
|
+
immediate = true
|
|
2589
2638
|
} = options;
|
|
2590
2639
|
const now2 = ref(/* @__PURE__ */ new Date());
|
|
2591
2640
|
const update = () => now2.value = /* @__PURE__ */ new Date();
|
|
2592
|
-
const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate
|
|
2641
|
+
const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate }) : useIntervalFn(update, interval, { immediate });
|
|
2593
2642
|
if (exposeControls) {
|
|
2594
2643
|
return {
|
|
2595
2644
|
now: now2,
|
|
@@ -2618,6 +2667,7 @@ function useObjectUrl(object) {
|
|
|
2618
2667
|
tryOnScopeDispose(release);
|
|
2619
2668
|
return readonly(url);
|
|
2620
2669
|
}
|
|
2670
|
+
// @__NO_SIDE_EFFECTS__
|
|
2621
2671
|
function useClamp(value, min, max) {
|
|
2622
2672
|
if (typeof value === "function" || isReadonly(value))
|
|
2623
2673
|
return computed(() => clamp(toValue$1(value), toValue$1(min), toValue$1(max)));
|
|
@@ -2640,12 +2690,12 @@ function useOffsetPagination(options) {
|
|
|
2640
2690
|
onPageSizeChange = noop,
|
|
2641
2691
|
onPageCountChange = noop
|
|
2642
2692
|
} = options;
|
|
2643
|
-
const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
|
|
2693
|
+
const currentPageSize = /* @__PURE__ */ useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
|
|
2644
2694
|
const pageCount = computed(() => Math.max(
|
|
2645
2695
|
1,
|
|
2646
2696
|
Math.ceil(toValue$1(total) / toValue$1(currentPageSize))
|
|
2647
2697
|
));
|
|
2648
|
-
const currentPage = useClamp(page, 1, pageCount);
|
|
2698
|
+
const currentPage = /* @__PURE__ */ useClamp(page, 1, pageCount);
|
|
2649
2699
|
const isFirstPage = computed(() => currentPage.value === 1);
|
|
2650
2700
|
const isLastPage = computed(() => currentPage.value === pageCount.value);
|
|
2651
2701
|
if (isRef(page)) {
|
|
@@ -2728,6 +2778,7 @@ function useSorted(...args) {
|
|
|
2728
2778
|
});
|
|
2729
2779
|
return source;
|
|
2730
2780
|
}
|
|
2781
|
+
// @__NO_SIDE_EFFECTS__
|
|
2731
2782
|
function useStepper(steps, initialStep) {
|
|
2732
2783
|
const stepsRef = ref(steps);
|
|
2733
2784
|
const stepNames = computed(() => Array.isArray(stepsRef.value) ? stepsRef.value : Object.keys(stepsRef.value));
|
|
@@ -2835,12 +2886,13 @@ const DEFAULT_MESSAGES = {
|
|
|
2835
2886
|
function DEFAULT_FORMATTER(date) {
|
|
2836
2887
|
return date.toISOString().slice(0, 10);
|
|
2837
2888
|
}
|
|
2889
|
+
// @__NO_SIDE_EFFECTS__
|
|
2838
2890
|
function useTimeAgo(time, options = {}) {
|
|
2839
2891
|
const {
|
|
2840
2892
|
controls: exposeControls = false,
|
|
2841
2893
|
updateInterval = 3e4
|
|
2842
2894
|
} = options;
|
|
2843
|
-
const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
|
|
2895
|
+
const { now: now2, ...controls } = /* @__PURE__ */ useNow({ interval: updateInterval, controls: true });
|
|
2844
2896
|
const timeAgo = computed(() => formatTimeAgo(new Date(toValue$1(time)), options, toValue$1(now2)));
|
|
2845
2897
|
if (exposeControls) {
|
|
2846
2898
|
return {
|
|
@@ -2961,7 +3013,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2961
3013
|
removeFalsyValues = false,
|
|
2962
3014
|
write: enableWrite = true,
|
|
2963
3015
|
writeMode = "replace",
|
|
2964
|
-
window: window2 = defaultWindow
|
|
3016
|
+
window: window2 = defaultWindow,
|
|
3017
|
+
stringify = (params) => params.toString()
|
|
2965
3018
|
} = options;
|
|
2966
3019
|
if (!window2)
|
|
2967
3020
|
return reactive(initialValue);
|
|
@@ -2978,7 +3031,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2978
3031
|
}
|
|
2979
3032
|
}
|
|
2980
3033
|
function constructQuery(params) {
|
|
2981
|
-
const stringified = params
|
|
3034
|
+
const stringified = stringify(params);
|
|
2982
3035
|
if (mode === "history")
|
|
2983
3036
|
return `${stringified ? `?${stringified}` : ""}${window2.location.hash || ""}`;
|
|
2984
3037
|
if (mode === "hash-params")
|
|
@@ -3020,7 +3073,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
3020
3073
|
},
|
|
3021
3074
|
{ deep: true }
|
|
3022
3075
|
);
|
|
3023
|
-
function write(params, shouldUpdate) {
|
|
3076
|
+
function write(params, shouldUpdate, shouldWriteHistory = true) {
|
|
3024
3077
|
pause();
|
|
3025
3078
|
if (shouldUpdate)
|
|
3026
3079
|
updateState(params);
|
|
@@ -3031,18 +3084,20 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
3031
3084
|
window2.location.pathname + constructQuery(params)
|
|
3032
3085
|
);
|
|
3033
3086
|
} else {
|
|
3034
|
-
|
|
3035
|
-
window2.history.
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3087
|
+
if (shouldWriteHistory) {
|
|
3088
|
+
window2.history.pushState(
|
|
3089
|
+
window2.history.state,
|
|
3090
|
+
window2.document.title,
|
|
3091
|
+
window2.location.pathname + constructQuery(params)
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3039
3094
|
}
|
|
3040
|
-
resume();
|
|
3095
|
+
nextTick(() => resume());
|
|
3041
3096
|
}
|
|
3042
3097
|
function onChanged() {
|
|
3043
3098
|
if (!enableWrite)
|
|
3044
3099
|
return;
|
|
3045
|
-
write(read(), true);
|
|
3100
|
+
write(read(), true, false);
|
|
3046
3101
|
}
|
|
3047
3102
|
const listenerOptions = { passive: true };
|
|
3048
3103
|
useEventListener(window2, "popstate", onChanged, listenerOptions);
|