@reactive-vscode/vueuse 1.0.0-beta.1 → 1.0.0-beta.2

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/dist/index.cjs CHANGED
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const reactivity = require("@reactive-vscode/reactivity");
4
- function getCurrentInstance() {
5
- return null;
6
- }
7
4
  function computedEager(fn, options) {
8
5
  var _options$flush;
9
6
  const result = reactivity.shallowRef();
@@ -97,38 +94,6 @@ function createGlobalState(stateFactory) {
97
94
  return state;
98
95
  });
99
96
  }
100
- const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
101
- const injectLocal = /* @__NO_SIDE_EFFECTS__ */ (...args) => {
102
- var _getCurrentInstance;
103
- const key = args[0];
104
- const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
105
- const owner = instance !== null && instance !== void 0 ? instance : reactivity.getCurrentScope();
106
- if (owner == null && !reactivity.hasInjectionContext()) throw new Error("injectLocal must be called in setup");
107
- if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)) return localProvidedStateMap.get(owner)[key];
108
- return reactivity.inject(...args);
109
- };
110
- function provideLocal(key, value) {
111
- var _getCurrentInstance;
112
- const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
113
- const owner = instance !== null && instance !== void 0 ? instance : reactivity.getCurrentScope();
114
- if (owner == null) throw new Error("provideLocal must be called in setup");
115
- if (!localProvidedStateMap.has(owner)) localProvidedStateMap.set(owner, /* @__PURE__ */ Object.create(null));
116
- const localProvidedState = localProvidedStateMap.get(owner);
117
- localProvidedState[key] = value;
118
- return reactivity.provide(key, value);
119
- }
120
- // @__NO_SIDE_EFFECTS__
121
- function createInjectionState(composable, options) {
122
- const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
123
- const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
124
- const useProvidingState = (...args) => {
125
- const state = composable(...args);
126
- provideLocal(key, state);
127
- return state;
128
- };
129
- const useInjectedState = () => /* @__PURE__ */ injectLocal(key, defaultValue);
130
- return [useProvidingState, useInjectedState];
131
- }
132
97
  // @__NO_SIDE_EFFECTS__
133
98
  function createRef(value, deep) {
134
99
  if (deep === true) return reactivity.ref(value);
@@ -354,9 +319,6 @@ const camelizeRE = /-(\w)/g;
354
319
  const camelize = cacheStringFunction((str) => {
355
320
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
356
321
  });
357
- function getLifeCycleTarget(target) {
358
- return target || getCurrentInstance();
359
- }
360
322
  // @__NO_SIDE_EFFECTS__
361
323
  function createSharedComposable(composable) {
362
324
  if (!isClient) return composable;
@@ -714,22 +676,10 @@ function toRefs(objectRef, options = {}) {
714
676
  }));
715
677
  return result;
716
678
  }
717
- function tryOnBeforeMount(fn, sync = true, target) {
718
- if (getLifeCycleTarget(target)) reactivity.onBeforeMount(fn, target);
719
- else if (sync) fn();
720
- else reactivity.nextTick(fn);
721
- }
722
- function tryOnBeforeUnmount(fn, target) {
723
- if (getLifeCycleTarget(target)) reactivity.onBeforeUnmount(fn, target);
724
- }
725
679
  function tryOnMounted(fn, sync = true, target) {
726
- if (getLifeCycleTarget(target)) ;
727
- else if (sync) fn();
680
+ if (sync) fn();
728
681
  else reactivity.nextTick(fn);
729
682
  }
