@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.cjs CHANGED
@@ -21,8 +21,9 @@ const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ vueDemi.defineComponent({
21
21
  });
22
22
 
23
23
  function unrefElement(elRef) {
24
+ var _a;
24
25
  const plain = shared.toValue(elRef);
25
- return plain?.$el ?? plain;
26
+ return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
26
27
  }
27
28
 
28
29
  const defaultWindow = shared.isClient ? window : void 0;
@@ -59,9 +60,10 @@ function useEventListener(...args) {
59
60
  cleanup();
60
61
  if (!el)
61
62
  return;
63
+ const optionsClone = shared.isObject(options2) ? { ...options2 } : options2;
62
64
  cleanups.push(
63
65
  ...events.flatMap((event) => {
64
- return listeners.map((listener) => register(el, event, listener, options2));
66
+ return listeners.map((listener) => register(el, event, listener, optionsClone));
65
67
  })
66
68
  );
67
69
  },
@@ -117,8 +119,9 @@ function onClickOutside(target, handler, options = {}) {
117
119
  }, { passive: true }),
118
120
  detectIframe && useEventListener(window, "blur", (event) => {
119
121
  setTimeout(() => {
122
+ var _a;
120
123
  const el = unrefElement(target);
121
- if (window.document.activeElement?.tagName === "IFRAME" && !el?.contains(window.document.activeElement))
124
+ if (((_a = window.document.activeElement) == null ? void 0 : _a.tagName) === "IFRAME" && !(el == null ? void 0 : el.contains(window.document.activeElement)))
122
125
  handler(event);
123
126
  }, 0);
124
127
  })
