@vueuse/components 10.4.0 → 10.5.0

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
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, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
3
- import { toValue, isClient, noop, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, toRef, tryOnMounted, useToggle, notNullish, promiseTimeout, until, useDebounceFn, useThrottleFn } from '@vueuse/shared';
3
+ import { toValue, isClient, noop, isObject, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, toRef, tryOnMounted, useToggle, notNullish, promiseTimeout, until, useDebounceFn, useThrottleFn } from '@vueuse/shared';
4
4
 
5
5
  const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
6
6
  name: "OnClickOutside",
@@ -19,8 +19,9 @@ const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
19
19
  });
20
20
 
21
21
  function unrefElement(elRef) {
22
+ var _a;
22
23
  const plain = toValue(elRef);
23
- return plain?.$el ?? plain;
24
+ return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
24
25
  }
25
26
 
26
27
  const defaultWindow = isClient ? window : void 0;
@@ -57,9 +58,10 @@ function useEventListener(...args) {
57
58
  cleanup();
58
59
  if (!el)
59
60
  return;
61
+ const optionsClone = isObject(options2) ? { ...options2 } : options2;
60
62
  cleanups.push(
61
63
  ...events.flatMap((event) => {
62
- return listeners.map((listener) => register(el, event, listener, options2));
64
+ return listeners.map((listener) => register(el, event, listener, optionsClone));
63
65
  })
64
66
  );
65
67
  },
@@ -115,8 +117,9 @@ function onClickOutside(target, handler, options = {}) {
115
117
  }, { passive: true }),
116
118
  detectIframe && useEventListener(window, "blur", (event) => {
117
119
  setTimeout(() => {
120
+ var _a;
118
121
  const el = unrefElement(target);
119
- if (window.document.activeElement?.tagName === "IFRAME" && !el?.contains(window.document.activeElement))
122
+ if (((_a = window.document.activeElement) == null ? void 0 : _a.tagName) === "IFRAME" && !(el == null ? void 0 : el.contains(window.document.activeElement)))
120
123
  handler(event);
121
124
  }, 0);
122
125
  })
