@vueuse/components 10.0.0-beta.3 → 10.0.0-beta.5

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
@@ -1,6 +1,6 @@
1
- import { defineComponent, ref, h, watch, computed, reactive, shallowRef, nextTick, getCurrentInstance, onMounted, watchEffect, toRef, toRefs } from 'vue-demi';
1
+ import { defineComponent, ref, h, watch, computed, reactive, shallowRef, nextTick, getCurrentInstance, onMounted, watchEffect, toRefs } from 'vue-demi';
2
2
  import { onClickOutside as onClickOutside$1, useActiveElement, useBattery, useBrowserLocation, useDark, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDocumentVisibility, useStorage as useStorage$1, isClient as isClient$1, useDraggable, useElementBounding, useElementSize as useElementSize$1, useElementVisibility as useElementVisibility$1, useEyeDropper, useFullscreen, useGeolocation, useIdle, useMouse, useMouseInElement, useMousePressed, useNetwork, useNow, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, usePointer, usePointerLock, usePreferredColorScheme, usePreferredContrast, usePreferredDark as usePreferredDark$1, usePreferredLanguages, usePreferredReducedMotion, useMutationObserver, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
3
- import { resolveUnref, isClient, isString, noop, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, isFunction, resolveRef, tryOnMounted, useToggle, promiseTimeout, useDebounceFn, useThrottleFn } from '@vueuse/shared';
3
+ import { toValue, isClient, noop, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, toRef, tryOnMounted, useToggle, promiseTimeout, useDebounceFn, useThrottleFn } from '@vueuse/shared';
4
4
 
5
5
  const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
6
6
  name: "OnClickOutside",
@@ -20,7 +20,7 @@ const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
20
20
 
21
21
  function unrefElement(elRef) {
22
22
  var _a;
23
- const plain = resolveUnref(elRef);
23
+ const plain = toValue(elRef);
24
24
  return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
25
25
  }
26
26
 
@@ -31,7 +31,7 @@ function useEventListener(...args) {
31
31
  let events;
32
32
  let listeners;
33
33
  let options;
34
- if (isString(args[0]) || Array.isArray(args[0])) {
34
+ if (typeof args[0] === "string" || Array.isArray(args[0])) {
35
35
  [events, listeners, options] = args;
36
36
  target = defaultWindow;
37
37
  } else {
@@ -53,7 +53,7 @@ function useEventListener(...args) {
53
53
  return () => el.removeEventListener(event, listener, options2);
54
54
  };
55
55
  const stopWatch = watch(
56
- () => [unrefElement(target), resolveUnref(options)],
56
+ () => [unrefElement(target), toValue(options)],
57
57
  ([el, options2]) => {
58
58
  cleanup();
59
59
  if (!el)
@@ -177,7 +177,7 @@ function onKeyStroke(...args) {
177
177
  } = options;
178
178
  const predicate = createKeyPredicate(key);
179
179
  const listener = (e) => {
180
- if (e.repeat && resolveUnref(dedupe))
180
+ if (e.repeat && toValue(dedupe))
181
181
  return;
182
182
  if (predicate(e))
183
183
  handler(e);
@@ -318,8 +318,12 @@ const UseBrowserLocation = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
318
318
 
319
319
  const _global = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
320
320
  const globalKey = "__vueuse_ssr_handlers__";
321
- _global[globalKey] = _global[globalKey] || {};
322
- const handlers = _global[globalKey];
321
+ const handlers = /* @__PURE__ */ getHandlers();
322
+ function getHandlers() {
323
+ if (!(globalKey in _global))
324
+ _global[globalKey] = _global[globalKey] || {};
325
+ return _global[globalKey];
326
+ }
323
327
  function getSSRHandler(key, fallback) {
324
328
  return handlers[key] || fallback;
325
329
  }
@@ -407,7 +411,7 @@ function useStorage(key, defaults, storage, options = {}) {
407
411
  }
408
412
  if (!storage)
409
413
  return data;
410
- const rawInit = resolveUnref(defaults);
414
+ const rawInit = toValue(defaults);
411
415
  const type = guessSerializerType(rawInit);
412
416
  const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
413
417
  const { pause: pauseWatch, resume: resumeWatch } = pausableWatch(
@@ -454,7 +458,7 @@ function useStorage(key, defaults, storage, options = {}) {
454
458
  return rawInit;
455
459
  } else if (!event && mergeDefaults) {
456
460
  const value = serializer.read(rawValue);
457
- if (isFunction(mergeDefaults))
461
+ if (typeof mergeDefaults === "function")
458
462
  return mergeDefaults(value, rawInit);
459
463
  else if (type === "object" && !Array.isArray(value))
460
464
  return __spreadValues$c(__spreadValues$c({}, rawInit), value);
@@ -526,7 +530,7 @@ function useMediaQuery(query, options = {}) {
526
530
  if (!isSupported.value)
527
531
  return;
528
532
  cleanup();
529
- mediaQuery = window.matchMedia(resolveRef(query).value);
533
+ mediaQuery = window.matchMedia(toRef(query).value);
530
534
  matches.value = !!(mediaQuery == null ? void 0 : mediaQuery.matches);
531
535
  if (!mediaQuery)
532
536
  return;
@@ -571,8 +575,7 @@ function useColorMode(options = {}) {
571
575
  listenToStorageChanges = true,
572
576
  storageRef,
573
577
  emitAuto,
574
- // TODO: switch to true in v10
575
- disableTransition = false
578
+ disableTransition = true
576
579
  } = options;
577
580
  const modes = __spreadValues$b({
578
581
  auto: "",
@@ -580,11 +583,11 @@ function useColorMode(options = {}) {
580
583
  dark: "dark"
581
584
  }, options.modes || {});
582
585
  const preferredDark = usePreferredDark({ window });
583
- const preferredMode = computed(() => preferredDark.value ? "dark" : "light");
586
+ const system = computed(() => preferredDark.value ? "dark" : "light");
584
587
  const store = storageRef || (storageKey == null ? ref(initialValue) : useStorage(storageKey, initialValue, storage, { window, listenToStorageChanges }));
585
588
  const state = computed({
586
589
  get() {
587
- return store.value === "auto" && !emitAuto ? preferredMode.value : store.value;
590
+ return store.value === "auto" && !emitAuto ? system.value : store.value;
588
591
  },
589
592
  set(v) {
590
593
  store.value = v;
@@ -593,13 +596,12 @@ function useColorMode(options = {}) {
593
596
  const updateHTMLAttrs = getSSRHandler(
594
597
  "updateHTMLAttrs",
595
598
  (selector2, attribute2, value) => {
596
- const el = window == null ? void 0 : window.document.querySelector(selector2);
599
+ const el = typeof selector2 === "string" ? window == null ? void 0 : window.document.querySelector(selector2) : toValue(selector2);
597
600
  if (!el)
598
601
  return;
599
602
  let style;
600
603
  if (disableTransition) {
601
604
  style = window.document.createElement("style");
602
- style.type = "text/css";
603
605
  style.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}"));
604
606
  window.document.head.appendChild(style);
605
607
  }
@@ -622,7 +624,7 @@ function useColorMode(options = {}) {
622
624
  );
623
625
  function defaultOnChanged(mode) {
624
626
  var _a;
625
- const resolvedMode = mode === "auto" ? preferredMode.value : mode;
627
+ const resolvedMode = mode === "auto" ? system.value : mode;
626
628
  updateHTMLAttrs(selector, attribute, (_a = modes[resolvedMode]) != null ? _a : resolvedMode);
627
629
  }
628
630
  function onChanged(mode) {
@@ -633,9 +635,13 @@ function useColorMode(options = {}) {
633
635
  }
634
636
  watch(state, onChanged, { flush: "post", immediate: true });
635
637
  if (emitAuto)
636
- watch(preferredMode, () => onChanged(state.value), { flush: "post" });
638
+ watch(system, () => onChanged(state.value), { flush: "post" });
637
639
  tryOnMounted(() => onChanged(state.value));
638
- return state;
640
+ try {
641
+ return Object.assign(state, { store, system });
642
+ } catch (e) {
643
+ return state;
644
+ }
639
645
  }
640
646
 
641
647
  const UseColorMode = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
@@ -644,7 +650,9 @@ const UseColorMode = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
644
650
  setup(props, { slots }) {
645
651
  const mode = useColorMode(props);
646
652
  const data = reactive({
647
- mode
653
+ mode,
654
+ system: mode.system,
655
+ store: mode.store
648
656
  });
649
657
  return () => {
650
658
  if (slots.default)
@@ -770,7 +778,7 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
770
778
  });
771
779
  const storageValue = props.storageKey && useStorage$1(
772
780
  props.storageKey,
773
- resolveUnref(props.initialValue) || { x: 0, y: 0 },
781
+ toValue(props.initialValue) || { x: 0, y: 0 },
774
782
  isClient$1 ? props.storageType === "session" ? sessionStorage : localStorage : void 0
775
783
  );
776
784
  const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
@@ -979,23 +987,24 @@ function useIntersectionObserver(target, callback, options = {}) {
979
987
  root,
980
988
  rootMargin = "0px",
981
989
  threshold = 0.1,
982
- window = defaultWindow
990
+ window = defaultWindow,
991
+ immediate = true
983
992
  } = options;
984
993
  const isSupported = useSupported(() => window && "IntersectionObserver" in window);
985
994
  let cleanup = noop;
995
+ const isActive = ref(immediate);
986
996
  const stopWatch = isSupported.value ? watch(
987
- () => ({
988
- el: unrefElement(target),
989
- root: unrefElement(root)
990
- }),
991
- ({ el, root: root2 }) => {
997
+ () => [unrefElement(target), unrefElement(root), isActive.value],
998
+ ([el, root2]) => {
992
999
  cleanup();
1000
+ if (!isActive.value)
1001
+ return;
993
1002
  if (!el)
994
1003
  return;
995
1004
  const observer = new IntersectionObserver(
996
1005
  callback,
997
1006
  {
998
- root: root2,
1007
+ root: unrefElement(root2),
999
1008
  rootMargin,
1000
1009
  threshold
1001
1010
  }
@@ -1006,15 +1015,24 @@ function useIntersectionObserver(target, callback, options = {}) {
1006
1015
  cleanup = noop;
1007
1016
  };
1008
1017
  },
1009
- { immediate: true, flush: "post" }
1018
+ { immediate, flush: "post" }
1010
1019
  ) : noop;
1011
1020
  const stop = () => {
1012
1021
  cleanup();
1013
1022
  stopWatch();
1023
+ isActive.value = false;
1014
1024
  };
1015
1025
  tryOnScopeDispose(stop);
1016
1026
  return {
1017
1027
  isSupported,
1028
+ isActive,
1029
+ pause() {
1030
+ cleanup();
1031
+ isActive.value = false;
1032
+ },
1033
+ resume() {
1034
+ isActive.value = true;
1035
+ },
1018
1036
  stop
1019
1037
  };
1020
1038
  }
@@ -1179,14 +1197,14 @@ async function loadImage(options) {
1179
1197
  }
1180
1198
  function useImage(options, asyncStateOptions = {}) {
1181
1199
  const state = useAsyncState(
1182
- () => loadImage(resolveUnref(options)),
1200
+ () => loadImage(toValue(options)),
1183
1201
  void 0,
1184
1202
  __spreadValues$9({
1185
1203
  resetOnExecute: true
1186
1204
  }, asyncStateOptions)
1187
1205
  );
1188
1206
  watch(
1189
- () => resolveUnref(options),
1207
+ () => toValue(options),
1190
1208
  () => state.execute(asyncStateOptions.delay),
1191
1209
  { deep: true }
1192
1210
  );
@@ -1254,13 +1272,13 @@ function useScroll(element, options = {}) {
1254
1272
  });
1255
1273
  function scrollTo(_x, _y) {
1256
1274
  var _a, _b, _c;
1257
- const _element = resolveUnref(element);
1275
+ const _element = toValue(element);
1258
1276
  if (!_element)
1259
1277
  return;
1260
1278
  (_c = _element instanceof Document ? document.body : _element) == null ? void 0 : _c.scrollTo({
1261
- top: (_a = resolveUnref(_y)) != null ? _a : y.value,
1262
- left: (_b = resolveUnref(_x)) != null ? _b : x.value,
1263
- behavior: resolveUnref(behavior)
1279
+ top: (_a = toValue(_y)) != null ? _a : y.value,
1280
+ left: (_b = toValue(_x)) != null ? _b : x.value,
1281
+ behavior: toValue(behavior)
1264
1282
  });
1265
1283
  }
1266
1284
  const isScrolling = ref(false);
@@ -1289,19 +1307,34 @@ function useScroll(element, options = {}) {
1289
1307
  const onScrollEndDebounced = useDebounceFn(onScrollEnd, throttle + idle);
1290
1308
  const onScrollHandler = (e) => {
1291
1309
  const eventTarget = e.target === document ? e.target.documentElement : e.target;
1310
+ const { display, flexDirection } = getComputedStyle(eventTarget);
1292
1311
  const scrollLeft = eventTarget.scrollLeft;
1293
1312
  directions.left = scrollLeft < internalX.value;
1294
- directions.right = scrollLeft > internalY.value;
1295
- arrivedState.left = scrollLeft <= 0 + (offset.left || 0);
1296
- arrivedState.right = scrollLeft + eventTarget.clientWidth >= eventTarget.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
1313
+ directions.right = scrollLeft > internalX.value;
1314
+ const left = Math.abs(scrollLeft) <= 0 + (offset.left || 0);
1315
+ const right = Math.abs(scrollLeft) + eventTarget.clientWidth >= eventTarget.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
1316
+ if (display === "flex" && flexDirection === "row-reverse") {
1317
+ arrivedState.left = right;
1318
+ arrivedState.right = left;
1319
+ } else {
1320
+ arrivedState.left = left;
1321
+ arrivedState.right = right;
1322
+ }
1297
1323
  internalX.value = scrollLeft;
1298
1324
  let scrollTop = eventTarget.scrollTop;
1299
1325
  if (e.target === document && !scrollTop)
1300
1326
  scrollTop = document.body.scrollTop;
1301
1327
  directions.top = scrollTop < internalY.value;
1302
1328
  directions.bottom = scrollTop > internalY.value;
1303
- arrivedState.top = scrollTop <= 0 + (offset.top || 0);
1304
- arrivedState.bottom = scrollTop + eventTarget.clientHeight >= eventTarget.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
1329
+ const top = Math.abs(scrollTop) <= 0 + (offset.top || 0);
1330
+ const bottom = Math.abs(scrollTop) + eventTarget.clientHeight >= eventTarget.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
1331
+ if (display === "flex" && flexDirection === "column-reverse") {
1332
+ arrivedState.top = bottom;
1333
+ arrivedState.bottom = top;
1334
+ } else {
1335
+ arrivedState.top = top;
1336
+ arrivedState.bottom = bottom;
1337
+ }
1305
1338
  internalY.value = scrollTop;
1306
1339
  isScrolling.value = true;
1307
1340
  onScrollEndDebounced(e);
@@ -1348,38 +1381,46 @@ var __spreadValues$8 = (a, b) => {
1348
1381
  };
1349
1382
  var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1350
1383
  function useInfiniteScroll(element, onLoadMore, options = {}) {
1351
- var _a, _b;
1352
- const direction = (_a = options.direction) != null ? _a : "bottom";
1384
+ var _a;
1385
+ const {
1386
+ direction = "bottom",
1387
+ interval = 100
1388
+ } = options;
1353
1389
  const state = reactive(useScroll(
1354
1390
  element,
1355
1391
  __spreadProps$7(__spreadValues$8({}, options), {
1356
1392
  offset: __spreadValues$8({
1357
- [direction]: (_b = options.distance) != null ? _b : 0
1393
+ [direction]: (_a = options.distance) != null ? _a : 0
1358
1394
  }, options.offset)
1359
1395
  })
1360
1396
  ));
1361
- watch(
1362
- () => state.arrivedState[direction],
1363
- async (v) => {
1364
- var _a2, _b2;
1365
- if (v) {
1366
- const elem = resolveUnref(element);
1367
- const previous = {
1368
- height: (_a2 = elem == null ? void 0 : elem.scrollHeight) != null ? _a2 : 0,
1369
- width: (_b2 = elem == null ? void 0 : elem.scrollWidth) != null ? _b2 : 0
1370
- };
1371
- await onLoadMore(state);
1372
- if (options.preserveScrollPosition && elem) {
1373
- nextTick(() => {
1374
- elem.scrollTo({
1375
- top: elem.scrollHeight - previous.height,
1376
- left: elem.scrollWidth - previous.width
1377
- });
1378
- });
1379
- }
1397
+ const promise = ref();
1398
+ const isLoading = computed(() => !!promise.value);
1399
+ function checkAndLoad() {
1400
+ const el = toValue(element);
1401
+ if (!el)
1402
+ return;
1403
+ const isNarrower = direction === "bottom" || direction === "top" ? el.scrollHeight <= el.clientHeight : el.scrollWidth <= el.clientWidth;
1404
+ if (state.arrivedState[direction] || isNarrower) {
1405
+ if (!promise.value) {
1406
+ promise.value = Promise.all([
1407
+ onLoadMore(state),
1408
+ new Promise((resolve) => setTimeout(resolve, interval))
1409
+ ]).finally(() => {
1410
+ promise.value = null;
1411
+ nextTick(() => checkAndLoad());
1412
+ });
1380
1413
  }
1381
1414
  }
1415
+ }
1416
+ watch(
1417
+ () => [state.arrivedState[direction], toValue(element)],
1418
+ checkAndLoad,
1419
+ { immediate: true }
1382
1420
  );
1421
+ return {
1422
+ isLoading
1423
+ };
1383
1424
  }
1384
1425
 
1385
1426
  const vInfiniteScroll = {
@@ -1724,8 +1765,8 @@ function useCssVar(prop, target, options = {}) {
1724
1765
  });
1725
1766
  function updateCssVar() {
1726
1767
  var _a;
1727
- const key = resolveUnref(prop);
1728
- const el = resolveUnref(elRef);
1768
+ const key = toValue(prop);
1769
+ const el = toValue(elRef);
1729
1770
  if (el && window) {
1730
1771
  const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
1731
1772
  variable.value = value || initialValue;
@@ -1738,7 +1779,7 @@ function useCssVar(prop, target, options = {}) {
1738
1779
  });
1739
1780
  }
1740
1781
  watch(
1741
- [elRef, () => resolveUnref(prop)],
1782
+ [elRef, () => toValue(prop)],
1742
1783
  updateCssVar,
1743
1784
  { immediate: true }
1744
1785
  );
@@ -1747,7 +1788,7 @@ function useCssVar(prop, target, options = {}) {
1747
1788
  (val) => {
1748
1789
  var _a;
1749
1790
  if ((_a = elRef.value) == null ? void 0 : _a.style)
1750
- elRef.value.style.setProperty(resolveUnref(prop), val);
1791
+ elRef.value.style.setProperty(toValue(prop), val);
1751
1792
  }
1752
1793
  );
1753
1794
  return variable;
@@ -1901,7 +1942,7 @@ function useScrollLock(element, initialState = false) {
1901
1942
  const isLocked = ref(initialState);
1902
1943
  let stopTouchMoveListener = null;
1903
1944
  let initialOverflow;
1904
- watch(resolveRef(element), (el) => {
1945
+ watch(toRef(element), (el) => {
1905
1946
  if (el) {
1906
1947
  const ele = el;
1907
1948
  initialOverflow = ele.style.overflow;
@@ -1912,7 +1953,7 @@ function useScrollLock(element, initialState = false) {
1912
1953
  immediate: true
1913
1954
  });
1914
1955
  const lock = () => {
1915
- const ele = resolveUnref(element);
1956
+ const ele = toValue(element);
1916
1957
  if (!ele || isLocked.value)
1917
1958
  return;
1918
1959
  if (isIOS) {
@@ -1929,7 +1970,7 @@ function useScrollLock(element, initialState = false) {
1929
1970
  isLocked.value = true;
1930
1971
  };
1931
1972
  const unlock = () => {
1932
- const ele = resolveUnref(element);
1973
+ const ele = toValue(element);
1933
1974
  if (!ele || !isLocked.value)
1934
1975
  return;
1935
1976
  isIOS && (stopTouchMoveListener == null ? void 0 : stopTouchMoveListener());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/components",
3
- "version": "10.0.0-beta.3",
3
+ "version": "10.0.0-beta.5",
4
4
  "description": "Renderless components for VueUse",
5
5
  "author": "Jacob Clevenger<https://github.com/wheatjs>",
6
6
  "license": "MIT",
@@ -33,8 +33,8 @@
33
33
  "jsdelivr": "./index.iife.min.js",
34
34
  "types": "./index.d.ts",
35
35
  "dependencies": {
36
- "@vueuse/core": "10.0.0-beta.3",
37
- "@vueuse/shared": "10.0.0-beta.3",
38
- "vue-demi": "*"
36
+ "@vueuse/core": "10.0.0-beta.5",
37
+ "@vueuse/shared": "10.0.0-beta.5",
38
+ "vue-demi": ">=0.14.0"
39
39
  }
40
40
  }