730
- function tryOnUnmounted(fn, target) {
731
- if (getLifeCycleTarget(target)) reactivity.onUnmounted(fn, target);
732
- }
733
683
  function createUntil(r, isNot = false) {
734
684
  function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
735
685
  let stop = null;
@@ -2964,7 +2914,6 @@ exports.createEventHook = createEventHook;
2964
2914
  exports.createFetch = createFetch;
2965
2915
  exports.createFilterWrapper = createFilterWrapper;
2966
2916
  exports.createGlobalState = createGlobalState;
2967
- exports.createInjectionState = createInjectionState;
2968
2917
  exports.createReactiveFn = createReactiveFn;
2969
2918
  exports.createRef = createRef;
2970
2919
  exports.createSharedComposable = createSharedComposable;
@@ -2978,13 +2927,11 @@ exports.extendRef = extendRef;
2978
2927
  exports.formatDate = formatDate;
2979
2928
  exports.formatTimeAgo = formatTimeAgo;
2980
2929
  exports.get = get;
2981
- exports.getLifeCycleTarget = getLifeCycleTarget;
2982
2930
  exports.hasOwn = hasOwn;
2983
2931
  exports.hyphenate = hyphenate;
2984
2932
  exports.identity = identity;
2985
2933
  exports.ignorableWatch = ignorableWatch;
2986
2934
  exports.increaseWithUnit = increaseWithUnit;
2987
- exports.injectLocal = injectLocal;
2988
2935
  exports.invoke = invoke;
2989
2936
  exports.isDef = isDef;
2990
2937
  exports.isDefined = isDefined;
@@ -3000,7 +2947,6 @@ exports.objectPick = objectPick;
3000
2947
  exports.pausableFilter = pausableFilter;
3001
2948
  exports.pausableWatch = pausableWatch;
3002
2949
  exports.promiseTimeout = promiseTimeout;
3003
- exports.provideLocal = provideLocal;
3004
2950
  exports.pxValue = pxValue;
3005
2951
  exports.rand = rand;
3006
2952
  exports.reactify = reactify;
@@ -3025,11 +2971,6 @@ exports.toArray = toArray;
3025
2971
  exports.toReactive = toReactive;
3026
2972
  exports.toRef = toRef;
3027
2973
  exports.toRefs = toRefs;
3028
- exports.tryOnBeforeMount = tryOnBeforeMount;
3029
- exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
3030
- exports.tryOnMounted = tryOnMounted;
3031
- exports.tryOnScopeDispose = tryOnScopeDispose;
3032
- exports.tryOnUnmounted = tryOnUnmounted;
3033
2974
  exports.until = until;
3034
2975
  exports.useArrayDifference = useArrayDifference;
3035
2976
  exports.useArrayEvery = useArrayEvery;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
- import { ComponentInternalInstance } from '@reactive-vscode/reactivity';
2
1
  import { ComputedGetter } from '@reactive-vscode/reactivity';
3
2
  import { ComputedRef } from '@reactive-vscode/reactivity';
4
3
  import { getCurrentInstance } from '@reactive-vscode/reactivity';
5
- import { inject } from '@reactive-vscode/reactivity';
6
- import { InjectionKey } from '@reactive-vscode/reactivity';
7
4
  import { MaybeRef } from '@reactive-vscode/reactivity';
8
5
  import { MaybeRefOrGetter } from '@reactive-vscode/reactivity';
9
6
  import { MultiWatchSources } from '@reactive-vscode/reactivity';
@@ -310,41 +307,6 @@ export declare function createGlobalState<Fn$1 extends AnyFn>(stateFactory: Fn$1
310
307
 
311
308
  export declare type CreateGlobalStateReturn<Fn$1 extends AnyFn = AnyFn> = Fn$1;
312
309
 
313
- /**
314
- * Create global state that can be injected into components.
315
- *
316
- * @see https://vueuse.org/createInjectionState
317
- *
318
- * @__NO_SIDE_EFFECTS__
319
- */
320
- export declare function createInjectionState<Arguments extends Array<any>, Return>(composable: (...args: Arguments) => Return, options?: CreateInjectionStateOptions<Return>): CreateInjectionStateReturn<Arguments, Return>;
321
-
322
- export declare interface CreateInjectionStateOptions<Return> {
323
- /**
324
- * Custom injectionKey for InjectionState
325
- */
326
- injectionKey?: string | InjectionKey<Return>;
327
- /**
328
- * Default value for the InjectionState
329
- */
330
- defaultValue?: Return;
331
- }
332
-
333
- export declare type CreateInjectionStateReturn<Arguments extends Array<any>, Return> = Readonly<[
334
- /**
335
- * Call this function in a provider component to create and provide the state.
336
- *
337
- * @param args Arguments passed to the composable
338
- * @returns The state returned by the composable
339
- */
340
- useProvidingState: (...args: Arguments) => Return,
341
- /**
342
- * Call this function in a consumer component to inject the state.
343
- *
344
- * @returns The injected state, or `undefined` if not provided and no default value was set.
345
- */
346
- useInjectedState: () => Return | undefined]>;
347
-
348
310
  /** @deprecated use `reactify` instead */
349
311
  export declare const createReactiveFn: typeof reactify;
350
312
 
@@ -572,8 +534,6 @@ export declare function get<T$1>(ref: MaybeRef<T$1>): T$1;
572
534
 
573
535
  export declare function get<T$1, K$1 extends keyof T$1>(ref: MaybeRef<T$1>, key: K$1): T$1[K$1];
574
536
 
575
- export declare function getLifeCycleTarget(target?: ComponentInternalInstance | null): ComponentInternalInstance | null;
576
-
577
537
  export declare const hasOwn: <T extends object, K extends keyof T>(val: T, key: K) => key is K;
578
538
 
579
539
  export declare const hyphenate: (str: string) => string;
@@ -606,19 +566,6 @@ export declare function increaseWithUnit(target: string, delta: number): string;
606
566
 
607
567
  export declare function increaseWithUnit(target: string | number, delta: number): string | number;
608
568
 
609
- /**
610
- * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
611
- *
612
- * @example
613
- * ```ts
614
- * injectLocal('MyInjectionKey', 1)
615
- * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
616
- * ```
617
- *
618
- * @__NO_SIDE_EFFECTS__
619
- */
620
- export declare const injectLocal: typeof inject;
621
-
622
569
  export declare type InstanceProxy = NonNullable<NonNullable<ReturnType<typeof getCurrentInstance>>['proxy']>;
623
570
 
624
571
  /**
@@ -651,8 +598,6 @@ export declare type IsDefinedReturn = boolean;
651
598
 
652
599
  export declare const isObject: (val: any) => val is object;
653
600
 
654
- declare type LocalProvidedKey<T$1> = InjectionKey<T$1> | string | number;
655
-
656
601
  export declare function makeDestructurable<T$1 extends Record<string, unknown>, A$1 extends readonly any[]>(obj: T$1, arr: A$1): T$1 & A$1;
657
602
 
658
603
  /**
@@ -757,19 +702,6 @@ export declare type Promisify<T$1> = Promise<Awaited_2<T$1>>;
757
702
 
758
703
  export declare type PromisifyFn<T$1 extends AnyFn> = (...args: ArgumentsType<T$1>) => Promisify<ReturnType<T$1>>;
759
704
 
760
- /**
761
- * On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
762
- *
763
- * @example
764
- * ```ts
765
- * provideLocal('MyInjectionKey', 1)
766
- * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
767
- * ```
768
- */
769
- export declare function provideLocal<T$1, K$1 = LocalProvidedKey<T$1>>(key: K$1, value: K$1 extends InjectionKey<infer V> ? V : T$1): ProvideLocalReturn;
770
-
771
- export declare type ProvideLocalReturn = void;
772
-
773
705
  /**
774
706
  * Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client
775
707
  */
@@ -1134,47 +1066,6 @@ declare interface Transform<L, R$1> {
1134
1066
 
1135
1067
  declare type TransformType<D extends Direction, L, R$1> = Equal<L, R$1> extends true ? EqualType<D, L, R$1> : IncludeButNotEqual<L, R$1> extends true ? StrictIncludeType<'LR', D, L, R$1> : IncludeButNotEqual<R$1, L> extends true ? StrictIncludeType<'RL', D, L, R$1> : IntersectButNotEqual<L, R$1> extends true ? IntersectButNotEqualType<D, L, R$1> : NotIntersect<L, R$1> extends true ? NotIntersectType<D, L, R$1> : never;
1136
1068
 
1137
- /**
1138
- * Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
1139
- *
1140
- * @param fn
1141
- * @param sync if set to false, it will run in the nextTick() of Vue
1142
- * @param target
1143
- */
1144
- export declare function tryOnBeforeMount(fn: Fn, sync?: boolean, target?: ComponentInternalInstance | null): void;
1145
-
1146
- /**
1147
- * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
1148
- *
1149
- * @param fn
1150
- * @param target
1151
- */
1152
- export declare function tryOnBeforeUnmount(fn: Fn, target?: ComponentInternalInstance | null): void;
1153
-
1154
- /**
1155
- * Call onMounted() if it's inside a component lifecycle, if not, just call the function
1156
- *
1157
- * @param fn
1158
- * @param sync if set to false, it will run in the nextTick() of Vue
1159
- * @param target
1160
- */
1161
- export declare function tryOnMounted(fn: Fn, sync?: boolean, target?: ComponentInternalInstance | null): void;
1162
-
1163
- /**
1164
- * Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
1165
- *
1166
- * @param fn
1167
- */
1168
- export declare function tryOnScopeDispose(fn: Fn, failSilently?: boolean): boolean;
1169
-
1170
- /**
1171
- * Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
1172
- *
1173
- * @param fn
1174
- * @param target
1175
- */
1176
- export declare function tryOnUnmounted(fn: Fn, target?: ComponentInternalInstance | null): void;
1177
-
1178
1069
  export declare type UnrefFn<T> = T extends ((...args: infer A) => infer R) ? (...args: { [K in keyof A]: MaybeRef<A[K]> }) => R : never;
1179
1070
 
1180
1071
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
- import { customRef, toValue, shallowRef, watchEffect, readonly, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, getCurrentScope, hasInjectionContext, inject, provide, toRefs as toRefs$1, reactive, toRef as toRef$1, onBeforeMount, nextTick, onBeforeUnmount, onScopeDispose, onUnmounted, isReactive, isReadonly, markRaw } from "@reactive-vscode/reactivity";
2
- function getCurrentInstance() {
3
- return null;
4
- }
1
+ import { customRef, toValue, shallowRef, watchEffect, readonly, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, toRefs as toRefs$1, reactive, toRef as toRef$1, nextTick, getCurrentScope, onScopeDispose, isReactive, isReadonly, markRaw } from "@reactive-vscode/reactivity";
5
2
  function computedEager(fn, options) {
6
3
  var _options$flush;
7
4
  const result = shallowRef();
@@ -95,38 +92,6 @@ function createGlobalState(stateFactory) {
95
92
  return state;
96
93
  });
97
94
  }
98
- const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
99
- const injectLocal = /* @__NO_SIDE_EFFECTS__ */ (...args) => {
100
- var _getCurrentInstance;
101
- const key = args[0];
102
- const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
103
- const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
104
- if (owner == null && !hasInjectionContext()) throw new Error("injectLocal must be called in setup");
105
- if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)) return localProvidedStateMap.get(owner)[key];
106
- return inject(...args);
107
- };
108
- function provideLocal(key, value) {
109
- var _getCurrentInstance;
110
- const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
111
- const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
112
- if (owner == null) throw new Error("provideLocal must be called in setup");
113
- if (!localProvidedStateMap.has(owner)) localProvidedStateMap.set(owner, /* @__PURE__ */ Object.create(null));
114
- const localProvidedState = localProvidedStateMap.get(owner);
115
- localProvidedState[key] = value;
116
- return provide(key, value);
117
- }
118
- // @__NO_SIDE_EFFECTS__
119
- function createInjectionState(composable, options) {
120
- const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
121
- const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
122
- const useProvidingState = (...args) => {
123
- const state = composable(...args);
124
- provideLocal(key, state);
125
- return state;
126
- };
127
- const useInjectedState = () => /* @__PURE__ */ injectLocal(key, defaultValue);
128
- return [useProvidingState, useInjectedState];
129
- }
130
95
  // @__NO_SIDE_EFFECTS__
