@tb-dev/vue 3.2.3 → 3.3.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.
@@ -2,6 +2,7 @@ import { Ref } from 'vue';
2
2
  export interface LocalRefOptions {
3
3
  deep?: boolean;
4
4
  initOnMounted?: boolean;
5
+ listenToStorageChanges?: boolean;
5
6
  onError?: (err: unknown) => void;
6
7
  writeDefaults?: boolean;
7
8
  }
@@ -2,6 +2,7 @@ import { Ref } from 'vue';
2
2
  export interface SessionRefOptions {
3
3
  deep?: boolean;
4
4
  initOnMounted?: boolean;
5
+ listenToStorageChanges?: boolean;
5
6
  onError?: (err: unknown) => void;
6
7
  writeDefaults?: boolean;
7
8
  }
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
- import { unwrap, isNil } from "@tb-dev/utils";
2
- import { inject as inject$1, toValue, toRef, ref, readonly, computed, effectScope } from "vue";
3
- import { watchImmediate, useAsyncState, useLocalStorage, tryOnScopeDispose, onKeyStroke, useSessionStorage, computedAsync, useWindowSize, useElementSize as useElementSize$1 } from "@vueuse/core";
4
- import { useWindowSize as useWindowSize2 } from "@vueuse/core";
5
- import { Mutex } from "es-toolkit";
1
+ import { unwrap, isNil } from '@tb-dev/utils';
2
+ import { inject as inject$1, toValue, toRef, ref, readonly, computed, effectScope } from 'vue';
3
+ import { watchImmediate, useAsyncState, useLocalStorage, tryOnScopeDispose, onKeyStroke, useSessionStorage, computedAsync, useWindowSize, useElementSize as useElementSize$1 } from '@vueuse/core';
4
+ export { useWindowSize } from '@vueuse/core';
5
+ import { Mutex } from 'es-toolkit';
6
+
6
7
  function getCurrentApp() {
7
8
  return unwrap(globalThis.__VUEUTILS__.app, "No active app");
8
9
  }
@@ -39,6 +40,7 @@ function tryInjectOrElse(key, fn) {
39
40
  }
40
41
  return value;
41
42
  }
43
+
42
44
  function getErrorHandler() {
43
45
  return globalThis.__VUEUTILS__.errorHandler;
44
46
  }
@@ -62,10 +64,12 @@ function handleError(err, rethrow = true) {
62
64
  throw err;
63
65
  }
64
66
  }
67
+
65
68
  function maybe(value, fn) {
66
69
  const _value = toValue(value);
67
70
  return isNil(_value) ? null : fn(_value);
68
71
  }