@@ -190,7 +193,8 @@ function onKeyStroke(...args) {
190
193
 
191
194
  const vOnKeyStroke = {
192
195
  [shared.directiveHooks.mounted](el, binding) {
193
- const keys = binding.arg?.split(",") ?? true;
196
+ var _a, _b;
197
+ const keys = (_b = (_a = binding.arg) == null ? void 0 : _a.split(",")) != null ? _b : true;
194
198
  if (typeof binding.value === "function") {
195
199
  onKeyStroke(keys, binding.value, {
196
200
  target: el
@@ -207,6 +211,7 @@ const vOnKeyStroke = {
207
211
 
208
212
  const DEFAULT_DELAY = 500;
209
213
  function onLongPress(target, handler, options) {
214
+ var _a, _b;
210
215
  const elementRef = vueDemi.computed(() => unrefElement(target));
211
216
  let timeout;
212
217
  function clear() {
@@ -216,21 +221,22 @@ function onLongPress(target, handler, options) {
216
221
  }
217
222
  }
218
223
  function onDown(ev) {
219
- if (options?.modifiers?.self && ev.target !== elementRef.value)
224
+ var _a2, _b2, _c, _d;
225
+ if (((_a2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _a2.self) && ev.target !== elementRef.value)
220
226
  return;
221
227
  clear();
222
- if (options?.modifiers?.prevent)
228
+ if ((_b2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _b2.prevent)
223
229
  ev.preventDefault();
224
- if (options?.modifiers?.stop)
230
+ if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
225
231
  ev.stopPropagation();
226
232
  timeout = setTimeout(
227
233
  () => handler(ev),
228
- options?.delay ?? DEFAULT_DELAY
234
+ (_d = options == null ? void 0 : options.delay) != null ? _d : DEFAULT_DELAY
229
235
  );
230
236
  }
231
237
  const listenerOptions = {
232
- capture: options?.modifiers?.capture,
233
- once: options?.modifiers?.once
238
+ capture: (_a = options == null ? void 0 : options.modifiers) == null ? void 0 : _a.capture,
239
+ once: (_b = options == null ? void 0 : options.modifiers) == null ? void 0 : _b.once
234
240
  };
235
241
  useEventListener(elementRef, "pointerdown", onDown, listenerOptions);
236
242
  useEventListener(elementRef, ["pointerup", "pointerleave"], clear, listenerOptions);
@@ -352,6 +358,7 @@ const StorageSerializers = {
352
358
  };
353
359
  const customStorageEventName = "vueuse-storage";
354
360
  function useStorage(key, defaults, storage, options = {}) {
361
+ var _a;
355
362
  const {
356
363
  flush = "pre",
357
364
  deep = true,
@@ -368,7 +375,10 @@ function useStorage(key, defaults, storage, options = {}) {
368
375
  const data = (shallow ? vueDemi.shallowRef : vueDemi.ref)(defaults);
369
376
  if (!storage) {
370
377
  try {
371
- storage = getSSRHandler("getDefaultStorage", () => defaultWindow?.localStorage)();
378
+ storage = getSSRHandler("getDefaultStorage", () => {
379
+ var _a2;
380
+ return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
381
+ })();
372
382
  } catch (e) {
373
383
  onError(e);
374
384
  }
@@ -377,7 +387,7 @@ function useStorage(key, defaults, storage, options = {}) {
377
387
  return data;
378
388
  const rawInit = shared.toValue(defaults);
379
389
  const type = guessSerializerType(rawInit);
380
- const serializer = options.serializer ?? StorageSerializers[type];
390
+ const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
381
391
  const { pause: pauseWatch, resume: resumeWatch } = shared.pausableWatch(
382
392
  data,
383
393
  () => write(data.value),
@@ -447,7 +457,7 @@ function useStorage(key, defaults, storage, options = {}) {
447
457
  return;
448
458
  pauseWatch();
449
459
  try {
450
- if (event?.newValue !== serializer.write(data.value))
460
+ if ((event == null ? void 0 : event.newValue) !== serializer.write(data.value))
451
461
  data.value = read(event);
452
462
  } catch (e) {
453
463
  onError(e);
@@ -539,13 +549,11 @@ function useColorMode(options = {}) {
539
549
  const preferredDark = usePreferredDark({ window });
540
550
  const system = vueDemi.computed(() => preferredDark.value ? "dark" : "light");
541
551
  const store = storageRef || (storageKey == null ? shared.toRef(initialValue) : useStorage(storageKey, initialValue, storage, { window, listenToStorageChanges }));
542
- const state = vueDemi.computed(
543
- () => store.value === "auto" ? system.value : store.value
544
- );
552
+ const state = vueDemi.computed(() => store.value === "auto" ? system.value : store.value);
545
553
  const updateHTMLAttrs = getSSRHandler(
546
554
  "updateHTMLAttrs",
547
555
  (selector2, attribute2, value) => {
548
- const el = typeof selector2 === "string" ? window?.document.querySelector(selector2) : unrefElement(selector2);
556
+ const el = typeof selector2 === "string" ? window == null ? void 0 : window.document.querySelector(selector2) : unrefElement(selector2);
549
557
  if (!el)
550
558
  return;
551
559
  let style;
@@ -573,7 +581,8 @@ function useColorMode(options = {}) {
573
581
  }
574
582
  );
575
583
  function defaultOnChanged(mode) {
576
- updateHTMLAttrs(selector, attribute, modes[mode] ?? mode);
584
+ var _a;
585
+ updateHTMLAttrs(selector, attribute, (_a = modes[mode]) != null ? _a : mode);
577
586
  }
578
587
  function onChanged(mode) {
579
588
  if (options.onChanged)
@@ -710,7 +719,10 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ vueDemi.defineComponent({
710
719
  ],
711
720
  setup(props, { slots }) {
712
721
  const target = vueDemi.ref();
713
- const handle = vueDemi.computed(() => props.handle ?? target.value);
722
+ const handle = vueDemi.computed(() => {
723
+ var _a;
724
+ return (_a = props.handle) != null ? _a : target.value;
725
+ });
714
726
  const storageValue = props.storageKey && core.useStorage(
715
727
  props.storageKey,
716
728
  shared.toValue(props.initialValue) || { x: 0, y: 0 },
@@ -718,7 +730,8 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ vueDemi.defineComponent({
718
730
  );
719
731
  const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
720
732
  const onEnd = (position, event) => {
721
- props.onEnd?.(position, event);
733
+ var _a;
734
+ (_a = props.onEnd) == null ? void 0 : _a.call(props, position, event);
722
735
  if (!storageValue)
723
736
  return;
724
737
  storageValue.value.x = position.x;
@@ -808,9 +821,7 @@ function useResizeObserver(target, callback, options = {}) {
808
821
  observer = void 0;
809
822
  }
810
823
  };
811
- const targets = vueDemi.computed(
812
- () => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]
813
- );
824
+ const targets = vueDemi.computed(() => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]);
814
825
  const stopWatch = vueDemi.watch(
815
826
  targets,
816
827
  (els) => {
@@ -836,7 +847,10 @@ function useResizeObserver(target, callback, options = {}) {
836
847
 
837
848
  function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
838
849
  const { window = defaultWindow, box = "content-box" } = options;
839
- const isSVG = vueDemi.computed(() => unrefElement(target)?.namespaceURI?.includes("svg"));
850
+ const isSVG = vueDemi.computed(() => {
851
+ var _a, _b;
852
+ return (_b = (_a = unrefElement(target)) == null ? void 0 : _a.namespaceURI) == null ? void 0 : _b.includes("svg");
853
+ });
840
854
  const width = vueDemi.ref(initialSize.width);
841
855
  const height = vueDemi.ref(initialSize.height);
842
856
  useResizeObserver(
@@ -878,7 +892,8 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
878
892
 
879
893
  const vElementSize = {
880
894
  [shared.directiveHooks.mounted](el, binding) {
881
- const handler = typeof binding.value === "function" ? binding.value : binding.value?.[0];
895
+ var _a;
896
+ const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ? void 0 : _a[0];
882
897
  const options = typeof binding.value === "function" ? [] : binding.value.slice(1);
883
898
  const { width, height } = useElementSize(el, ...options);
884
899
  vueDemi.watch([width, height], ([width2, height2]) => handler({ width: width2, height: height2 }));
@@ -959,7 +974,8 @@ function useIntersectionObserver(target, callback, options = {}) {
959
974
  };
960
975
  }
961
976
 
962
- function useElementVisibility(element, { window = defaultWindow, scrollTarget } = {}) {
977
+ function useElementVisibility(element, options = {}) {
978
+ const { window = defaultWindow, scrollTarget } = options;
963
979
  const elementIsVisible = vueDemi.ref(false);
964
980
  useIntersectionObserver(
965
981
  element,
@@ -1049,7 +1065,7 @@ function useAsyncState(promise, initialState, options) {
1049
1065
  resetOnExecute = true,
1050
1066
  shallow = true,
1051
1067
  throwError
1052
- } = options ?? {};
1068
+ } = options != null ? options : {};
1053
1069
  const state = shallow ? vueDemi.shallowRef(initialState) : vueDemi.ref(initialState);
1054
1070
  const isReady = vueDemi.ref(false);
1055
1071
  const isLoading = vueDemi.ref(false);
@@ -1204,14 +1220,15 @@ function useScroll(element, options = {}) {
1204
1220
  }
1205
1221
  });
1206
1222
  function scrollTo(_x, _y) {
1223
+ var _a, _b, _c;
1207
1224
  if (!window)
1208
1225
  return;
1209
1226
  const _element = shared.toValue(element);
1210
1227
  if (!_element)
1211
1228
  return;
1212
- (_element instanceof Document ? window.document.body : _element)?.scrollTo({
1213
- top: shared.toValue(_y) ?? y.value,
1214
- left: shared.toValue(_x) ?? x.value,
1229
+ (_c = _element instanceof Document ? window.document.body : _element) == null ? void 0 : _c.scrollTo({
1230
+ top: (_a = shared.toValue(_y)) != null ? _a : y.value,
1231
+ left: (_b = shared.toValue(_x)) != null ? _b : x.value,
1215
1232
  behavior: shared.toValue(behavior)
1216
1233
  });
1217
1234
  }
@@ -1240,9 +1257,10 @@ function useScroll(element, options = {}) {
1240
1257
  };
1241
1258
  const onScrollEndDebounced = shared.useDebounceFn(onScrollEnd, throttle + idle);
1242
1259
  const setArrivedState = (target) => {
1260
+ var _a;
1243
1261
  if (!window)
1244
1262
  return;
1245
- const el = target.document ? target.document.documentElement : target.documentElement ?? target;
1263
+ const el = target.document ? target.document.documentElement : (_a = target.documentElement) != null ? _a : target;
1246
1264
  const { display, flexDirection } = getComputedStyle(el);
1247
1265
  const scrollLeft = el.scrollLeft;
1248
1266
  directions.left = scrollLeft < internalX.value;
@@ -1274,9 +1292,10 @@ function useScroll(element, options = {}) {
1274
1292
  internalY.value = scrollTop;
1275
1293
  };
1276
1294
  const onScrollHandler = (e) => {
1295
+ var _a;
1277
1296
  if (!window)
1278
1297
  return;
1279
- const eventTarget = e.target.documentElement ?? e.target;
1298
+ const eventTarget = (_a = e.target.documentElement) != null ? _a : e.target;
1280
1299
  setArrivedState(eventTarget);
1281
1300
  isScrolling.value = true;
1282
1301
  onScrollEndDebounced(e);
@@ -1317,6 +1336,7 @@ function resolveElement(el) {
1317
1336
  }
1318
1337
 
1319
1338
  function useInfiniteScroll(element, onLoadMore, options = {}) {
1339
+ var _a;
1320
1340
  const {
1321
1341
  direction = "bottom",
1322
1342
  interval = 100
@@ -1326,7 +1346,7 @@ function useInfiniteScroll(element, onLoadMore, options = {}) {
1326
1346
  {
1327
1347
  ...options,
1328
1348
  offset: {
1329
- [direction]: options.distance ?? 0,
1349
+ [direction]: (_a = options.distance) != null ? _a : 0,
1330
1350
  ...options.offset
1331
1351
  }
1332
1352
  }
@@ -1478,15 +1498,18 @@ const UseOffsetPagination = /* @__PURE__ */ /* #__PURE__ */ vueDemi.defineCompon
1478
1498
  const data = vueDemi.reactive(core.useOffsetPagination({
1479
1499
  ...props,
1480
1500
  onPageChange(...args) {
1481
- props.onPageChange?.(...args);
1501
+ var _a;
1502
+ (_a = props.onPageChange) == null ? void 0 : _a.call(props, ...args);
1482
1503
  emit("page-change", ...args);
1483
1504
  },
1484
1505
  onPageSizeChange(...args) {
1485
- props.onPageSizeChange?.(...args);
1506
+ var _a;
1507
+ (_a = props.onPageSizeChange) == null ? void 0 : _a.call(props, ...args);
1486
1508
  emit("page-size-change", ...args);
1487
1509
  },
1488
1510
  onPageCountChange(...args) {
1489
- props.onPageCountChange?.(...args);
1511
+ var _a;
1512
+ (_a = props.onPageCountChange) == null ? void 0 : _a.call(props, ...args);
1490
1513
  emit("page-count-change", ...args);
1491
1514
  }
1492
1515
  }));
@@ -1656,12 +1679,16 @@ function useMutationObserver(target, callback, options = {}) {
1656
1679
  function useCssVar(prop, target, options = {}) {
1657
1680
  const { window = defaultWindow, initialValue = "", observe = false } = options;
1658
1681
  const variable = vueDemi.ref(initialValue);
1659
- const elRef = vueDemi.computed(() => unrefElement(target) || window?.document?.documentElement);
1682
+ const elRef = vueDemi.computed(() => {
1683
+ var _a;
1684
+ return unrefElement(target) || ((_a = window == null ? void 0 : window.document) == null ? void 0 : _a.documentElement);
1685
+ });
1660
1686
  function updateCssVar() {
1687
+ var _a;
1661
1688
  const key = shared.toValue(prop);
1662
1689
  const el = shared.toValue(elRef);
1663
1690
  if (el && window) {
1664
- const value = window.getComputedStyle(el).getPropertyValue(key)?.trim();
1691
+ const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
1665
1692
  variable.value = value || initialValue;
1666
1693
  }
1667
1694
  }
@@ -1679,7 +1706,8 @@ function useCssVar(prop, target, options = {}) {
1679
1706
  vueDemi.watch(
1680
1707
  variable,
1681
1708
  (val) => {
1682
- if (elRef.value?.style)
1709
+ var _a;
1710
+ if ((_a = elRef.value) == null ? void 0 : _a.style)
1683
1711
  elRef.value.style.setProperty(shared.toValue(prop), val);
1684
1712
  }
1685
1713
  );
@@ -1776,11 +1804,13 @@ const vScroll = {
1776
1804
  const state = useScroll(el, {
1777
1805
  ...options,
1778
1806
  onScroll(e) {
1779
- options.onScroll?.(e);
1807
+ var _a;
1808
+ (_a = options.onScroll) == null ? void 0 : _a.call(options, e);
1780
1809
  handler(state);
1781
1810
  },
1782
1811
  onStop(e) {
1783
- options.onStop?.(e);
1812
+ var _a;
1813
+ (_a = options.onStop) == null ? void 0 : _a.call(options, e);
1784
1814
  handler(state);
1785
1815
  }
1786
1816
  });
@@ -1846,7 +1876,7 @@ function useScrollLock(element, initialState = false) {
1846
1876
  const el = resolveElement(shared.toValue(element));
1847
1877
  if (!el || !isLocked.value)
1848
1878
  return;
1849
- shared.isIOS && stopTouchMoveListener?.();
1879
+ shared.isIOS && (stopTouchMoveListener == null ? void 0 : stopTouchMoveListener());
1850
1880
  el.style.overflow = initialOverflow;
1851
1881
  isLocked.value = false;
1852
1882
  };
@@ -1914,21 +1944,9 @@ const UseVirtualList = /* @__PURE__ */ /* #__PURE__ */ vueDemi.defineComponent({
1914
1944
  const { list, containerProps, wrapperProps, scrollTo } = core.useVirtualList(listRef, props.options);
1915
1945
  expose({ scrollTo });
1916
1946
  typeof containerProps.style === "object" && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || "300px");
1917
- return () => vueDemi.h(
1918
- "div",
1919
- { ...containerProps },
1920
- [
1921
- vueDemi.h(
1922
- "div",
1923
- { ...wrapperProps.value },
1924
- list.value.map((item) => vueDemi.h(
1925
- "div",
1926
- { style: { overFlow: "hidden", height: item.height } },
1927
- slots.default ? slots.default(item) : "Please set content!"
1928
- ))
1929
- )
1930
- ]
1931
- );
1947
+ return () => vueDemi.h("div", { ...containerProps }, [
1948
+ vueDemi.h("div", { ...wrapperProps.value }, list.value.map((item) => vueDemi.h("div", { style: { overFlow: "hidden", height: item.height } }, slots.default ? slots.default(item) : "Please set content!")))
1949
+ ]);
1932
1950
  }
1933
1951
  });
1934
1952
 
package/index.d.cts CHANGED
@@ -297,9 +297,6 @@ interface ElementSize {
297
297
  * Reactive size of an HTML element.
298
298
  *
299
299
  * @see https://vueuse.org/useElementSize
300
- * @param target
301
- * @param callback
302
- * @param options
303
300
  */
304
301
  declare function useElementSize(target: MaybeComputedElementRef, initialSize?: ElementSize, options?: UseResizeObserverOptions): {
305
302
  width: vue_demi.Ref<number>;
package/index.d.mts CHANGED
@@ -297,9 +297,6 @@ interface ElementSize {
297
297
  * Reactive size of an HTML element.
298
298
  *
299
299
  * @see https://vueuse.org/useElementSize
300
- * @param target
301
- * @param callback
302
- * @param options
303
300
  */
304
301
  declare function useElementSize(target: MaybeComputedElementRef, initialSize?: ElementSize, options?: UseResizeObserverOptions): {
305
302
  width: vue_demi.Ref<number>;
package/index.d.ts CHANGED
@@ -297,9 +297,6 @@ interface ElementSize {
297
297
  * Reactive size of an HTML element.
298
298
  *
299
299
  * @see https://vueuse.org/useElementSize
300
- * @param target
301
- * @param callback
302
- * @param options
303
300
  */
304
301
  declare function useElementSize(target: MaybeComputedElementRef, initialSize?: ElementSize, options?: UseResizeObserverOptions): {
305
302
  width: vue_demi.Ref<number>;