@tonar/vue-kit 0.0.1-canary

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 sonion
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,72 @@
1
+ # @tonar/vue-kit
2
+
3
+ `@tonar/vue-kit` 是 Tonar 的 Vue 3 组件包,当前提供权限渲染组件能力。
4
+
5
+ `@tonar/vue-kit` is Tonar's Vue 3 component package, currently focused on permission-based rendering.
6
+
7
+ - ✅ 支持 Vue 3+
8
+ - ✅ TypeScript 类型支持
9
+ - ✅ 仅支持 ESM(不支持 CommonJS)
10
+ - ✅ 支持 Tree-shaking
11
+
12
+ ## 📦 Installation / 安装
13
+
14
+ ```bash
15
+ npm install @tonar/vue-kit@latest
16
+ pnpm add @tonar/vue-kit
17
+ yarn add @tonar/vue-kit
18
+ ```
19
+
20
+ ## 🚀 Usage / 使用方法
21
+
22
+ ```vue
23
+ <script setup lang="ts">
24
+ import { SoAuthority } from '@tonar/vue-kit';
25
+
26
+ const userPermissions = ['dashboard:view', 'dashboard:edit'];
27
+ </script>
28
+
29
+ <template>
30
+ <SoAuthority
31
+ :user-permissions="userPermissions"
32
+ required-permissions="dashboard:view"
33
+ >
34
+ <button>Search</button>
35
+ </SoAuthority>
36
+ </template>
37
+ ```
38
+
39
+ ## 🧩 Components / 组件
40
+
41
+ - `SoAuthority`:权限渲染组件,根据用户权限和组件所需权限决定是否渲染默认插槽
42
+ - `SoAuthority` 支持字符串、数字、字符串数组、数字数组作为权限值
43
+ - `SoAuthority` 也支持通过函数自定义权限判断逻辑
44
+
45
+ ## 📖 Custom permission check / 自定义权限判断
46
+
47
+ ```vue
48
+ <script setup lang="ts">
49
+ import { SoAuthority } from '@tonar/vue-kit';
50
+
51
+ const userPermissions = ['admin'];
52
+ const requiredPermissions = (
53
+ permissions: string | number | string[] | number[]
54
+ ) => Array.isArray(permissions) && permissions.includes('admin');
55
+ </script>
56
+
57
+ <template>
58
+ <SoAuthority
59
+ :user-permissions="userPermissions"
60
+ :required-permissions="requiredPermissions"
61
+ >
62
+ <span>Only admins can see this.</span>
63
+ </SoAuthority>
64
+ </template>
65
+ ```
66
+
67
+ ## 📝 License / 许可证
68
+
69
+ MIT © Sonion
70
+
71
+ 欢迎 [Pull Requests](https://github.com/sonion028/gonar/pulls) 和 [Issues](https://github.com/sonion028/gonar/issues)
72
+ 源码仓库:[https://github.com/sonion028/gonar](https://github.com/sonion028/gonar)
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./js/components.BgTB9fgn.js";
2
+ export { e as SoAuthority };
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./js/components.BgTB9fgn.js";
2
+ export { e as SoAuthority };
@@ -0,0 +1,41 @@
1
+ import { defineComponent as e, ref 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) => {
9
+ let n = t(!1);
10
+ return [n, () => n.value = (typeof e.requiredPermissions == "function" ? e.requiredPermissions : r)(e.userPermissions, e.requiredPermissions)];
11
+ }, a = e({
12
+ name: "so-authority",
13
+ props: {
14
+ requiredPermissions: {
15
+ type: [
16
+ String,
17
+ Number,
18
+ Array,
19
+ Function
20
+ ],
21
+ required: !0
22
+ },
23
+ userPermissions: {
24
+ type: [
25
+ String,
26
+ Number,
27
+ Array
28
+ ],
29
+ required: !0
30
+ }
31
+ },
32
+ setup(e, { slots: t }) {
33
+ let [n, r] = i(e);
34
+ return () => r() ? t.default?.({
35
+ userPermissions: e.userPermissions,
36
+ isPermission: n.value
37
+ }) : null;
38
+ }
39
+ });
40
+ //#endregion
41
+ export { a as t };
@@ -0,0 +1 @@
1
+ export { default as SoAuthority } from './so-authority';
@@ -0,0 +1,15 @@
1
+ type PermissionType = string | number | string[] | number[];
2
+ export type AuthorityProps = {
3
+ requiredPermissions: PermissionType | ((userPermissions: PermissionType) => boolean);
4
+ userPermissions: PermissionType;
5
+ };
6
+ /**
7
+ * @author sonion
8
+ * @description 验证是否有具有权限
9
+ * @param {object} props - 组件props
10
+ * @param {PermissionType} props.componentPermissions - 组件所需权限 常改变,每个组件需要的权限不一样
11
+ * @param {PermissionType} props.userPermissions - 用户具有的权限 不怎么改变
12
+ * @returns {boolean} - 是否具有权限
13
+ */
14
+ export declare const usePermission: (props: AuthorityProps) => readonly [import('vue').Ref<boolean, boolean>, () => boolean];
15
+ export {};
@@ -0,0 +1,28 @@
1
+ import { PropType } from 'vue';
2
+ import { AuthorityProps } from './composables';
3
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ /** 组件需要的权限 */
5
+ requiredPermissions: {
6
+ type: PropType<AuthorityProps["requiredPermissions"]>;
7
+ required: true;
8
+ };
9
+ /** 用户具有的权限 */
10
+ userPermissions: {
11
+ type: PropType<AuthorityProps["userPermissions"]>;
12
+ required: true;
13
+ };
14
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
15
+ [key: string]: any;
16
+ }>[] | null | undefined, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
17
+ /** 组件需要的权限 */
18
+ requiredPermissions: {
19
+ type: PropType<AuthorityProps["requiredPermissions"]>;
20
+ required: true;
21
+ };
22
+ /** 用户具有的权限 */
23
+ userPermissions: {
24
+ type: PropType<AuthorityProps["userPermissions"]>;
25
+ required: true;
26
+ };
27
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
28
+ export default _default;
@@ -0,0 +1 @@
1
+ export * from './components';
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@tonar/vue-kit",
3
+ "version": "0.0.1-canary",
4
+ "private": false,
5
+ "description": "@tonar/vue-kit: Vue 3 ESM toolkit with permission-based rendering components such as SoAuthority.",
6
+ "keywords": [
7
+ "components",
8
+ "composables",
9
+ "vue"
10
+ ],
11
+ "bugs": "https://github.com/sonion028/gonar/issues",
12
+ "license": "MIT",
13
+ "author": "sonion",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/sonion028/gonar"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "package.json",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": [
26
+ "**/*.css"
27
+ ],
28
+ "module": "dist/index.esm.js",
29
+ "types": "dist/types/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "import": "./dist/index.esm.js",
33
+ "types": "./dist/types/index.d.ts"
34
+ },
35
+ "./composables": {
36
+ "import": "./dist/composables.esm.js",
37
+ "types": "./dist/types/composables.d.ts"
38
+ },
39
+ "./components": {
40
+ "import": "./dist/components.esm.js",
41
+ "types": "./dist/types/components.d.ts"
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "@vitejs/plugin-vue": "^6.0.7",
46
+ "vue": "^3.5.38"
47
+ },
48
+ "peerDependencies": {
49
+ "vue": "^3.0.0"
50
+ },
51
+ "devEngines": {
52
+ "packageManager": {
53
+ "name": "pnpm",
54
+ "onFail": "error"
55
+ }
56
+ },
57
+ "scripts": {
58
+ "build": "rimraf dist && vite build"
59
+ }
60
+ }