@vueuse/shared 6.7.6 → 6.9.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/index.mjs CHANGED
@@ -162,6 +162,12 @@ function createGlobalState(stateFactory) {
162
162
  };
163
163
  }
164
164
 
165
+ function reactify(fn) {
166
+ return function(...args) {
167
+ return computed(() => fn.apply(this, args.map((i) => unref(i))));
168
+ };
169
+ }
170
+
165
171
  function tryOnScopeDispose(fn) {
166
172
  if (getCurrentScope()) {
167
173
  onScopeDispose(fn);
@@ -226,15 +232,35 @@ function createFilterWrapper(filter, fn) {
226
232
  const bypassFilter = (invoke) => {
227
233
  return invoke();
228
234
  };
229
- function debounceFilter(ms) {
235
+ function debounceFilter(ms, options = {}) {
230
236
  let timer;
237
+ let maxTimer;
231
238
  const filter = (invoke) => {
232
239
  const duration = unref(ms);
240
+ const maxDuration = unref(options.maxWait);
233
241
  if (timer)
234
242
  clearTimeout(timer);
235
- if (duration <= 0)
243
+ if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
244
+ if (maxTimer) {
245
+ clearTimeout(maxTimer);
246
+ maxTimer = null;
247
+ }
236
248
  return invoke();
237
- timer = setTimeout(invoke, duration);
249
+ }
250
+ if (maxDuration && !maxTimer) {
251
+ maxTimer = setTimeout(() => {
252
+ if (timer)
253
+ clearTimeout(timer);
254
+ maxTimer = null;
255
+ invoke();
256
+ }, maxDuration);
257
+ }
258
+ timer = setTimeout(() => {
259
+ if (maxTimer)
260
+ clearTimeout(maxTimer);
261
+ maxTimer = null;
262
+ invoke();
263
+ }, duration);
238
264
  };
239
265
  return filter;
240
266
  }
@@ -344,17 +370,32 @@ function objectPick(obj, keys, omitUndefined = false) {
344
370
  }, {});
345
371
  }
346
372
 
347
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
348
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
349
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
373
+ function useDebounceFn(fn, ms = 200, options = {}) {
374
+ return createFilterWrapper(debounceFilter(ms, options), fn);
375
+ }
376
+
377
+ function useDebounce(value, ms = 200, options = {}) {
378
+ if (ms <= 0)
379
+ return value;
380
+ const debounced = ref(value.value);
381
+ const updater = useDebounceFn(() => {
382
+ debounced.value = value.value;
383
+ }, ms, options);
384
+ watch(value, () => updater());
385
+ return debounced;
386
+ }
387
+
388
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
389
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
390
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
350
391
  var __objRest$5 = (source, exclude) => {
351
392
  var target = {};
352
393
  for (var prop in source)
353
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
394
+ if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
354
395
  target[prop] = source[prop];
355
- if (source != null && __getOwnPropSymbols$8)
356
- for (var prop of __getOwnPropSymbols$8(source)) {
357
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
396
+ if (source != null && __getOwnPropSymbols$9)
397
+ for (var prop of __getOwnPropSymbols$9(source)) {
398
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
358
399
  target[prop] = source[prop];
359
400
  }
360
401
  return target;
@@ -368,33 +409,33 @@ function watchWithFilter(source, cb, options = {}) {
368
409
  return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
369
410
  }
370
411
 
371
- var __defProp$6 = Object.defineProperty;
372
- var __defProps$3 = Object.defineProperties;
373
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
374
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
375
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
376
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
377
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
378
- var __spreadValues$6 = (a, b) => {
412
+ var __defProp$7 = Object.defineProperty;
413
+ var __defProps$4 = Object.defineProperties;
414
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
415
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
416
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
417
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
418
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
419
+ var __spreadValues$7 = (a, b) => {
379
420
  for (var prop in b || (b = {}))
380
- if (__hasOwnProp$7.call(b, prop))
381
- __defNormalProp$6(a, prop, b[prop]);
382
- if (__getOwnPropSymbols$7)
383
- for (var prop of __getOwnPropSymbols$7(b)) {
384
- if (__propIsEnum$7.call(b, prop))
385
- __defNormalProp$6(a, prop, b[prop]);
421
+ if (__hasOwnProp$8.call(b, prop))
422
+ __defNormalProp$7(a, prop, b[prop]);
423
+ if (__getOwnPropSymbols$8)
424
+ for (var prop of __getOwnPropSymbols$8(b)) {
425
+ if (__propIsEnum$8.call(b, prop))
426
+ __defNormalProp$7(a, prop, b[prop]);
386
427
  }
387
428
  return a;
388
429
  };
389
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
430
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
390
431
  var __objRest$4 = (source, exclude) => {
391
432
  var target = {};
392
433
  for (var prop in source)
393
- if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
434
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
394
435
  target[prop] = source[prop];
395
- if (source != null && __getOwnPropSymbols$7)
396
- for (var prop of __getOwnPropSymbols$7(source)) {
397
- if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
436
+ if (source != null && __getOwnPropSymbols$8)
437
+ for (var prop of __getOwnPropSymbols$8(source)) {
438
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
398
439
  target[prop] = source[prop];
399
440
  }
400
441
  return target;
@@ -405,7 +446,7 @@ function debouncedWatch(source, cb, options = {}) {
405
446
  } = _a, watchOptions = __objRest$4(_a, [
406
447
  "debounce"
407
448
  ]);
408
- return watchWithFilter(source, cb, __spreadProps$3(__spreadValues$6({}, watchOptions), {
449
+ return watchWithFilter(source, cb, __spreadProps$4(__spreadValues$7({}, watchOptions), {
409
450
  eventFilter: debounceFilter(debounce)
410
451
  }));
411
452
  }
@@ -424,33 +465,33 @@ function get(obj, key) {
424
465
  return unref(obj)[key];
425
466
  }
426
467
 
427
- var __defProp$5 = Object.defineProperty;
428
- var __defProps$2 = Object.defineProperties;
429
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
430
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
431
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
432
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
433
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
434
- var __spreadValues$5 = (a, b) => {
468
+ var __defProp$6 = Object.defineProperty;
469
+ var __defProps$3 = Object.defineProperties;
470
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
471
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
472
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
473
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
474
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
475
+ var __spreadValues$6 = (a, b) => {
435
476
  for (var prop in b || (b = {}))
436
- if (__hasOwnProp$6.call(b, prop))
437
- __defNormalProp$5(a, prop, b[prop]);
438
- if (__getOwnPropSymbols$6)
439
- for (var prop of __getOwnPropSymbols$6(b)) {
440
- if (__propIsEnum$6.call(b, prop))
441
- __defNormalProp$5(a, prop, b[prop]);
477
+ if (__hasOwnProp$7.call(b, prop))
478
+ __defNormalProp$6(a, prop, b[prop]);
479
+ if (__getOwnPropSymbols$7)
480
+ for (var prop of __getOwnPropSymbols$7(b)) {
481
+ if (__propIsEnum$7.call(b, prop))
482
+ __defNormalProp$6(a, prop, b[prop]);
442
483
  }
443
484
  return a;
444
485
  };
445
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
486
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
446
487
  var __objRest$3 = (source, exclude) => {
447
488
  var target = {};
448
489
  for (var prop in source)
449
- if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
490
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
450
491
  target[prop] = source[prop];
451
- if (source != null && __getOwnPropSymbols$6)
452
- for (var prop of __getOwnPropSymbols$6(source)) {
453
- if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
492
+ if (source != null && __getOwnPropSymbols$7)
493
+ for (var prop of __getOwnPropSymbols$7(source)) {
494
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
454
495
  target[prop] = source[prop];
455
496
  }
456
497
  return target;
@@ -487,7 +528,7 @@ function ignorableWatch(source, cb, options = {}) {
487
528
  };
488
529
  disposables.push(watch(source, () => {
489
530
  syncCounter.value++;
490
- }, __spreadProps$2(__spreadValues$5({}, watchOptions), { flush: "sync" })));
531
+ }, __spreadProps$3(__spreadValues$6({}, watchOptions), { flush: "sync" })));
491
532
  ignoreUpdates = (updater) => {
492
533
  const syncCounterPrev = syncCounter.value;
493
534
  updater();
@@ -512,25 +553,25 @@ function isDefined(v) {
512
553
  return unref(v) != null;
513
554
  }
514
555
 
515
- var __defProp$4 = Object.defineProperty;
516
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
517
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
518
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
519
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
520
- var __spreadValues$4 = (a, b) => {
556
+ var __defProp$5 = Object.defineProperty;
557
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
558
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
559
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
560
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
561
+ var __spreadValues$5 = (a, b) => {
521
562
  for (var prop in b || (b = {}))
522
- if (__hasOwnProp$5.call(b, prop))
523
- __defNormalProp$4(a, prop, b[prop]);
524
- if (__getOwnPropSymbols$5)
525
- for (var prop of __getOwnPropSymbols$5(b)) {
526
- if (__propIsEnum$5.call(b, prop))
527
- __defNormalProp$4(a, prop, b[prop]);
563
+ if (__hasOwnProp$6.call(b, prop))
564
+ __defNormalProp$5(a, prop, b[prop]);
565
+ if (__getOwnPropSymbols$6)
566
+ for (var prop of __getOwnPropSymbols$6(b)) {
567
+ if (__propIsEnum$6.call(b, prop))
568
+ __defNormalProp$5(a, prop, b[prop]);
528
569
  }
529
570
  return a;
530
571
  };
531
572
  function makeDestructurable(obj, arr) {
532
573
  if (typeof Symbol !== "undefined") {
533
- const clone = __spreadValues$4({}, obj);
574
+ const clone = __spreadValues$5({}, obj);
534
575
  Object.defineProperty(clone, Symbol.iterator, {
535
576
  enumerable: false,
536
577
  value() {
@@ -557,33 +598,33 @@ function or(...args) {
557
598
  return computed(() => args.some((i) => unref(i)));
558
599
  }
559
600
 
560
- var __defProp$3 = Object.defineProperty;
561
- var __defProps$1 = Object.defineProperties;
562
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
563
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
564
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
565
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
566
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
567
- var __spreadValues$3 = (a, b) => {
601
+ var __defProp$4 = Object.defineProperty;
602
+ var __defProps$2 = Object.defineProperties;
603
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
604
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
605
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
606
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
607
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
608
+ var __spreadValues$4 = (a, b) => {
568
609
  for (var prop in b || (b = {}))
569
- if (__hasOwnProp$4.call(b, prop))
570
- __defNormalProp$3(a, prop, b[prop]);
571
- if (__getOwnPropSymbols$4)
572
- for (var prop of __getOwnPropSymbols$4(b)) {
573
- if (__propIsEnum$4.call(b, prop))
574
- __defNormalProp$3(a, prop, b[prop]);
610
+ if (__hasOwnProp$5.call(b, prop))
611
+ __defNormalProp$4(a, prop, b[prop]);
612
+ if (__getOwnPropSymbols$5)
613
+ for (var prop of __getOwnPropSymbols$5(b)) {
614
+ if (__propIsEnum$5.call(b, prop))
615
+ __defNormalProp$4(a, prop, b[prop]);
575
616
  }
576
617
  return a;
577
618
  };
578
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
619
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
579
620
  var __objRest$2 = (source, exclude) => {
580
621
  var target = {};
581
622
  for (var prop in source)
582
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
623
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
583
624
  target[prop] = source[prop];
584
- if (source != null && __getOwnPropSymbols$4)
585
- for (var prop of __getOwnPropSymbols$4(source)) {
586
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
625
+ if (source != null && __getOwnPropSymbols$5)
626
+ for (var prop of __getOwnPropSymbols$5(source)) {
627
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
587
628
  target[prop] = source[prop];
588
629
  }
589
630
  return target;
@@ -595,18 +636,12 @@ function pausableWatch(source, cb, options = {}) {
595
636
  "eventFilter"
596
637
  ]);
597
638
  const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
598
- const stop = watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
639
+ const stop = watchWithFilter(source, cb, __spreadProps$2(__spreadValues$4({}, watchOptions), {
599
640
  eventFilter
600
641
  }));
601
642
  return { stop, pause, resume, isActive };
602
643
  }
603
644
 
604
- function reactify(fn) {
605
- return function(...args) {
606
- return computed(() => fn.apply(this, args.map((i) => unref(i))));
607
- };
608
- }
609
-
610
645
  function reactifyObject(obj, optionsOrKeys = {}) {
611
646
  let keys = [];
612
647
  if (Array.isArray(optionsOrKeys)) {
@@ -664,42 +699,51 @@ function syncRef(source, targets, {
664
699
  } = {}) {
665
700
  if (!Array.isArray(targets))
666
701
  targets = [targets];
667
- return watch(source, (newValue) => {
668
- targets.forEach((target) => target.value = newValue);
669
- }, {
670
- flush,
671
- deep,
672
- immediate
673
- });
702
+ return watch(source, (newValue) => targets.forEach((target) => target.value = newValue), { flush, deep, immediate });
674
703
  }
675
704
 
676
- var __defProp$2 = Object.defineProperty;
677
- var __defProps = Object.defineProperties;
678
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
679
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
680
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
681
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
682
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
683
- var __spreadValues$2 = (a, b) => {
705
+ function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
706
+ return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
707
+ }
708
+
709
+ function useThrottle(value, delay = 200, trailing = true, leading = true) {
710
+ if (delay <= 0)
711
+ return value;
712
+ const throttled = ref(value.value);
713
+ const updater = useThrottleFn(() => {
714
+ throttled.value = value.value;
715
+ }, delay, trailing, leading);
716
+ watch(value, () => updater());
717
+ return throttled;
718
+ }
719
+
720
+ var __defProp$3 = Object.defineProperty;
721
+ var __defProps$1 = Object.defineProperties;
722
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
723
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
724
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
725
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
726
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
727
+ var __spreadValues$3 = (a, b) => {
684
728
  for (var prop in b || (b = {}))
685
- if (__hasOwnProp$3.call(b, prop))
686
- __defNormalProp$2(a, prop, b[prop]);
687
- if (__getOwnPropSymbols$3)
688
- for (var prop of __getOwnPropSymbols$3(b)) {
689
- if (__propIsEnum$3.call(b, prop))
690
- __defNormalProp$2(a, prop, b[prop]);
729
+ if (__hasOwnProp$4.call(b, prop))
730
+ __defNormalProp$3(a, prop, b[prop]);
731
+ if (__getOwnPropSymbols$4)
732
+ for (var prop of __getOwnPropSymbols$4(b)) {
733
+ if (__propIsEnum$4.call(b, prop))
734
+ __defNormalProp$3(a, prop, b[prop]);
691
735
  }
692
736
  return a;
693
737
  };
694
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
738
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
695
739
  var __objRest$1 = (source, exclude) => {
696
740
  var target = {};
697
741
  for (var prop in source)
698
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
742
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
699
743
  target[prop] = source[prop];
700
- if (source != null && __getOwnPropSymbols$3)
701
- for (var prop of __getOwnPropSymbols$3(source)) {
702
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
744
+ if (source != null && __getOwnPropSymbols$4)
745
+ for (var prop of __getOwnPropSymbols$4(source)) {
746
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
703
747
  target[prop] = source[prop];
704
748
  }
705
749
  return target;
@@ -714,7 +758,7 @@ function throttledWatch(source, cb, options = {}) {
714
758
  "trailing",
715
759
  "leading"
716
760
  ]);
717
- return watchWithFilter(source, cb, __spreadProps(__spreadValues$2({}, watchOptions), {
761
+ return watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
718
762
  eventFilter: throttleFilter(throttle, trailing, leading)
719
763
  }));
720
764
  }
@@ -749,6 +793,25 @@ function toReactive(objectRef) {
749
793
  return reactive(proxy);
750
794
  }
751
795
 
796
+ var __defProp$2 = Object.defineProperty;
797
+ var __defProps = Object.defineProperties;
798
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
799
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
800
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
801
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
802
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
803
+ var __spreadValues$2 = (a, b) => {
804
+ for (var prop in b || (b = {}))
805
+ if (__hasOwnProp$3.call(b, prop))
806
+ __defNormalProp$2(a, prop, b[prop]);
807
+ if (__getOwnPropSymbols$3)
808
+ for (var prop of __getOwnPropSymbols$3(b)) {
809
+ if (__propIsEnum$3.call(b, prop))
810
+ __defNormalProp$2(a, prop, b[prop]);
811
+ }
812
+ return a;
813
+ };
814
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
752
815
  function toRefs(objectRef) {
753
816
  if (!isRef(objectRef))
754
817
  return toRefs$1(objectRef);
@@ -759,7 +822,13 @@ function toRefs(objectRef) {
759
822
  return objectRef.value[key];
760
823
  },
761
824
  set(v) {
762
- objectRef.value[key] = v;
825
+ if (Array.isArray(objectRef.value)) {
826
+ const copy = [...objectRef.value];
827
+ copy[key] = v;
828
+ objectRef.value = copy;
829
+ } else {
830
+ objectRef.value = __spreadProps(__spreadValues$2({}, objectRef.value), { [key]: v });
831
+ }
763
832
  }
764
833
  }));
765
834
  }
@@ -871,10 +940,14 @@ function until(r) {
871
940
  }
872
941
  }
873
942
 
874
- function useCounter(initialValue = 0) {
943
+ function useCounter(initialValue = 0, options = {}) {
875
944
  const count = ref(initialValue);
876
- const inc = (delta = 1) => count.value += delta;
877
- const dec = (delta = 1) => count.value -= delta;
945
+ const {
946
+ max = Infinity,
947
+ min = -Infinity
948
+ } = options;
949
+ const inc = (delta = 1) => count.value = Math.min(max, count.value + delta);
950
+ const dec = (delta = 1) => count.value = Math.max(min, count.value - delta);
878
951
  const get = () => count.value;
879
952
  const set = (val) => count.value = val;
880
953
  const reset = (val = initialValue) => {
@@ -884,21 +957,6 @@ function useCounter(initialValue = 0) {
884
957
  return { count, inc, dec, get, set, reset };
885
958
  }
886
959
 
887
- function useDebounceFn(fn, ms = 200) {
888
- return createFilterWrapper(debounceFilter(ms), fn);
889
- }
890
-
891
- function useDebounce(value, ms = 200) {
892
- if (ms <= 0)
893
- return value;
894
- const debounced = ref(value.value);
895
- const updater = useDebounceFn(() => {
896
- debounced.value = value.value;
897
- }, ms);
898
- watch(value, () => updater());
899
- return debounced;
900
- }
901
-
902
960
  function useIntervalFn(cb, interval = 1e3, options = {}) {
903
961
  const {
904
962
  immediate = true,
@@ -974,21 +1032,6 @@ function useLastChanged(source, options = {}) {
974
1032
  return ms;
975
1033
  }
976
1034
 
977
- function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
978
- return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
979
- }
980
-
981
- function useThrottle(value, delay = 200, trailing = true, leading = true) {
982
- if (delay <= 0)
983
- return value;
984
- const throttled = ref(value.value);
985
- const updater = useThrottleFn(() => {
986
- throttled.value = value.value;
987
- }, delay, trailing, leading);
988
- watch(value, () => updater());
989
- return throttled;
990
- }
991
-
992
1035
  function useTimeoutFn(cb, interval, options = {}) {
993
1036
  const {
994
1037
  immediate = true
@@ -1117,4 +1160,4 @@ function whenever(source, cb, options) {
1117
1160
  }, options);
1118
1161
  }
1119
1162
 
1120
- export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
1163
+ export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, useDebounce as debouncedRef, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, useThrottle as throttledRef, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/shared",
3
- "version": "6.7.6",
3
+ "version": "6.9.2",
4
4
  "keywords": [
5
5
  "vue",
6
6
  "vue-use",