@tonar/vue-kit 0.1.0-beta.0 → 0.1.0-beta.1
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/components.esm.js +2 -2
- package/dist/composables.esm.js +44 -0
- package/dist/index.esm.js +3 -2
- package/dist/js/components.c2ySYHVt.js +47 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/so-authority/composables/index.d.ts +2 -1
- package/dist/types/composables/index.d.ts +1 -0
- package/dist/types/composables/storage/index.d.ts +18 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +11 -5
- package/dist/js/components.tnGdFJvX.js +0 -38
package/dist/components.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as SoAuthority };
|
|
1
|
+
import { n as e, t } from "./js/components.c2ySYHVt.js";
|
|
2
|
+
export { e as SoAuthority, t as SoTest };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { computed as e, ref as t } from "vue";
|
|
2
|
+
//#region src/composables/storage/index.ts
|
|
3
|
+
var n = ({ key: n, defaultValue: r, hasDiff: i, onChange: a, storage: o = localStorage, checkType: s = () => !0, beforeunload: c }) => {
|
|
4
|
+
let l = (e) => {
|
|
5
|
+
try {
|
|
6
|
+
let t = e ? JSON.parse(e) : r;
|
|
7
|
+
return s(t) ? t : r;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
return console.warn("规范化出错,已使用默认值", e), r;
|
|
10
|
+
}
|
|
11
|
+
}, u = /* @__PURE__ */ new WeakSet(), d = (e) => {
|
|
12
|
+
let t = JSON.stringify(e);
|
|
13
|
+
o.setItem(n, t);
|
|
14
|
+
let r = new StorageEvent("storage", {
|
|
15
|
+
key: n,
|
|
16
|
+
newValue: t,
|
|
17
|
+
storageArea: o
|
|
18
|
+
});
|
|
19
|
+
u.add(r), window.dispatchEvent(r);
|
|
20
|
+
}, f = t(l(o.getItem(n) ?? "")), p = (e, t = !1) => {
|
|
21
|
+
(i ?? ((e, t) => e !== t))(f.value, e) && (a?.(e), f.value = e, t && d(e));
|
|
22
|
+
}, m = e({
|
|
23
|
+
get() {
|
|
24
|
+
return f.value;
|
|
25
|
+
},
|
|
26
|
+
set(e) {
|
|
27
|
+
p(e, !0);
|
|
28
|
+
}
|
|
29
|
+
}), h = (e) => {
|
|
30
|
+
if (!(u.has(e) || e.storageArea !== o || e.key !== n)) try {
|
|
31
|
+
let t = l(e.newValue ?? "");
|
|
32
|
+
p(t, !1);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error("storage事件处理出错", e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return window.addEventListener("storage", h), c && window.addEventListener("beforeunload", c), [
|
|
38
|
+
m,
|
|
39
|
+
() => window.removeEventListener("storage", h),
|
|
40
|
+
() => c && window.removeEventListener("beforeunload", c)
|
|
41
|
+
];
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { n as useStorage };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as e, t } from "./js/components.c2ySYHVt.js";
|
|
2
|
+
import { useStorage as n } from "./composables.esm.js";
|
|
3
|
+
export { e as SoAuthority, t as SoTest, n as useStorage };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { computed as e, createElementBlock as t, createElementVNode as n, defineComponent as r, openBlock as i, ref as a, toDisplayString as o } from "vue";
|
|
2
|
+
import { isNil as s } from "@tonar/utils";
|
|
3
|
+
//#region src/components/so-authority/composables/index.ts
|
|
4
|
+
var c = (e) => typeof e == "string" || typeof e == "bigint" || typeof e == "number" && Number.isFinite(e), l = (e) => c(e) || Array.isArray(e) && e.every(c), u = (e) => Array.isArray(e), d = (e, t) => {
|
|
5
|
+
if (!l(t)) throw TypeError("组件所需权限类型错误: 应该为 String、Number、BigInt 或 String[]、Number[]、BigInt[]");
|
|
6
|
+
if (!l(e)) throw TypeError("用户权限类型错误: 应该为 String、Number、BigInt 或 String[]、Number[]、BigInt[]");
|
|
7
|
+
let n = u(t), r = u(e);
|
|
8
|
+
return n && !r ? !1 : !n && r ? e.includes(t) : n && r ? t.every((t) => e.includes(t)) : Object.is(e, t);
|
|
9
|
+
}, f = (t) => [e(() => typeof t.requiredPermissions == "function" ? t.requiredPermissions(t.userPermissions) : s(t.requiredPermissions) || s(t.userPermissions) ? !1 : d(t.userPermissions, t.requiredPermissions))], p = r({
|
|
10
|
+
name: "SoAuthority",
|
|
11
|
+
props: {
|
|
12
|
+
requiredPermissions: {
|
|
13
|
+
type: [
|
|
14
|
+
String,
|
|
15
|
+
Number,
|
|
16
|
+
BigInt,
|
|
17
|
+
Array,
|
|
18
|
+
Function
|
|
19
|
+
],
|
|
20
|
+
required: !0
|
|
21
|
+
},
|
|
22
|
+
userPermissions: {
|
|
23
|
+
type: [
|
|
24
|
+
String,
|
|
25
|
+
Number,
|
|
26
|
+
BigInt,
|
|
27
|
+
Array
|
|
28
|
+
],
|
|
29
|
+
required: !0
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
setup(e, { slots: t }) {
|
|
33
|
+
let [n] = f(e);
|
|
34
|
+
return () => n.value ? t.default?.({
|
|
35
|
+
userPermissions: e.userPermissions,
|
|
36
|
+
isPermission: n.value
|
|
37
|
+
}) : null;
|
|
38
|
+
}
|
|
39
|
+
}), m = /* @__PURE__ */ r({
|
|
40
|
+
__name: "so-test",
|
|
41
|
+
setup(e) {
|
|
42
|
+
let r = a(0);
|
|
43
|
+
return console.log("SoTest", (e) => (console.log(e), r.value++, r.value)), (e, a) => (i(), t("div", null, [a[0] || (a[0] = n("h1", null, "Hello Vue 3!", -1)), n("p", null, "count: " + o(r.value), 1)]));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
47
|
+
export { p as n, m as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
type
|
|
1
|
+
type PermissionValue = string | number | bigint;
|
|
2
|
+
type PermissionType = PermissionValue | PermissionValue[];
|
|
2
3
|
export type AuthorityProps = {
|
|
3
4
|
requiredPermissions: PermissionType | ((userPermissions: PermissionType) => boolean);
|
|
4
5
|
userPermissions: PermissionType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './storage';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type StorageParams<T> = {
|
|
2
|
+
/** 储存的key */
|
|
3
|
+
key: string;
|
|
4
|
+
/** 默认值 */
|
|
5
|
+
defaultValue: T;
|
|
6
|
+
/** 对比函数,默认对比引用是否不相同。 */
|
|
7
|
+
hasDiff?: (prev: T, next: T) => boolean;
|
|
8
|
+
/** 变化回调 */
|
|
9
|
+
onChange?: (val: T) => void;
|
|
10
|
+
/** 储存类型。 localStorage 或 sessionStorage */
|
|
11
|
+
storage?: typeof localStorage | typeof sessionStorage;
|
|
12
|
+
/** 初始化类型检查函数,检查不通过使用初始值。可避免类型不对引起的错误 */
|
|
13
|
+
checkType?: (val: T) => boolean;
|
|
14
|
+
/** tab关闭前的回调, 相同key的不同回调只有初始生效。 */
|
|
15
|
+
beforeunload?: () => void;
|
|
16
|
+
};
|
|
17
|
+
export declare const useStorage: <T>({ key, defaultValue, hasDiff, onChange, storage, checkType, beforeunload, }: StorageParams<T>) => readonly [import('vue').WritableComputedRef<T, T>, () => void, () => void | undefined];
|
|
18
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonar/vue-kit",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "@tonar/vue-kit: Vue 3 ESM toolkit with permission-based rendering components such as SoAuthority.",
|
|
6
6
|
"keywords": [
|
|
@@ -34,16 +34,20 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./composables": {
|
|
36
36
|
"import": "./dist/composables.esm.js",
|
|
37
|
-
"types": "./dist/types/composables.d.ts"
|
|
37
|
+
"types": "./dist/types/composables/index.d.ts"
|
|
38
38
|
},
|
|
39
39
|
"./components": {
|
|
40
40
|
"import": "./dist/components.esm.js",
|
|
41
|
-
"types": "./dist/types/components.d.ts"
|
|
41
|
+
"types": "./dist/types/components/index.d.ts"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@tonar/utils": "0.1.0-beta.1"
|
|
46
|
+
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
46
|
-
"vue": "^
|
|
49
|
+
"@vue/test-utils": "^2.4.11",
|
|
50
|
+
"vue": "^3.5.39"
|
|
47
51
|
},
|
|
48
52
|
"peerDependencies": {
|
|
49
53
|
"vue": "^3.0.0"
|
|
@@ -55,6 +59,8 @@
|
|
|
55
59
|
}
|
|
56
60
|
},
|
|
57
61
|
"scripts": {
|
|
58
|
-
"build": "rimraf dist && vite build"
|
|
62
|
+
"build": "rimraf dist && vite build",
|
|
63
|
+
"test": "vitest --run",
|
|
64
|
+
"typecheck": "pnpm exec tsc --noEmit"
|
|
59
65
|
}
|
|
60
66
|
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { computed as e, defineComponent as t } from "vue";
|
|
2
|
-
//#region src/components/so-authority/composables/index.ts
|
|
3
|
-
var n = (e) => typeof e == "string" || typeof e == "number" || Array.isArray(e) && !!e.length, r = (e, t) => {
|
|
4
|
-
if (!n(t)) throw TypeError("组件所需权限类型错误: 应该为 String、Number 或 String[]");
|
|
5
|
-
if (!n(e)) throw TypeError("用户权限类型错误: 应该为 String、Number 或 String[]");
|
|
6
|
-
let r = Array.isArray(t), i = Array.isArray(e);
|
|
7
|
-
return r && !i ? !1 : !r && i ? e.includes(t) : !r && !i ? Object.is(e, t) : t.every((t) => e.includes(t));
|
|
8
|
-
}, i = (e) => Array.isArray(e) && !e.length, a = (t) => [e(() => typeof t.requiredPermissions == "function" ? t.requiredPermissions(t.userPermissions) : !t.requiredPermissions || !t.userPermissions || i(t.requiredPermissions) || i(t.userPermissions) ? !1 : r(t.userPermissions, t.requiredPermissions))], o = t({
|
|
9
|
-
name: "so-authority",
|
|
10
|
-
props: {
|
|
11
|
-
requiredPermissions: {
|
|
12
|
-
type: [
|
|
13
|
-
String,
|
|
14
|
-
Number,
|
|
15
|
-
Array,
|
|
16
|
-
Function
|
|
17
|
-
],
|
|
18
|
-
required: !0
|
|
19
|
-
},
|
|
20
|
-
userPermissions: {
|
|
21
|
-
type: [
|
|
22
|
-
String,
|
|
23
|
-
Number,
|
|
24
|
-
Array
|
|
25
|
-
],
|
|
26
|
-
required: !0
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
setup(e, { slots: t }) {
|
|
30
|
-
let [n] = a(e);
|
|
31
|
-
return () => n.value ? t.default?.({
|
|
32
|
-
userPermissions: e.userPermissions,
|
|
33
|
-
isPermission: n.value
|
|
34
|
-
}) : null;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
//#endregion
|
|
38
|
-
export { o as t };
|