131
96
  function createRef(value, deep) {
132
97
  if (deep === true) return ref(value);
@@ -352,9 +317,6 @@ const camelizeRE = /-(\w)/g;
352
317
  const camelize = cacheStringFunction((str) => {
353
318
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
354
319
  });
355
- function getLifeCycleTarget(target) {
356
- return target || getCurrentInstance();
357
- }
358
320
  // @__NO_SIDE_EFFECTS__
359
321
  function createSharedComposable(composable) {
360
322
  if (!isClient) return composable;
@@ -712,22 +674,10 @@ function toRefs(objectRef, options = {}) {
712
674
  }));
713
675
  return result;
714
676
  }
715
- function tryOnBeforeMount(fn, sync = true, target) {
716
- if (getLifeCycleTarget(target)) onBeforeMount(fn, target);
717
- else if (sync) fn();
718
- else nextTick(fn);
719
- }
720
- function tryOnBeforeUnmount(fn, target) {
721
- if (getLifeCycleTarget(target)) onBeforeUnmount(fn, target);
722
- }
723
677
  function tryOnMounted(fn, sync = true, target) {
724
- if (getLifeCycleTarget(target)) ;
725
- else if (sync) fn();
678
+ if (sync) fn();
726
679
  else nextTick(fn);
727
680
  }
