@vue-spark/app-helpers 0.1.0 → 0.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.
@@ -115,7 +115,8 @@ function createPermission(options = {}) {
115
115
  const vPermission = { mounted(el, binding) {
116
116
  const { value, arg, instance } = binding;
117
117
  const permission = instance && instance.$permission;
118
- if (!permission || !permission.check(value, arg)) el.remove();
118
+ if (!permission) throw new Error("`vPermission` directive must be used after `app.use(createPermission())`");
119
+ if (!permission.check(value, arg)) el.remove();
119
120
  } };
120
121
 
121
122
  //#endregion
@@ -3,6 +3,13 @@ import { EffectScope } from "vue";
3
3
  //#region src/tabs/index.d.ts
4
4
  type TabType = string;
5
5
  type TabsSideType = 'left' | 'right';
6
+ interface TabsHelperRemoveOptions {
7
+ /**
8
+ * 当前激活的标签被移除时,是否激活下一个标签
9
+ * @default true
10
+ */
11
+ activeNext?: boolean;
12
+ }
6
13
  interface TabsHelperOptions<TabData extends {}> {
7
14
  /**
8
15
  * 判断标签是否可移除,返回假值时,标签将不可移除
@@ -89,8 +96,15 @@ interface TabsHelper<TabData extends {}> {
89
96
  * 添加标签和标签数据,遇到重复的标签将会跳过,否则会在添加后更新激活标签
90
97
  * @param tab 标签
91
98
  * @param tabData 标签数据
99
+ * @param options 选项
92
100
  */
93
- addTab: (tab: TabType, tabData: TabData) => void;
101
+ addTab: (tab: TabType, tabData: TabData, options?: {
102
+ /**
103
+ * 是否激活该标签
104
+ * @default true
105
+ */
106
+ active?: boolean;
107
+ }) => void;
94
108
  /**
95
109
  * 判断是否存在指定标签
96
110
  * @param tab 标签
@@ -119,19 +133,22 @@ interface TabsHelper<TabData extends {}> {
119
133
  /**
120
134
  * 移除指定标签,若移除的是当前激活标签则移除前会自动激活下一个标签
121
135
  * @param tab 指定标签,默认为当前激活的标签
136
+ * @param options 选项
122
137
  */
123
- removeTab: (tab?: TabType) => Promise<void>;
138
+ removeTab: (tab?: TabType, options?: TabsHelperRemoveOptions) => Promise<void>;
124
139
  /**
125
140
  * 移除除过指定标签的其他可移除的标签,并将指定标签设置为激活标签
126
141
  * @param tab 指定标签,默认为当前激活的标签
142
+ * @param options 选项
127
143
  */
128
- removeOtherTabs: (tab?: TabType) => Promise<void>;
144
+ removeOtherTabs: (tab?: TabType, options?: TabsHelperRemoveOptions) => Promise<void>;
129
145
  /**
130
146
  * 移除指定标签的指定方向侧的所有可移除的标签,若当前激活的标签存在被移除的标签内,则将指定标签设置为激活标签
131
147
  * @param tab 指定标签,默认为当前激活的标签
148
+ * @param options 选项
132
149
  */
133
- removeSideTabs: (side: TabsSideType, tab?: TabType) => Promise<void>;
150
+ removeSideTabs: (side: TabsSideType, tab?: TabType, options?: TabsHelperRemoveOptions) => Promise<void>;
134
151
  }
135
152
  declare function createTabsHelper<TabData extends {}>(userOptions?: TabsHelperOptions<TabData>): TabsHelper<TabData>;
136
153
  //#endregion
137
- export { TabsHelper, TabsHelperOptions, TabsSideType, createTabsHelper };
154
+ export { TabsHelper, TabsHelperOptions, TabsHelperRemoveOptions, TabsSideType, createTabsHelper };
@@ -66,10 +66,10 @@ function createTabsHelper(userOptions = {}) {
66
66
  const index = helper.indexOf(targetTab);
67
67
  return side === "left" ? tabs.slice(0, index) : tabs.slice(index + 1);
68
68
  },
69
- addTab(targetTab, tabData) {
69
+ addTab(targetTab, tabData, { active = true } = {}) {
70
70
  if (!helper.hasTab(targetTab)) {
71
71
  setTab(targetTab, tabData);
72
- setActiveTab(targetTab);
72
+ active && setActiveTab(targetTab);
73
73
  }
74
74
  },
75
75
  hasTab(targetTab) {
@@ -101,28 +101,28 @@ function createTabsHelper(userOptions = {}) {
101
101
  }
102
102
  return valid;
103
103
  },
104
- async removeTab(targetTab = helper.activeTab) {
104
+ async removeTab(targetTab = helper.activeTab, { activeNext = true } = {}) {
105
105
  if (tabMap.value.size <= 1 || !targetTab || !canRemoveTab(targetTab) || !await helper.tryRemoveTabs([targetTab])) return;
106
106
  const tabs = helper.getTabs();
107
107
  const index = helper.indexOf(targetTab);
108
108
  const isActive = targetTab === helper.activeTab;
109
109
  const nextTab = isActive ? tabs[index - 1] || tabs[index + 1] : null;
110
- nextTab && setActiveTab(nextTab);
110
+ nextTab && activeNext && setActiveTab(nextTab);
111
111
  removeTabs([targetTab]);
112
112
  },
113
- async removeOtherTabs(targetTab = helper.activeTab) {
113
+ async removeOtherTabs(targetTab = helper.activeTab, { activeNext = true } = {}) {
114
114
  if (!targetTab) return;
115
115
  const otherTabs = helper.getTabs().filter(([tab]) => tab !== targetTab && canRemoveTab(tab));
116
116
  if (!await helper.tryRemoveTabs(otherTabs)) return;
117
- targetTab !== helper.activeTab && setActiveTab(targetTab);
117
+ activeNext && targetTab !== helper.activeTab && setActiveTab(targetTab);
118
118
  removeTabs(otherTabs);
119
119
  },
120
- async removeSideTabs(side, targetTab = helper.activeTab) {
120
+ async removeSideTabs(side, targetTab = helper.activeTab, { activeNext = true } = {}) {
121
121
  if (!targetTab) return;
122
122
  const sideTabs = helper.getSideTabs(targetTab, side).filter(canRemoveTab);
123
123
  if (!await helper.tryRemoveTabs(sideTabs)) return;
124
124
  const activeInSide = targetTab !== helper.activeTab && sideTabs.some(([tab]) => tab === helper.activeTab);
125
- activeInSide && setActiveTab(targetTab);
125
+ activeInSide && activeNext && setActiveTab(targetTab);
126
126
  removeTabs(sideTabs);
127
127
  }
128
128
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vue-spark/app-helpers",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "packageManager": "pnpm@10.11.0",
6
6
  "description": "Lightweight Helpers for Vue 3 Application Development.",
7
7
  "author": "leihaohao <https://github.com/l246804>",
@@ -56,20 +56,20 @@
56
56
  "devDependencies": {
57
57
  "@antfu/eslint-config": "^4.14.1",
58
58
  "@sxzz/prettier-config": "^2.2.3",
59
- "@tsconfig/node22": "^22.0.2",
60
- "@types/node": "^22.15.17",
59
+ "@tsconfig/node24": "^24.0.0",
60
+ "@types/node": "^24.10.0",
61
61
  "@vue/tsconfig": "^0.7.0",
62
62
  "bumpp": "^10.1.0",
63
63
  "eslint": "^9.26.0",
64
64
  "eslint-plugin-format": "^1.0.1",
65
- "happy-dom": "^17.4.7",
65
+ "happy-dom": "^20.0.0",
66
66
  "lint-staged": "^16.1.2",
67
67
  "prettier": "^3.5.3",
68
68
  "simple-git-hooks": "^2.13.0",
69
69
  "tsdown": "^0.11.9",
70
70
  "tsx": "^4.19.4",
71
71
  "typescript": "^5.8.3",
72
- "vitest": "^3.1.3",
72
+ "vitest": "^4.0.3",
73
73
  "vue": "^3.5.16",
74
74
  "vue-router": "^4.5.1"
75
75
  },