@v-c/util 1.0.20 → 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.
- package/dist/hooks/useDelayState.d.ts +16 -0
- package/dist/hooks/useDelayState.js +33 -0
- package/dist/pickAttrs.js +6 -1
- package/dist/vnode.js +2 -1
- package/package.json +1 -1
|
@@ -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
|
|
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/dist/vnode.js
CHANGED
|
@@ -60,8 +60,9 @@ function resolveToElement(node) {
|
|
|
60
60
|
}
|
|
61
61
|
if (isDOM(exposed?.$el)) return exposed.$el;
|
|
62
62
|
else if (exposed.$el) {
|
|
63
|
+
const hasElementContract = exposed.nativeElement != null || exposed.el != null || typeof exposed.getElement === "function";
|
|
63
64
|
const dom = exposed.$el;
|
|
64
|
-
if (
|
|
65
|
+
if (!hasElementContract && (dom.nodeType === 3 || dom.nodeType === 8) && dom.nextElementSibling) return dom.nextElementSibling;
|
|
65
66
|
}
|
|
66
67
|
return null;
|
|
67
68
|
}
|
package/package.json
CHANGED