yc-design-vue 1.4.2 → 1.4.4
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/es/Breadcrumb/BreadcrumbSeparator.vue2.js +1 -1
- package/es/Calendar/Calendar.vue.d.ts +1 -1
- package/es/Calendar/index.d.ts +3 -3
- package/es/Collapse/Collapse.vue.d.ts +1 -1
- package/es/Collapse/index.d.ts +3 -3
- package/es/ColorPicker/ColorPicker.vue.d.ts +1 -1
- package/es/ColorPicker/index.d.ts +3 -3
- package/es/Dropdown/Dgroup.vue.js +1 -1
- package/es/Dropdown/Dgroup.vue2.js +2 -2
- package/es/Dropdown/Doption.vue.js +1 -1
- package/es/Dropdown/Doption.vue2.js +3 -1
- package/es/Dropdown/Dropdown.vue.d.ts +0 -1
- package/es/Dropdown/Dropdown.vue.js +4 -3
- package/es/Dropdown/Dsubmenu.vue.js +1 -1
- package/es/Dropdown/Dsubmenu.vue2.js +3 -4
- package/es/Dropdown/hooks/useContext.d.ts +1 -3
- package/es/Dropdown/hooks/useContext.js +1 -4
- package/es/Dropdown/index.d.ts +0 -3
- package/es/Dropdown/type.d.ts +1 -2
- package/es/Input/InputSuffix.vue2.js +2 -2
- package/es/Layout/LayoutSider.vue.d.ts +2 -2
- package/es/Layout/LayoutSider.vue.js +1 -1
- package/es/Layout/LayoutSider.vue2.js +4 -5
- package/es/Layout/hooks/useSiderContext.d.ts +1 -0
- package/es/Layout/hooks/useSiderContext.js +21 -2
- package/es/Layout/index.d.ts +6 -6
- package/es/Menu/Menu.vue.d.ts +7 -7
- package/es/Menu/Menu.vue2.js +2 -2
- package/es/Menu/MenuEllipsis.vue.js +1 -1
- package/es/Menu/MenuEllipsis.vue2.js +3 -4
- package/es/Menu/MenuItem.vue.js +1 -1
- package/es/Menu/MenuItem.vue2.js +3 -4
- package/es/Menu/MenuItemGroup.vue2.js +2 -2
- package/es/Menu/SubMenu.vue2.js +2 -2
- package/es/Menu/hooks/useContext.js +2 -2
- package/es/Menu/index.d.ts +20 -20
- package/es/_shared/icons/IconEyeClose.vue.js +1 -20
- package/es/_shared/icons/IconEyeClose.vue2.js +20 -1
- package/es/_shared/icons/IconEyeOpen.vue.js +1 -17
- package/es/_shared/icons/IconEyeOpen.vue2.js +17 -1
- package/es/_shared/icons/IconSeparator.vue.js +1 -16
- package/es/_shared/icons/IconSeparator.vue2.js +16 -1
- package/es/index.d.ts +6 -6
- package/es/node_modules/@vueuse/core/index.js +319 -4
- package/es/node_modules/@vueuse/shared/index.js +65 -2
- package/es/style.css +1 -1
- package/lib/Breadcrumb/BreadcrumbSeparator.vue2.js +1 -1
- package/lib/Calendar/Calendar.vue.d.ts +1 -1
- package/lib/Calendar/index.d.ts +3 -3
- package/lib/Collapse/Collapse.vue.d.ts +1 -1
- package/lib/Collapse/index.d.ts +3 -3
- package/lib/ColorPicker/ColorPicker.vue.d.ts +1 -1
- package/lib/ColorPicker/index.d.ts +3 -3
- package/lib/Dropdown/Dgroup.vue.js +1 -1
- package/lib/Dropdown/Dgroup.vue2.js +1 -1
- package/lib/Dropdown/Doption.vue.js +1 -1
- package/lib/Dropdown/Doption.vue2.js +1 -1
- package/lib/Dropdown/Dropdown.vue.d.ts +0 -1
- package/lib/Dropdown/Dropdown.vue.js +1 -1
- package/lib/Dropdown/Dsubmenu.vue.js +1 -1
- package/lib/Dropdown/Dsubmenu.vue2.js +1 -1
- package/lib/Dropdown/hooks/useContext.d.ts +1 -3
- package/lib/Dropdown/hooks/useContext.js +1 -1
- package/lib/Dropdown/index.d.ts +0 -3
- package/lib/Dropdown/type.d.ts +1 -2
- package/lib/Input/InputSuffix.vue2.js +1 -1
- package/lib/Layout/LayoutSider.vue.d.ts +2 -2
- package/lib/Layout/LayoutSider.vue.js +1 -1
- package/lib/Layout/LayoutSider.vue2.js +1 -1
- package/lib/Layout/hooks/useSiderContext.d.ts +1 -0
- package/lib/Layout/hooks/useSiderContext.js +1 -1
- package/lib/Layout/index.d.ts +6 -6
- package/lib/Menu/Menu.vue.d.ts +7 -7
- package/lib/Menu/MenuEllipsis.vue.js +1 -1
- package/lib/Menu/MenuEllipsis.vue2.js +1 -1
- package/lib/Menu/MenuItem.vue.js +1 -1
- package/lib/Menu/MenuItem.vue2.js +1 -1
- package/lib/Menu/index.d.ts +20 -20
- package/lib/_shared/icons/IconEyeClose.vue.js +1 -1
- package/lib/_shared/icons/IconEyeClose.vue2.js +1 -1
- package/lib/_shared/icons/IconEyeOpen.vue.js +1 -1
- package/lib/_shared/icons/IconEyeOpen.vue2.js +1 -1
- package/lib/_shared/icons/IconSeparator.vue.js +1 -1
- package/lib/_shared/icons/IconSeparator.vue2.js +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/node_modules/@vueuse/core/index.js +1 -1
- package/lib/node_modules/@vueuse/shared/index.js +1 -1
- package/lib/style.css +1 -1
- package/package.json +1 -1
@@ -1,6 +1,6 @@
|
|
1
|
-
import { tryOnScopeDispose, toArray, watchImmediate, isClient, isObject, makeDestructurable, camelize, tryOnMounted, toRefs, noop, isIOS, notNullish, useThrottleFn, useDebounceFn, pxValue, injectLocal, useTimeoutFn, createSingletonPromise } from "../shared/index.js";
|
2
|
-
import { createFilterWrapper, debounceFilter, getLifeCycleTarget, throttleFilter } from "../shared/index.js";
|
3
|
-
import { computed, toValue, watch, shallowRef, getCurrentInstance, onMounted, unref, defineComponent, ref, reactive, watchEffect, hasInjectionContext, toRaw } from "vue";
|
1
|
+
import { tryOnScopeDispose, toArray, watchImmediate, isClient, isObject, makeDestructurable, camelize, tryOnMounted, toRefs, noop, isIOS, notNullish, useThrottleFn, useDebounceFn, pxValue, injectLocal, toRef, pausableWatch as watchPausable, useTimeoutFn, createSingletonPromise } from "../shared/index.js";
|
2
|
+
import { bypassFilter, createFilterWrapper, debounceFilter, getLifeCycleTarget, pausableFilter, throttleFilter, watchWithFilter } from "../shared/index.js";
|
3
|
+
import { computed, toValue, watch, shallowRef, getCurrentInstance, onMounted, unref, defineComponent, ref, reactive, watchEffect, hasInjectionContext, nextTick, toRaw } from "vue";
|
4
4
|
function createReusableTemplate(options = {}) {
|
5
5
|
const {
|
6
6
|
inheritAttrs = true
|
@@ -439,6 +439,308 @@ function useClipboard(options = {}) {
|
|
439
439
|
copy
|
440
440
|
};
|
441
441
|
}
|
442
|
+
const _global = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
443
|
+
const globalKey = "__vueuse_ssr_handlers__";
|
444
|
+
const handlers = /* @__PURE__ */ getHandlers();
|
445
|
+
function getHandlers() {
|
446
|
+
if (!(globalKey in _global))
|
447
|
+
_global[globalKey] = _global[globalKey] || {};
|
448
|
+
return _global[globalKey];
|
449
|
+
}
|
450
|
+
function getSSRHandler(key, fallback) {
|
451
|
+
return handlers[key] || fallback;
|
452
|
+
}
|
453
|
+
function usePreferredDark(options) {
|
454
|
+
return useMediaQuery("(prefers-color-scheme: dark)", options);
|
455
|
+
}
|
456
|
+
function guessSerializerType(rawInit) {
|
457
|
+
return rawInit == null ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
|
458
|
+
}
|
459
|
+
const StorageSerializers = {
|
460
|
+
boolean: {
|
461
|
+
read: (v) => v === "true",
|
462
|
+
write: (v) => String(v)
|
463
|
+
},
|
464
|
+
object: {
|
465
|
+
read: (v) => JSON.parse(v),
|
466
|
+
write: (v) => JSON.stringify(v)
|
467
|
+
},
|
468
|
+
number: {
|
469
|
+
read: (v) => Number.parseFloat(v),
|
470
|
+
write: (v) => String(v)
|
471
|
+
},
|
472
|
+
any: {
|
473
|
+
read: (v) => v,
|
474
|
+
write: (v) => String(v)
|
475
|
+
},
|
476
|
+
string: {
|
477
|
+
read: (v) => v,
|
478
|
+
write: (v) => String(v)
|
479
|
+
},
|
480
|
+
map: {
|
481
|
+
read: (v) => new Map(JSON.parse(v)),
|
482
|
+
write: (v) => JSON.stringify(Array.from(v.entries()))
|
483
|
+
},
|
484
|
+
set: {
|
485
|
+
read: (v) => new Set(JSON.parse(v)),
|
486
|
+
write: (v) => JSON.stringify(Array.from(v))
|
487
|
+
},
|
488
|
+
date: {
|
489
|
+
read: (v) => new Date(v),
|
490
|
+
write: (v) => v.toISOString()
|
491
|
+
}
|
492
|
+
};
|
493
|
+
const customStorageEventName = "vueuse-storage";
|
494
|
+
function useStorage(key, defaults, storage, options = {}) {
|
495
|
+
var _a;
|
496
|
+
const {
|
497
|
+
flush = "pre",
|
498
|
+
deep = true,
|
499
|
+
listenToStorageChanges = true,
|
500
|
+
writeDefaults = true,
|
501
|
+
mergeDefaults = false,
|
502
|
+
shallow,
|
503
|
+
window: window2 = defaultWindow,
|
504
|
+
eventFilter,
|
505
|
+
onError = (e) => {
|
506
|
+
console.error(e);
|
507
|
+
},
|
508
|
+
initOnMounted
|
509
|
+
} = options;
|
510
|
+
const data = (shallow ? shallowRef : ref)(typeof defaults === "function" ? defaults() : defaults);
|
511
|
+
const keyComputed = computed(() => toValue(key));
|
512
|
+
if (!storage) {
|
513
|
+
try {
|
514
|
+
storage = getSSRHandler("getDefaultStorage", () => {
|
515
|
+
var _a2;
|
516
|
+
return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
|
517
|
+
})();
|
518
|
+
} catch (e) {
|
519
|
+
onError(e);
|
520
|
+
}
|
521
|
+
}
|
522
|
+
if (!storage)
|
523
|
+
return data;
|
524
|
+
const rawInit = toValue(defaults);
|
525
|
+
const type = guessSerializerType(rawInit);
|
526
|
+
const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
527
|
+
const { pause: pauseWatch, resume: resumeWatch } = watchPausable(
|
528
|
+
data,
|
529
|
+
() => write(data.value),
|
530
|
+
{ flush, deep, eventFilter }
|
531
|
+
);
|
532
|
+
watch(keyComputed, () => update(), { flush });
|
533
|
+
if (window2 && listenToStorageChanges) {
|
534
|
+
tryOnMounted(() => {
|
535
|
+
if (storage instanceof Storage)
|
536
|
+
useEventListener(window2, "storage", update, { passive: true });
|
537
|
+
else
|
538
|
+
useEventListener(window2, customStorageEventName, updateFromCustomEvent);
|
539
|
+
if (initOnMounted)
|
540
|
+
update();
|
541
|
+
});
|
542
|
+
}
|
543
|
+
if (!initOnMounted)
|
544
|
+
update();
|
545
|
+
function dispatchWriteEvent(oldValue, newValue) {
|
546
|
+
if (window2) {
|
547
|
+
const payload = {
|
548
|
+
key: keyComputed.value,
|
549
|
+
oldValue,
|
550
|
+
newValue,
|
551
|
+
storageArea: storage
|
552
|
+
};
|
553
|
+
window2.dispatchEvent(storage instanceof Storage ? new StorageEvent("storage", payload) : new CustomEvent(customStorageEventName, {
|
554
|
+
detail: payload
|
555
|
+
}));
|
556
|
+
}
|
557
|
+
}
|
558
|
+
function write(v) {
|
559
|
+
try {
|
560
|
+
const oldValue = storage.getItem(keyComputed.value);
|
561
|
+
if (v == null) {
|
562
|
+
dispatchWriteEvent(oldValue, null);
|
563
|
+
storage.removeItem(keyComputed.value);
|
564
|
+
} else {
|
565
|
+
const serialized = serializer.write(v);
|
566
|
+
if (oldValue !== serialized) {
|
567
|
+
storage.setItem(keyComputed.value, serialized);
|
568
|
+
dispatchWriteEvent(oldValue, serialized);
|
569
|
+
}
|
570
|
+
}
|
571
|
+
} catch (e) {
|
572
|
+
onError(e);
|
573
|
+
}
|
574
|
+
}
|
575
|
+
function read(event) {
|
576
|
+
const rawValue = event ? event.newValue : storage.getItem(keyComputed.value);
|
577
|
+
if (rawValue == null) {
|
578
|
+
if (writeDefaults && rawInit != null)
|
579
|
+
storage.setItem(keyComputed.value, serializer.write(rawInit));
|
580
|
+
return rawInit;
|
581
|
+
} else if (!event && mergeDefaults) {
|
582
|
+
const value = serializer.read(rawValue);
|
583
|
+
if (typeof mergeDefaults === "function")
|
584
|
+
return mergeDefaults(value, rawInit);
|
585
|
+
else if (type === "object" && !Array.isArray(value))
|
586
|
+
return { ...rawInit, ...value };
|
587
|
+
return value;
|
588
|
+
} else if (typeof rawValue !== "string") {
|
589
|
+
return rawValue;
|
590
|
+
} else {
|
591
|
+
return serializer.read(rawValue);
|
592
|
+
}
|
593
|
+
}
|
594
|
+
function update(event) {
|
595
|
+
if (event && event.storageArea !== storage)
|
596
|
+
return;
|
597
|
+
if (event && event.key == null) {
|
598
|
+
data.value = rawInit;
|
599
|
+
return;
|
600
|
+
}
|
601
|
+
if (event && event.key !== keyComputed.value)
|
602
|
+
return;
|
603
|
+
pauseWatch();
|
604
|
+
try {
|
605
|
+
if ((event == null ? void 0 : event.newValue) !== serializer.write(data.value))
|
606
|
+
data.value = read(event);
|
607
|
+
} catch (e) {
|
608
|
+
onError(e);
|
609
|
+
} finally {
|
610
|
+
if (event)
|
611
|
+
nextTick(resumeWatch);
|
612
|
+
else
|
613
|
+
resumeWatch();
|
614
|
+
}
|
615
|
+
}
|
616
|
+
function updateFromCustomEvent(event) {
|
617
|
+
update(event.detail);
|
618
|
+
}
|
619
|
+
return data;
|
620
|
+
}
|
621
|
+
const CSS_DISABLE_TRANS = "*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
|
622
|
+
function useColorMode(options = {}) {
|
623
|
+
const {
|
624
|
+
selector = "html",
|
625
|
+
attribute = "class",
|
626
|
+
initialValue = "auto",
|
627
|
+
window: window2 = defaultWindow,
|
628
|
+
storage,
|
629
|
+
storageKey = "vueuse-color-scheme",
|
630
|
+
listenToStorageChanges = true,
|
631
|
+
storageRef,
|
632
|
+
emitAuto,
|
633
|
+
disableTransition = true
|
634
|
+
} = options;
|
635
|
+
const modes = {
|
636
|
+
auto: "",
|
637
|
+
light: "light",
|
638
|
+
dark: "dark",
|
639
|
+
...options.modes || {}
|
640
|
+
};
|
641
|
+
const preferredDark = usePreferredDark({ window: window2 });
|
642
|
+
const system = computed(() => preferredDark.value ? "dark" : "light");
|
643
|
+
const store = storageRef || (storageKey == null ? toRef(initialValue) : useStorage(storageKey, initialValue, storage, { window: window2, listenToStorageChanges }));
|
644
|
+
const state = computed(() => store.value === "auto" ? system.value : store.value);
|
645
|
+
const updateHTMLAttrs = getSSRHandler(
|
646
|
+
"updateHTMLAttrs",
|
647
|
+
(selector2, attribute2, value) => {
|
648
|
+
const el = typeof selector2 === "string" ? window2 == null ? void 0 : window2.document.querySelector(selector2) : unrefElement(selector2);
|
649
|
+
if (!el)
|
650
|
+
return;
|
651
|
+
const classesToAdd = /* @__PURE__ */ new Set();
|
652
|
+
const classesToRemove = /* @__PURE__ */ new Set();
|
653
|
+
let attributeToChange = null;
|
654
|
+
if (attribute2 === "class") {
|
655
|
+
const current = value.split(/\s/g);
|
656
|
+
Object.values(modes).flatMap((i) => (i || "").split(/\s/g)).filter(Boolean).forEach((v) => {
|
657
|
+
if (current.includes(v))
|
658
|
+
classesToAdd.add(v);
|
659
|
+
else
|
660
|
+
classesToRemove.add(v);
|
661
|
+
});
|
662
|
+
} else {
|
663
|
+
attributeToChange = { key: attribute2, value };
|
664
|
+
}
|
665
|
+
if (classesToAdd.size === 0 && classesToRemove.size === 0 && attributeToChange === null)
|
666
|
+
return;
|
667
|
+
let style;
|
668
|
+
if (disableTransition) {
|
669
|
+
style = window2.document.createElement("style");
|
670
|
+
style.appendChild(document.createTextNode(CSS_DISABLE_TRANS));
|
671
|
+
window2.document.head.appendChild(style);
|
672
|
+
}
|
673
|
+
for (const c of classesToAdd) {
|
674
|
+
el.classList.add(c);
|
675
|
+
}
|
676
|
+
for (const c of classesToRemove) {
|
677
|
+
el.classList.remove(c);
|
678
|
+
}
|
679
|
+
if (attributeToChange) {
|
680
|
+
el.setAttribute(attributeToChange.key, attributeToChange.value);
|
681
|
+
}
|
682
|
+
if (disableTransition) {
|
683
|
+
window2.getComputedStyle(style).opacity;
|
684
|
+
document.head.removeChild(style);
|
685
|
+
}
|
686
|
+
}
|
687
|
+
);
|
688
|
+
function defaultOnChanged(mode) {
|
689
|
+
var _a;
|
690
|
+
updateHTMLAttrs(selector, attribute, (_a = modes[mode]) != null ? _a : mode);
|
691
|
+
}
|
692
|
+
function onChanged(mode) {
|
693
|
+
if (options.onChanged)
|
694
|
+
options.onChanged(mode, defaultOnChanged);
|
695
|
+
else
|
696
|
+
defaultOnChanged(mode);
|
697
|
+
}
|
698
|
+
watch(state, onChanged, { flush: "post", immediate: true });
|
699
|
+
tryOnMounted(() => onChanged(state.value));
|
700
|
+
const auto = computed({
|
701
|
+
get() {
|
702
|
+
return emitAuto ? store.value : state.value;
|
703
|
+
},
|
704
|
+
set(v) {
|
705
|
+
store.value = v;
|
706
|
+
}
|
707
|
+
});
|
708
|
+
return Object.assign(auto, { store, system, state });
|
709
|
+
}
|
710
|
+
function useDark(options = {}) {
|
711
|
+
const {
|
712
|
+
valueDark = "dark",
|
713
|
+
valueLight = ""
|
714
|
+
} = options;
|
715
|
+
const mode = useColorMode({
|
716
|
+
...options,
|
717
|
+
onChanged: (mode2, defaultHandler) => {
|
718
|
+
var _a;
|
719
|
+
if (options.onChanged)
|
720
|
+
(_a = options.onChanged) == null ? void 0 : _a.call(options, mode2 === "dark", defaultHandler, mode2);
|
721
|
+
else
|
722
|
+
defaultHandler(mode2);
|
723
|
+
},
|
724
|
+
modes: {
|
725
|
+
dark: valueDark,
|
726
|
+
light: valueLight
|
727
|
+
}
|
728
|
+
});
|
729
|
+
const system = computed(() => mode.system.value);
|
730
|
+
const isDark = computed({
|
731
|
+
get() {
|
732
|
+
return mode.value === "dark";
|
733
|
+
},
|
734
|
+
set(v) {
|
735
|
+
const modeVal = v ? "dark" : "light";
|
736
|
+
if (system.value === modeVal)
|
737
|
+
mode.value = "auto";
|
738
|
+
else
|
739
|
+
mode.value = modeVal;
|
740
|
+
}
|
741
|
+
});
|
742
|
+
return isDark;
|
743
|
+
}
|
442
744
|
function useDraggable(target, options = {}) {
|
443
745
|
var _a;
|
444
746
|
const {
|
@@ -1050,14 +1352,18 @@ function useVerticalVirtualList(options, list) {
|
|
1050
1352
|
};
|
1051
1353
|
}
|
1052
1354
|
export {
|
1355
|
+
StorageSerializers,
|
1356
|
+
bypassFilter,
|
1053
1357
|
camelize,
|
1054
1358
|
createFilterWrapper,
|
1055
1359
|
createReusableTemplate,
|
1056
1360
|
createSingletonPromise,
|
1361
|
+
customStorageEventName,
|
1057
1362
|
debounceFilter,
|
1058
1363
|
defaultNavigator,
|
1059
1364
|
defaultWindow,
|
1060
1365
|
getLifeCycleTarget,
|
1366
|
+
getSSRHandler,
|
1061
1367
|
injectLocal,
|
1062
1368
|
isClient,
|
1063
1369
|
isIOS,
|
@@ -1067,14 +1373,19 @@ export {
|
|
1067
1373
|
notNullish,
|
1068
1374
|
onClickOutside,
|
1069
1375
|
onKeyStroke,
|
1376
|
+
pausableFilter,
|
1377
|
+
watchPausable as pausableWatch,
|
1070
1378
|
pxValue,
|
1071
1379
|
throttleFilter,
|
1072
1380
|
toArray,
|
1381
|
+
toRef,
|
1073
1382
|
toRefs,
|
1074
1383
|
tryOnMounted,
|
1075
1384
|
tryOnScopeDispose,
|
1076
1385
|
unrefElement,
|
1077
1386
|
useClipboard,
|
1387
|
+
useColorMode,
|
1388
|
+
useDark,
|
1078
1389
|
useDebounceFn,
|
1079
1390
|
useDraggable,
|
1080
1391
|
useElementBounding,
|
@@ -1084,12 +1395,16 @@ export {
|
|
1084
1395
|
useMounted,
|
1085
1396
|
useMutationObserver,
|
1086
1397
|
usePermission,
|
1398
|
+
usePreferredDark,
|
1087
1399
|
useResizeObserver,
|
1088
1400
|
useSSRWidth,
|
1089
1401
|
useScroll,
|
1402
|
+
useStorage,
|
1090
1403
|
useSupported,
|
1091
1404
|
useThrottleFn,
|
1092
1405
|
useTimeoutFn,
|
1093
1406
|
useVirtualList,
|
1094
|
-
watchImmediate
|
1407
|
+
watchImmediate,
|
1408
|
+
watchPausable,
|
1409
|
+
watchWithFilter
|
1095
1410
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getCurrentScope, onScopeDispose, watch, onMounted, nextTick, isRef, toRefs as toRefs$1, customRef, toValue, getCurrentInstance, hasInjectionContext, inject,
|
1
|
+
import { getCurrentScope, onScopeDispose, watch, onMounted, nextTick, isRef, toRefs as toRefs$1, customRef, toValue, getCurrentInstance, hasInjectionContext, inject, toRef as toRef$1, readonly, ref, shallowRef } from "vue";
|
2
2
|
function tryOnScopeDispose(fn) {
|
3
3
|
if (getCurrentScope()) {
|
4
4
|
onScopeDispose(fn);
|
@@ -57,6 +57,9 @@ function createFilterWrapper(filter, fn) {
|
|
57
57
|
}
|
58
58
|
return wrapper;
|
59
59
|
}
|
60
|
+
const bypassFilter = (invoke) => {
|
61
|
+
return invoke();
|
62
|
+
};
|
60
63
|
function debounceFilter(ms, options = {}) {
|
61
64
|
let timer;
|
62
65
|
let maxTimer;
|
@@ -154,6 +157,23 @@ function throttleFilter(...args) {
|
|
154
157
|
};
|
155
158
|
return filter;
|
156
159
|
}
|
160
|
+
function pausableFilter(extendFilter = bypassFilter, options = {}) {
|
161
|
+
const {
|
162
|
+
initialState = "active"
|
163
|
+
} = options;
|
164
|
+
const isActive = toRef(initialState === "active");
|
165
|
+
function pause() {
|
166
|
+
isActive.value = false;
|
167
|
+
}
|
168
|
+
function resume() {
|
169
|
+
isActive.value = true;
|
170
|
+
}
|
171
|
+
const eventFilter = (...args) => {
|
172
|
+
if (isActive.value)
|
173
|
+
extendFilter(...args);
|
174
|
+
};
|
175
|
+
return { isActive: readonly(isActive), pause, resume, eventFilter };
|
176
|
+
}
|
157
177
|
function cacheStringFunction(fn) {
|
158
178
|
const cache = /* @__PURE__ */ Object.create(null);
|
159
179
|
return (str) => {
|
@@ -189,6 +209,12 @@ function getLifeCycleTarget(target) {
|
|
189
209
|
function toArray(value) {
|
190
210
|
return Array.isArray(value) ? value : [value];
|
191
211
|
}
|
212
|
+
function toRef(...args) {
|
213
|
+
if (args.length !== 1)
|
214
|
+
return toRef$1(...args);
|
215
|
+
const r = args[0];
|
216
|
+
return typeof r === "function" ? readonly(customRef(() => ({ get: r, set: noop }))) : ref(r);
|
217
|
+
}
|
192
218
|
function useDebounceFn(fn, ms = 200, options = {}) {
|
193
219
|
return createFilterWrapper(
|
194
220
|
debounceFilter(ms, options),
|
@@ -201,6 +227,37 @@ function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnC
|
|
201
227
|
fn
|
202
228
|
);
|
203
229
|
}
|
230
|
+
function watchWithFilter(source, cb, options = {}) {
|
231
|
+
const {
|
232
|
+
eventFilter = bypassFilter,
|
233
|
+
...watchOptions
|
234
|
+
} = options;
|
235
|
+
return watch(
|
236
|
+
source,
|
237
|
+
createFilterWrapper(
|
238
|
+
eventFilter,
|
239
|
+
cb
|
240
|
+
),
|
241
|
+
watchOptions
|
242
|
+
);
|
243
|
+
}
|
244
|
+
function watchPausable(source, cb, options = {}) {
|
245
|
+
const {
|
246
|
+
eventFilter: filter,
|
247
|
+
initialState = "active",
|
248
|
+
...watchOptions
|
249
|
+
} = options;
|
250
|
+
const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
|
251
|
+
const stop = watchWithFilter(
|
252
|
+
source,
|
253
|
+
cb,
|
254
|
+
{
|
255
|
+
...watchOptions,
|
256
|
+
eventFilter
|
257
|
+
}
|
258
|
+
);
|
259
|
+
return { stop, pause, resume, isActive };
|
260
|
+
}
|
204
261
|
function toRefs(objectRef, options = {}) {
|
205
262
|
if (!isRef(objectRef))
|
206
263
|
return toRefs$1(objectRef);
|
@@ -291,6 +348,7 @@ function watchImmediate(source, cb, options) {
|
|
291
348
|
);
|
292
349
|
}
|
293
350
|
export {
|
351
|
+
bypassFilter,
|
294
352
|
camelize,
|
295
353
|
createFilterWrapper,
|
296
354
|
createSingletonPromise,
|
@@ -303,14 +361,19 @@ export {
|
|
303
361
|
makeDestructurable,
|
304
362
|
noop,
|
305
363
|
notNullish,
|
364
|
+
pausableFilter,
|
365
|
+
watchPausable as pausableWatch,
|
306
366
|
pxValue,
|
307
367
|
throttleFilter,
|
308
368
|
toArray,
|
369
|
+
toRef,
|
309
370
|
toRefs,
|
310
371
|
tryOnMounted,
|
311
372
|
tryOnScopeDispose,
|
312
373
|
useDebounceFn,
|
313
374
|
useThrottleFn,
|
314
375
|
useTimeoutFn,
|
315
|
-
watchImmediate
|
376
|
+
watchImmediate,
|
377
|
+
watchPausable,
|
378
|
+
watchWithFilter
|
316
379
|
};
|