72
+
69
73
  const console = {
70
74
  assert,
71
75
  debug,
@@ -98,6 +102,7 @@ function trace(source) {
98
102
  function warn(source) {
99
103
  return watchImmediate(toRef(source), (value) => globalThis.console.warn(value));
100
104
  }
105
+
101
106
  function useMutex(options) {
102
107
  const mutex = new Mutex();
103
108
  const locked = ref(mutex.isLocked);
@@ -130,6 +135,7 @@ function useMutex(options) {
130
135
  lock
131
136
  };
132
137
  }
138
+
133
139
  function asyncRef(initial, fn, options = {}) {
134
140
  const value = useAsyncState(fn, initial, {
135
141
  immediate: options.immediate ?? true,
@@ -149,11 +155,13 @@ function asyncRef(initial, fn, options = {}) {
149
155
  execute
150
156
  };
151
157
  }
158
+
152
159
  function localRef(key, initial, options) {
153
160
  const defaultValue = { inner: initial };
154
161
  const local = useLocalStorage(key, defaultValue, {
155
162
  deep: options?.deep ?? true,
156
163
  initOnMounted: options?.initOnMounted ?? true,
164
+ listenToStorageChanges: options?.listenToStorageChanges ?? true,
157
165
  onError: options?.onError ?? handleError,
158
166
  writeDefaults: options?.writeDefaults ?? true,
159
167
  serializer: {
@@ -168,6 +176,7 @@ function localRef(key, initial, options) {
168
176
  }
169
177
  });
170
178
  }
179
+
171
180
  function onKeyDown(key, handler, options = {}) {
172
181
  const {
173
182
  altKey = false,
@@ -226,11 +235,13 @@ function onShiftKeyDown(key, handler, options) {
226
235
  function onCtrlShiftKeyDown(key, handler, options) {
227
236
  return onKeyDown(key, handler, { ...options, ctrlKey: true, shiftKey: true });
228
237
  }
238
+
229
239
  function sessionRef(key, initial, options) {
230
240
  const defaultValue = { inner: initial };
231
241
  const session = useSessionStorage(key, defaultValue, {
232
242
  deep: options?.deep ?? true,
233
243
  initOnMounted: options?.initOnMounted ?? true,
244
+ listenToStorageChanges: options?.listenToStorageChanges ?? true,
234
245
  onError: options?.onError ?? handleError,
235
246
  writeDefaults: options?.writeDefaults ?? true,
236
247
  serializer: {
@@ -245,6 +256,7 @@ function sessionRef(key, initial, options) {
245
256
  }
246
257
  });
247
258
  }
259
+
248
260
  function asyncComputed(initial, callback, options) {
249
261
  const state = computedAsync(callback, initial, {
250
262
  onError: handleError,
@@ -254,12 +266,14 @@ function asyncComputed(initial, callback, options) {
254
266
  });
255
267
  return state;
256
268
  }
269
+
257
270
  function useWindowHeight() {
258
271
  return useWindowSize().height;
259
272
  }
260
273
  function useWindowWidth() {
261
274
  return useWindowSize().width;
262
275
  }
276
+
263
277
  function useElementSize(element) {
264
278
  return useElementSize$1(toRef(element), { height: 0, width: 0 }, { box: "border-box" });
265
279
  }
@@ -279,6 +293,7 @@ function useWidthDiff(element, lhs) {
279
293
  const lhsRef = lhs ? toRef(lhs) : useWindowWidth();
280
294
  return computed(() => lhsRef.value - width.value);
281
295
  }
296
+
282
297
  if (!Object.hasOwn(globalThis, "__VUEUTILS__")) {
283
298
  Object.defineProperty(globalThis, "__VUEUTILS__", {
284
299
  configurable: false,
@@ -287,37 +302,5 @@ if (!Object.hasOwn(globalThis, "__VUEUTILS__")) {
287
302
  value: {}
288
303
  });
289
304
  }
290
- export {
291
- asyncComputed,
292
- asyncRef,
293
- console,
294
- getCurrentApp,
295
- getErrorHandler,
296
- handleError,
297
- inject,
298
- localRef,
299
- maybe,
300
- onAltKeyDown,
301
- onCtrlKeyDown,
302
- onCtrlShiftKeyDown,
303
- onKeyDown,
304
- onShiftKeyDown,
305
- provide,
306
- runWithContext,
307
- sessionRef,
308
- setCurrentApp,
309
- setErrorHandler,
310
- tryGetCurrentApp,
311
- tryInject,
312
- tryInjectOrElse,
313
- trySetCurrentApp,
314
- useElementSize,
315
- useHeight,
316
- useHeightDiff,
317
- useMutex,
318
- useWidth,
319
- useWidthDiff,
320
- useWindowHeight,
321
- useWindowSize2 as useWindowSize,
322
- useWindowWidth
323
- };
305
+
306
+ export { asyncComputed, asyncRef, console, getCurrentApp, getErrorHandler, handleError, inject, localRef, maybe, onAltKeyDown, onCtrlKeyDown, onCtrlShiftKeyDown, onKeyDown, onShiftKeyDown, provide, runWithContext, sessionRef, setCurrentApp, setErrorHandler, tryGetCurrentApp, tryInject, tryInjectOrElse, trySetCurrentApp, useElementSize, useHeight, useHeightDiff, useMutex, useWidth, useWidthDiff, useWindowHeight, useWindowWidth };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/vue",
3
- "version": "3.2.3",
3
+ "version": "3.3.0",
4
4
  "description": "Vue utilities",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,20 +24,20 @@
24
24
  "composables"
25
25
  ],
26
26
  "dependencies": {
27
- "@tb-dev/utils": "^7.0.13",
28
- "@vueuse/core": "^13.8.0",
27
+ "@tb-dev/utils": "^7.0.14",
28
+ "@vueuse/core": "^13.9.0",
29
29
  "es-toolkit": "^1.39.10",
30
- "vue": "^3.5.20"
30
+ "vue": "^3.5.21"
31
31
  },
32
32
  "devDependencies": {
33
- "@tb-dev/eslint-config": "^8.0.7",
34
- "@types/node": "^24.3.0",
35
- "eslint": "^9.34.0",
33
+ "@tb-dev/eslint-config": "^8.0.11",
34
+ "@types/node": "^24.3.1",
35
+ "eslint": "^9.35.0",
36
36
  "tslib": "^2.8.1",
37
- "typedoc": "^0.28.11",
37
+ "typedoc": "^0.28.12",
38
38
  "typedoc-plugin-mdn-links": "^5.0.9",
39
39
  "typescript": "~5.9.2",
40
- "vite": "^7.1.3",
40
+ "vite": "^7.1.4",
41
41
  "vite-plugin-dts": "^4.5.4"
42
42
  },
43
43
  "files": [