@tb-dev/vue 4.0.14 → 4.0.15
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.js +37 -37
- package/dist/src/composables/index.d.ts +2 -2
- package/dist/src/composables/onKeyDown/index.d.ts +1 -1
- package/dist/src/composables/useMutex/index.d.ts +1 -1
- package/dist/src/types/ref.d.ts +1 -1
- package/dist/src/utils/app.d.ts +2 -2
- package/dist/src/utils/error.d.ts +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -97,35 +97,6 @@ function warn(source) {
|
|
|
97
97
|
return watchImmediate(toRef(source), (value) => globalThis.console.warn(value));
|
|
98
98
|
}
|
|
99
99
|
//#endregion
|
|
100
|
-
//#region src/composables/useMutex/index.ts
|
|
101
|
-
function useMutex(options) {
|
|
102
|
-
const mutex = new Mutex();
|
|
103
|
-
const locked = ref(mutex.isLocked);
|
|
104
|
-
let onError;
|
|
105
|
-
if (typeof options?.onError === "function") onError = options.onError;
|
|
106
|
-
else if (options?.onError !== false) onError = handleError;
|
|
107
|
-
async function acquire() {
|
|
108
|
-
await mutex.acquire();
|
|
109
|
-
locked.value = mutex.isLocked;
|
|
110
|
-
}
|
|
111
|
-
function release() {
|
|
112
|
-
mutex.release();
|
|
113
|
-
locked.value = mutex.isLocked;
|
|
114
|
-
}
|
|
115
|
-
function lock(fn) {
|
|
116
|
-
const { resolve, reject, promise } = Promise.withResolvers();
|
|
117
|
-
acquire().then(() => fn()).then((value) => resolve(value)).catch(reject).finally(release);
|
|
118
|
-
if (onError) return promise.catch(onError);
|
|
119
|
-
return promise;
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
locked: readonly(locked),
|
|
123
|
-
acquire,
|
|
124
|
-
release,
|
|
125
|
-
lock
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
100
|
//#region src/composables/asyncRef/index.ts
|
|
130
101
|
function asyncRef(initial, fn, options = {}) {
|
|
131
102
|
const value = useAsyncState(fn, initial, {
|
|
@@ -164,6 +135,35 @@ function localRef(key, initial, options) {
|
|
|
164
135
|
});
|
|
165
136
|
}
|
|
166
137
|
//#endregion
|
|
138
|
+
//#region src/composables/useMutex/index.ts
|
|
139
|
+
function useMutex(options) {
|
|
140
|
+
const mutex = new Mutex();
|
|
141
|
+
const locked = ref(mutex.isLocked);
|
|
142
|
+
let onError;
|
|
143
|
+
if (typeof options?.onError === "function") onError = options.onError;
|
|
144
|
+
else if (options?.onError !== false) onError = handleError;
|
|
145
|
+
async function acquire() {
|
|
146
|
+
await mutex.acquire();
|
|
147
|
+
locked.value = mutex.isLocked;
|
|
148
|
+
}
|
|
149
|
+
function release() {
|
|
150
|
+
mutex.release();
|
|
151
|
+
locked.value = mutex.isLocked;
|
|
152
|
+
}
|
|
153
|
+
function lock(fn) {
|
|
154
|
+
const { resolve, reject, promise } = Promise.withResolvers();
|
|
155
|
+
acquire().then(() => fn()).then((value) => resolve(value)).catch(reject).finally(release);
|
|
156
|
+
if (onError) return promise.catch(onError);
|
|
157
|
+
return promise;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
locked: readonly(locked),
|
|
161
|
+
acquire,
|
|
162
|
+
release,
|
|
163
|
+
lock
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
167
|
//#region src/composables/onKeyDown/index.ts
|
|
168
168
|
function onKeyDown(key, handler, options = {}) {
|
|
169
169
|
const { altKey = false, ctrlKey = false, dedupe = true, detached = false, enabled = true, metaKey = false, prevent = true, shiftKey = false, stopPropagation = false } = options;
|
|
@@ -249,6 +249,14 @@ function useWindowWidth() {
|
|
|
249
249
|
return useWindowSize().width;
|
|
250
250
|
}
|
|
251
251
|
//#endregion
|
|
252
|
+
//#region src/composables/useBreakpoints/index.ts
|
|
253
|
+
var breakpointsKey = Symbol();
|
|
254
|
+
function useBreakpoints() {
|
|
255
|
+
return tryInjectOrElse(breakpointsKey, () => {
|
|
256
|
+
return useBreakpoints$1(breakpointsTailwind);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
252
260
|
//#region src/composables/useElementSize/index.ts
|
|
253
261
|
function useElementSize(element) {
|
|
254
262
|
return useElementSize$1(toRef(element), {
|
|
@@ -273,14 +281,6 @@ function useWidthDiff(element, lhs) {
|
|
|
273
281
|
return computed(() => lhsRef.value - width.value);
|
|
274
282
|
}
|
|
275
283
|
//#endregion
|
|
276
|
-
//#region src/composables/useBreakpoints/index.ts
|
|
277
|
-
var breakpointsKey = Symbol();
|
|
278
|
-
function useBreakpoints() {
|
|
279
|
-
return tryInjectOrElse(breakpointsKey, () => {
|
|
280
|
-
return useBreakpoints$1(breakpointsTailwind);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
//#endregion
|
|
284
284
|
//#region src/index.ts
|
|
285
285
|
if (!Object.hasOwn(globalThis, "__VUEUTILS__")) Object.defineProperty(globalThis, "__VUEUTILS__", {
|
|
286
286
|
configurable: false,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from './console';
|
|
2
|
-
export * from './useMutex';
|
|
3
2
|
export * from './asyncRef';
|
|
4
3
|
export * from './localRef';
|
|
4
|
+
export * from './useMutex';
|
|
5
5
|
export * from './onKeyDown';
|
|
6
6
|
export * from './sessionRef';
|
|
7
7
|
export * from './asyncComputed';
|
|
8
8
|
export * from './useWindowSize';
|
|
9
|
-
export * from './useElementSize';
|
|
10
9
|
export * from './useBreakpoints';
|
|
10
|
+
export * from './useElementSize';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MaybeNilRef } from '../../types/ref';
|
|
2
|
-
import { MaybePromise, Option } from '@tb-dev/utils';
|
|
2
|
+
import { Fn, MaybePromise, Option } from '@tb-dev/utils';
|
|
3
3
|
import { KeyFilter, OnKeyStrokeOptions } from '@vueuse/core';
|
|
4
4
|
export type KeyDownEventHandler = Option<(event: KeyboardEvent) => MaybePromise<unknown>>;
|
|
5
5
|
export type OnKeyDownOptions = Omit<OnKeyStrokeOptions, 'eventName'> & {
|
|
@@ -5,5 +5,5 @@ export declare function useMutex(options?: UseMutexOptions): {
|
|
|
5
5
|
locked: Readonly<import('vue').Ref<boolean, boolean>>;
|
|
6
6
|
acquire: () => Promise<void>;
|
|
7
7
|
release: () => void;
|
|
8
|
-
lock: <T = unknown>(fn: () => Promise<T>) => Promise<T>;
|
|
8
|
+
lock: <T = unknown>(fn: () => Promise<T>) => Promise<void | T>;
|
|
9
9
|
};
|
package/dist/src/types/ref.d.ts
CHANGED
package/dist/src/utils/app.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { App, InjectionKey } from 'vue';
|
|
2
|
-
export declare function getCurrentApp(): any
|
|
2
|
+
export declare function getCurrentApp(): App<any>;
|
|
3
3
|
export declare function setCurrentApp(app: App): void;
|
|
4
|
-
export declare function tryGetCurrentApp(): any
|
|
4
|
+
export declare function tryGetCurrentApp(): import('@tb-dev/utils').Option<App<any>>;
|
|
5
5
|
export declare function trySetCurrentApp(app: App): void;
|
|
6
6
|
export declare function runWithContext<T>(fn: () => T): T;
|
|
7
7
|
export declare function provide<T>(key: InjectionKey<T>, value: T): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
import { MaybePromise, Option } from '@tb-dev/utils';
|
|
3
3
|
export type ErrorHandler = (err: unknown) => MaybePromise<void>;
|
|
4
|
-
export declare function getErrorHandler():
|
|
4
|
+
export declare function getErrorHandler(): Option<ErrorHandler>;
|
|
5
5
|
export declare function setErrorHandler(fn: ErrorHandler, app?: Option<App | boolean>): void;
|
|
6
6
|
export declare function handleError(err: unknown, rethrow?: boolean): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/vue",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.15",
|
|
4
4
|
"description": "Vue utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"composables"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tb-dev/utils": "^7.3.
|
|
27
|
+
"@tb-dev/utils": "^7.3.13",
|
|
28
28
|
"@vueuse/core": "^14.2.1",
|
|
29
29
|
"es-toolkit": "^1.45.1",
|
|
30
30
|
"vue": "^3.5.31"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tb-dev/eslint-config": "^9.1.
|
|
33
|
+
"@tb-dev/eslint-config": "^9.1.2",
|
|
34
34
|
"@types/node": "^25.5.0",
|
|
35
35
|
"eslint": "^10.1.0",
|
|
36
36
|
"tslib": "^2.8.1",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"main": "./dist/index.js",
|
|
47
|
-
"types": "./dist/index.d.ts",
|
|
47
|
+
"types": "./dist/src/index.d.ts",
|
|
48
48
|
"exports": {
|
|
49
49
|
".": {
|
|
50
|
-
"types": "./dist/index.d.ts",
|
|
50
|
+
"types": "./dist/src/index.d.ts",
|
|
51
51
|
"import": "./dist/index.js"
|
|
52
52
|
}
|
|
53
53
|
},
|