zova-module-a-routerstack 5.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/dist/index.js +181 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
- package/rest/component/routerViewStack.ts +8 -0
- package/rest/components.ts +1 -0
- package/rest/index.ts +1 -0
- package/src/.metadata/component/routerViewStack.ts +23 -0
- package/src/.metadata/index.ts +103 -0
- package/src/.metadata/this.ts +2 -0
- package/src/component/routerViewStack/controller.tsx +34 -0
- package/src/index.ts +2 -0
- package/src/model/stack.ts +153 -0
- package/src/types/index.ts +1 -0
- package/src/types/stack.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present Zova
|
|
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/dist/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { BeanInfo, BeanScopeBase, Use, deepExtend, prepareComponentOptions, useComputed, useController } from "zova";
|
|
2
|
+
import { mutate } from "mutate-on-copy";
|
|
3
|
+
import { BeanModelBase, Model } from "zova-module-a-model";
|
|
4
|
+
import { Controller, Scope } from "zova-module-a-bean";
|
|
5
|
+
import { BeanRouterViewBase } from "zova-module-a-router";
|
|
6
|
+
import { defineComponent } from "vue";
|
|
7
|
+
//#region src/model/stack.ts
|
|
8
|
+
var _dec$2, _dec2$2, _class$2;
|
|
9
|
+
var ModelStack$1 = (_dec$2 = Model({
|
|
10
|
+
enableSelector: true,
|
|
11
|
+
max: -1
|
|
12
|
+
}), _dec2$2 = BeanInfo({ module: "a-routerstack" }), _dec$2(_class$2 = _dec2$2(_class$2 = class ModelStack extends BeanModelBase {
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
super(...args);
|
|
15
|
+
this.stackOptions = void 0;
|
|
16
|
+
this.tabs = void 0;
|
|
17
|
+
this.keepAliveInclude = void 0;
|
|
18
|
+
}
|
|
19
|
+
async __init__(scene, options) {
|
|
20
|
+
await super.__init__(scene);
|
|
21
|
+
this.bean._setBean("$$modelStack", this);
|
|
22
|
+
this.stackOptions = deepExtend({}, this.$onionOptions, options);
|
|
23
|
+
this.tabs = [];
|
|
24
|
+
this.keepAliveInclude = useComputed(() => {
|
|
25
|
+
return this._getKeepAliveInclude();
|
|
26
|
+
});
|
|
27
|
+
if (this.$currentRoute) this.forwardRoute(this.$currentRoute);
|
|
28
|
+
}
|
|
29
|
+
addTab(tab) {
|
|
30
|
+
return this._addTab(tab);
|
|
31
|
+
}
|
|
32
|
+
_addTab(tab) {
|
|
33
|
+
const tabKey = tab.tabKey;
|
|
34
|
+
if (!tabKey) return false;
|
|
35
|
+
const [index, tabOld] = this.findTab(tabKey);
|
|
36
|
+
if (index === -1) {
|
|
37
|
+
const tabNew = {
|
|
38
|
+
tabKey,
|
|
39
|
+
updatedAt: Date.now()
|
|
40
|
+
};
|
|
41
|
+
this.tabs = mutate(this.tabs, (copyState) => {
|
|
42
|
+
copyState.push(tabNew);
|
|
43
|
+
});
|
|
44
|
+
this.pruneTabs();
|
|
45
|
+
} else {
|
|
46
|
+
if (!this._checkIfTabNeedUpdate(tabOld, tab)) return false;
|
|
47
|
+
this.updateTab(tab);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
findTab(tabKey) {
|
|
52
|
+
if (!tabKey) return [-1, void 0];
|
|
53
|
+
const index = this.tabs.findIndex((item) => item.tabKey === tabKey);
|
|
54
|
+
if (index === -1) return [index, void 0];
|
|
55
|
+
return [index, this.tabs[index]];
|
|
56
|
+
}
|
|
57
|
+
deleteTab(tabKey) {
|
|
58
|
+
if (!tabKey) return false;
|
|
59
|
+
const [index] = this.findTab(tabKey);
|
|
60
|
+
if (index === -1) return false;
|
|
61
|
+
this.tabs = mutate(this.tabs, (copyState) => {
|
|
62
|
+
copyState.splice(index, 1);
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
updateTab(tab) {
|
|
67
|
+
const tabKey = tab.tabKey;
|
|
68
|
+
const [index, tabOld] = this.findTab(tabKey);
|
|
69
|
+
if (index === -1 || !tabOld) return;
|
|
70
|
+
const tabNew = {
|
|
71
|
+
...tabOld,
|
|
72
|
+
tabKey,
|
|
73
|
+
updatedAt: Date.now()
|
|
74
|
+
};
|
|
75
|
+
this.tabs = mutate(this.tabs, (copyState) => {
|
|
76
|
+
copyState.splice(index, 1, tabNew);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async pruneTabs() {
|
|
80
|
+
let max = this.stackOptions.max;
|
|
81
|
+
if (max === void 0 || max === -1) return;
|
|
82
|
+
if (max < 1) max = 1;
|
|
83
|
+
while (true) {
|
|
84
|
+
if (this.tabs.length <= max) break;
|
|
85
|
+
let tabKey;
|
|
86
|
+
let updatedAt = Date.now();
|
|
87
|
+
for (const tab of this.tabs) if (tab.updatedAt < updatedAt) {
|
|
88
|
+
tabKey = tab.tabKey;
|
|
89
|
+
updatedAt = tab.updatedAt;
|
|
90
|
+
}
|
|
91
|
+
if (!tabKey) break;
|
|
92
|
+
this.deleteTab(tabKey);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
_checkIfTabNeedUpdate(tabOld, _tabNew) {
|
|
96
|
+
if (this.tabs.findIndex((item) => item.tabKey !== tabOld.tabKey && (item.updatedAt ?? 0) >= (tabOld.updatedAt ?? 0)) > -1) return true;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
_getKeepAliveInclude() {
|
|
100
|
+
const include = [];
|
|
101
|
+
for (const tab of this.tabs) if (!include.includes(tab.tabKey)) include.push(tab.tabKey);
|
|
102
|
+
return include;
|
|
103
|
+
}
|
|
104
|
+
backRoute(route) {
|
|
105
|
+
this.deleteTab(route.fullPath);
|
|
106
|
+
}
|
|
107
|
+
forwardRoute(route) {
|
|
108
|
+
const componentMeta = this.prepareRouteMeta(route);
|
|
109
|
+
this.addTab(componentMeta);
|
|
110
|
+
}
|
|
111
|
+
prepareRouteMeta(route) {
|
|
112
|
+
const fullPath = route.fullPath;
|
|
113
|
+
return {
|
|
114
|
+
tabKey: fullPath,
|
|
115
|
+
componentKey: fullPath,
|
|
116
|
+
fullPath
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}) || _class$2) || _class$2);
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/component/routerViewStack/controller.tsx
|
|
122
|
+
var _dec$1, _dec2$1, _dec3, _dec4, _class$1, _class2, _descriptor, _ControllerRouterViewStack;
|
|
123
|
+
function _initializerDefineProperty(e, i, r, l) {
|
|
124
|
+
r && Object.defineProperty(e, i, {
|
|
125
|
+
enumerable: r.enumerable,
|
|
126
|
+
configurable: r.configurable,
|
|
127
|
+
writable: r.writable,
|
|
128
|
+
value: r.initializer ? r.initializer.call(l) : void 0
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) {
|
|
132
|
+
var a = {};
|
|
133
|
+
return Object.keys(n).forEach(function(i) {
|
|
134
|
+
a[i] = n[i];
|
|
135
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
|
|
136
|
+
return n(i, e, r) || r;
|
|
137
|
+
}, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
|
|
138
|
+
}
|
|
139
|
+
var ControllerRouterViewStack = (_dec$1 = Controller(), _dec2$1 = BeanInfo({ module: "a-routerstack" }), _dec3 = Use({ injectionScope: "skipSelf" }), _dec4 = Reflect.metadata("design:type", typeof ModelStack === "undefined" ? Object : ModelStack), _dec$1(_class$1 = _dec2$1(_class$1 = (_class2 = (_ControllerRouterViewStack = class ControllerRouterViewStack extends BeanRouterViewBase {
|
|
140
|
+
constructor(...args) {
|
|
141
|
+
super(...args);
|
|
142
|
+
_initializerDefineProperty(this, "$$modelStack", _descriptor, this);
|
|
143
|
+
}
|
|
144
|
+
backRoute(route) {
|
|
145
|
+
this.$$modelStack.backRoute(route);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
forwardRoute(route) {
|
|
149
|
+
this.$$modelStack.forwardRoute(route);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
prepareRouteMeta(route) {
|
|
153
|
+
return this.$$modelStack.prepareRouteMeta(route);
|
|
154
|
+
}
|
|
155
|
+
getKeepAliveInclude() {
|
|
156
|
+
return this.$$modelStack.keepAliveInclude;
|
|
157
|
+
}
|
|
158
|
+
}, _ControllerRouterViewStack.$propsDefault = {}, _ControllerRouterViewStack), _descriptor = _applyDecoratedDescriptor(_class2.prototype, "$$modelStack", [_dec3, _dec4], {
|
|
159
|
+
configurable: true,
|
|
160
|
+
enumerable: true,
|
|
161
|
+
writable: true,
|
|
162
|
+
initializer: null
|
|
163
|
+
}), _class2)) || _class$1) || _class$1);
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/.metadata/component/routerViewStack.ts
|
|
166
|
+
var ZRouterViewStack = defineComponent((_props) => {
|
|
167
|
+
useController(ControllerRouterViewStack, void 0, void 0);
|
|
168
|
+
return () => {};
|
|
169
|
+
}, prepareComponentOptions());
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/.metadata/index.ts
|
|
172
|
+
/** components: end */
|
|
173
|
+
/** scope: begin */
|
|
174
|
+
var _dec, _dec2, _class;
|
|
175
|
+
var components = { "routerViewStack": ZRouterViewStack };
|
|
176
|
+
var ScopeModuleARouterstack = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-routerstack" }), _dec(_class = _dec2(_class = class ScopeModuleARouterstack extends BeanScopeBase {}) || _class) || _class);
|
|
177
|
+
/** scope: end */
|
|
178
|
+
//#endregion
|
|
179
|
+
export { ControllerRouterViewStack, ModelStack$1 as ModelStack, ScopeModuleARouterstack, ZRouterViewStack, components };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["Use","Controller","BeanRouterViewBase","ControllerRouterViewStack","_dec","_dec2","__z_BeanInfo","module","_dec3","injectionScope","_dec4","Reflect","metadata","ModelStack","Object","_class","_class2","_ControllerRouterViewStack","constructor","args","_initializerDefineProperty","_descriptor","backRoute","route","$$modelStack","forwardRoute","prepareRouteMeta","getKeepAliveInclude","keepAliveInclude","$propsDefault","_applyDecoratedDescriptor","prototype","configurable","enumerable","writable","initializer"],"sources":["../src/model/stack.ts","../src/component/routerViewStack/controller.tsx","../src/.metadata/component/routerViewStack.ts","../src/.metadata/index.ts"],"sourcesContent":["import type { IDecoratorModelOptions } from 'zova-module-a-model';\n\nimport { RouteLocationNormalizedLoadedGeneric } from '@cabloy/vue-router';\nimport { mutate } from 'mutate-on-copy';\nimport { deepExtend, useComputed } from 'zova';\nimport { BeanModelBase, Model } from 'zova-module-a-model';\nimport { IRouteViewRouteMeta } from 'zova-module-a-router';\n\nimport { ModelStackOptions, ModelStackOptionsBase, RouteTab, RouteTabTransient } from '../types/stack.js';\n\nexport interface IModelOptionsStack extends IDecoratorModelOptions, ModelStackOptionsBase {}\n\n@Model<IModelOptionsStack>({\n enableSelector: true,\n max: -1,\n})\nexport class ModelStack extends BeanModelBase {\n stackOptions: ModelStackOptions;\n tabs: RouteTab[];\n keepAliveInclude: string[];\n\n protected async __init__(scene: string, options?: ModelStackOptions) {\n await super.__init__(scene);\n this.bean._setBean('$$modelStack', this);\n // options\n this.stackOptions = deepExtend({}, this.$onionOptions, options);\n // tabs: always []\n this.tabs = [];\n // computed\n this.keepAliveInclude = useComputed(() => {\n return this._getKeepAliveInclude();\n });\n // first route\n if (this.$currentRoute) {\n this.forwardRoute(this.$currentRoute);\n }\n }\n\n addTab(tab: RouteTabTransient): boolean {\n return this._addTab(tab);\n }\n\n _addTab(tab: Partial<RouteTabTransient>): boolean {\n const tabKey = tab.tabKey;\n if (!tabKey) return false;\n // tab\n const [index, tabOld] = this.findTab(tabKey);\n // tabs\n if (index === -1) {\n // new\n const tabNew: RouteTab = {\n tabKey,\n updatedAt: Date.now(),\n };\n this.tabs = mutate(this.tabs, copyState => {\n copyState.push(tabNew);\n });\n this.pruneTabs();\n } else {\n // update\n if (!this._checkIfTabNeedUpdate(tabOld!, tab)) {\n return false;\n }\n this.updateTab(tab);\n }\n return true;\n }\n\n findTab(tabKey?: string): [number, RouteTab | undefined] {\n if (!tabKey) return [-1, undefined];\n const index = this.tabs.findIndex(item => item.tabKey === tabKey);\n if (index === -1) return [index, undefined];\n return [index, this.tabs[index]];\n }\n\n deleteTab(tabKey?: string) {\n if (!tabKey) return false;\n // tabs\n const [index] = this.findTab(tabKey);\n if (index === -1) return false;\n // tabs\n this.tabs = mutate(this.tabs, copyState => {\n copyState.splice(index, 1);\n });\n return true;\n }\n\n updateTab(tab: Partial<RouteTabTransient>) {\n const tabKey = tab.tabKey!;\n const [index, tabOld] = this.findTab(tabKey);\n if (index === -1 || !tabOld) return;\n const tabNew: RouteTab = {\n ...tabOld,\n tabKey,\n updatedAt: Date.now(),\n };\n this.tabs = mutate(this.tabs, copyState => {\n copyState.splice(index, 1, tabNew);\n });\n }\n\n async pruneTabs() {\n let max = this.stackOptions.max;\n if (max === undefined || max === -1) return;\n if (max < 1) max = 1;\n while (true) {\n if (this.tabs.length <= max) break;\n let tabKey: string | undefined;\n let updatedAt = Date.now();\n for (const tab of this.tabs) {\n if (tab.updatedAt < updatedAt) {\n tabKey = tab.tabKey;\n updatedAt = tab.updatedAt;\n }\n }\n if (!tabKey) break;\n this.deleteTab(tabKey);\n }\n }\n\n // special for _addTab\n private _checkIfTabNeedUpdate(tabOld: RouteTab, _tabNew: Partial<RouteTabTransient>) {\n const recentTabIndex = this.tabs.findIndex(item => item.tabKey !== tabOld.tabKey && (item.updatedAt ?? 0) >= (tabOld.updatedAt ?? 0));\n if (recentTabIndex > -1) return true;\n return false;\n }\n\n private _getKeepAliveInclude() {\n const include: string[] = [];\n for (const tab of this.tabs) {\n if (!include.includes(tab.tabKey)) {\n include.push(tab.tabKey);\n }\n }\n return include;\n }\n\n backRoute(route: RouteLocationNormalizedLoadedGeneric) {\n this.deleteTab(route.fullPath);\n }\n\n forwardRoute(route: RouteLocationNormalizedLoadedGeneric) {\n const componentMeta = this.prepareRouteMeta(route);\n this.addTab(componentMeta);\n }\n\n prepareRouteMeta(route: RouteLocationNormalizedLoadedGeneric): IRouteViewRouteMeta {\n // fullPath\n const fullPath = route.fullPath;\n // tab\n return { tabKey: fullPath, componentKey: fullPath, fullPath };\n }\n}\n","import { RouteLocationNormalizedLoadedGeneric } from '@cabloy/vue-router';\nimport { Use } from 'zova';\nimport { Controller } from 'zova-module-a-bean';\nimport { BeanRouterViewBase, IRouterViewPropsBase, IRouteViewRouteMeta } from 'zova-module-a-router';\n\nimport type { ModelStack } from '../../model/stack.js';\n\nexport interface ControllerRouterViewStackProps extends IRouterViewPropsBase {}\n\n@Controller()\nexport class ControllerRouterViewStack extends BeanRouterViewBase {\n static $propsDefault = {};\n\n @Use({ injectionScope: 'skipSelf' })\n $$modelStack: ModelStack;\n\n public backRoute(route: RouteLocationNormalizedLoadedGeneric) {\n this.$$modelStack.backRoute(route);\n return true;\n }\n\n public forwardRoute(route: RouteLocationNormalizedLoadedGeneric) {\n this.$$modelStack.forwardRoute(route);\n return true;\n }\n\n protected prepareRouteMeta(route: RouteLocationNormalizedLoadedGeneric): IRouteViewRouteMeta {\n return this.$$modelStack.prepareRouteMeta(route);\n }\n\n protected getKeepAliveInclude(): string[] | undefined {\n return this.$$modelStack.keepAliveInclude;\n }\n}\n","import type { TypeControllerInnerProps } from 'zova';\n\nimport { defineComponent } from 'vue';\nimport { prepareComponentOptions, useController } from 'zova';\n\nimport type { ControllerRouterViewStackProps } from '../../component/routerViewStack/controller.jsx';\n\nimport { ControllerRouterViewStack } from '../../component/routerViewStack/controller.jsx';\nexport type TypeControllerRouterViewStackPublicProps = {\n controllerRef?: (ref: ControllerRouterViewStack) => void;\n} & ControllerRouterViewStackProps;\n\ntype ControllerInnerProps = TypeControllerInnerProps<ControllerRouterViewStackProps, keyof typeof ControllerRouterViewStack.$propsDefault>;\ndeclare module 'zova-module-a-routerstack' {\n export interface ControllerRouterViewStack {\n $props: ControllerInnerProps;\n }\n}\n\nexport const ZRouterViewStack = defineComponent((_props: TypeControllerRouterViewStackPublicProps) => {\n useController(ControllerRouterViewStack, undefined, undefined);\n return () => {};\n}, prepareComponentOptions());\n","// eslint-disable\n/** model: begin */\nexport * from '../model/stack.js';\nimport { IModelOptionsStack } from '../model/stack.js';\nimport 'zova-module-a-model';\ndeclare module 'zova-module-a-model' {\n \n export interface IModelRecord {\n 'a-routerstack:stack': IModelOptionsStack;\n }\n\n \n}\ndeclare module 'zova-module-a-routerstack' {\n \n export interface ModelStack {\n /** @internal */\n get scope(): ScopeModuleARouterstack;\n }\n\n export interface ModelStack {\n get $beanFullName(): 'a-routerstack.model.stack';\n get $onionName(): 'a-routerstack:stack';\n get $onionOptions(): IModelOptionsStack;\n } \n}\n/** model: end */\n/** model: begin */\nimport { ModelStack } from '../model/stack.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordGeneral {\n 'a-routerstack.model.stack': ModelStack;\n }\n}\n/** model: end */\n/** controller: begin */\nexport * from '../component/routerViewStack/controller.jsx';\n\nimport 'zova';\ndeclare module 'zova' {\n \n \n}\ndeclare module 'zova-module-a-routerstack' {\n \n export interface ControllerRouterViewStack {\n /** @internal */\n get scope(): ScopeModuleARouterstack;\n } \n}\n/** controller: end */\n/** controller: begin */\nimport { ControllerRouterViewStack } from '../component/routerViewStack/controller.jsx';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordLocal {\n 'a-routerstack.controller.routerViewStack': ControllerRouterViewStack;\n }\n}\n/** controller: end */\n\n/** components: begin */\nexport * from './component/routerViewStack.js';\nimport { ZRouterViewStack } from './component/routerViewStack.js';\nexport const components = {\n 'routerViewStack': ZRouterViewStack,\n};\nimport 'zova';\ndeclare module 'zova' {\nexport interface IComponentRecord {\n 'a-routerstack:routerViewStack': ControllerRouterViewStack;\n}\nexport interface IZovaComponentRecord {\n 'a-routerstack:routerViewStack': typeof ZRouterViewStack;\n}\n}\n/** components: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleARouterstack extends BeanScopeBase {}\n\nexport interface ScopeModuleARouterstack {\n util: BeanScopeUtil;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-routerstack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gCAAA,cAAA,GAAA,IAAA,OAAA,IAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zova-module-a-routerstack",
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Zova Module"
|
|
7
|
+
],
|
|
8
|
+
"author": "",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"mock",
|
|
12
|
+
"rest",
|
|
13
|
+
"src",
|
|
14
|
+
"icons",
|
|
15
|
+
"assets"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": [
|
|
21
|
+
"./src/index.ts",
|
|
22
|
+
"./dist/index.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./*": "./*"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
30
|
+
"tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap",
|
|
31
|
+
"prepublishOnly": "npm run tsc:publish",
|
|
32
|
+
"prepack": "clean-package",
|
|
33
|
+
"postpack": "clean-package restore && npm run clean"
|
|
34
|
+
},
|
|
35
|
+
"title": "a-routerstack",
|
|
36
|
+
"gitHead": "bf1ceb4582381c74ba41ccf11b89d3b9e7b73628"
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';
|
|
2
|
+
|
|
3
|
+
import type { ControllerRouterViewStackProps } from '../../src/component/routerViewStack/controller.jsx';
|
|
4
|
+
|
|
5
|
+
type TypeControllerRouterViewStackPublicProps = TypeRenderComponentJsxPropsPublic & ControllerRouterViewStackProps;
|
|
6
|
+
export function ZZRouterstackRouterViewStack(_props: TypeControllerRouterViewStackPublicProps) {
|
|
7
|
+
return 'a-routerstack:routerViewStack';
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './component/routerViewStack.js';
|
package/rest/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TypeControllerInnerProps } from 'zova';
|
|
2
|
+
|
|
3
|
+
import { defineComponent } from 'vue';
|
|
4
|
+
import { prepareComponentOptions, useController } from 'zova';
|
|
5
|
+
|
|
6
|
+
import type { ControllerRouterViewStackProps } from '../../component/routerViewStack/controller.jsx';
|
|
7
|
+
|
|
8
|
+
import { ControllerRouterViewStack } from '../../component/routerViewStack/controller.jsx';
|
|
9
|
+
export type TypeControllerRouterViewStackPublicProps = {
|
|
10
|
+
controllerRef?: (ref: ControllerRouterViewStack) => void;
|
|
11
|
+
} & ControllerRouterViewStackProps;
|
|
12
|
+
|
|
13
|
+
type ControllerInnerProps = TypeControllerInnerProps<ControllerRouterViewStackProps, keyof typeof ControllerRouterViewStack.$propsDefault>;
|
|
14
|
+
declare module 'zova-module-a-routerstack' {
|
|
15
|
+
export interface ControllerRouterViewStack {
|
|
16
|
+
$props: ControllerInnerProps;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ZRouterViewStack = defineComponent((_props: TypeControllerRouterViewStackPublicProps) => {
|
|
21
|
+
useController(ControllerRouterViewStack, undefined, undefined);
|
|
22
|
+
return () => {};
|
|
23
|
+
}, prepareComponentOptions());
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// eslint-disable
|
|
2
|
+
/** model: begin */
|
|
3
|
+
export * from '../model/stack.js';
|
|
4
|
+
import { IModelOptionsStack } from '../model/stack.js';
|
|
5
|
+
import 'zova-module-a-model';
|
|
6
|
+
declare module 'zova-module-a-model' {
|
|
7
|
+
|
|
8
|
+
export interface IModelRecord {
|
|
9
|
+
'a-routerstack:stack': IModelOptionsStack;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
declare module 'zova-module-a-routerstack' {
|
|
15
|
+
|
|
16
|
+
export interface ModelStack {
|
|
17
|
+
/** @internal */
|
|
18
|
+
get scope(): ScopeModuleARouterstack;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ModelStack {
|
|
22
|
+
get $beanFullName(): 'a-routerstack.model.stack';
|
|
23
|
+
get $onionName(): 'a-routerstack:stack';
|
|
24
|
+
get $onionOptions(): IModelOptionsStack;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** model: end */
|
|
28
|
+
/** model: begin */
|
|
29
|
+
import { ModelStack } from '../model/stack.js';
|
|
30
|
+
import 'zova';
|
|
31
|
+
declare module 'zova' {
|
|
32
|
+
export interface IBeanRecordGeneral {
|
|
33
|
+
'a-routerstack.model.stack': ModelStack;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** model: end */
|
|
37
|
+
/** controller: begin */
|
|
38
|
+
export * from '../component/routerViewStack/controller.jsx';
|
|
39
|
+
|
|
40
|
+
import 'zova';
|
|
41
|
+
declare module 'zova' {
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
declare module 'zova-module-a-routerstack' {
|
|
46
|
+
|
|
47
|
+
export interface ControllerRouterViewStack {
|
|
48
|
+
/** @internal */
|
|
49
|
+
get scope(): ScopeModuleARouterstack;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** controller: end */
|
|
53
|
+
/** controller: begin */
|
|
54
|
+
import { ControllerRouterViewStack } from '../component/routerViewStack/controller.jsx';
|
|
55
|
+
import 'zova';
|
|
56
|
+
declare module 'zova' {
|
|
57
|
+
export interface IBeanRecordLocal {
|
|
58
|
+
'a-routerstack.controller.routerViewStack': ControllerRouterViewStack;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** controller: end */
|
|
62
|
+
|
|
63
|
+
/** components: begin */
|
|
64
|
+
export * from './component/routerViewStack.js';
|
|
65
|
+
import { ZRouterViewStack } from './component/routerViewStack.js';
|
|
66
|
+
export const components = {
|
|
67
|
+
'routerViewStack': ZRouterViewStack,
|
|
68
|
+
};
|
|
69
|
+
import 'zova';
|
|
70
|
+
declare module 'zova' {
|
|
71
|
+
export interface IComponentRecord {
|
|
72
|
+
'a-routerstack:routerViewStack': ControllerRouterViewStack;
|
|
73
|
+
}
|
|
74
|
+
export interface IZovaComponentRecord {
|
|
75
|
+
'a-routerstack:routerViewStack': typeof ZRouterViewStack;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** components: end */
|
|
79
|
+
/** scope: begin */
|
|
80
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'zova';
|
|
81
|
+
import { Scope } from 'zova-module-a-bean';
|
|
82
|
+
|
|
83
|
+
@Scope()
|
|
84
|
+
export class ScopeModuleARouterstack extends BeanScopeBase {}
|
|
85
|
+
|
|
86
|
+
export interface ScopeModuleARouterstack {
|
|
87
|
+
util: BeanScopeUtil;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
import 'zova';
|
|
91
|
+
declare module 'zova' {
|
|
92
|
+
export interface IBeanScopeRecord {
|
|
93
|
+
'a-routerstack': ScopeModuleARouterstack;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** scope: end */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RouteLocationNormalizedLoadedGeneric } from '@cabloy/vue-router';
|
|
2
|
+
import { Use } from 'zova';
|
|
3
|
+
import { Controller } from 'zova-module-a-bean';
|
|
4
|
+
import { BeanRouterViewBase, IRouterViewPropsBase, IRouteViewRouteMeta } from 'zova-module-a-router';
|
|
5
|
+
|
|
6
|
+
import type { ModelStack } from '../../model/stack.js';
|
|
7
|
+
|
|
8
|
+
export interface ControllerRouterViewStackProps extends IRouterViewPropsBase {}
|
|
9
|
+
|
|
10
|
+
@Controller()
|
|
11
|
+
export class ControllerRouterViewStack extends BeanRouterViewBase {
|
|
12
|
+
static $propsDefault = {};
|
|
13
|
+
|
|
14
|
+
@Use({ injectionScope: 'skipSelf' })
|
|
15
|
+
$$modelStack: ModelStack;
|
|
16
|
+
|
|
17
|
+
public backRoute(route: RouteLocationNormalizedLoadedGeneric) {
|
|
18
|
+
this.$$modelStack.backRoute(route);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public forwardRoute(route: RouteLocationNormalizedLoadedGeneric) {
|
|
23
|
+
this.$$modelStack.forwardRoute(route);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected prepareRouteMeta(route: RouteLocationNormalizedLoadedGeneric): IRouteViewRouteMeta {
|
|
28
|
+
return this.$$modelStack.prepareRouteMeta(route);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected getKeepAliveInclude(): string[] | undefined {
|
|
32
|
+
return this.$$modelStack.keepAliveInclude;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'zova-module-a-model';
|
|
2
|
+
|
|
3
|
+
import { RouteLocationNormalizedLoadedGeneric } from '@cabloy/vue-router';
|
|
4
|
+
import { mutate } from 'mutate-on-copy';
|
|
5
|
+
import { deepExtend, useComputed } from 'zova';
|
|
6
|
+
import { BeanModelBase, Model } from 'zova-module-a-model';
|
|
7
|
+
import { IRouteViewRouteMeta } from 'zova-module-a-router';
|
|
8
|
+
|
|
9
|
+
import { ModelStackOptions, ModelStackOptionsBase, RouteTab, RouteTabTransient } from '../types/stack.js';
|
|
10
|
+
|
|
11
|
+
export interface IModelOptionsStack extends IDecoratorModelOptions, ModelStackOptionsBase {}
|
|
12
|
+
|
|
13
|
+
@Model<IModelOptionsStack>({
|
|
14
|
+
enableSelector: true,
|
|
15
|
+
max: -1,
|
|
16
|
+
})
|
|
17
|
+
export class ModelStack extends BeanModelBase {
|
|
18
|
+
stackOptions: ModelStackOptions;
|
|
19
|
+
tabs: RouteTab[];
|
|
20
|
+
keepAliveInclude: string[];
|
|
21
|
+
|
|
22
|
+
protected async __init__(scene: string, options?: ModelStackOptions) {
|
|
23
|
+
await super.__init__(scene);
|
|
24
|
+
this.bean._setBean('$$modelStack', this);
|
|
25
|
+
// options
|
|
26
|
+
this.stackOptions = deepExtend({}, this.$onionOptions, options);
|
|
27
|
+
// tabs: always []
|
|
28
|
+
this.tabs = [];
|
|
29
|
+
// computed
|
|
30
|
+
this.keepAliveInclude = useComputed(() => {
|
|
31
|
+
return this._getKeepAliveInclude();
|
|
32
|
+
});
|
|
33
|
+
// first route
|
|
34
|
+
if (this.$currentRoute) {
|
|
35
|
+
this.forwardRoute(this.$currentRoute);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
addTab(tab: RouteTabTransient): boolean {
|
|
40
|
+
return this._addTab(tab);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_addTab(tab: Partial<RouteTabTransient>): boolean {
|
|
44
|
+
const tabKey = tab.tabKey;
|
|
45
|
+
if (!tabKey) return false;
|
|
46
|
+
// tab
|
|
47
|
+
const [index, tabOld] = this.findTab(tabKey);
|
|
48
|
+
// tabs
|
|
49
|
+
if (index === -1) {
|
|
50
|
+
// new
|
|
51
|
+
const tabNew: RouteTab = {
|
|
52
|
+
tabKey,
|
|
53
|
+
updatedAt: Date.now(),
|
|
54
|
+
};
|
|
55
|
+
this.tabs = mutate(this.tabs, copyState => {
|
|
56
|
+
copyState.push(tabNew);
|
|
57
|
+
});
|
|
58
|
+
this.pruneTabs();
|
|
59
|
+
} else {
|
|
60
|
+
// update
|
|
61
|
+
if (!this._checkIfTabNeedUpdate(tabOld!, tab)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
this.updateTab(tab);
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
findTab(tabKey?: string): [number, RouteTab | undefined] {
|
|
70
|
+
if (!tabKey) return [-1, undefined];
|
|
71
|
+
const index = this.tabs.findIndex(item => item.tabKey === tabKey);
|
|
72
|
+
if (index === -1) return [index, undefined];
|
|
73
|
+
return [index, this.tabs[index]];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
deleteTab(tabKey?: string) {
|
|
77
|
+
if (!tabKey) return false;
|
|
78
|
+
// tabs
|
|
79
|
+
const [index] = this.findTab(tabKey);
|
|
80
|
+
if (index === -1) return false;
|
|
81
|
+
// tabs
|
|
82
|
+
this.tabs = mutate(this.tabs, copyState => {
|
|
83
|
+
copyState.splice(index, 1);
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
updateTab(tab: Partial<RouteTabTransient>) {
|
|
89
|
+
const tabKey = tab.tabKey!;
|
|
90
|
+
const [index, tabOld] = this.findTab(tabKey);
|
|
91
|
+
if (index === -1 || !tabOld) return;
|
|
92
|
+
const tabNew: RouteTab = {
|
|
93
|
+
...tabOld,
|
|
94
|
+
tabKey,
|
|
95
|
+
updatedAt: Date.now(),
|
|
96
|
+
};
|
|
97
|
+
this.tabs = mutate(this.tabs, copyState => {
|
|
98
|
+
copyState.splice(index, 1, tabNew);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async pruneTabs() {
|
|
103
|
+
let max = this.stackOptions.max;
|
|
104
|
+
if (max === undefined || max === -1) return;
|
|
105
|
+
if (max < 1) max = 1;
|
|
106
|
+
while (true) {
|
|
107
|
+
if (this.tabs.length <= max) break;
|
|
108
|
+
let tabKey: string | undefined;
|
|
109
|
+
let updatedAt = Date.now();
|
|
110
|
+
for (const tab of this.tabs) {
|
|
111
|
+
if (tab.updatedAt < updatedAt) {
|
|
112
|
+
tabKey = tab.tabKey;
|
|
113
|
+
updatedAt = tab.updatedAt;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!tabKey) break;
|
|
117
|
+
this.deleteTab(tabKey);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// special for _addTab
|
|
122
|
+
private _checkIfTabNeedUpdate(tabOld: RouteTab, _tabNew: Partial<RouteTabTransient>) {
|
|
123
|
+
const recentTabIndex = this.tabs.findIndex(item => item.tabKey !== tabOld.tabKey && (item.updatedAt ?? 0) >= (tabOld.updatedAt ?? 0));
|
|
124
|
+
if (recentTabIndex > -1) return true;
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private _getKeepAliveInclude() {
|
|
129
|
+
const include: string[] = [];
|
|
130
|
+
for (const tab of this.tabs) {
|
|
131
|
+
if (!include.includes(tab.tabKey)) {
|
|
132
|
+
include.push(tab.tabKey);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return include;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
backRoute(route: RouteLocationNormalizedLoadedGeneric) {
|
|
139
|
+
this.deleteTab(route.fullPath);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
forwardRoute(route: RouteLocationNormalizedLoadedGeneric) {
|
|
143
|
+
const componentMeta = this.prepareRouteMeta(route);
|
|
144
|
+
this.addTab(componentMeta);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
prepareRouteMeta(route: RouteLocationNormalizedLoadedGeneric): IRouteViewRouteMeta {
|
|
148
|
+
// fullPath
|
|
149
|
+
const fullPath = route.fullPath;
|
|
150
|
+
// tab
|
|
151
|
+
return { tabKey: fullPath, componentKey: fullPath, fullPath };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stack.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IRouteViewRouteMeta } from 'zova-module-a-router';
|
|
2
|
+
|
|
3
|
+
export interface ModelStackOptionsBase {
|
|
4
|
+
/** -1: infinite 0: Affix Only */
|
|
5
|
+
max?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ModelStackOptions extends ModelStackOptionsBase {}
|
|
9
|
+
|
|
10
|
+
export interface RouteTabBase {
|
|
11
|
+
tabKey: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface RouteTabTransient extends IRouteViewRouteMeta {}
|
|
15
|
+
|
|
16
|
+
export interface RouteTab extends RouteTabBase {
|
|
17
|
+
updatedAt: number;
|
|
18
|
+
}
|