zova-core 5.0.110 → 5.0.113
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/bean/beanBaseSimple.d.ts.map +1 -1
- package/dist/bean/beanBaseSimple.js +10 -2
- package/dist/bean/beanBaseSimple.js.map +1 -1
- package/dist/core/resource.d.ts +6 -6
- package/dist/core/resource.d.ts.map +1 -1
- package/dist/core/resource.js +2 -6
- package/dist/core/resource.js.map +1 -1
- package/dist/decorator/class/use.js +8 -5
- package/dist/decorator/class/use.js.map +1 -1
- package/package.json +4 -3
- package/src/bean/beanBase.ts +53 -0
- package/src/bean/beanBaseSimple.ts +38 -0
- package/src/bean/beanContainer.ts +963 -0
- package/src/bean/beanControllerBase.ts +58 -0
- package/src/bean/beanControllerLike.ts +29 -0
- package/src/bean/beanControllerPageBase.ts +18 -0
- package/src/bean/beanRenderBase.ts +7 -0
- package/src/bean/beanRenderLike.ts +33 -0
- package/src/bean/beanSimple.ts +11 -0
- package/src/bean/beanStyleBase.ts +3 -0
- package/src/bean/index.ts +13 -0
- package/src/bean/resource/component/index.ts +1 -0
- package/src/bean/resource/component/type.ts +5 -0
- package/src/bean/resource/config/index.ts +1 -0
- package/src/bean/resource/config/type.ts +32 -0
- package/src/bean/resource/constant/index.ts +1 -0
- package/src/bean/resource/constant/type.ts +1 -0
- package/src/bean/resource/error/beanScopeError.ts +21 -0
- package/src/bean/resource/error/errorClass.ts +57 -0
- package/src/bean/resource/error/errorGlobal.ts +7 -0
- package/src/bean/resource/error/errorInternal.ts +66 -0
- package/src/bean/resource/error/errorObject.ts +4 -0
- package/src/bean/resource/error/index.ts +6 -0
- package/src/bean/resource/error/type.ts +10 -0
- package/src/bean/resource/icon/icon.ts +161 -0
- package/src/bean/resource/icon/iconGroup.ts +10 -0
- package/src/bean/resource/icon/index.ts +4 -0
- package/src/bean/resource/icon/types.ts +21 -0
- package/src/bean/resource/icon/useZovaIcon.ts +20 -0
- package/src/bean/resource/icon/utils.ts +20 -0
- package/src/bean/resource/icon/zovaIcon.ts +52 -0
- package/src/bean/resource/index.ts +8 -0
- package/src/bean/resource/locale/beanScopeLocale.ts +22 -0
- package/src/bean/resource/locale/index.ts +2 -0
- package/src/bean/resource/locale/type.ts +21 -0
- package/src/bean/resource/page/index.ts +1 -0
- package/src/bean/resource/page/type.ts +12 -0
- package/src/bean/resource/service/beanScopeService.ts +24 -0
- package/src/bean/resource/service/index.ts +2 -0
- package/src/bean/resource/service/type.ts +8 -0
- package/src/bean/scope/beanScopeBase.ts +74 -0
- package/src/bean/scope/index.ts +4 -0
- package/src/bean/scope/type.ts +23 -0
- package/src/bean/type.ts +31 -0
- package/src/composables/index.ts +4 -0
- package/src/composables/onControllerMounted.ts +12 -0
- package/src/composables/useApp.ts +7 -0
- package/src/composables/useContext.ts +7 -0
- package/src/composables/useController.ts +125 -0
- package/src/core/app/application.ts +76 -0
- package/src/core/app/config.ts +68 -0
- package/src/core/app/constant.ts +11 -0
- package/src/core/app/index.ts +6 -0
- package/src/core/app/locale.ts +12 -0
- package/src/core/app/meta.ts +44 -0
- package/src/core/app/util.ts +31 -0
- package/src/core/component/component.ts +44 -0
- package/src/core/component/cookie.ts +16 -0
- package/src/core/component/error.ts +18 -0
- package/src/core/component/event.ts +87 -0
- package/src/core/component/index.ts +3 -0
- package/src/core/component/locale.ts +97 -0
- package/src/core/component/module.ts +281 -0
- package/src/core/context/component.ts +34 -0
- package/src/core/context/context.ts +38 -0
- package/src/core/context/index.ts +4 -0
- package/src/core/context/meta.ts +26 -0
- package/src/core/context/state.ts +28 -0
- package/src/core/context/util.ts +20 -0
- package/src/core/index.ts +5 -0
- package/src/core/metadata.ts +54 -0
- package/src/core/resource.ts +186 -0
- package/src/decorator/class/bean.ts +19 -0
- package/src/decorator/class/index.ts +12 -0
- package/src/decorator/class/local.ts +18 -0
- package/src/decorator/class/model.ts +18 -0
- package/src/decorator/class/scope.ts +18 -0
- package/src/decorator/class/store.ts +18 -0
- package/src/decorator/class/style.ts +18 -0
- package/src/decorator/class/theme.ts +18 -0
- package/src/decorator/class/tool.ts +18 -0
- package/src/decorator/class/use.ts +37 -0
- package/src/decorator/class/useComposable.ts +16 -0
- package/src/decorator/class/useScope.ts +21 -0
- package/src/decorator/class/virtual.ts +20 -0
- package/src/decorator/index.ts +7 -0
- package/src/decorator/interface/beanOptions.ts +80 -0
- package/src/decorator/interface/useOptions.ts +37 -0
- package/src/decorator/type/constructable.ts +1 -0
- package/src/decorator/type/containerScope.ts +1 -0
- package/src/decorator/type/functionable.ts +1 -0
- package/src/decorator/type/injectionScope.ts +1 -0
- package/src/index.ts +9 -0
- package/src/plugins/bean.ts +16 -0
- package/src/plugins/index.ts +2 -0
- package/src/plugins/zova.ts +28 -0
- package/src/types/index.ts +2 -0
- package/src/types/interface/component.ts +36 -0
- package/src/types/interface/event.ts +28 -0
- package/src/types/interface/index.ts +6 -0
- package/src/types/interface/inject.ts +2 -0
- package/src/types/interface/module.ts +38 -0
- package/src/types/interface/monkey.ts +38 -0
- package/src/types/interface/pluginZova.ts +17 -0
- package/src/types/utils/cast.ts +8 -0
- package/src/types/utils/env.ts +35 -0
- package/src/types/utils/index.ts +3 -0
- package/src/types/utils/powerPartial.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/isClass.ts +17 -0
- package/src/utils/stateLock.ts +47 -0
- package/src/utils/uuid.ts +84 -0
- package/src/vue/composable.ts +10 -0
- package/src/vue/computed.ts +7 -0
- package/src/vue/customRef.ts +5 -0
- package/src/vue/index.ts +4 -0
- package/src/vue/ref.ts +12 -0
- package/src/zod/index.ts +2 -0
- package/src/zod/zz.ts +77 -0
- package/dist/decorator/class/data.d.ts +0 -3
- package/dist/decorator/class/data.d.ts.map +0 -1
- package/dist/decorator/class/data.js +0 -18
- package/dist/decorator/class/data.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineComponent } from 'vue';
|
|
2
|
+
import { mergeProps, createVNode } from 'vue';
|
|
3
|
+
import { useZovaIcon } from './useZovaIcon.js';
|
|
4
|
+
|
|
5
|
+
export const ZovaIcon = defineComponent({
|
|
6
|
+
name: 'ZovaIcon',
|
|
7
|
+
inheritAttrs: true,
|
|
8
|
+
props: {
|
|
9
|
+
name: String,
|
|
10
|
+
href: String,
|
|
11
|
+
width: [String, Number],
|
|
12
|
+
height: [String, Number],
|
|
13
|
+
color: String,
|
|
14
|
+
},
|
|
15
|
+
setup(props, _ref2) {
|
|
16
|
+
const { iconInfo } = useZovaIcon(() => props.name);
|
|
17
|
+
return () => {
|
|
18
|
+
// href
|
|
19
|
+
let href = props.href;
|
|
20
|
+
if (!href) {
|
|
21
|
+
href = `#${iconInfo.value?.symbolId || ''}`;
|
|
22
|
+
}
|
|
23
|
+
// svgProps
|
|
24
|
+
const svgProps = mergeProps(
|
|
25
|
+
{
|
|
26
|
+
class: 'zova-icon__svg',
|
|
27
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
28
|
+
viewBox: '0 0 24 24',
|
|
29
|
+
fill: 'currentColor',
|
|
30
|
+
role: 'img',
|
|
31
|
+
'aria-hidden': 'true',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
width: props.width,
|
|
35
|
+
height: props.height,
|
|
36
|
+
style: {
|
|
37
|
+
color: props.color,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
return createVNode('svg', svgProps, [
|
|
42
|
+
createVNode(
|
|
43
|
+
'use',
|
|
44
|
+
{
|
|
45
|
+
'xlink:href': href,
|
|
46
|
+
},
|
|
47
|
+
null,
|
|
48
|
+
),
|
|
49
|
+
]);
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './component/index.js';
|
|
2
|
+
export * from './config/index.js';
|
|
3
|
+
export * from './constant/index.js';
|
|
4
|
+
export * from './error/index.js';
|
|
5
|
+
export * from './icon/index.js';
|
|
6
|
+
export * from './locale/index.js';
|
|
7
|
+
export * from './page/index.js';
|
|
8
|
+
export * from './service/index.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IModuleLocale } from './type.js';
|
|
2
|
+
import { BeanSimple } from '../../beanSimple.js';
|
|
3
|
+
|
|
4
|
+
const BeanModuleScope = Symbol('BeanScopeLocale#ModuleScope');
|
|
5
|
+
|
|
6
|
+
export class BeanScopeLocale extends BeanSimple {
|
|
7
|
+
// @ts-ignore: ignore
|
|
8
|
+
private [BeanModuleScope]: string;
|
|
9
|
+
private __instances: Record<string, IModuleLocale> = {};
|
|
10
|
+
|
|
11
|
+
constructor(moduleScope) {
|
|
12
|
+
super();
|
|
13
|
+
this[BeanModuleScope] = moduleScope;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
protected __get__(prop) {
|
|
17
|
+
if (!this.__instances[prop]) {
|
|
18
|
+
this.__instances[prop] = this.app.meta.locale.createScopeLocaleText(this[BeanModuleScope], prop);
|
|
19
|
+
}
|
|
20
|
+
return this.__instances[prop];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IModuleLocale {
|
|
2
|
+
(...args: any[]): string;
|
|
3
|
+
locale: <T extends keyof ILocalInfos>(locale: T, ...args: any[]) => string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface IModuleLocaleText {
|
|
7
|
+
(text: string, ...args: any[]): string;
|
|
8
|
+
locale: <T extends keyof ILocalInfos>(locale: T, text: string, ...args: any[]) => string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TypeModuleLocales<T> = {
|
|
12
|
+
[prop in string & keyof T]: IModuleLocale;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type TypeLocaleBase = 'zh-cn';
|
|
16
|
+
|
|
17
|
+
export interface ILocalInfo {}
|
|
18
|
+
export interface ILocalInfos {
|
|
19
|
+
'en-us': ILocalInfo;
|
|
20
|
+
'zh-cn': ILocalInfo;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export interface IPagePathRecord {}
|
|
4
|
+
export interface IPageNameRecord {}
|
|
5
|
+
|
|
6
|
+
export type TypePageParamsQuery<Q, P = unknown> = {
|
|
7
|
+
query?: Q;
|
|
8
|
+
params?: P;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type TypePageSchema = { params?: z.ZodTypeAny; query: z.ZodTypeAny };
|
|
12
|
+
export type TypePageSchemas = Record<string, TypePageSchema>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BeanSimple } from '../../beanSimple.js';
|
|
2
|
+
|
|
3
|
+
const BeanModuleScope = Symbol('BeanScopeLocale#ModuleScope');
|
|
4
|
+
|
|
5
|
+
export class BeanScopeService extends BeanSimple {
|
|
6
|
+
// @ts-ignore: ignore
|
|
7
|
+
private [BeanModuleScope]: string;
|
|
8
|
+
private __instances: Record<string, object> = {};
|
|
9
|
+
|
|
10
|
+
constructor(moduleScope) {
|
|
11
|
+
super();
|
|
12
|
+
this[BeanModuleScope] = moduleScope;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected __get__(prop) {
|
|
16
|
+
if (!this.__instances[prop]) {
|
|
17
|
+
const module = this.app.meta.module.get(this[BeanModuleScope]);
|
|
18
|
+
const services = module!.resource.services;
|
|
19
|
+
if (!services || !services[prop]) return undefined;
|
|
20
|
+
this.__instances[prop] = services[prop](this.app);
|
|
21
|
+
}
|
|
22
|
+
return this.__instances[prop];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ZovaApplication } from '../../../core/app/application.js';
|
|
2
|
+
|
|
3
|
+
export type TypeModuleServices<T extends Record<string, (app: ZovaApplication) => object> | unknown> =
|
|
4
|
+
T extends Record<string, (app: ZovaApplication) => object>
|
|
5
|
+
? {
|
|
6
|
+
[K in keyof T]: ReturnType<T[K]>;
|
|
7
|
+
}
|
|
8
|
+
: never;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { BeanBaseSimple, SymbolModuleBelong } from '../beanBaseSimple.js';
|
|
2
|
+
import { BeanScopeError } from '../resource/error/beanScopeError.js';
|
|
3
|
+
import { BeanScopeService } from '../resource/service/beanScopeService.js';
|
|
4
|
+
import { BeanScopeLocale } from '../resource/locale/beanScopeLocale.js';
|
|
5
|
+
import { IModule } from '@cabloy/module-info';
|
|
6
|
+
|
|
7
|
+
export { type IModule } from '@cabloy/module-info';
|
|
8
|
+
|
|
9
|
+
const BeanModuleError = Symbol('BeanScopeBase#BeanModuleError');
|
|
10
|
+
const BeanModuleLocale = Symbol('BeanScopeBase#BeanModuleLocale');
|
|
11
|
+
const BeanModuleConfig = Symbol('BeanScopeBase#BeanModuleConfig');
|
|
12
|
+
const BeanModuleConstant = Symbol('BeanScopeBase#BeanModuleConstant');
|
|
13
|
+
const BeanModuleComponent = Symbol('BeanScopeBase#BeanModuleComponent');
|
|
14
|
+
const BeanModuleService = Symbol('BeanScopeBase#BeanModuleService');
|
|
15
|
+
|
|
16
|
+
export class BeanScopeBase extends BeanBaseSimple {
|
|
17
|
+
private [BeanModuleError]: BeanScopeError;
|
|
18
|
+
private [BeanModuleLocale]: BeanScopeLocale;
|
|
19
|
+
private [BeanModuleConfig]: unknown;
|
|
20
|
+
private [BeanModuleConstant]: unknown;
|
|
21
|
+
private [BeanModuleComponent]: unknown;
|
|
22
|
+
private [BeanModuleService]: unknown;
|
|
23
|
+
|
|
24
|
+
get module(): IModule {
|
|
25
|
+
return this.app.meta.module.get(this[SymbolModuleBelong]) as unknown as IModule;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected __get__(prop) {
|
|
29
|
+
const moduleBelong = this[SymbolModuleBelong];
|
|
30
|
+
// error
|
|
31
|
+
if (prop === 'error') {
|
|
32
|
+
if (!this[BeanModuleError]) {
|
|
33
|
+
this[BeanModuleError] = this.bean._newBeanSimple(BeanScopeError, false, moduleBelong);
|
|
34
|
+
}
|
|
35
|
+
return this[BeanModuleError];
|
|
36
|
+
}
|
|
37
|
+
// locale
|
|
38
|
+
if (prop === 'locale') {
|
|
39
|
+
if (!this[BeanModuleLocale]) {
|
|
40
|
+
this[BeanModuleLocale] = this.bean._newBeanSimple(BeanScopeLocale, false, moduleBelong);
|
|
41
|
+
}
|
|
42
|
+
return this[BeanModuleLocale];
|
|
43
|
+
}
|
|
44
|
+
// config
|
|
45
|
+
if (prop === 'config') {
|
|
46
|
+
if (!this[BeanModuleConfig]) {
|
|
47
|
+
this[BeanModuleConfig] = this.app.config.modules[moduleBelong];
|
|
48
|
+
}
|
|
49
|
+
return this[BeanModuleConfig];
|
|
50
|
+
}
|
|
51
|
+
// constant
|
|
52
|
+
if (prop === 'constant') {
|
|
53
|
+
if (!this[BeanModuleConstant]) {
|
|
54
|
+
this[BeanModuleConstant] = this.app.constant.modules[moduleBelong];
|
|
55
|
+
}
|
|
56
|
+
return this[BeanModuleConstant];
|
|
57
|
+
}
|
|
58
|
+
// component
|
|
59
|
+
if (prop === 'component') {
|
|
60
|
+
if (!this[BeanModuleComponent]) {
|
|
61
|
+
const module = this.app.meta.module.get(moduleBelong);
|
|
62
|
+
this[BeanModuleComponent] = module!.resource.components;
|
|
63
|
+
}
|
|
64
|
+
return this[BeanModuleComponent];
|
|
65
|
+
}
|
|
66
|
+
// service
|
|
67
|
+
if (prop === 'service') {
|
|
68
|
+
if (!this[BeanModuleService]) {
|
|
69
|
+
this[BeanModuleService] = this.bean._newBeanSimple(BeanScopeService, false, moduleBelong);
|
|
70
|
+
}
|
|
71
|
+
return this[BeanModuleService];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TypeModuleConfig } from '../resource/config/type.js';
|
|
2
|
+
import { TypeModuleErrors } from '../resource/error/type.js';
|
|
3
|
+
import { TypeModuleLocales } from '../resource/locale/type.js';
|
|
4
|
+
import { TypeModuleConstants } from '../resource/constant/type.js';
|
|
5
|
+
import { ZovaApplication } from '../../core/app/application.js';
|
|
6
|
+
import { TypeModuleComponents } from '../resource/component/type.js';
|
|
7
|
+
import { TypeModuleServices } from '../resource/index.js';
|
|
8
|
+
|
|
9
|
+
export type TypeModuleResource<
|
|
10
|
+
COMPONENTS,
|
|
11
|
+
CONFIG extends (app: ZovaApplication) => object,
|
|
12
|
+
ERRORS,
|
|
13
|
+
LOCALES,
|
|
14
|
+
CONSTANTS = object,
|
|
15
|
+
SERVICES = undefined,
|
|
16
|
+
> = {
|
|
17
|
+
component: TypeModuleComponents<COMPONENTS>;
|
|
18
|
+
config: TypeModuleConfig<CONFIG>;
|
|
19
|
+
error: TypeModuleErrors<ERRORS>;
|
|
20
|
+
locale: TypeModuleLocales<LOCALES>;
|
|
21
|
+
constant: TypeModuleConstants<CONSTANTS>;
|
|
22
|
+
service: TypeModuleServices<SERVICES>;
|
|
23
|
+
};
|
package/src/bean/type.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** bean merge: bean.instance */
|
|
2
|
+
export interface IBeanRecord {}
|
|
3
|
+
export type TypeBeanRecordKeys = keyof IBeanRecord;
|
|
4
|
+
|
|
5
|
+
export interface IBeanScopeRecord {}
|
|
6
|
+
export type TypeBeanScopeRecordKeys = keyof IBeanScopeRecord;
|
|
7
|
+
|
|
8
|
+
export interface IBeanScopeConfig {}
|
|
9
|
+
export type TypeBeanScopeConfigKeys = keyof IBeanScopeConfig;
|
|
10
|
+
|
|
11
|
+
export interface IBeanScopeLocale {}
|
|
12
|
+
export type TypeBeanScopeLocaleKeys = keyof IBeanScopeLocale;
|
|
13
|
+
|
|
14
|
+
export interface IControllerDataContext {
|
|
15
|
+
attrs?: unknown;
|
|
16
|
+
emit?: unknown;
|
|
17
|
+
slots?: object;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IControllerData {
|
|
21
|
+
props?: unknown;
|
|
22
|
+
context: IControllerDataContext;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const BeanControllerIdentifier = '$$c';
|
|
26
|
+
export const BeanRenderIdentifier = '$$r';
|
|
27
|
+
export const BeanStyleIdentifier = '$$s';
|
|
28
|
+
|
|
29
|
+
export function getBeanName<K extends keyof IBeanRecord>(beanFullName: K): K {
|
|
30
|
+
return beanFullName;
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from './useContext.js';
|
|
2
|
+
|
|
3
|
+
export async function onControllerMounted(fn) {
|
|
4
|
+
const ctx = useContext();
|
|
5
|
+
if (!ctx) {
|
|
6
|
+
throw new Error('run in the invalid context');
|
|
7
|
+
}
|
|
8
|
+
await ctx.meta.state.mounted.wait();
|
|
9
|
+
if (fn) {
|
|
10
|
+
return await ctx.meta.util.instanceScope(fn);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getCurrentInstance, onBeforeUnmount, onUnmounted, queuePostFlushCb, useAttrs, useSlots } from 'vue';
|
|
2
|
+
import { Constructable } from '../decorator/index.js';
|
|
3
|
+
import { ZovaContext } from '../core/context/index.js';
|
|
4
|
+
import {
|
|
5
|
+
BeanControllerIdentifier,
|
|
6
|
+
BeanRenderIdentifier,
|
|
7
|
+
BeanStyleIdentifier,
|
|
8
|
+
IBeanRecord,
|
|
9
|
+
IControllerData,
|
|
10
|
+
} from '../bean/type.js';
|
|
11
|
+
|
|
12
|
+
export function useControllerPage<M, R, S>(
|
|
13
|
+
controllerBeanFullName: Constructable<M>,
|
|
14
|
+
renderBeanFullName?: Constructable<R>,
|
|
15
|
+
styleBeanFullName?: Constructable<S>,
|
|
16
|
+
);
|
|
17
|
+
export function useControllerPage<
|
|
18
|
+
MK extends keyof IBeanRecord,
|
|
19
|
+
RK extends keyof IBeanRecord,
|
|
20
|
+
SK extends keyof IBeanRecord,
|
|
21
|
+
>(controllerBeanFullName: MK, renderBeanFullName?: RK, styleBeanFullName?: SK);
|
|
22
|
+
// not use type string for typed params
|
|
23
|
+
//export function useControllerPage(controllerBeanFullName: string, renderBeanFullName?: string, styleBeanFullName?: string);
|
|
24
|
+
export function useControllerPage(
|
|
25
|
+
controllerBeanFullName: Constructable | string,
|
|
26
|
+
renderBeanFullName?: Constructable | string,
|
|
27
|
+
styleBeanFullName?: Constructable | string,
|
|
28
|
+
) {
|
|
29
|
+
// controllerData
|
|
30
|
+
const controllerData = { context: {} };
|
|
31
|
+
// use controller
|
|
32
|
+
_useController(controllerData, controllerBeanFullName, renderBeanFullName, styleBeanFullName);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useController<M, R, S>(
|
|
36
|
+
props: unknown | undefined,
|
|
37
|
+
emit: unknown | undefined,
|
|
38
|
+
controllerBeanFullName: Constructable<M>,
|
|
39
|
+
renderBeanFullName?: Constructable<R>,
|
|
40
|
+
styleBeanFullName?: Constructable<S>,
|
|
41
|
+
);
|
|
42
|
+
export function useController<MK extends keyof IBeanRecord, RK extends keyof IBeanRecord, SK extends keyof IBeanRecord>(
|
|
43
|
+
props: unknown | undefined,
|
|
44
|
+
emit: unknown | undefined,
|
|
45
|
+
controllerBeanFullName: MK,
|
|
46
|
+
renderBeanFullName?: RK,
|
|
47
|
+
styleBeanFullName?: SK,
|
|
48
|
+
);
|
|
49
|
+
// not use type string for typed params
|
|
50
|
+
// export function useController(
|
|
51
|
+
// props: unknown | undefined,
|
|
52
|
+
// emit: unknown | undefined,
|
|
53
|
+
// controllerBeanFullName: string,
|
|
54
|
+
// renderBeanFullName?: string,
|
|
55
|
+
// styleBeanFullName?: string,
|
|
56
|
+
// );
|
|
57
|
+
export function useController(
|
|
58
|
+
props: unknown | undefined,
|
|
59
|
+
emit: unknown | undefined,
|
|
60
|
+
controllerBeanFullName: Constructable | string,
|
|
61
|
+
renderBeanFullName?: Constructable | string,
|
|
62
|
+
styleBeanFullName?: Constructable | string,
|
|
63
|
+
) {
|
|
64
|
+
// attrs
|
|
65
|
+
const attrs = useAttrs();
|
|
66
|
+
// slots
|
|
67
|
+
const slots = useSlots();
|
|
68
|
+
// controllerData
|
|
69
|
+
const controllerData = { props, context: { attrs, slots, emit } };
|
|
70
|
+
// use controller
|
|
71
|
+
_useController(controllerData, controllerBeanFullName, renderBeanFullName, styleBeanFullName);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function _useController(
|
|
75
|
+
controllerData: IControllerData,
|
|
76
|
+
controllerBeanFullName: Constructable | string,
|
|
77
|
+
renderBeanFullName?: Constructable | string,
|
|
78
|
+
styleBeanFullName?: Constructable | string,
|
|
79
|
+
) {
|
|
80
|
+
// ctx
|
|
81
|
+
const ctx = new ZovaContext(getCurrentInstance()!);
|
|
82
|
+
// monkey
|
|
83
|
+
if (ctx.app) {
|
|
84
|
+
ctx.app.meta.module._monkeyModuleSync('controllerDataPrepare', undefined, controllerData);
|
|
85
|
+
}
|
|
86
|
+
// dispose
|
|
87
|
+
onBeforeUnmount(() => {
|
|
88
|
+
if (!ctx.bean) return;
|
|
89
|
+
// undefined better than null
|
|
90
|
+
setControllerRef(ctx, false);
|
|
91
|
+
if (ctx.bean !== ctx.app.bean) {
|
|
92
|
+
ctx.bean.dispose();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
onUnmounted(() => {
|
|
96
|
+
if (!ctx.bean) return;
|
|
97
|
+
ctx.dispose();
|
|
98
|
+
});
|
|
99
|
+
// controller
|
|
100
|
+
//onMounted(async () => {
|
|
101
|
+
await ctx.bean._newBeanInner(true, BeanControllerIdentifier, controllerData, undefined, controllerBeanFullName, true);
|
|
102
|
+
if (styleBeanFullName) {
|
|
103
|
+
await ctx.bean._newBeanInner(true, BeanStyleIdentifier, undefined, undefined, styleBeanFullName, true);
|
|
104
|
+
}
|
|
105
|
+
if (renderBeanFullName) {
|
|
106
|
+
await ctx.bean._newBeanInner(true, BeanRenderIdentifier, undefined, undefined, renderBeanFullName, true);
|
|
107
|
+
}
|
|
108
|
+
ctx.meta.state.inited.touch();
|
|
109
|
+
ctx.meta.util.instanceScope(() => {
|
|
110
|
+
queuePostFlushCb(() => {
|
|
111
|
+
ctx.meta.state.mounted.touch();
|
|
112
|
+
setControllerRef(ctx, true);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
//});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function setControllerRef(ctx: ZovaContext, on: boolean) {
|
|
119
|
+
const controller = ctx.bean?._getBeanSyncOnly(BeanControllerIdentifier) as any;
|
|
120
|
+
if (!controller) return;
|
|
121
|
+
// instanceScope useless for emit, because emiter and receiver not the same instance
|
|
122
|
+
if (controller.$props?.controllerRef) {
|
|
123
|
+
controller.$props.controllerRef(on ? controller : undefined);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { App, markRaw } from 'vue';
|
|
2
|
+
import { BeanContainer } from '../../bean/beanContainer.js';
|
|
3
|
+
import { AppMeta } from './meta.js';
|
|
4
|
+
import { PluginZovaOptions } from '../../types/interface/pluginZova.js';
|
|
5
|
+
import { ZovaConfig, configDefault } from './config.js';
|
|
6
|
+
import { ZovaConstant, constantDefault } from './constant.js';
|
|
7
|
+
import { Cast } from '../../types/utils/cast.js';
|
|
8
|
+
import { ZovaContext } from '../context/context.js';
|
|
9
|
+
|
|
10
|
+
export class ZovaApplication {
|
|
11
|
+
private reloadDelayTimer: number = 0;
|
|
12
|
+
vue: App;
|
|
13
|
+
bean: BeanContainer;
|
|
14
|
+
meta: AppMeta;
|
|
15
|
+
config: ZovaConfig;
|
|
16
|
+
constant: ZovaConstant;
|
|
17
|
+
|
|
18
|
+
constructor(vue: App, ctxRoot: ZovaContext) {
|
|
19
|
+
markRaw(this);
|
|
20
|
+
vue.zova = this;
|
|
21
|
+
this.vue = vue;
|
|
22
|
+
this.bean = ctxRoot.bean;
|
|
23
|
+
Cast(this.bean).app = this;
|
|
24
|
+
ctxRoot.app = this;
|
|
25
|
+
this.meta = this.bean._newBeanSimple(AppMeta, false);
|
|
26
|
+
Cast(ctxRoot.instance.appContext).reload = () => {
|
|
27
|
+
this.reloadDelay();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @internal */
|
|
32
|
+
public async initialize({ modulesMeta, AppMonkey, locales, config }: PluginZovaOptions) {
|
|
33
|
+
// monkey
|
|
34
|
+
await this.meta.initialize(AppMonkey);
|
|
35
|
+
// component
|
|
36
|
+
await this.meta.component.initialize();
|
|
37
|
+
// locales
|
|
38
|
+
await this.meta.locale.initialize(locales);
|
|
39
|
+
// errors
|
|
40
|
+
await this.meta.error.initialize();
|
|
41
|
+
// config
|
|
42
|
+
this.config = this.meta.util.extend({}, configDefault, config);
|
|
43
|
+
// constant
|
|
44
|
+
this.constant = constantDefault;
|
|
45
|
+
// module
|
|
46
|
+
await this.meta.module.initialize(modulesMeta);
|
|
47
|
+
// monkey: appInitialize
|
|
48
|
+
await this.meta.module._monkeyModule('appInitialize', undefined, this.bean);
|
|
49
|
+
// monkey: appInitialized
|
|
50
|
+
await this.meta.module._monkeyModule('appInitialized', undefined, this.bean);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public reload() {
|
|
54
|
+
window.location.reload();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public reloadDelay(cancel?: boolean) {
|
|
58
|
+
if (cancel) {
|
|
59
|
+
if (this.reloadDelayTimer !== 0) {
|
|
60
|
+
window.clearTimeout(this.reloadDelayTimer);
|
|
61
|
+
this.reloadDelayTimer = 0;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
this.reloadDelay(true);
|
|
65
|
+
this.reloadDelayTimer = window.setTimeout(() => {
|
|
66
|
+
this.reload();
|
|
67
|
+
}, 100);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare module 'vue' {
|
|
73
|
+
export interface App {
|
|
74
|
+
zova: ZovaApplication;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZovaConfigEnv,
|
|
3
|
+
ZovaConfigMeta,
|
|
4
|
+
IBeanScopeConfig,
|
|
5
|
+
ILocalInfos,
|
|
6
|
+
PowerPartial,
|
|
7
|
+
IComponentLayoutRecord,
|
|
8
|
+
IBeanScopeRecord,
|
|
9
|
+
} from '../../index.js';
|
|
10
|
+
|
|
11
|
+
export const configDefault = {
|
|
12
|
+
meta: {},
|
|
13
|
+
env: {},
|
|
14
|
+
base: {
|
|
15
|
+
jwt: false,
|
|
16
|
+
},
|
|
17
|
+
api: {
|
|
18
|
+
baseURL: '',
|
|
19
|
+
prefix: '',
|
|
20
|
+
},
|
|
21
|
+
icon: {
|
|
22
|
+
defaultModule: 'home-icon',
|
|
23
|
+
},
|
|
24
|
+
locale: {
|
|
25
|
+
default: 'en-us',
|
|
26
|
+
storeKey: 'locale',
|
|
27
|
+
items: {
|
|
28
|
+
'en-us': 'English',
|
|
29
|
+
'zh-cn': 'Chinese',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
layout: {
|
|
33
|
+
component: {
|
|
34
|
+
default: 'home-layout:layoutDefault',
|
|
35
|
+
empty: 'home-layout:layoutEmpty',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
modules: {},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ZovaConfig = {
|
|
42
|
+
meta: ZovaConfigMeta;
|
|
43
|
+
env: ZovaConfigEnv;
|
|
44
|
+
base: {
|
|
45
|
+
jwt: boolean;
|
|
46
|
+
};
|
|
47
|
+
api: {
|
|
48
|
+
baseURL: string;
|
|
49
|
+
prefix: string;
|
|
50
|
+
};
|
|
51
|
+
icon: {
|
|
52
|
+
defaultModule: keyof IBeanScopeRecord;
|
|
53
|
+
};
|
|
54
|
+
locale: {
|
|
55
|
+
default: keyof ILocalInfos;
|
|
56
|
+
storeKey: string;
|
|
57
|
+
items: Record<keyof ILocalInfos, string>;
|
|
58
|
+
};
|
|
59
|
+
layout: {
|
|
60
|
+
component: {
|
|
61
|
+
default: keyof IComponentLayoutRecord;
|
|
62
|
+
empty: keyof IComponentLayoutRecord;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
modules: IBeanScopeConfig;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type ZovaConfigOptional = PowerPartial<ZovaConfig>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PowerPartial } from '../../index.js';
|
|
2
|
+
|
|
3
|
+
export const constantDefault = {
|
|
4
|
+
modules: {},
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ZovaConstant = {
|
|
8
|
+
modules: Record<string, object>;
|
|
9
|
+
} & typeof constantDefault;
|
|
10
|
+
|
|
11
|
+
export type ZovaConstantOptional = PowerPartial<ZovaConstant>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBeanScopeLocale, PowerPartial } from '../../index.js';
|
|
2
|
+
|
|
3
|
+
export const localeDefault = {
|
|
4
|
+
modules: {},
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ZovaLocale = {
|
|
8
|
+
modules: IBeanScopeLocale;
|
|
9
|
+
} & typeof localeDefault;
|
|
10
|
+
|
|
11
|
+
export type ZovaLocaleOptional = PowerPartial<ZovaLocale>;
|
|
12
|
+
export type ZovaLocaleOptionalMap = Record<string, ZovaLocaleOptional>;
|