@@ -188,7 +191,8 @@ function onKeyStroke(...args) {
188
191
 
189
192
  const vOnKeyStroke = {
190
193
  [directiveHooks.mounted](el, binding) {
191
- const keys = binding.arg?.split(",") ?? true;
194
+ var _a, _b;
195
+ const keys = (_b = (_a = binding.arg) == null ? void 0 : _a.split(",")) != null ? _b : true;
192
196
  if (typeof binding.value === "function") {
193
197
  onKeyStroke(keys, binding.value, {
194
198
  target: el
@@ -205,6 +209,7 @@ const vOnKeyStroke = {
205
209
 
206
210
  const DEFAULT_DELAY = 500;
207
211
  function onLongPress(target, handler, options) {
212
+ var _a, _b;
208
213
  const elementRef = computed(() => unrefElement(target));
209
214
  let timeout;
210
215
  function clear() {
@@ -214,21 +219,22 @@ function onLongPress(target, handler, options) {
214
219
  }
215
220
  }
216
221
  function onDown(ev) {
217
- if (options?.modifiers?.self && ev.target !== elementRef.value)
222
+ var _a2, _b2, _c, _d;
223
+ if (((_a2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _a2.self) && ev.target !== elementRef.value)
218
224
  return;
219
225
  clear();
220
- if (options?.modifiers?.prevent)
226
+ if ((_b2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _b2.prevent)
221
227
  ev.preventDefault();
222
- if (options?.modifiers?.stop)
228
+ if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
223
229
  ev.stopPropagation();
224
230
  timeout = setTimeout(
225
231
  () => handler(ev),
226
- options?.delay ?? DEFAULT_DELAY
232
+ (_d = options == null ? void 0 : options.delay) != null ? _d : DEFAULT_DELAY
227
233
  );
228
234
  }
229
235
  const listenerOptions = {
230
- capture: options?.modifiers?.capture,
231
- once: options?.modifiers?.once
236
+ capture: (_a = options == null ? void 0 : options.modifiers) == null ? void 0 : _a.capture,
237
+ once: (_b = options == null ? void 0 : options.modifiers) == null ? void 0 : _b.once
232
238
  };
233
239
  useEventListener(elementRef, "pointerdown", onDown, listenerOptions);
234
240
  useEventListener(elementRef, ["pointerup", "pointerleave"], clear, listenerOptions);
@@ -350,6 +356,7 @@ const StorageSerializers = {
350
356
  };
351
357
  const customStorageEventName = "vueuse-storage";
352
358
  function useStorage(key, defaults, storage, options = {}) {
359
+ var _a;
353
360
  const {
354
361
  flush = "pre",
355
362
  deep = true,
@@ -366,7 +373,10 @@ function useStorage(key, defaults, storage, options = {}) {
366
373
  const data = (shallow ? shallowRef : ref)(defaults);
367
374
  if (!storage) {
368
375
  try {
369
- storage = getSSRHandler("getDefaultStorage", () => defaultWindow?.localStorage)();
376
+ storage = getSSRHandler("getDefaultStorage", () => {
377
+ var _a2;
378
+ return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
379
+ })();
370
380
  } catch (e) {
371
381
  onError(e);
372
382
  }
@@ -375,7 +385,7 @@ function useStorage(key, defaults, storage, options = {}) {
375
385
  return data;
376
386
  const rawInit = toValue(defaults);
377
387
  const type = guessSerializerType(rawInit);
378
- const serializer = options.serializer ?? StorageSerializers[type];
388
+ const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
379
389
  const { pause: pauseWatch, resume: resumeWatch } = pausableWatch(
380
390
  data,
381
391
  () => write(data.value),
@@ -445,7 +455,7 @@ function useStorage(key, defaults, storage, options = {}) {
445
455
  return;
446
456
  pauseWatch();
447
457
  try {
448
- if (event?.newValue !== serializer.write(data.value))
458
+ if ((event == null ? void 0 : event.newValue) !== serializer.write(data.value))
449
459
  data.value = read(event);
450
460
  } catch (e) {
451
461
  onError(e);
@@ -537,13 +547,11 @@ function useColorMode(options = {}) {
537
547
  const preferredDark = usePreferredDark({ window });
538
548
  const system = computed(() => preferredDark.value ? "dark" : "light");
539
549
  const store = storageRef || (storageKey == null ? toRef(initialValue) : useStorage(storageKey, initialValue, storage, { window, listenToStorageChanges }));
540
- const state = computed(
541
- () => store.value === "auto" ? system.value : store.value
542
- );
550
+ const state = computed(() => store.value === "auto" ? system.value : store.value);
543
551
  const updateHTMLAttrs = getSSRHandler(
544
552
  "updateHTMLAttrs",
545
553
  (selector2, attribute2, value) => {
546
- const el = typeof selector2 === "string" ? window?.document.querySelector(selector2) : unrefElement(selector2);
554
+ const el = typeof selector2 === "string" ? window == null ? void 0 : window.document.querySelector(selector2) : unrefElement(selector2);
547
555
  if (!el)
548
556
  return;
549
557
  let style;
@@ -571,7 +579,8 @@ function useColorMode(options = {}) {
571
579
  }
572
580
  );
573
581
  function defaultOnChanged(mode) {
574
- updateHTMLAttrs(selector, attribute, modes[mode] ?? mode);
582
+ var _a;
583
+ updateHTMLAttrs(selector, attribute, (_a = modes[mode]) != null ? _a : mode);
575
584
  }
576
585
  function onChanged(mode) {
577
586
  if (options.onChanged)
@@ -708,7 +717,10 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
708
717
  ],
709
718
  setup(props, { slots }) {
710
719
  const target = ref();
711
- const handle = computed(() => props.handle ?? target.value);
720
+ const handle = computed(() => {
721
+ var _a;
722
+ return (_a = props.handle) != null ? _a : target.value;
723
+ });
712
724
  const storageValue = props.storageKey && useStorage$1(
713
725
  props.storageKey,
714
726
  toValue(props.initialValue) || { x: 0, y: 0 },
@@ -716,7 +728,8 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
716
728
  );
717
729
  const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
718
730
  const onEnd = (position, event) => {
719
- props.onEnd?.(position, event);
731
+ var _a;
732
+ (_a = props.onEnd) == null ? void 0 : _a.call(props, position, event);
720
733
  if (!storageValue)
721
734
  return;
722
735
  storageValue.value.x = position.x;
@@ -806,9 +819,7 @@ function useResizeObserver(target, callback, options = {}) {
806
819
  observer = void 0;
807
820
  }
808
821
  };
809
- const targets = computed(
810
- () => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]
811
- );
822
+ const targets = computed(() => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]);
812
823
  const stopWatch = watch(
813
824
  targets,
814
825
  (els) => {
@@ -834,7 +845,10 @@ function useResizeObserver(target, callback, options = {}) {
834
845
 
835
846
  function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
836
847
  const { window = defaultWindow, box = "content-box" } = options;
837
- const isSVG = computed(() => unrefElement(target)?.namespaceURI?.includes("svg"));
848
+ const isSVG = computed(() => {
849
+ var _a, _b;
850
+ return (_b = (_a = unrefElement(target)) == null ? void 0 : _a.namespaceURI) == null ? void 0 : _b.includes("svg");
851
+ });
838
852
  const width = ref(initialSize.width);
839
853
  const height = ref(initialSize.height);
840
854
  useResizeObserver(
@@ -876,7 +890,8 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
876
890
 
877
891
  const vElementSize = {
878
892
  [directiveHooks.mounted](el, binding) {
879
- const handler = typeof binding.value === "function" ? binding.value : binding.value?.[0];
893
+ var _a;
894
+ const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ? void 0 : _a[0];
880
895
  const options = typeof binding.value === "function" ? [] : binding.value.slice(1);
881
896
  const { width, height } = useElementSize(el, ...options);
882
897
  watch([width, height], ([width2, height2]) => handler({ width: width2, height: height2 }));
@@ -957,7 +972,8 @@ function useIntersectionObserver(target, callback, options = {}) {
957
972
  };
958
973
  }
959
974
 
960
- function useElementVisibility(element, { window = defaultWindow, scrollTarget } = {}) {
975
+ function useElementVisibility(element, options = {}) {
976
+ const { window = defaultWindow, scrollTarget } = options;
961
977
  const elementIsVisible = ref(false);
962
978
  useIntersectionObserver(
963
979
  element,
@@ -1047,7 +1063,7 @@ function useAsyncState(promise, initialState, options) {
1047
1063
  resetOnExecute = true,
1048
1064
  shallow = true,
1049
1065
  throwError
1050
- } = options ?? {};
1066
+ } = options != null ? options : {};
1051
1067
  const state = shallow ? shallowRef(initialState) : ref(initialState);
1052
1068
  const isReady = ref(false);
1053
1069
  const isLoading = ref(false);
@@ -1202,14 +1218,15 @@ function useScroll(element, options = {}) {
1202
1218
  }
1203
1219
  });
1204
1220
  function scrollTo(_x, _y) {
1221
+ var _a, _b, _c;
1205
1222
  if (!window)
1206
1223
  return;
1207
1224
  const _element = toValue(element);
1208
1225
  if (!_element)
1209
1226
  return;
1210
- (_element instanceof Document ? window.document.body : _element)?.scrollTo({
1211
- top: toValue(_y) ?? y.value,
1212
- left: toValue(_x) ?? x.value,
1227
+ (_c = _element instanceof Document ? window.document.body : _element) == null ? void 0 : _c.scrollTo({
1228
+ top: (_a = toValue(_y)) != null ? _a : y.value,
1229
+ left: (_b = toValue(_x)) != null ? _b : x.value,
1213
1230
  behavior: toValue(behavior)
1214
1231
  });
1215
1232
  }
@@ -1238,9 +1255,10 @@ function useScroll(element, options = {}) {
1238
1255
  };
1239
1256
  const onScrollEndDebounced = useDebounceFn(onScrollEnd, throttle + idle);
1240
1257
  const setArrivedState = (target) => {
1258
+ var _a;
1241
1259
  if (!window)
1242
1260
  return;
1243
- const el = target.document ? target.document.documentElement : target.documentElement ?? target;
1261
+ const el = target.document ? target.document.documentElement : (_a = target.documentElement) != null ? _a : target;
1244
1262
  const { display, flexDirection } = getComputedStyle(el);
1245
1263
  const scrollLeft = el.scrollLeft;
1246
1264
  directions.left = scrollLeft < internalX.value;
@@ -1272,9 +1290,10 @@ function useScroll(element, options = {}) {
1272
1290
  internalY.value = scrollTop;
1273
1291
  };
1274
1292
  const onScrollHandler = (e) => {
1293
+ var _a;
1275
1294
  if (!window)
1276
1295
  return;
1277
- const eventTarget = e.target.documentElement ?? e.target;
1296
+ const eventTarget = (_a = e.target.documentElement) != null ? _a : e.target;
1278
1297
  setArrivedState(eventTarget);
1279
1298
  isScrolling.value = true;
1280
1299
  onScrollEndDebounced(e);
@@ -1315,6 +1334,7 @@ function resolveElement(el) {
1315
1334
  }
1316
1335
 
1317
1336
  function useInfiniteScroll(element, onLoadMore, options = {}) {
1337
+ var _a;
1318
1338
  const {
1319
1339
  direction = "bottom",
1320
1340
  interval = 100
@@ -1324,7 +1344,7 @@ function useInfiniteScroll(element, onLoadMore, options = {}) {
1324
1344
  {
1325
1345
  ...options,
1326
1346
  offset: {
1327
- [direction]: options.distance ?? 0,
1347
+ [direction]: (_a = options.distance) != null ? _a : 0,
1328
1348
  ...options.offset
1329
1349
  }
1330
1350
  }
@@ -1476,15 +1496,18 @@ const UseOffsetPagination = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
1476
1496
  const data = reactive(useOffsetPagination({
1477
1497
  ...props,
1478
1498
  onPageChange(...args) {
1479
- props.onPageChange?.(...args);
1499
+ var _a;
1500
+ (_a = props.onPageChange) == null ? void 0 : _a.call(props, ...args);
1480
1501
  emit("page-change", ...args);
1481
1502
  },
1482
1503
  onPageSizeChange(...args) {
1483
- props.onPageSizeChange?.(...args);
1504
+ var _a;
1505
+ (_a = props.onPageSizeChange) == null ? void 0 : _a.call(props, ...args);
1484
1506
  emit("page-size-change", ...args);
1485
1507
  },
1486
1508
  onPageCountChange(...args) {
1487
- props.onPageCountChange?.(...args);
1509
+ var _a;
1510
+ (_a = props.onPageCountChange) == null ? void 0 : _a.call(props, ...args);
1488
1511
  emit("page-count-change", ...args);
1489
1512
  }
1490
1513
  }));
@@ -1654,12 +1677,16 @@ function useMutationObserver(target, callback, options = {}) {
1654
1677
  function useCssVar(prop, target, options = {}) {
1655
1678
  const { window = defaultWindow, initialValue = "", observe = false } = options;
1656
1679
  const variable = ref(initialValue);
1657
- const elRef = computed(() => unrefElement(target) || window?.document?.documentElement);
1680
+ const elRef = computed(() => {
1681
+ var _a;
1682
+ return unrefElement(target) || ((_a = window == null ? void 0 : window.document) == null ? void 0 : _a.documentElement);
1683
+ });
1658
1684
  function updateCssVar() {
1685
+ var _a;
1659
1686
  const key = toValue(prop);
1660
1687
  const el = toValue(elRef);
1661
1688
  if (el && window) {
1662
- const value = window.getComputedStyle(el).getPropertyValue(key)?.trim();
1689
+ const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
1663
1690
  variable.value = value || initialValue;
1664
1691
  }
1665
1692
  }
@@ -1677,7 +1704,8 @@ function useCssVar(prop, target, options = {}) {
1677
1704
  watch(
1678
1705
  variable,
1679
1706
  (val) => {
1680
- if (elRef.value?.style)
1707
+ var _a;
1708
+ if ((_a = elRef.value) == null ? void 0 : _a.style)
1681
1709
  elRef.value.style.setProperty(toValue(prop), val);
1682
1710
  }
1683
1711
  );
@@ -1774,11 +1802,13 @@ const vScroll = {
1774
1802
  const state = useScroll(el, {
1775
1803
  ...options,
1776
1804
  onScroll(e) {
1777
- options.onScroll?.(e);
1805
+ var _a;
1806
+ (_a = options.onScroll) == null ? void 0 : _a.call(options, e);
1778
1807
  handler(state);
1779
1808
  },
1780
1809
  onStop(e) {
1781
- options.onStop?.(e);
1810
+ var _a;
1811
+ (_a = options.onStop) == null ? void 0 : _a.call(options, e);
1782
1812
  handler(state);
1783
1813
  }
1784
1814
  });
@@ -1844,7 +1874,7 @@ function useScrollLock(element, initialState = false) {
1844
1874
  const el = resolveElement(toValue(element));
1845
1875
  if (!el || !isLocked.value)
1846
1876
  return;
1847
- isIOS && stopTouchMoveListener?.();
1877
+ isIOS && (stopTouchMoveListener == null ? void 0 : stopTouchMoveListener());
1848
1878
  el.style.overflow = initialOverflow;
1849
1879
  isLocked.value = false;
1850
1880
  };
@@ -1912,21 +1942,9 @@ const UseVirtualList = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
1912
1942
  const { list, containerProps, wrapperProps, scrollTo } = useVirtualList(listRef, props.options);
1913
1943
  expose({ scrollTo });
1914
1944
  typeof containerProps.style === "object" && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || "300px");
1915
- return () => h(
1916
- "div",
1917
- { ...containerProps },
1918
- [
1919
- h(
1920
- "div",
1921
- { ...wrapperProps.value },
1922
- list.value.map((item) => h(
1923
- "div",
1924
- { style: { overFlow: "hidden", height: item.height } },
1925
- slots.default ? slots.default(item) : "Please set content!"
1926
- ))
1927
- )
1928
- ]
1929
- );
1945
+ return () => h("div", { ...containerProps }, [
1946
+ h("div", { ...wrapperProps.value }, list.value.map((item) => h("div", { style: { overFlow: "hidden", height: item.height } }, slots.default ? slots.default(item) : "Please set content!")))
1947
+ ]);
1930
1948
  }
1931
1949
  });
1932
1950
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/components",
3
- "version": "10.4.0",
3
+ "version": "10.5.0",
4
4
  "description": "Renderless components for VueUse",
5
5
  "author": "Jacob Clevenger<https://github.com/wheatjs>",
6
6
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "jsdelivr": "./index.iife.min.js",
33
33
  "types": "./index.d.cts",
34
34
  "dependencies": {
35
- "@vueuse/core": "10.4.0",
36
- "@vueuse/shared": "10.4.0",
37
- "vue-demi": ">=0.14.5"
35
+ "@vueuse/core": "10.5.0",
36
+ "@vueuse/shared": "10.5.0",
37
+ "vue-demi": ">=0.14.6"
38
38
  }
39
39
  }