@tb-dev/vue 2.0.14 → 2.2.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/dist/composables/index.d.ts +8 -7
- package/dist/composables/useMutex/index.d.ts +6 -0
- package/dist/composables/{window-size → useWindowSize}/index.d.ts +2 -0
- package/dist/index.js +91 -65
- package/package.json +2 -1
- /package/dist/composables/{async-computed → asyncComputed}/index.d.ts +0 -0
- /package/dist/composables/{async-ref → asyncRef}/index.d.ts +0 -0
- /package/dist/composables/{local-ref → localRef}/index.d.ts +0 -0
- /package/dist/composables/{key-down → onKeyDown}/index.d.ts +0 -0
- /package/dist/composables/{session-ref → sessionRef}/index.d.ts +0 -0
- /package/dist/composables/{element-size → useElementSize}/index.d.ts +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export * from './async-computed';
|
|
2
|
-
export * from './async-ref';
|
|
3
1
|
export * from './console';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
2
|
+
export * from './useMutex';
|
|
3
|
+
export * from './asyncRef';
|
|
4
|
+
export * from './localRef';
|
|
5
|
+
export * from './onKeyDown';
|
|
6
|
+
export * from './sessionRef';
|
|
7
|
+
export * from './asyncComputed';
|
|
8
|
+
export * from './useWindowSize';
|
|
9
|
+
export * from './useElementSize';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
+
import { watch, ref, readonly, inject as inject$1, computed, effectScope, toValue, toRef } from 'vue';
|
|
2
|
+
import { Mutex } from 'es-toolkit';
|
|
1
3
|
import { unwrap, isNil } from '@tb-dev/utils';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
+
import { useAsyncState, useLocalStorage, tryOnScopeDispose, onKeyStroke, useSessionStorage, computedAsync, useWindowSize, useElementSize as useElementSize$1 } from '@vueuse/core';
|
|
5
|
+
export { useWindowSize } from '@vueuse/core';
|
|
6
|
+
|
|
7
|
+
function log(source) {
|
|
8
|
+
return watch(source, (value) => console.log(value));
|
|
9
|
+
}
|
|
10
|
+
function warn(source) {
|
|
11
|
+
return watch(source, (value) => console.warn(value));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function useMutex() {
|
|
15
|
+
const mutex = new Mutex();
|
|
16
|
+
const locked = ref(mutex.isLocked);
|
|
17
|
+
async function acquire() {
|
|
18
|
+
await mutex.acquire();
|
|
19
|
+
locked.value = mutex.isLocked;
|
|
20
|
+
}
|
|
21
|
+
function release() {
|
|
22
|
+
mutex.release();
|
|
23
|
+
locked.value = mutex.isLocked;
|
|
24
|
+
}
|
|
25
|
+
function lock(fn) {
|
|
26
|
+
const { resolve, reject, promise } = Promise.withResolvers();
|
|
27
|
+
acquire().then(() => fn()).then((value) => resolve(value)).catch(reject).finally(release);
|
|
28
|
+
return promise;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
locked: readonly(locked),
|
|
32
|
+
acquire,
|
|
33
|
+
release,
|
|
34
|
+
lock
|
|
35
|
+
};
|
|
36
|
+
}
|
|
4
37
|
|
|
5
38
|
function create$1() {
|
|
6
39
|
let APP = null;
|
|
@@ -80,16 +113,6 @@ function create() {
|
|
|
80
113
|
}
|
|
81
114
|
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create();
|
|
82
115
|
|
|
83
|
-
function asyncComputed(initial, callback, options) {
|
|
84
|
-
const state = computedAsync(callback, initial, {
|
|
85
|
-
onError: handleError,
|
|
86
|
-
shallow: true,
|
|
87
|
-
lazy: false,
|
|
88
|
-
...options
|
|
89
|
-
});
|
|
90
|
-
return state;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
116
|
function asyncRef(initial, fn, options = {}) {
|
|
94
117
|
const { immediate = true } = options;
|
|
95
118
|
const value = useAsyncState(fn, initial, {
|
|
@@ -111,38 +134,24 @@ function asyncRef(initial, fn, options = {}) {
|
|
|
111
134
|
};
|
|
112
135
|
}
|
|
113
136
|
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return useElementSize(element).height;
|
|
133
|
-
}
|
|
134
|
-
function useHeightDiff(element) {
|
|
135
|
-
const height = useHeight(element);
|
|
136
|
-
const windowHeight = useWindowHeight();
|
|
137
|
-
return computed(() => windowHeight.value - height.value);
|
|
138
|
-
}
|
|
139
|
-
function useWidth(element) {
|
|
140
|
-
return useElementSize(element).width;
|
|
141
|
-
}
|
|
142
|
-
function useWidthDiff(element) {
|
|
143
|
-
const width = useWidth(element);
|
|
144
|
-
const windowWidth = useWindowWidth();
|
|
145
|
-
return computed(() => windowWidth.value - width.value);
|
|
137
|
+
function localRef(key, initial, options) {
|
|
138
|
+
const defaultValue = { inner: initial };
|
|
139
|
+
const local = useLocalStorage(key, defaultValue, {
|
|
140
|
+
deep: options?.deep ?? true,
|
|
141
|
+
initOnMounted: options?.initOnMounted ?? true,
|
|
142
|
+
onError: options?.onError ?? handleError,
|
|
143
|
+
writeDefaults: options?.writeDefaults ?? true,
|
|
144
|
+
serializer: {
|
|
145
|
+
read: JSON.parse,
|
|
146
|
+
write: JSON.stringify
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return computed({
|
|
150
|
+
get: () => local.value.inner,
|
|
151
|
+
set: (value) => {
|
|
152
|
+
local.value.inner = value;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
function onKeyDown(key, handler, options = {}) {
|
|
@@ -204,26 +213,6 @@ function onCtrlShiftKeyDown(key, handler, options) {
|
|
|
204
213
|
return onKeyDown(key, handler, { ...options, ctrlKey: true, shiftKey: true });
|
|
205
214
|
}
|
|
206
215
|
|
|
207
|
-
function localRef(key, initial, options) {
|
|
208
|
-
const defaultValue = { inner: initial };
|
|
209
|
-
const local = useLocalStorage(key, defaultValue, {
|
|
210
|
-
deep: options?.deep ?? true,
|
|
211
|
-
initOnMounted: options?.initOnMounted ?? true,
|
|
212
|
-
onError: options?.onError ?? handleError,
|
|
213
|
-
writeDefaults: options?.writeDefaults ?? true,
|
|
214
|
-
serializer: {
|
|
215
|
-
read: JSON.parse,
|
|
216
|
-
write: JSON.stringify
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
return computed({
|
|
220
|
-
get: () => local.value.inner,
|
|
221
|
-
set: (value) => {
|
|
222
|
-
local.value.inner = value;
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
216
|
function sessionRef(key, initial, options) {
|
|
228
217
|
const defaultValue = { inner: initial };
|
|
229
218
|
const session = useSessionStorage(key, defaultValue, {
|
|
@@ -244,9 +233,46 @@ function sessionRef(key, initial, options) {
|
|
|
244
233
|
});
|
|
245
234
|
}
|
|
246
235
|
|
|
236
|
+
function asyncComputed(initial, callback, options) {
|
|
237
|
+
const state = computedAsync(callback, initial, {
|
|
238
|
+
onError: handleError,
|
|
239
|
+
shallow: true,
|
|
240
|
+
lazy: false,
|
|
241
|
+
...options
|
|
242
|
+
});
|
|
243
|
+
return state;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function useWindowHeight() {
|
|
247
|
+
return useWindowSize().height;
|
|
248
|
+
}
|
|
249
|
+
function useWindowWidth() {
|
|
250
|
+
return useWindowSize().width;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function useElementSize(element) {
|
|
254
|
+
return useElementSize$1(toRef(element), { height: 0, width: 0 }, { box: "border-box" });
|
|
255
|
+
}
|
|
256
|
+
function useHeight(element) {
|
|
257
|
+
return useElementSize(element).height;
|
|
258
|
+
}
|
|
259
|
+
function useHeightDiff(element) {
|
|
260
|
+
const height = useHeight(element);
|
|
261
|
+
const windowHeight = useWindowHeight();
|
|
262
|
+
return computed(() => windowHeight.value - height.value);
|
|
263
|
+
}
|
|
264
|
+
function useWidth(element) {
|
|
265
|
+
return useElementSize(element).width;
|
|
266
|
+
}
|
|
267
|
+
function useWidthDiff(element) {
|
|
268
|
+
const width = useWidth(element);
|
|
269
|
+
const windowWidth = useWindowWidth();
|
|
270
|
+
return computed(() => windowWidth.value - width.value);
|
|
271
|
+
}
|
|
272
|
+
|
|
247
273
|
function maybe(value, fn) {
|
|
248
274
|
const _value = toValue(value);
|
|
249
275
|
return isNil(_value) ? null : fn(_value);
|
|
250
276
|
}
|
|
251
277
|
|
|
252
|
-
export { asyncComputed, asyncRef, getCurrentApp, getErrorHandler, handleError, inject, localRef, log, maybe, onAltKeyDown, onCtrlKeyDown, onCtrlShiftKeyDown, onKeyDown, onShiftKeyDown, provide, runWithContext, sessionRef, setCurrentApp, setErrorHandler, tryGetCurrentApp, tryInject, tryInjectOrElse, trySetCurrentApp, useElementSize, useHeight, useHeightDiff, useWidth, useWidthDiff, useWindowHeight, useWindowWidth, warn };
|
|
278
|
+
export { asyncComputed, asyncRef, getCurrentApp, getErrorHandler, handleError, inject, localRef, log, maybe, onAltKeyDown, onCtrlKeyDown, onCtrlShiftKeyDown, onKeyDown, onShiftKeyDown, provide, runWithContext, sessionRef, setCurrentApp, setErrorHandler, tryGetCurrentApp, tryInject, tryInjectOrElse, trySetCurrentApp, useElementSize, useHeight, useHeightDiff, useMutex, useWidth, useWidthDiff, useWindowHeight, useWindowWidth, warn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/vue",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Vue utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@tb-dev/utils": "^7.0.8",
|
|
28
28
|
"@vueuse/core": "^13.5.0",
|
|
29
|
+
"es-toolkit": "^1.39.7",
|
|
29
30
|
"vue": "^3.5.18"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|