@vueuse/shared 10.4.1 → 10.6.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/index.cjs +67 -35
- package/index.d.cts +136 -63
- package/index.d.mts +136 -63
- package/index.d.ts +136 -63
- package/index.iife.js +67 -35
- package/index.iife.min.js +1 -1
- package/index.mjs +66 -37
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -70,7 +70,7 @@ function createEventHook() {
|
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
72
|
const trigger = (param) => {
|
|
73
|
-
return Promise.all(Array.from(fns).map((fn) => fn(param)));
|
|
73
|
+
return Promise.all(Array.from(fns).map((fn) => param ? fn(param) : fn()));
|
|
74
74
|
};
|
|
75
75
|
return {
|
|
76
76
|
on,
|
|
@@ -92,14 +92,39 @@ function createGlobalState(stateFactory) {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
|
|
96
|
+
|
|
97
|
+
const provideLocal = (key, value) => {
|
|
98
|
+
var _a;
|
|
99
|
+
const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
100
|
+
if (instance == null)
|
|
101
|
+
throw new Error("provideLocal must be called in setup");
|
|
102
|
+
if (!localProvidedStateMap.has(instance))
|
|
103
|
+
localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
|
|
104
|
+
const localProvidedState = localProvidedStateMap.get(instance);
|
|
105
|
+
localProvidedState[key] = value;
|
|
106
|
+
vueDemi.provide(key, value);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const injectLocal = (...args) => {
|
|
110
|
+
var _a;
|
|
111
|
+
const key = args[0];
|
|
112
|
+
const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
113
|
+
if (instance == null)
|
|
114
|
+
throw new Error("injectLocal must be called in setup");
|
|
115
|
+
if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
|
|
116
|
+
return localProvidedStateMap.get(instance)[key];
|
|
117
|
+
return vueDemi.inject(...args);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
function createInjectionState(composable, options) {
|
|
121
|
+
const key = (options == null ? void 0 : options.injectionKey) || Symbol("InjectionState");
|
|
97
122
|
const useProvidingState = (...args) => {
|
|
98
123
|
const state = composable(...args);
|
|
99
|
-
|
|
124
|
+
provideLocal(key, state);
|
|
100
125
|
return state;
|
|
101
126
|
};
|
|
102
|
-
const useInjectedState = () =>
|
|
127
|
+
const useInjectedState = () => injectLocal(key);
|
|
103
128
|
return [useProvidingState, useInjectedState];
|
|
104
129
|
}
|
|
105
130
|
|
|
@@ -258,12 +283,11 @@ function reactiveComputed(fn) {
|
|
|
258
283
|
function reactiveOmit(obj, ...keys) {
|
|
259
284
|
const flatKeys = keys.flat();
|
|
260
285
|
const predicate = flatKeys[0];
|
|
261
|
-
return reactiveComputed(
|
|
262
|
-
() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter((e) => !flatKeys.includes(e[0])))
|
|
263
|
-
);
|
|
286
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
264
287
|
}
|
|
265
288
|
|
|
266
289
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
290
|
+
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
267
291
|
const isDef = (val) => typeof val !== "undefined";
|
|
268
292
|
const notNullish = (val) => val != null;
|
|
269
293
|
const assert = (condition, ...infos) => {
|
|
@@ -416,9 +440,7 @@ function cacheStringFunction(fn) {
|
|
|
416
440
|
};
|
|
417
441
|
}
|
|
418
442
|
const hyphenateRE = /\B([A-Z])/g;
|
|
419
|
-
const hyphenate = cacheStringFunction(
|
|
420
|
-
(str) => str.replace(hyphenateRE, "-$1").toLowerCase()
|
|
421
|
-
);
|
|
443
|
+
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
422
444
|
const camelizeRE = /-(\w)/g;
|
|
423
445
|
const camelize = cacheStringFunction((str) => {
|
|
424
446
|
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
@@ -670,18 +692,17 @@ function watchPausable(source, cb, options = {}) {
|
|
|
670
692
|
return { stop, pause, resume, isActive };
|
|
671
693
|
}
|
|
672
694
|
|
|
673
|
-
function syncRef(left, right, options
|
|
674
|
-
var _a, _b;
|
|
695
|
+
function syncRef(left, right, ...[options]) {
|
|
675
696
|
const {
|
|
676
697
|
flush = "sync",
|
|
677
698
|
deep = false,
|
|
678
699
|
immediate = true,
|
|
679
700
|
direction = "both",
|
|
680
701
|
transform = {}
|
|
681
|
-
} = options;
|
|
702
|
+
} = options || {};
|
|
682
703
|
const watchers = [];
|
|
683
|
-
const transformLTR =
|
|
684
|
-
const transformRTL =
|
|
704
|
+
const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
|
|
705
|
+
const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
|
|
685
706
|
if (direction === "both" || direction === "ltr") {
|
|
686
707
|
watchers.push(watchPausable(
|
|
687
708
|
left,
|
|
@@ -927,11 +948,9 @@ function useArrayFilter(list, fn) {
|
|
|
927
948
|
}
|
|
928
949
|
|
|
929
950
|
function useArrayFind(list, fn) {
|
|
930
|
-
return vueDemi.computed(
|
|
931
|
-
() => toValue(
|
|
932
|
-
|
|
933
|
-
)
|
|
934
|
-
);
|
|
951
|
+
return vueDemi.computed(() => toValue(
|
|
952
|
+
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
953
|
+
));
|
|
935
954
|
}
|
|
936
955
|
|
|
937
956
|
function useArrayFindIndex(list, fn) {
|
|
@@ -947,11 +966,9 @@ function findLast(arr, cb) {
|
|
|
947
966
|
return void 0;
|
|
948
967
|
}
|
|
949
968
|
function useArrayFindLast(list, fn) {
|
|
950
|
-
return vueDemi.computed(
|
|
951
|
-
() => toValue(
|
|
952
|
-
|
|
953
|
-
)
|
|
954
|
-
);
|
|
969
|
+
return vueDemi.computed(() => toValue(
|
|
970
|
+
!Array.prototype.findLast ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array)) : toValue(list).findLast((element, index, array) => fn(toValue(element), index, array))
|
|
971
|
+
));
|
|
955
972
|
}
|
|
956
973
|
|
|
957
974
|
function isArrayIncludesOptions(obj) {
|
|
@@ -972,11 +989,12 @@ function useArrayIncludes(...args) {
|
|
|
972
989
|
comparator = (element, value2) => element[key] === toValue(value2);
|
|
973
990
|
}
|
|
974
991
|
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
975
|
-
return vueDemi.computed(
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
992
|
+
return vueDemi.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
993
|
+
toValue(element),
|
|
994
|
+
toValue(value),
|
|
995
|
+
index,
|
|
996
|
+
toValue(array)
|
|
997
|
+
)));
|
|
980
998
|
}
|
|
981
999
|
|
|
982
1000
|
function useArrayJoin(list, separator) {
|
|
@@ -1035,13 +1053,18 @@ function useCounter(initialValue = 0, options = {}) {
|
|
|
1035
1053
|
}
|
|
1036
1054
|
|
|
1037
1055
|
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
|
1038
|
-
const REGEX_FORMAT =
|
|
1056
|
+
const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
1039
1057
|
function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
|
|
1040
1058
|
let m = hours < 12 ? "AM" : "PM";
|
|
1041
1059
|
if (hasPeriod)
|
|
1042
1060
|
m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
|
|
1043
1061
|
return isLowercase ? m.toLowerCase() : m;
|
|
1044
1062
|
}
|
|
1063
|
+
function formatOrdinal(num) {
|
|
1064
|
+
const suffixes = ["th", "st", "nd", "rd"];
|
|
1065
|
+
const v = num % 100;
|
|
1066
|
+
return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
1067
|
+
}
|
|
1045
1068
|
function formatDate(date, formatStr, options = {}) {
|
|
1046
1069
|
var _a;
|
|
1047
1070
|
const years = date.getFullYear();
|
|
@@ -1054,21 +1077,28 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1054
1077
|
const day = date.getDay();
|
|
1055
1078
|
const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
|
|
1056
1079
|
const matches = {
|
|
1080
|
+
Yo: () => formatOrdinal(years),
|
|
1057
1081
|
YY: () => String(years).slice(-2),
|
|
1058
1082
|
YYYY: () => years,
|
|
1059
1083
|
M: () => month + 1,
|
|
1084
|
+
Mo: () => formatOrdinal(month + 1),
|
|
1060
1085
|
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
1061
1086
|
MMM: () => date.toLocaleDateString(options.locales, { month: "short" }),
|
|
1062
1087
|
MMMM: () => date.toLocaleDateString(options.locales, { month: "long" }),
|
|
1063
1088
|
D: () => String(days),
|
|
1089
|
+
Do: () => formatOrdinal(days),
|
|
1064
1090
|
DD: () => `${days}`.padStart(2, "0"),
|
|
1065
1091
|
H: () => String(hours),
|
|
1092
|
+
Ho: () => formatOrdinal(hours),
|
|
1066
1093
|
HH: () => `${hours}`.padStart(2, "0"),
|
|
1067
1094
|
h: () => `${hours % 12 || 12}`.padStart(1, "0"),
|
|
1095
|
+
ho: () => formatOrdinal(hours % 12 || 12),
|
|
1068
1096
|
hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
|
|
1069
1097
|
m: () => String(minutes),
|
|
1098
|
+
mo: () => formatOrdinal(minutes),
|
|
1070
1099
|
mm: () => `${minutes}`.padStart(2, "0"),
|
|
1071
1100
|
s: () => String(seconds),
|
|
1101
|
+
so: () => formatOrdinal(seconds),
|
|
1072
1102
|
ss: () => `${seconds}`.padStart(2, "0"),
|
|
1073
1103
|
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
1074
1104
|
d: () => day,
|
|
@@ -1294,9 +1324,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1294
1324
|
}
|
|
1295
1325
|
|
|
1296
1326
|
function watchArray(source, cb, options) {
|
|
1297
|
-
let oldList = (options == null ? void 0 : options.immediate) ? [] : [
|
|
1298
|
-
...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)
|
|
1299
|
-
];
|
|
1327
|
+
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
|
|
1300
1328
|
return vueDemi.watch(source, (newList, _, onCleanup) => {
|
|
1301
1329
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1302
1330
|
const added = [];
|
|
@@ -1451,6 +1479,7 @@ function watchOnce(source, cb, options) {
|
|
|
1451
1479
|
vueDemi.nextTick(() => stop());
|
|
1452
1480
|
return cb(...args);
|
|
1453
1481
|
}, options);
|
|
1482
|
+
return stop;
|
|
1454
1483
|
}
|
|
1455
1484
|
|
|
1456
1485
|
function watchThrottled(source, cb, options = {}) {
|
|
@@ -1552,12 +1581,14 @@ exports.hyphenate = hyphenate;
|
|
|
1552
1581
|
exports.identity = identity;
|
|
1553
1582
|
exports.ignorableWatch = watchIgnorable;
|
|
1554
1583
|
exports.increaseWithUnit = increaseWithUnit;
|
|
1584
|
+
exports.injectLocal = injectLocal;
|
|
1555
1585
|
exports.invoke = invoke;
|
|
1556
1586
|
exports.isClient = isClient;
|
|
1557
1587
|
exports.isDef = isDef;
|
|
1558
1588
|
exports.isDefined = isDefined;
|
|
1559
1589
|
exports.isIOS = isIOS;
|
|
1560
1590
|
exports.isObject = isObject;
|
|
1591
|
+
exports.isWorker = isWorker;
|
|
1561
1592
|
exports.makeDestructurable = makeDestructurable;
|
|
1562
1593
|
exports.noop = noop;
|
|
1563
1594
|
exports.normalizeDate = normalizeDate;
|
|
@@ -1569,6 +1600,7 @@ exports.objectPick = objectPick;
|
|
|
1569
1600
|
exports.pausableFilter = pausableFilter;
|
|
1570
1601
|
exports.pausableWatch = watchPausable;
|
|
1571
1602
|
exports.promiseTimeout = promiseTimeout;
|
|
1603
|
+
exports.provideLocal = provideLocal;
|
|
1572
1604
|
exports.rand = rand;
|
|
1573
1605
|
exports.reactify = reactify;
|
|
1574
1606
|
exports.reactifyObject = reactifyObject;
|