@varlet/use 2.12.0-alpha.1687974059976 → 2.12.0-alpha.1688105697429

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/use",
3
- "version": "2.12.0-alpha.1687974059976",
3
+ "version": "2.12.0-alpha.1688105697429",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -24,9 +24,10 @@
24
24
  "url": "https://github.com/varletjs/varlet/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@varlet/shared": "2.12.0-alpha.1687974059976"
27
+ "@varlet/shared": "2.12.0-alpha.1688105697429"
28
28
  },
29
29
  "devDependencies": {
30
+ "rimraf": "^5.0.1",
30
31
  "typescript": "^5.1.5",
31
32
  "vue": "3.3.4"
32
33
  },
@@ -35,6 +36,6 @@
35
36
  },
36
37
  "scripts": {
37
38
  "dev": "tsc --watch",
38
- "build": "tsc"
39
+ "build": "rimraf ./lib && tsc"
39
40
  }
40
41
  }
@@ -1 +0,0 @@
1
- export declare function onSmartMounted(hook: () => void): void;
package/lib/onMounted.js DELETED
@@ -1,16 +0,0 @@
1
- import { onMounted, nextTick, onActivated } from 'vue';
2
- export function onSmartMounted(hook) {
3
- let isMounted = false;
4
- onMounted(() => {
5
- hook();
6
- nextTick(() => {
7
- isMounted = true;
8
- });
9
- });
10
- onActivated(() => {
11
- if (!isMounted) {
12
- return;
13
- }
14
- hook();
15
- });
16
- }
@@ -1 +0,0 @@
1
- export declare function onSmartMounted(hook: () => void): void;
@@ -1,16 +0,0 @@
1
- import { onMounted, nextTick, onActivated } from 'vue';
2
- export function onSmartMounted(hook) {
3
- let isMounted = false;
4
- onMounted(() => {
5
- hook();
6
- nextTick(() => {
7
- isMounted = true;
8
- });
9
- });
10
- onActivated(() => {
11
- if (!isMounted) {
12
- return;
13
- }
14
- hook();
15
- });
16
- }
@@ -1,12 +0,0 @@
1
- import { type Ref } from 'vue'
2
- export declare type UseEventListenerTarget = EventTarget | undefined | Ref<EventTarget | undefined>
3
- export interface UseEventListenerOptions {
4
- capture?: boolean
5
- passive?: boolean
6
- }
7
- export declare function useEventListener<T extends keyof DocumentEventMap>(
8
- target: UseEventListenerTarget,
9
- type: T,
10
- listener: (event: DocumentEventMap[T]) => void,
11
- options?: UseEventListenerOptions
12
- ): () => void
@@ -1,63 +0,0 @@
1
- import { inBrowser } from '@varlet/shared'
2
- import { isRef, onActivated, onDeactivated, onMounted, onUnmounted, unref, watch } from 'vue'
3
- export function useEventListener(target, type, listener, options = {}) {
4
- if (!inBrowser()) {
5
- return
6
- }
7
- const { passive = false, capture = false } = options
8
- let listening = false
9
- let cleaned = false
10
- const add = (target) => {
11
- if (listening || cleaned) {
12
- return
13
- }
14
- const element = unref(target)
15
- if (element) {
16
- element.addEventListener(type, listener, {
17
- passive,
18
- capture,
19
- })
20
- listening = true
21
- }
22
- }
23
- const remove = (target) => {
24
- if (!listening || cleaned) {
25
- return
26
- }
27
- const element = unref(target)
28
- if (element) {
29
- element.removeEventListener(type, listener, {
30
- capture,
31
- })
32
- listening = false
33
- }
34
- }
35
- let watchStopHandle
36
- if (isRef(target)) {
37
- watchStopHandle = watch(
38
- () => target.value,
39
- (newValue, oldValue) => {
40
- remove(oldValue)
41
- add(newValue)
42
- }
43
- )
44
- }
45
- const cleanup = () => {
46
- watchStopHandle === null || watchStopHandle === void 0 ? void 0 : watchStopHandle()
47
- remove(target)
48
- cleaned = true
49
- }
50
- onMounted(() => {
51
- add(target)
52
- })
53
- onActivated(() => {
54
- add(target)
55
- })
56
- onUnmounted(() => {
57
- remove(target)
58
- })
59
- onDeactivated(() => {
60
- remove(target)
61
- })
62
- return cleanup
63
- }
@@ -1 +0,0 @@
1
- export declare function useMounted(hook: () => void): void;
package/lib/useMounted.js DELETED
@@ -1,16 +0,0 @@
1
- import { onMounted, nextTick, onActivated } from 'vue';
2
- export function useMounted(hook) {
3
- let isMounted = false;
4
- onMounted(() => {
5
- hook();
6
- nextTick(() => {
7
- isMounted = true;
8
- });
9
- });
10
- onActivated(() => {
11
- if (!isMounted) {
12
- return;
13
- }
14
- hook();
15
- });
16
- }
@@ -1,7 +0,0 @@
1
- export interface UseVModelOptions<P, K extends keyof P> {
2
- passive?: boolean;
3
- eventName?: string;
4
- defaultValue?: P[K];
5
- emit?: (event: string, value: P[K]) => void;
6
- }
7
- export declare function useVModel<P extends Record<string, any>, K extends keyof P>(props: P, key: K, options?: UseVModelOptions<P, K>): import("vue").WritableComputedRef<P[K]> | ([P[K]] extends [import("vue").Ref<any>] ? P[K] : import("vue").Ref<import("vue").UnwrapRef<P[K]>>);
package/lib/useVModel.js DELETED
@@ -1,25 +0,0 @@
1
- import { computed, getCurrentInstance, ref, watch } from 'vue';
2
- export function useVModel(props, key, options = {}) {
3
- const vm = getCurrentInstance();
4
- const { passive = true, eventName, defaultValue, emit = vm === null || vm === void 0 ? void 0 : vm.emit } = options;
5
- const event = eventName !== null && eventName !== void 0 ? eventName : `update:${key.toString()}`;
6
- const getValue = () => (props[key] != null ? props[key] : defaultValue);
7
- if (!passive) {
8
- return computed({
9
- get() {
10
- return getValue();
11
- },
12
- set(value) {
13
- emit(event, value);
14
- },
15
- });
16
- }
17
- const proxy = ref(getValue());
18
- watch(() => props[key], () => {
19
- proxy.value = getValue();
20
- });
21
- watch(() => proxy.value, (newValue) => {
22
- emit(event, newValue);
23
- });
24
- return proxy;
25
- }
@@ -1 +0,0 @@
1
- export declare function useWindowResize(listener: EventListener): void;
@@ -1,5 +0,0 @@
1
- import { useEventListener } from './useEventListener';
2
- export function useWindowResize(listener) {
3
- useEventListener(() => window, 'resize', listener, { passive: true });
4
- useEventListener(() => window, 'orientationchange', listener, { passive: true });
5
- }