@tb-dev/vue 0.1.6 → 0.1.8
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 +56 -38
- package/dist/utils/app.d.ts +3 -2
- package/dist/utils/error.d.ts +1 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineComponent, createBlock, openBlock, unref, withCtx, createElementBlock, renderSlot, toDisplayString, toRef, effectScope, toValue, computed
|
|
1
|
+
import { defineComponent, createBlock, openBlock, unref, withCtx, createElementBlock, renderSlot, toDisplayString, inject as inject$1, toRef, effectScope, toValue, computed } from 'vue';
|
|
2
2
|
import { RouterLink } from 'vue-router';
|
|
3
|
-
import { computedAsync, useAsyncState, useElementSize as useElementSize$1, tryOnScopeDispose, onKeyStroke, useLocalStorage, useWindowSize } from '@vueuse/core';
|
|
4
3
|
import { unwrap, isNil } from '@tb-dev/utils';
|
|
4
|
+
import { computedAsync, useAsyncState, useElementSize as useElementSize$1, tryOnScopeDispose, onKeyStroke, useLocalStorage, useWindowSize } from '@vueuse/core';
|
|
5
5
|
|
|
6
6
|
const _hoisted_1 = { key: 0 };
|
|
7
7
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -25,28 +25,74 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
function create$1() {
|
|
28
|
+
let APP = null;
|
|
29
|
+
function get() {
|
|
30
|
+
return unwrap(APP, "no active app");
|
|
31
|
+
}
|
|
32
|
+
function tryGet() {
|
|
33
|
+
return APP;
|
|
34
|
+
}
|
|
35
|
+
function set(app) {
|
|
36
|
+
APP = app;
|
|
37
|
+
}
|
|
38
|
+
function trySet(app) {
|
|
39
|
+
APP ??= app;
|
|
40
|
+
}
|
|
41
|
+
return { get, set, tryGet, trySet };
|
|
42
|
+
}
|
|
43
|
+
const {
|
|
44
|
+
get: getCurrentApp,
|
|
45
|
+
set: setCurrentApp,
|
|
46
|
+
tryGet: tryGetCurrentApp,
|
|
47
|
+
trySet: trySetCurrentApp
|
|
48
|
+
} = create$1();
|
|
49
|
+
function runWithContext(fn) {
|
|
50
|
+
return getCurrentApp().runWithContext(fn);
|
|
51
|
+
}
|
|
52
|
+
function provide(key, value) {
|
|
53
|
+
getCurrentApp().provide(key, value);
|
|
54
|
+
}
|
|
55
|
+
function inject(key) {
|
|
56
|
+
const value = tryInject(key);
|
|
57
|
+
if (typeof value === "undefined") {
|
|
58
|
+
throw new TypeError("injection failed: value not provided");
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function tryInject(key) {
|
|
63
|
+
return runWithContext(() => inject$1(key));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function create() {
|
|
28
67
|
let ERROR_HANDLER_FN = null;
|
|
29
68
|
function get() {
|
|
30
69
|
return ERROR_HANDLER_FN;
|
|
31
70
|
}
|
|
32
|
-
function set(fn,
|
|
71
|
+
function set(fn, app = true) {
|
|
33
72
|
ERROR_HANDLER_FN = fn;
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
73
|
+
if (app) {
|
|
74
|
+
let _app;
|
|
75
|
+
if (app === true) {
|
|
76
|
+
_app = getCurrentApp();
|
|
77
|
+
} else {
|
|
78
|
+
trySetCurrentApp(app);
|
|
79
|
+
_app = app;
|
|
80
|
+
}
|
|
81
|
+
_app.config.errorHandler = (err) => {
|
|
82
|
+
handle(err, true);
|
|
37
83
|
};
|
|
38
84
|
}
|
|
39
85
|
}
|
|
40
|
-
function handle(err,
|
|
86
|
+
function handle(err, rethrow = true) {
|
|
41
87
|
if (ERROR_HANDLER_FN) {
|
|
42
88
|
void Promise.try(ERROR_HANDLER_FN, err);
|
|
43
|
-
} else if (
|
|
89
|
+
} else if (rethrow) {
|
|
44
90
|
throw err;
|
|
45
91
|
}
|
|
46
92
|
}
|
|
47
93
|
return { get, set, handle };
|
|
48
94
|
}
|
|
49
|
-
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create
|
|
95
|
+
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create();
|
|
50
96
|
|
|
51
97
|
function asyncComputed(initial, callback, options) {
|
|
52
98
|
const state = computedAsync(callback, initial, {
|
|
@@ -165,37 +211,9 @@ function useWindowWidth() {
|
|
|
165
211
|
return useWindowSize().width;
|
|
166
212
|
}
|
|
167
213
|
|
|
168
|
-
function create() {
|
|
169
|
-
let APP = null;
|
|
170
|
-
function get() {
|
|
171
|
-
return unwrap(APP, "no active app");
|
|
172
|
-
}
|
|
173
|
-
function set(app) {
|
|
174
|
-
APP = app;
|
|
175
|
-
}
|
|
176
|
-
return { get, set };
|
|
177
|
-
}
|
|
178
|
-
const { get: getCurrentApp, set: setCurrentApp } = create();
|
|
179
|
-
function runWithContext(fn) {
|
|
180
|
-
return getCurrentApp().runWithContext(fn);
|
|
181
|
-
}
|
|
182
|
-
function provide(key, value) {
|
|
183
|
-
getCurrentApp().provide(key, value);
|
|
184
|
-
}
|
|
185
|
-
function inject(key) {
|
|
186
|
-
const value = fallibleInject(key);
|
|
187
|
-
if (typeof value === "undefined") {
|
|
188
|
-
throw new TypeError("injection failed: value not provided");
|
|
189
|
-
}
|
|
190
|
-
return value;
|
|
191
|
-
}
|
|
192
|
-
function fallibleInject(key) {
|
|
193
|
-
return runWithContext(() => inject$1(key));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
214
|
function maybe(value, fn) {
|
|
197
215
|
const _value = toValue(value);
|
|
198
216
|
return isNil(_value) ? null : fn(_value);
|
|
199
217
|
}
|
|
200
218
|
|
|
201
|
-
export { _sfc_main as Link, asyncComputed, asyncRef,
|
|
219
|
+
export { _sfc_main as Link, asyncComputed, asyncRef, getCurrentApp, getErrorHandler, handleError, inject, localRef, maybe, onAltKeyDown, onCtrlKeyDown, onCtrlShiftKeyDown, onKeyDown, onShiftKeyDown, provide, runWithContext, setCurrentApp, setErrorHandler, tryGetCurrentApp, tryInject, trySetCurrentApp, useElementSize, useHeight, useWidth, useWindowHeight, useWindowWidth };
|
package/dist/utils/app.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Option } from '@tb-dev/utils';
|
|
1
2
|
import { App, InjectionKey } from 'vue';
|
|
2
|
-
export declare const getCurrentApp: () => App<
|
|
3
|
+
export declare const getCurrentApp: () => App, setCurrentApp: (app: App) => void, tryGetCurrentApp: () => Option<App>, trySetCurrentApp: (app: App) => void;
|
|
3
4
|
export declare function runWithContext<T>(fn: () => T): T;
|
|
4
5
|
export declare function provide<T>(key: InjectionKey<T>, value: T): void;
|
|
5
6
|
export declare function inject<T>(key: InjectionKey<T>): T;
|
|
6
|
-
export declare function
|
|
7
|
+
export declare function tryInject<T>(key: InjectionKey<T>): T | undefined;
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
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
|
|
5
|
-
app?: App;
|
|
6
|
-
}
|
|
7
|
-
export interface HandleErrorOptions {
|
|
8
|
-
rethrow?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare const getErrorHandler: () => Option<ErrorHandler>, setErrorHandler: (fn: ErrorHandler, options?: SetErrorHandlerOptions) => void, handleError: (err: unknown, options?: HandleErrorOptions) => void;
|
|
4
|
+
export declare const getErrorHandler: () => Option<ErrorHandler>, setErrorHandler: (fn: ErrorHandler, app?: Option<App | boolean>) => void, handleError: (err: unknown, rethrow?: boolean) => void;
|