@vueuse/shared 10.4.1 → 10.5.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { shallowRef, watchEffect, readonly, ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, provide, inject, isVue3, version, isRef, unref, computed, reactive, toRefs as toRefs$1, toRef as toRef$1, isVue2, set as set$1, getCurrentInstance, onBeforeMount, nextTick, onBeforeUnmount, onMounted, onUnmounted, isReactive } from 'vue-demi';
1
+ import { shallowRef, watchEffect, readonly, ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, getCurrentInstance, provide, inject, isVue3, version, isRef, unref, computed, reactive, toRefs as toRefs$1, toRef as toRef$1, isVue2, set as set$1, onBeforeMount, nextTick, onBeforeUnmount, onMounted, onUnmounted, isReactive } from 'vue-demi';
2
2
 
3
3
  function computedEager(fn, options) {
4
4
  var _a;
@@ -90,14 +90,39 @@ function createGlobalState(stateFactory) {
90
90
  };
91
91
  }
92
92
 
93
- function createInjectionState(composable) {
94
- const key = Symbol("InjectionState");
93
+ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
94
+
95
+ const provideLocal = (key, value) => {
96
+ var _a;
97
+ const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
98
+ if (instance == null)
99
+ throw new Error("provideLocal must be called in setup");
100
+ if (!localProvidedStateMap.has(instance))
101
+ localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
102
+ const localProvidedState = localProvidedStateMap.get(instance);
103
+ localProvidedState[key] = value;
104
+ provide(key, value);
105
+ };
106
+
107
+ const injectLocal = (...args) => {
108
+ var _a;
109
+ const key = args[0];
110
+ const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
111
+ if (instance == null)
112
+ throw new Error("injectLocal must be called in setup");
113
+ if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
114
+ return localProvidedStateMap.get(instance)[key];
115
+ return inject(...args);
116
+ };
117
+
118
+ function createInjectionState(composable, options) {
119
+ const key = (options == null ? void 0 : options.injectionKey) || Symbol("InjectionState");
95
120
  const useProvidingState = (...args) => {
96
121
  const state = composable(...args);
97
- provide(key, state);
122
+ provideLocal(key, state);
98
123
  return state;
99
124
  };
100
- const useInjectedState = () => inject(key);
125
+ const useInjectedState = () => injectLocal(key);
101
126
  return [useProvidingState, useInjectedState];
102
127
  }
103
128
 
@@ -256,9 +281,7 @@ function reactiveComputed(fn) {
256
281
  function reactiveOmit(obj, ...keys) {
257
282
  const flatKeys = keys.flat();
258
283
  const predicate = flatKeys[0];
259
- return reactiveComputed(
260
- () => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0])))
261
- );
284
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
262
285
  }
263
286
 
264
287
  const isClient = typeof window !== "undefined" && typeof document !== "undefined";
@@ -414,9 +437,7 @@ function cacheStringFunction(fn) {
414
437
  };
415
438
  }
416
439
  const hyphenateRE = /\B([A-Z])/g;
417
- const hyphenate = cacheStringFunction(
418
- (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
419
- );
440
+ const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
420
441
  const camelizeRE = /-(\w)/g;
421
442
  const camelize = cacheStringFunction((str) => {
422
443
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
@@ -925,11 +946,9 @@ function useArrayFilter(list, fn) {
925
946
  }
926
947
 
927
948
  function useArrayFind(list, fn) {
928
- return computed(
929
- () => toValue(
930
- toValue(list).find((element, index, array) => fn(toValue(element), index, array))
931
- )
932
- );
949
+ return computed(() => toValue(
950
+ toValue(list).find((element, index, array) => fn(toValue(element), index, array))
951
+ ));
933
952
  }
934
953
 
935
954
  function useArrayFindIndex(list, fn) {
@@ -945,11 +964,9 @@ function findLast(arr, cb) {
945
964
  return void 0;
946
965
  }
947
966
  function useArrayFindLast(list, fn) {
948
- return computed(
949
- () => toValue(
950
- !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))
951
- )
952
- );
967
+ return computed(() => toValue(
968
+ !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))
969
+ ));
953
970
  }
954
971
 
955
972
  function isArrayIncludesOptions(obj) {
@@ -970,11 +987,12 @@ function useArrayIncludes(...args) {
970
987
  comparator = (element, value2) => element[key] === toValue(value2);
971
988
  }
972
989
  comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
973
- return computed(
974
- () => toValue(list).slice(formIndex).some(
975
- (element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))
976
- )
977
- );
990
+ return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
991
+ toValue(element),
992
+ toValue(value),
993
+ index,
994
+ toValue(array)
995
+ )));
978
996
  }
979
997
 
980
998
  function useArrayJoin(list, separator) {
@@ -1292,9 +1310,7 @@ function useToggle(initialValue = false, options = {}) {
1292
1310
  }
1293
1311
 
1294
1312
  function watchArray(source, cb, options) {
1295
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [
1296
- ...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)
1297
- ];
1313
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
1298
1314
  return watch(source, (newList, _, onCleanup) => {
1299
1315
  const oldListRemains = Array.from({ length: oldList.length });
1300
1316
  const added = [];
@@ -1520,4 +1536,4 @@ function whenever(source, cb, options) {
1520
1536
  );
1521
1537
  }
1522
1538
 
1523
- export { assert, refAutoReset as autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, directiveHooks, computedEager as eagerComputed, extendRef, formatDate, get, hasOwn, hyphenate, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isClient, isDef, isDefined, isIOS, isObject, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRef, toRefs, toValue, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
1539
+ export { assert, refAutoReset as autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, directiveHooks, computedEager as eagerComputed, extendRef, formatDate, get, hasOwn, hyphenate, identity, watchIgnorable as ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, provideLocal, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRef, toRefs, toValue, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/shared",
3
- "version": "10.4.1",
3
+ "version": "10.5.0",
4
4
  "author": "Anthony Fu <https://github.com/antfu>",
5
5
  "license": "MIT",
6
6
  "funding": "https://github.com/sponsors/antfu",
@@ -32,6 +32,6 @@
32
32
  "jsdelivr": "./index.iife.min.js",
33
33
  "types": "./index.d.cts",
34
34
  "dependencies": {
35
- "vue-demi": ">=0.14.5"
35
+ "vue-demi": ">=0.14.6"
36
36
  }
37
37
  }