@varlet/use 3.2.5 → 3.2.6-alpha.1713858357643
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.cjs +31 -14
- package/lib/index.d.cts +3 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +21 -5
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -52,6 +52,7 @@ __export(src_exports, {
|
|
|
52
52
|
onWindowResize: () => onWindowResize,
|
|
53
53
|
useChildren: () => useChildren,
|
|
54
54
|
useClickOutside: () => useClickOutside,
|
|
55
|
+
useClientId: () => useClientId,
|
|
55
56
|
useEventListener: () => useEventListener,
|
|
56
57
|
useId: () => useId,
|
|
57
58
|
useInitialized: () => useInitialized,
|
|
@@ -416,15 +417,30 @@ function useId() {
|
|
|
416
417
|
return id;
|
|
417
418
|
}
|
|
418
419
|
|
|
419
|
-
// src/
|
|
420
|
-
var import_shared6 = require("@varlet/shared");
|
|
420
|
+
// src/useClientId.ts
|
|
421
421
|
var import_vue10 = require("vue");
|
|
422
|
+
var import_shared6 = require("@varlet/shared");
|
|
423
|
+
function useClientId() {
|
|
424
|
+
const instance = (0, import_vue10.getCurrentInstance)();
|
|
425
|
+
const name = (0, import_shared6.kebabCase)(instance.type.name);
|
|
426
|
+
const id = (0, import_vue10.ref)(process.env.NODE_ENV === "test" ? `${name}-mock-id` : "");
|
|
427
|
+
(0, import_vue10.onMounted)(() => {
|
|
428
|
+
if (process.env.NODE_ENV !== "test") {
|
|
429
|
+
id.value = `${name}-${instance.uid}`;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
return id;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/useWindowSize.ts
|
|
436
|
+
var import_shared7 = require("@varlet/shared");
|
|
437
|
+
var import_vue11 = require("vue");
|
|
422
438
|
function useWindowSize(options = {}) {
|
|
423
439
|
const { initialWidth = 0, initialHeight = 0 } = options;
|
|
424
|
-
const width = (0,
|
|
425
|
-
const height = (0,
|
|
440
|
+
const width = (0, import_vue11.ref)(initialWidth);
|
|
441
|
+
const height = (0, import_vue11.ref)(initialHeight);
|
|
426
442
|
const update = () => {
|
|
427
|
-
if (!(0,
|
|
443
|
+
if (!(0, import_shared7.inBrowser)()) {
|
|
428
444
|
return;
|
|
429
445
|
}
|
|
430
446
|
width.value = window.innerWidth;
|
|
@@ -439,8 +455,8 @@ function useWindowSize(options = {}) {
|
|
|
439
455
|
}
|
|
440
456
|
|
|
441
457
|
// src/useVModel.ts
|
|
442
|
-
var
|
|
443
|
-
var
|
|
458
|
+
var import_shared8 = require("@varlet/shared");
|
|
459
|
+
var import_vue12 = require("vue");
|
|
444
460
|
function useVModel(props, key, options = {}) {
|
|
445
461
|
const { passive = true, eventName, defaultValue, emit } = options;
|
|
446
462
|
const event = eventName != null ? eventName : `onUpdate:${key.toString()}`;
|
|
@@ -449,34 +465,34 @@ function useVModel(props, key, options = {}) {
|
|
|
449
465
|
return (_a = props[key]) != null ? _a : defaultValue;
|
|
450
466
|
};
|
|
451
467
|
if (!passive) {
|
|
452
|
-
return (0,
|
|
468
|
+
return (0, import_vue12.computed)({
|
|
453
469
|
get() {
|
|
454
470
|
return getValue();
|
|
455
471
|
},
|
|
456
472
|
set(value) {
|
|
457
|
-
emit ? emit(event, value) : (0,
|
|
473
|
+
emit ? emit(event, value) : (0, import_shared8.call)(props[event], value);
|
|
458
474
|
}
|
|
459
475
|
});
|
|
460
476
|
}
|
|
461
|
-
const proxy = (0,
|
|
477
|
+
const proxy = (0, import_vue12.ref)(getValue());
|
|
462
478
|
let shouldEmit = true;
|
|
463
|
-
(0,
|
|
479
|
+
(0, import_vue12.watch)(
|
|
464
480
|
() => props[key],
|
|
465
481
|
() => {
|
|
466
482
|
shouldEmit = false;
|
|
467
483
|
proxy.value = getValue();
|
|
468
|
-
(0,
|
|
484
|
+
(0, import_vue12.nextTick)(() => {
|
|
469
485
|
shouldEmit = true;
|
|
470
486
|
});
|
|
471
487
|
}
|
|
472
488
|
);
|
|
473
|
-
(0,
|
|
489
|
+
(0, import_vue12.watch)(
|
|
474
490
|
() => proxy.value,
|
|
475
491
|
(newValue) => {
|
|
476
492
|
if (!shouldEmit) {
|
|
477
493
|
return;
|
|
478
494
|
}
|
|
479
|
-
emit ? emit(event, newValue) : (0,
|
|
495
|
+
emit ? emit(event, newValue) : (0, import_shared8.call)(props[event], newValue);
|
|
480
496
|
}
|
|
481
497
|
);
|
|
482
498
|
return proxy;
|
|
@@ -489,6 +505,7 @@ function useVModel(props, key, options = {}) {
|
|
|
489
505
|
onWindowResize,
|
|
490
506
|
useChildren,
|
|
491
507
|
useClickOutside,
|
|
508
|
+
useClientId,
|
|
492
509
|
useEventListener,
|
|
493
510
|
useId,
|
|
494
511
|
useInitialized,
|
package/lib/index.d.cts
CHANGED
|
@@ -69,6 +69,8 @@ declare function useTouch(): {
|
|
|
69
69
|
|
|
70
70
|
declare function useId(): vue.Ref<string | undefined>;
|
|
71
71
|
|
|
72
|
+
declare function useClientId(): vue.Ref<string>;
|
|
73
|
+
|
|
72
74
|
interface UseWindowSizeOptions {
|
|
73
75
|
initialWidth?: number;
|
|
74
76
|
initialHeight?: number;
|
|
@@ -86,4 +88,4 @@ interface UseVModelOptions<P, K extends keyof P> {
|
|
|
86
88
|
}
|
|
87
89
|
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
90
|
|
|
89
|
-
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
|
91
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useClientId, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
package/lib/index.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ declare function useTouch(): {
|
|
|
69
69
|
|
|
70
70
|
declare function useId(): vue.Ref<string | undefined>;
|
|
71
71
|
|
|
72
|
+
declare function useClientId(): vue.Ref<string>;
|
|
73
|
+
|
|
72
74
|
interface UseWindowSizeOptions {
|
|
73
75
|
initialWidth?: number;
|
|
74
76
|
initialHeight?: number;
|
|
@@ -86,4 +88,4 @@ interface UseVModelOptions<P, K extends keyof P> {
|
|
|
86
88
|
}
|
|
87
89
|
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
90
|
|
|
89
|
-
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
|
91
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useClientId, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
package/lib/index.js
CHANGED
|
@@ -394,13 +394,28 @@ function useId() {
|
|
|
394
394
|
return id;
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
+
// src/useClientId.ts
|
|
398
|
+
import { ref as ref4, getCurrentInstance as getCurrentInstance4, onMounted as onMounted3 } from "vue";
|
|
399
|
+
import { kebabCase as kebabCase2 } from "@varlet/shared";
|
|
400
|
+
function useClientId() {
|
|
401
|
+
const instance = getCurrentInstance4();
|
|
402
|
+
const name = kebabCase2(instance.type.name);
|
|
403
|
+
const id = ref4(process.env.NODE_ENV === "test" ? `${name}-mock-id` : "");
|
|
404
|
+
onMounted3(() => {
|
|
405
|
+
if (process.env.NODE_ENV !== "test") {
|
|
406
|
+
id.value = `${name}-${instance.uid}`;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
return id;
|
|
410
|
+
}
|
|
411
|
+
|
|
397
412
|
// src/useWindowSize.ts
|
|
398
413
|
import { inBrowser as inBrowser3 } from "@varlet/shared";
|
|
399
|
-
import { ref as
|
|
414
|
+
import { ref as ref5 } from "vue";
|
|
400
415
|
function useWindowSize(options = {}) {
|
|
401
416
|
const { initialWidth = 0, initialHeight = 0 } = options;
|
|
402
|
-
const width =
|
|
403
|
-
const height =
|
|
417
|
+
const width = ref5(initialWidth);
|
|
418
|
+
const height = ref5(initialHeight);
|
|
404
419
|
const update = () => {
|
|
405
420
|
if (!inBrowser3()) {
|
|
406
421
|
return;
|
|
@@ -418,7 +433,7 @@ function useWindowSize(options = {}) {
|
|
|
418
433
|
|
|
419
434
|
// src/useVModel.ts
|
|
420
435
|
import { call } from "@varlet/shared";
|
|
421
|
-
import { computed as computed3, nextTick as nextTick3, ref as
|
|
436
|
+
import { computed as computed3, nextTick as nextTick3, ref as ref6, watch as watch3 } from "vue";
|
|
422
437
|
function useVModel(props, key, options = {}) {
|
|
423
438
|
const { passive = true, eventName, defaultValue, emit } = options;
|
|
424
439
|
const event = eventName != null ? eventName : `onUpdate:${key.toString()}`;
|
|
@@ -436,7 +451,7 @@ function useVModel(props, key, options = {}) {
|
|
|
436
451
|
}
|
|
437
452
|
});
|
|
438
453
|
}
|
|
439
|
-
const proxy =
|
|
454
|
+
const proxy = ref6(getValue());
|
|
440
455
|
let shouldEmit = true;
|
|
441
456
|
watch3(
|
|
442
457
|
() => props[key],
|
|
@@ -466,6 +481,7 @@ export {
|
|
|
466
481
|
onWindowResize,
|
|
467
482
|
useChildren,
|
|
468
483
|
useClickOutside,
|
|
484
|
+
useClientId,
|
|
469
485
|
useEventListener,
|
|
470
486
|
useId,
|
|
471
487
|
useInitialized,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/use",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6-alpha.1713858357643",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "https://github.com/varletjs/varlet/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@varlet/shared": "3.2.
|
|
36
|
+
"@varlet/shared": "3.2.6-alpha.1713858357643"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^18.7.18",
|