728
- function tryOnUnmounted(fn, target) {
729
- if (getLifeCycleTarget(target)) onUnmounted(fn, target);
730
- }
731
681
  function createUntil(r, isNot = false) {
732
682
  function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
733
683
  let stop = null;
@@ -2963,7 +2913,6 @@ export {
2963
2913
  createFetch,
2964
2914
  createFilterWrapper,
2965
2915
  createGlobalState,
2966
- createInjectionState,
2967
2916
  createReactiveFn,
2968
2917
  createRef,
2969
2918
  createSharedComposable,
@@ -2977,13 +2926,11 @@ export {
2977
2926
  formatDate,
2978
2927
  formatTimeAgo,
2979
2928
  get,
2980
- getLifeCycleTarget,
2981
2929
  hasOwn,
2982
2930
  hyphenate,
2983
2931
  identity,
2984
2932
  ignorableWatch,
2985
2933
  increaseWithUnit,
2986
- injectLocal,
2987
2934
  invoke,
2988
2935
  isDef,
2989
2936
  isDefined,
@@ -2999,7 +2946,6 @@ export {
2999
2946
  pausableFilter,
3000
2947
  pausableWatch,
3001
2948
  promiseTimeout,
3002
- provideLocal,
3003
2949
  pxValue,
3004
2950
  rand,
3005
2951
  reactify,
@@ -3024,11 +2970,6 @@ export {
3024
2970
  toReactive,
3025
2971
  toRef,
3026
2972
  toRefs,
3027
- tryOnBeforeMount,
3028
- tryOnBeforeUnmount,
3029
- tryOnMounted,
3030
- tryOnScopeDispose,
3031
- tryOnUnmounted,
3032
2973
  until,
3033
2974
  useArrayDifference,
3034
2975
  useArrayEvery,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reactive-vscode/vueuse",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.1",
4
+ "version": "1.0.0-beta.2",
5
5
  "description": "Useful VueUse utilities for VSCode extension development",
6
6
  "author": "_Kerman <kermanx@qq.com>",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "tsconfig.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@reactive-vscode/reactivity": "1.0.0-beta.1"
36
+ "@reactive-vscode/reactivity": "1.0.0-beta.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^25.0.3",