@tb-dev/vue 0.1.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/link/Link.vue.d.ts +19 -0
- package/dist/components/link/index.d.ts +3 -0
- package/dist/components/link/types.d.ts +4 -0
- package/dist/composables/async-computed/index.d.ts +4 -0
- package/dist/composables/async-ref/index.d.ts +10 -0
- package/dist/composables/element-size/index.d.ts +9 -0
- package/dist/composables/index.d.ts +6 -0
- package/dist/composables/key-down/index.d.ts +15 -0
- package/dist/composables/local-ref/index.d.ts +8 -0
- package/dist/composables/window-size/index.d.ts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +161 -0
- package/dist/utils/error.d.ts +3 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/maybe.d.ts +3 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andrew Ferreira <andrew.shien2@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './link';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VNode } from 'vue';
|
|
2
|
+
import { LinkProps } from './types';
|
|
3
|
+
declare const _default: <T extends string>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & LinkProps<T> & Partial<{}>> & import('vue').PublicProps;
|
|
5
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
6
|
+
attrs: any;
|
|
7
|
+
slots: Readonly<{
|
|
8
|
+
default?: () => VNode;
|
|
9
|
+
}> & {
|
|
10
|
+
default?: () => VNode;
|
|
11
|
+
};
|
|
12
|
+
emit: {};
|
|
13
|
+
}>) => import('vue').VNode & {
|
|
14
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
17
|
+
type __VLS_PrettifyLocal<T> = {
|
|
18
|
+
[K in keyof T]: T[K];
|
|
19
|
+
} & {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
2
|
+
import { AsyncComputedOptions as Options } from '@vueuse/core';
|
|
3
|
+
export type AsyncComputedOptions = Omit<Options, 'shallow'>;
|
|
4
|
+
export declare function asyncComputed<T>(initial: T, callback: () => Promise<T> | T, options?: AsyncComputedOptions): Readonly<ShallowRef<T>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
2
|
+
import { UseAsyncStateOptions } from '@vueuse/core';
|
|
3
|
+
type Options = Omit<UseAsyncStateOptions<true>, 'shallow'>;
|
|
4
|
+
export interface AsyncRefOptions extends Options {
|
|
5
|
+
immediate?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function asyncRef<T>(initial: T, fn: () => Promise<T>, options?: AsyncRefOptions): Readonly<ShallowRef<T>> & {
|
|
8
|
+
execute: (delay?: number, ...args: any[]) => Promise<T>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { MaybeElement } from '@vueuse/core';
|
|
3
|
+
export declare function useElementSize<T extends MaybeElement>(element: MaybeRefOrGetter<T>): {
|
|
4
|
+
width: import('vue').ShallowRef<number, number>;
|
|
5
|
+
height: import('vue').ShallowRef<number, number>;
|
|
6
|
+
stop: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useHeight<T extends MaybeElement>(element: MaybeRefOrGetter<T>): Readonly<Ref<number>>;
|
|
9
|
+
export declare function useWidth<T extends MaybeElement>(element: MaybeRefOrGetter<T>): Readonly<Ref<number>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Fn, MaybePromise, Option } from '@tb-dev/utils';
|
|
2
|
+
import { KeyFilter, OnKeyStrokeOptions } from '@vueuse/core';
|
|
3
|
+
export type KeyDownEventHandler = Option<(event: KeyboardEvent) => MaybePromise<unknown>>;
|
|
4
|
+
export type OnKeyDownOptions = Omit<OnKeyStrokeOptions, 'eventName'> & {
|
|
5
|
+
altKey?: boolean;
|
|
6
|
+
ctrlKey?: boolean;
|
|
7
|
+
detached?: boolean;
|
|
8
|
+
metaKey?: boolean;
|
|
9
|
+
prevent?: boolean;
|
|
10
|
+
shiftKey?: boolean;
|
|
11
|
+
stopPropagation?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function onKeyDown(key: KeyFilter, handler?: KeyDownEventHandler, options?: OnKeyDownOptions): Fn;
|
|
14
|
+
export declare function onAltKeyDown(key: KeyFilter, handler?: KeyDownEventHandler, options?: Omit<OnKeyDownOptions, 'altKey' | 'eventName'>): Fn;
|
|
15
|
+
export declare function onCtrlKeyDown(key: KeyFilter, handler?: KeyDownEventHandler, options?: Omit<OnKeyDownOptions, 'ctrlKey' | 'eventName'>): Fn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export interface LocalRefOptions {
|
|
3
|
+
deep?: boolean;
|
|
4
|
+
initOnMounted?: boolean;
|
|
5
|
+
onError?: (err: unknown) => void;
|
|
6
|
+
writeDefaults?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function localRef<T>(key: string, initial: T, options?: LocalRefOptions): Ref<T>;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { defineComponent, createBlock, openBlock, unref, withCtx, createElementBlock, renderSlot, toDisplayString, toRef, effectScope, computed, toValue } from 'vue';
|
|
2
|
+
import { RouterLink } from 'vue-router';
|
|
3
|
+
import { computedAsync, useAsyncState, useElementSize as useElementSize$1, tryOnScopeDispose, onKeyStroke, useLocalStorage, useWindowSize } from '@vueuse/core';
|
|
4
|
+
import { isNil } from '@tb-dev/utils';
|
|
5
|
+
|
|
6
|
+
const _hoisted_1 = { key: 0 };
|
|
7
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
+
__name: "Link",
|
|
9
|
+
props: {
|
|
10
|
+
label: {},
|
|
11
|
+
to: {}
|
|
12
|
+
},
|
|
13
|
+
setup(__props) {
|
|
14
|
+
return (_ctx, _cache) => {
|
|
15
|
+
return openBlock(), createBlock(unref(RouterLink), {
|
|
16
|
+
to: { name: _ctx.to }
|
|
17
|
+
}, {
|
|
18
|
+
default: withCtx(() => [
|
|
19
|
+
_ctx.label ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(_ctx.label), 1)) : renderSlot(_ctx.$slots, "default", { key: 1 })
|
|
20
|
+
]),
|
|
21
|
+
_: 3
|
|
22
|
+
}, 8, ["to"]);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function create() {
|
|
28
|
+
let ERROR_HANDLER_FN = null;
|
|
29
|
+
function get() {
|
|
30
|
+
return ERROR_HANDLER_FN;
|
|
31
|
+
}
|
|
32
|
+
function set(fn) {
|
|
33
|
+
ERROR_HANDLER_FN = fn;
|
|
34
|
+
}
|
|
35
|
+
function handle(err) {
|
|
36
|
+
if (ERROR_HANDLER_FN) {
|
|
37
|
+
void Promise.try(ERROR_HANDLER_FN, err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { get, set, handle };
|
|
41
|
+
}
|
|
42
|
+
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create();
|
|
43
|
+
|
|
44
|
+
function asyncComputed(initial, callback, options) {
|
|
45
|
+
const state = computedAsync(callback, initial, {
|
|
46
|
+
onError: handleError,
|
|
47
|
+
shallow: true,
|
|
48
|
+
...options
|
|
49
|
+
});
|
|
50
|
+
return state;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function asyncRef(initial, fn, options = {}) {
|
|
54
|
+
const { immediate = true } = options;
|
|
55
|
+
const { execute, state } = useAsyncState(fn, initial, {
|
|
56
|
+
immediate,
|
|
57
|
+
onError: handleError,
|
|
58
|
+
resetOnExecute: false,
|
|
59
|
+
shallow: true,
|
|
60
|
+
throwError: false,
|
|
61
|
+
...options
|
|
62
|
+
});
|
|
63
|
+
return Object.assign(state, { execute });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useElementSize(element) {
|
|
67
|
+
return useElementSize$1(toRef(element), { height: 0, width: 0 }, { box: "border-box" });
|
|
68
|
+
}
|
|
69
|
+
function useHeight(element) {
|
|
70
|
+
return useElementSize(element).height;
|
|
71
|
+
}
|
|
72
|
+
function useWidth(element) {
|
|
73
|
+
return useElementSize(element).width;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function onKeyDown(key, handler, options = {}) {
|
|
77
|
+
const {
|
|
78
|
+
altKey = false,
|
|
79
|
+
ctrlKey = false,
|
|
80
|
+
detached = false,
|
|
81
|
+
metaKey = false,
|
|
82
|
+
prevent = true,
|
|
83
|
+
shiftKey = false,
|
|
84
|
+
stopPropagation = false
|
|
85
|
+
} = options;
|
|
86
|
+
const callback = (e) => {
|
|
87
|
+
if (e.altKey !== altKey || e.ctrlKey !== ctrlKey || e.metaKey !== metaKey || e.shiftKey !== shiftKey) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (prevent) {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
}
|
|
93
|
+
if (stopPropagation) {
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
}
|
|
96
|
+
if (handler) {
|
|
97
|
+
Promise.try(handler, e).catch(handleError);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const on = () => {
|
|
101
|
+
return onKeyStroke(key, callback, {
|
|
102
|
+
...options,
|
|
103
|
+
eventName: "keydown",
|
|
104
|
+
dedupe: true
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
let stop;
|
|
108
|
+
if (detached) {
|
|
109
|
+
const scope = effectScope(
|
|
110
|
+
/* detached */
|
|
111
|
+
true
|
|
112
|
+
);
|
|
113
|
+
stop = scope.run(() => on());
|
|
114
|
+
} else {
|
|
115
|
+
stop = on();
|
|
116
|
+
}
|
|
117
|
+
if (!detached) {
|
|
118
|
+
tryOnScopeDispose(() => stop());
|
|
119
|
+
}
|
|
120
|
+
return stop;
|
|
121
|
+
}
|
|
122
|
+
function onAltKeyDown(key, handler, options) {
|
|
123
|
+
return onKeyDown(key, handler, { ...options, altKey: true });
|
|
124
|
+
}
|
|
125
|
+
function onCtrlKeyDown(key, handler, options) {
|
|
126
|
+
return onKeyDown(key, handler, { ...options, ctrlKey: true });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function localRef(key, initial, options) {
|
|
130
|
+
const defaultValue = { inner: initial };
|
|
131
|
+
const local = useLocalStorage(key, defaultValue, {
|
|
132
|
+
deep: options?.deep ?? true,
|
|
133
|
+
initOnMounted: options?.initOnMounted ?? true,
|
|
134
|
+
onError: options?.onError ?? handleError,
|
|
135
|
+
writeDefaults: options?.writeDefaults ?? true,
|
|
136
|
+
serializer: {
|
|
137
|
+
read: JSON.parse,
|
|
138
|
+
write: JSON.stringify
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return computed({
|
|
142
|
+
get: () => local.value.inner,
|
|
143
|
+
set: (value) => {
|
|
144
|
+
local.value.inner = value;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function useWindowHeight() {
|
|
150
|
+
return useWindowSize().height;
|
|
151
|
+
}
|
|
152
|
+
function useWindowWidth() {
|
|
153
|
+
return useWindowSize().width;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function maybe(value, fn) {
|
|
157
|
+
const _value = toValue(value);
|
|
158
|
+
return isNil(_value) ? null : fn(_value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { _sfc_main as Link, asyncComputed, asyncRef, getErrorHandler, handleError, localRef, maybe, onAltKeyDown, onCtrlKeyDown, onKeyDown, setErrorHandler, useElementSize, useHeight, useWidth, useWindowHeight, useWindowWidth };
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tb-dev/vue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vue utilities",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"private": false,
|
|
8
|
+
"packageManager": "pnpm@10.7.0",
|
|
9
|
+
"funding": "https://github.com/sponsors/ferreira-tb",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Andrew Ferreira",
|
|
12
|
+
"email": "andrew.shien2@gmail.com",
|
|
13
|
+
"url": "https://github.com/ferreira-tb"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/ferreira-tb/vue-utils.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/ferreira-tb/vue-utils/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"vue",
|
|
24
|
+
"utils",
|
|
25
|
+
"components",
|
|
26
|
+
"composables"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"format": "prettier . --write",
|
|
31
|
+
"lint": "eslint . --config eslint.config.js",
|
|
32
|
+
"type-check": "vue-tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@tb-dev/utils": "^5.1.4",
|
|
36
|
+
"@vueuse/core": "^13.0.0",
|
|
37
|
+
"lucide-vue-next": "^0.484.0",
|
|
38
|
+
"vue": "^3.5.13",
|
|
39
|
+
"vue-router": "^4.5.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@tailwindcss/vite": "^4.0.15",
|
|
43
|
+
"@tb-dev/eslint-config": "^6.7.1",
|
|
44
|
+
"@types/node": "^22.13.14",
|
|
45
|
+
"@vitejs/plugin-vue": "^5.2.3",
|
|
46
|
+
"eslint": "^9.23.0",
|
|
47
|
+
"prettier": "^3.5.3",
|
|
48
|
+
"prettier-plugin-css-order": "^2.1.2",
|
|
49
|
+
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
50
|
+
"tailwindcss": "^4.0.15",
|
|
51
|
+
"tslib": "^2.8.1",
|
|
52
|
+
"typescript": "~5.8.2",
|
|
53
|
+
"vite": "^6.2.3",
|
|
54
|
+
"vite-plugin-dts": "^4.5.3",
|
|
55
|
+
"vue-tsc": "~2.2.8"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist"
|
|
59
|
+
],
|
|
60
|
+
"main": "./dist/index.js",
|
|
61
|
+
"types": "./dist/index.d.ts",
|
|
62
|
+
"exports": {
|
|
63
|
+
".": {
|
|
64
|
+
"types": "./dist/index.d.ts",
|
|
65
|
+
"import": "./dist/index.js"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|