@v-c/util 1.0.21 → 1.1.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.
@@ -0,0 +1,16 @@
1
+ import { Ref } from 'vue';
2
+ export type DelayConfig = {
3
+ frame: number;
4
+ ms?: never;
5
+ } | {
6
+ frame?: never;
7
+ ms: number;
8
+ };
9
+ export type SetDelayState<T> = (nextValue: T | ((prev: T) => T),
10
+ /** `true` updates immediately. `false` delays the update by one frame. */
11
+ immediatelyOrDelay?: boolean | DelayConfig) => void;
12
+ /**
13
+ * Similar to `useState`, but updates on the next frame by default.
14
+ * Pending updates are always replaced by the latest one.
15
+ */
16
+ export default function useDelayState<T>(defaultValue: T | (() => T)): [Ref<T>, SetDelayState<T>];
@@ -0,0 +1,33 @@
1
+ import wrapperRaf from "../raf.js";
2
+ import { onBeforeUnmount, ref } from "vue";
3
+ //#region src/hooks/useDelayState.ts
4
+ /**
5
+ * Similar to `useState`, but updates on the next frame by default.
6
+ * Pending updates are always replaced by the latest one.
7
+ */
8
+ function useDelayState(defaultValue) {
9
+ const value = ref(typeof defaultValue === "function" ? defaultValue() : defaultValue);
10
+ let delayInfo = null;
11
+ const cancelPending = () => {
12
+ if (delayInfo) {
13
+ const [isRaf, delay] = delayInfo;
14
+ if (isRaf) wrapperRaf.cancel(delay);
15
+ else clearTimeout(delay);
16
+ delayInfo = null;
17
+ }
18
+ };
19
+ const applyValue = (nextValue) => {
20
+ value.value = typeof nextValue === "function" ? nextValue(value.value) : nextValue;
21
+ };
22
+ const setDelayValue = (nextValue, immediatelyOrDelay) => {
23
+ const delayConfig = immediatelyOrDelay || { frame: 1 };
24
+ cancelPending();
25
+ if (delayConfig === true) applyValue(nextValue);
26
+ else if ("ms" in delayConfig) delayInfo = [false, setTimeout(() => applyValue(nextValue), delayConfig.ms)];
27
+ else delayInfo = [true, wrapperRaf(() => applyValue(nextValue), delayConfig.frame)];
28
+ };
29
+ onBeforeUnmount(cancelPending);
30
+ return [value, setDelayValue];
31
+ }
32
+ //#endregion
33
+ export { useDelayState as default };
package/dist/pickAttrs.js CHANGED
@@ -16,7 +16,12 @@ var propList = `accept acceptCharset accessKey action allowFullScreen allowTrans
16
16
  onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel
17
17
  onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough
18
18
  onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata
19
- onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError`.split(/\s+/);
19
+ onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad
20
+ onPointerDown onPointerMove onPointerUp onPointerCancel onPointerEnter onPointerLeave onPointerOver onPointerOut onGotPointerCapture onLostPointerCapture
21
+ onAnimationStart onAnimationEnd onAnimationIteration
22
+ onTransitionEnd onTransitionRun onTransitionStart onTransitionCancel
23
+ onBeforeInput onReset onInvalid
24
+ onAuxClick onToggle onBeforeToggle onCancel onClose onResize onScrollEnd`.split(/\s+/);
20
25
  var ariaPrefix = "aria-";
21
26
  var dataPrefix = "data-";
22
27
  function match(key, prefix) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/util",
3
3
  "type": "module",
4
- "version": "1.0.21",
4
+ "version": "1.1.0",
5
5
  "description": "Vue3 components utils",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/util",