@varlet/use 2.18.1 → 2.18.2-alpha.1698939289602
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/lib/index.d.ts +10 -2
- package/lib/index.js +34 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { Ref, ComponentInternalInstance, ComputedRef, WatchSource } from 'vue';
|
|
2
|
+
import { Ref, ComponentInternalInstance, ComputedRef, WatchSource, WritableComputedRef } from 'vue';
|
|
3
3
|
|
|
4
4
|
type UseEventListenerTarget = EventTarget | Ref<EventTarget | undefined | null> | (() => EventTarget);
|
|
5
5
|
interface UseEventListenerOptions {
|
|
@@ -78,4 +78,12 @@ declare function useWindowSize(options?: UseWindowSizeOptions): {
|
|
|
78
78
|
height: vue.Ref<number>;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
interface UseVModelOptions<P, K extends keyof P> {
|
|
82
|
+
passive?: boolean;
|
|
83
|
+
eventName?: string;
|
|
84
|
+
defaultValue?: P[K];
|
|
85
|
+
emit?: (event: string, value: P[K]) => void;
|
|
86
|
+
}
|
|
87
|
+
declare function useVModel<P extends Record<string, any>, K extends keyof P>(props: P, key: K, options?: UseVModelOptions<P, K>): WritableComputedRef<P[K]> | Ref<P[K]>;
|
|
88
|
+
|
|
89
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
package/lib/index.js
CHANGED
|
@@ -410,6 +410,39 @@ function useWindowSize(options = {}) {
|
|
|
410
410
|
height
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
+
|
|
414
|
+
// src/useVModel.ts
|
|
415
|
+
import { call } from "@varlet/shared";
|
|
416
|
+
import { computed as computed3, ref as ref5, watch as watch3 } from "vue";
|
|
417
|
+
function useVModel(props, key, options = {}) {
|
|
418
|
+
const { passive = true, eventName, defaultValue, emit } = options;
|
|
419
|
+
const event = eventName != null ? eventName : `onUpdate:${key.toString()}`;
|
|
420
|
+
const getValue = () => props[key] != null ? props[key] : defaultValue;
|
|
421
|
+
if (!passive) {
|
|
422
|
+
return computed3({
|
|
423
|
+
get() {
|
|
424
|
+
return getValue();
|
|
425
|
+
},
|
|
426
|
+
set(value) {
|
|
427
|
+
emit ? emit(event, value) : call(props[event], value);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
const proxy = ref5(getValue());
|
|
432
|
+
watch3(
|
|
433
|
+
() => props[key],
|
|
434
|
+
() => {
|
|
435
|
+
proxy.value = getValue();
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
watch3(
|
|
439
|
+
() => proxy.value,
|
|
440
|
+
(newValue) => {
|
|
441
|
+
emit ? emit(event, newValue) : call(props[event], newValue);
|
|
442
|
+
}
|
|
443
|
+
);
|
|
444
|
+
return proxy;
|
|
445
|
+
}
|
|
413
446
|
export {
|
|
414
447
|
keyInProvides,
|
|
415
448
|
onSmartMounted,
|
|
@@ -422,5 +455,6 @@ export {
|
|
|
422
455
|
useInitialized,
|
|
423
456
|
useParent,
|
|
424
457
|
useTouch,
|
|
458
|
+
useVModel,
|
|
425
459
|
useWindowSize
|
|
426
460
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/use",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.2-alpha.1698939289602",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/varletjs/varlet/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@varlet/shared": "2.18.
|
|
27
|
+
"@varlet/shared": "2.18.2-alpha.1698939289602"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^18.7.18",
|