zova-module-a-behavior 5.0.0 → 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/cli/behavior/boilerplate/{{sceneName}}.{{beanName}}.ts_ +20 -0
- package/cli/behavior/metadata/generate.ts +49 -0
- package/cli/tsconfig.json +8 -0
- package/dist/index.js +318 -0
- package/dist/index.js.map +1 -0
- package/dist-cli/behavior/metadata/generate.js +49 -0
- package/package.json +35 -23
- package/rest/component/behavior.ts +8 -0
- package/rest/components.ts +1 -0
- package/rest/index.ts +1 -0
- package/src/.metadata/component/behavior.ts +23 -0
- package/src/.metadata/index.ts +182 -0
- package/src/.metadata/this.ts +2 -0
- package/src/bean/bean.behavior.ts +13 -0
- package/src/bean/bean.behaviorBase.ts +42 -0
- package/src/bean/bean.behaviorsHolder.ts +81 -0
- package/src/bean/behavior.root_.ts +39 -0
- package/src/component/behavior/controller.tsx +36 -0
- package/src/index.ts +3 -0
- package/src/lib/behavior.ts +7 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/useBehavior.ts +14 -0
- package/src/service/composer.ts +100 -0
- package/src/types/behavior.ts +75 -0
- package/src/types/index.ts +1 -0
- package/README.md +0 -1
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.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
2
|
+
import type { IDecoratorBehaviorOptions, NextBehavior } from 'zova-module-a-behavior';
|
|
3
|
+
import { BeanBehaviorBase, Behavior } from 'zova-module-a-behavior';
|
|
4
|
+
|
|
5
|
+
export interface IBehaviorPropsInput<%=argv.beanNameCapitalize%> {}
|
|
6
|
+
|
|
7
|
+
export interface IBehaviorPropsOutput<%=argv.beanNameCapitalize%> extends IBehaviorPropsInput<%=argv.beanNameCapitalize%> {}
|
|
8
|
+
|
|
9
|
+
export interface IBehaviorOptions<%=argv.beanNameCapitalize%> extends IDecoratorBehaviorOptions {}
|
|
10
|
+
|
|
11
|
+
@Behavior<IBehaviorOptions<%=argv.beanNameCapitalize%>>()
|
|
12
|
+
export class Behavior<%=argv.beanNameCapitalize%> extends BeanBehaviorBase<
|
|
13
|
+
IBehaviorOptions<%=argv.beanNameCapitalize%>,
|
|
14
|
+
IBehaviorPropsInput<%=argv.beanNameCapitalize%>,
|
|
15
|
+
IBehaviorPropsOutput<%=argv.beanNameCapitalize%>
|
|
16
|
+
> {
|
|
17
|
+
protected render(_props: IBehaviorPropsInput<%=argv.beanNameCapitalize%>, next: NextBehavior<IBehaviorPropsOutput<%=argv.beanNameCapitalize%>>): VNode {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
|
|
2
|
+
|
|
3
|
+
export default async function (options: IMetadataCustomGenerateOptions): Promise<string> {
|
|
4
|
+
const { moduleName, globFiles } = options;
|
|
5
|
+
if (globFiles.length === 0) return '';
|
|
6
|
+
const contentRecords: string[] = [];
|
|
7
|
+
for (const { beanName, beanNameCapitalize, isIgnore } of globFiles) {
|
|
8
|
+
if (isIgnore) continue;
|
|
9
|
+
const behaviorAttrName = _combineBehaviorAttrName(moduleName, beanName);
|
|
10
|
+
contentRecords.push(`'${behaviorAttrName}'?: IBehaviorOptions${beanNameCapitalize} | '' | boolean;`);
|
|
11
|
+
}
|
|
12
|
+
// combine
|
|
13
|
+
const content = `/** behaviors: begin */
|
|
14
|
+
import 'vue';
|
|
15
|
+
import 'vue/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
declare module 'vue' {
|
|
18
|
+
export interface InputHTMLAttributes {
|
|
19
|
+
${contentRecords.join('\n')}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module 'vue/jsx-runtime' {
|
|
24
|
+
namespace JSX {
|
|
25
|
+
// need define class/style in IntrinsicAttributes
|
|
26
|
+
export interface IntrinsicAttributes {
|
|
27
|
+
${contentRecords.join('\n')}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** behaviors: end */
|
|
32
|
+
`;
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// bs-providerId-moduleName-beanName
|
|
37
|
+
function _combineBehaviorAttrName(moduleName: string, beanName: string) {
|
|
38
|
+
const parts = ['bs'];
|
|
39
|
+
if (!moduleName.startsWith('a-')) {
|
|
40
|
+
parts.push(moduleName);
|
|
41
|
+
} else {
|
|
42
|
+
const moduleNameShort = moduleName.substring('a-'.length);
|
|
43
|
+
if (!beanName.startsWith(moduleNameShort)) {
|
|
44
|
+
parts.push(moduleNameShort);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
parts.push(beanName);
|
|
48
|
+
return parts.join('-');
|
|
49
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { BeanBase, BeanControllerBase, BeanInfo, BeanScopeBase, SymbolControllerRefDisable, Use, Virtual, cast, createBeanDecorator, deepEqual, disposeInstance, prepareComponentOptions, useController } from "zova";
|
|
2
|
+
import { Bean, Controller, Scope, Service } from "zova-module-a-bean";
|
|
3
|
+
import { createVNode, defineComponent, toRaw } from "vue";
|
|
4
|
+
import { Log } from "zova-module-a-logger";
|
|
5
|
+
import "zova-module-a-behavior";
|
|
6
|
+
import "vue/jsx-runtime";
|
|
7
|
+
import "@vue/runtime-dom";
|
|
8
|
+
//#region src/service/composer.ts
|
|
9
|
+
var _dec$6, _dec2$6, _dec3$3, _dec4$3, _class$6, _class2$3, _descriptor$3;
|
|
10
|
+
function _initializerDefineProperty$3(e, i, r, l) {
|
|
11
|
+
r && Object.defineProperty(e, i, {
|
|
12
|
+
enumerable: r.enumerable,
|
|
13
|
+
configurable: r.configurable,
|
|
14
|
+
writable: r.writable,
|
|
15
|
+
value: r.initializer ? r.initializer.call(l) : void 0
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function _applyDecoratedDescriptor$3(i, e, r, n, l) {
|
|
19
|
+
var a = {};
|
|
20
|
+
return Object.keys(n).forEach(function(i) {
|
|
21
|
+
a[i] = n[i];
|
|
22
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
|
|
23
|
+
return n(i, e, r) || r;
|
|
24
|
+
}, 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;
|
|
25
|
+
}
|
|
26
|
+
var SymbolSliceOptionsOriginal = Symbol("SymbolSliceOptionsOriginal");
|
|
27
|
+
var ServiceComposer = (_dec$6 = Service(), _dec2$6 = BeanInfo({ module: "a-behavior" }), _dec3$3 = Use("a-bean.sys.onion"), _dec4$3 = Reflect.metadata("design:type", typeof SysOnion === "undefined" ? Object : SysOnion), _dec$6(_class$6 = _dec2$6(_class$6 = (_class2$3 = class ServiceComposer extends BeanBase {
|
|
28
|
+
constructor(...args) {
|
|
29
|
+
super(...args);
|
|
30
|
+
this._composer = void 0;
|
|
31
|
+
this._onionSlicesOriginal = void 0;
|
|
32
|
+
_initializerDefineProperty$3(this, "$$sysOnion", _descriptor$3, this);
|
|
33
|
+
}
|
|
34
|
+
async __init__(behaviors) {
|
|
35
|
+
await this.load(behaviors);
|
|
36
|
+
}
|
|
37
|
+
__dispose__() {
|
|
38
|
+
if (this._onionSlicesOriginal) for (const onionSlice of this._onionSlicesOriginal) disposeInstance(onionSlice.beanInstance);
|
|
39
|
+
}
|
|
40
|
+
async load(behaviors) {
|
|
41
|
+
await this.$renderFreezeScope(async () => {
|
|
42
|
+
await this._loadInner(behaviors);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async _loadInner(behaviors) {
|
|
46
|
+
const onionItems = this._prepareOnionItems(behaviors);
|
|
47
|
+
const onionSlices = await this.$$sysOnion.behavior.loadOnions(onionItems);
|
|
48
|
+
for (const onionSlice of onionSlices) {
|
|
49
|
+
const onionSliceOriginal = this._onionSlicesOriginal?.find((item) => item.beanFullName === onionSlice.beanFullName);
|
|
50
|
+
if (onionSliceOriginal) {
|
|
51
|
+
onionSlice.beanInstance = onionSliceOriginal.beanInstance;
|
|
52
|
+
if (!deepEqual(onionSliceOriginal[SymbolSliceOptionsOriginal], onionSlice.options)) await cast(onionSlice.beanInstance).onOptionsChange(onionSlice.options);
|
|
53
|
+
} else onionSlice.beanInstance = await this.bean._newBean(onionSlice.beanFullName, true, onionSlice.options);
|
|
54
|
+
onionSlice[SymbolSliceOptionsOriginal] = onionSlice.options;
|
|
55
|
+
}
|
|
56
|
+
if (this._onionSlicesOriginal) {
|
|
57
|
+
for (const onionSlice of this._onionSlicesOriginal) if (!onionSlices.find((item) => item.beanFullName === onionSlice.beanFullName)) disposeInstance(onionSlice.beanInstance);
|
|
58
|
+
}
|
|
59
|
+
this._onionSlicesOriginal = onionSlices;
|
|
60
|
+
this._composer = this.$$sysOnion.behavior.compose(onionSlices, (onionSlice, props, next) => {
|
|
61
|
+
return cast(cast(onionSlice.beanInstance)).render(props, next);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
render(props, next) {
|
|
65
|
+
return this._composer(props, next);
|
|
66
|
+
}
|
|
67
|
+
_prepareOnionItems(behaviors) {
|
|
68
|
+
return this._prepareOnionItemsInner([], behaviors);
|
|
69
|
+
}
|
|
70
|
+
_prepareOnionItemsInner(onionItems, behaviors) {
|
|
71
|
+
const behaviors2 = Array.isArray(behaviors) ? behaviors : [behaviors];
|
|
72
|
+
for (const behaviorItem of behaviors2) if (typeof behaviorItem === "string") onionItems.push({
|
|
73
|
+
name: behaviorItem,
|
|
74
|
+
options: void 0
|
|
75
|
+
});
|
|
76
|
+
else if (Array.isArray(behaviorItem)) this._prepareOnionItemsInner(onionItems, behaviorItem);
|
|
77
|
+
else if (typeof behaviorItem === "object") for (const key in behaviorItem) {
|
|
78
|
+
let options = behaviorItem[key];
|
|
79
|
+
if (options === false) continue;
|
|
80
|
+
if (options === true) options = void 0;
|
|
81
|
+
onionItems.push({
|
|
82
|
+
name: key,
|
|
83
|
+
options
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return onionItems;
|
|
87
|
+
}
|
|
88
|
+
}, _descriptor$3 = _applyDecoratedDescriptor$3(_class2$3.prototype, "$$sysOnion", [_dec3$3, _dec4$3], {
|
|
89
|
+
configurable: true,
|
|
90
|
+
enumerable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
initializer: null
|
|
93
|
+
}), _class2$3)) || _class$6) || _class$6);
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/bean/bean.behavior.ts
|
|
96
|
+
var _dec$5, _dec2$5, _class$5;
|
|
97
|
+
var BeanBehavior$1 = (_dec$5 = Bean(), _dec2$5 = BeanInfo({ module: "a-behavior" }), _dec$5(_class$5 = _dec2$5(_class$5 = class BeanBehavior extends BeanBase {
|
|
98
|
+
async createComposer(behaviors) {
|
|
99
|
+
return await this.bean._newBean(ServiceComposer, true, behaviors);
|
|
100
|
+
}
|
|
101
|
+
}) || _class$5) || _class$5);
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/bean/bean.behaviorBase.ts
|
|
104
|
+
var _dec$4, _dec2$4, _dec3$2, _dec4$2, _dec5$1, _dec6$1, _dec7$1, _dec8, _dec9, _class$4, _class2$2, _descriptor$2, _descriptor2;
|
|
105
|
+
function _initializerDefineProperty$2(e, i, r, l) {
|
|
106
|
+
r && Object.defineProperty(e, i, {
|
|
107
|
+
enumerable: r.enumerable,
|
|
108
|
+
configurable: r.configurable,
|
|
109
|
+
writable: r.writable,
|
|
110
|
+
value: r.initializer ? r.initializer.call(l) : void 0
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function _applyDecoratedDescriptor$2(i, e, r, n, l) {
|
|
114
|
+
var a = {};
|
|
115
|
+
return Object.keys(n).forEach(function(i) {
|
|
116
|
+
a[i] = n[i];
|
|
117
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
|
|
118
|
+
return n(i, e, r) || r;
|
|
119
|
+
}, 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;
|
|
120
|
+
}
|
|
121
|
+
var BeanBehaviorBase = (_dec$4 = Bean(), _dec2$4 = Virtual(), _dec3$2 = BeanInfo({ module: "a-behavior" }), _dec4$2 = Reflect.metadata("design:type", Function), _dec5$1 = Reflect.metadata("design:paramtypes", [typeof OPTIONS === "undefined" ? Object : OPTIONS]), _dec6$1 = Use({ injectionScope: "host" }), _dec7$1 = Reflect.metadata("design:type", typeof BeanBehavior === "undefined" ? Object : BeanBehavior), _dec8 = Use({ injectionScope: "host" }), _dec9 = Reflect.metadata("design:type", typeof IBehaviorTag === "undefined" ? Object : IBehaviorTag), _dec$4(_class$4 = _dec2$4(_class$4 = _dec3$2(_class$4 = _dec4$2(_class$4 = _dec5$1(_class$4 = (_class2$2 = class BeanBehaviorBase extends BeanBase {
|
|
122
|
+
constructor(options) {
|
|
123
|
+
super();
|
|
124
|
+
this.$options = void 0;
|
|
125
|
+
_initializerDefineProperty$2(this, "$$beanBehavior", _descriptor$2, this);
|
|
126
|
+
_initializerDefineProperty$2(this, "$$behaviorTag", _descriptor2, this);
|
|
127
|
+
this.$options = options;
|
|
128
|
+
}
|
|
129
|
+
async onOptionsChange(options) {
|
|
130
|
+
this.$options = options;
|
|
131
|
+
}
|
|
132
|
+
async createComposer(behaviors) {
|
|
133
|
+
return await this.$$beanBehavior.createComposer(behaviors);
|
|
134
|
+
}
|
|
135
|
+
render(_props, next) {
|
|
136
|
+
return next();
|
|
137
|
+
}
|
|
138
|
+
}, _descriptor$2 = _applyDecoratedDescriptor$2(_class2$2.prototype, "$$beanBehavior", [_dec6$1, _dec7$1], {
|
|
139
|
+
configurable: true,
|
|
140
|
+
enumerable: true,
|
|
141
|
+
writable: true,
|
|
142
|
+
initializer: null
|
|
143
|
+
}), _descriptor2 = _applyDecoratedDescriptor$2(_class2$2.prototype, "$$behaviorTag", [_dec8, _dec9], {
|
|
144
|
+
configurable: true,
|
|
145
|
+
enumerable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
initializer: null
|
|
148
|
+
}), _class2$2)) || _class$4) || _class$4) || _class$4) || _class$4) || _class$4);
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/lib/useBehavior.ts
|
|
151
|
+
function $UseBehavior(behaviorName, options) {
|
|
152
|
+
return { [behaviorName]: options };
|
|
153
|
+
}
|
|
154
|
+
function $UseBehaviorTag(component) {
|
|
155
|
+
return {
|
|
156
|
+
component,
|
|
157
|
+
name: typeof component === "string" ? component : void 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/bean/bean.behaviorsHolder.ts
|
|
162
|
+
var _dec$3, _dec2$3, _dec3$1, _dec4$1, _dec5, _dec6, _dec7, _class$3, _class2$1, _descriptor$1;
|
|
163
|
+
function _initializerDefineProperty$1(e, i, r, l) {
|
|
164
|
+
r && Object.defineProperty(e, i, {
|
|
165
|
+
enumerable: r.enumerable,
|
|
166
|
+
configurable: r.configurable,
|
|
167
|
+
writable: r.writable,
|
|
168
|
+
value: r.initializer ? r.initializer.call(l) : void 0
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function _applyDecoratedDescriptor$1(i, e, r, n, l) {
|
|
172
|
+
var a = {};
|
|
173
|
+
return Object.keys(n).forEach(function(i) {
|
|
174
|
+
a[i] = n[i];
|
|
175
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
|
|
176
|
+
return n(i, e, r) || r;
|
|
177
|
+
}, 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;
|
|
178
|
+
}
|
|
179
|
+
var BeanBehaviorsHolder = (_dec$3 = Bean(), _dec2$3 = BeanInfo({ module: "a-behavior" }), _dec3$1 = Use(), _dec4$1 = Reflect.metadata("design:type", typeof BeanBehavior$1 === "undefined" ? Object : BeanBehavior$1), _dec5 = Log({
|
|
180
|
+
args: false,
|
|
181
|
+
childName: "behavior",
|
|
182
|
+
level: "debug"
|
|
183
|
+
}), _dec6 = Reflect.metadata("design:type", Function), _dec7 = Reflect.metadata("design:paramtypes", [typeof IBehaviors === "undefined" ? Object : IBehaviors]), _dec$3(_class$3 = _dec2$3(_class$3 = (_class2$1 = class BeanBehaviorsHolder extends BeanBase {
|
|
184
|
+
constructor(...args) {
|
|
185
|
+
super(...args);
|
|
186
|
+
this.options = void 0;
|
|
187
|
+
this.composer = void 0;
|
|
188
|
+
_initializerDefineProperty$1(this, "$$beanBehavior", _descriptor$1, this);
|
|
189
|
+
}
|
|
190
|
+
async initialize(options) {
|
|
191
|
+
this.options = options;
|
|
192
|
+
this.bean._setBean("$$behaviorTag", this.options.behaviorTag);
|
|
193
|
+
this.composer = await this.$$beanBehavior.createComposer(this._getBehaviorRoot());
|
|
194
|
+
const behaviors = this.options.behaviors;
|
|
195
|
+
if (typeof behaviors === "function") this.$watch(behaviors, async (newValue, oldValue) => {
|
|
196
|
+
if (deepEqual(newValue, oldValue)) return;
|
|
197
|
+
await this.composer.load(this._getBehaviorRoot(newValue));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
__dispose__() {
|
|
201
|
+
disposeInstance(this.composer);
|
|
202
|
+
}
|
|
203
|
+
_getBehaviors() {
|
|
204
|
+
let behaviors = this.options.behaviors;
|
|
205
|
+
if (typeof behaviors === "function") behaviors = behaviors();
|
|
206
|
+
return behaviors;
|
|
207
|
+
}
|
|
208
|
+
_getBehaviorRoot(behaviors) {
|
|
209
|
+
if (!behaviors) behaviors = this._getBehaviors();
|
|
210
|
+
return $UseBehavior("a-behavior:root", { behaviors });
|
|
211
|
+
}
|
|
212
|
+
render(vNodeDefault, propsCustom) {
|
|
213
|
+
const { props, children } = this.ctx.instance.vnode;
|
|
214
|
+
const propsNew = Object.assign({}, propsCustom ?? props);
|
|
215
|
+
delete propsNew.behaviorTag;
|
|
216
|
+
delete propsNew.behaviors;
|
|
217
|
+
return this.composer.render(propsNew, (propsNew) => {
|
|
218
|
+
if (vNodeDefault) return vNodeDefault(propsNew);
|
|
219
|
+
return createVNode(toRaw(this.options.behaviorTag.component), propsNew, children);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}, _descriptor$1 = _applyDecoratedDescriptor$1(_class2$1.prototype, "$$beanBehavior", [_dec3$1, _dec4$1], {
|
|
223
|
+
configurable: true,
|
|
224
|
+
enumerable: true,
|
|
225
|
+
writable: true,
|
|
226
|
+
initializer: null
|
|
227
|
+
}), _applyDecoratedDescriptor$1(_class2$1.prototype, "_getBehaviorRoot", [
|
|
228
|
+
_dec5,
|
|
229
|
+
_dec6,
|
|
230
|
+
_dec7
|
|
231
|
+
], Object.getOwnPropertyDescriptor(_class2$1.prototype, "_getBehaviorRoot"), _class2$1.prototype), _class2$1)) || _class$3) || _class$3);
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/component/behavior/controller.tsx
|
|
234
|
+
var _dec$2, _dec2$2, _dec3, _dec4, _class$2, _class2, _descriptor, _ControllerBehavior;
|
|
235
|
+
function _initializerDefineProperty(e, i, r, l) {
|
|
236
|
+
r && Object.defineProperty(e, i, {
|
|
237
|
+
enumerable: r.enumerable,
|
|
238
|
+
configurable: r.configurable,
|
|
239
|
+
writable: r.writable,
|
|
240
|
+
value: r.initializer ? r.initializer.call(l) : void 0
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) {
|
|
244
|
+
var a = {};
|
|
245
|
+
return Object.keys(n).forEach(function(i) {
|
|
246
|
+
a[i] = n[i];
|
|
247
|
+
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function(r, n) {
|
|
248
|
+
return n(i, e, r) || r;
|
|
249
|
+
}, 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;
|
|
250
|
+
}
|
|
251
|
+
var ControllerBehavior = (_dec$2 = Controller(), _dec2$2 = BeanInfo({ module: "a-behavior" }), _dec3 = Use(), _dec4 = Reflect.metadata("design:type", typeof BeanBehaviorsHolder === "undefined" ? Object : BeanBehaviorsHolder), _dec$2(_class$2 = _dec2$2(_class$2 = (_class2 = (_ControllerBehavior = class ControllerBehavior extends BeanControllerBase {
|
|
252
|
+
constructor(...args) {
|
|
253
|
+
super(...args);
|
|
254
|
+
this[SymbolControllerRefDisable] = true;
|
|
255
|
+
_initializerDefineProperty(this, "$$beanBehaviorsHolder", _descriptor, this);
|
|
256
|
+
}
|
|
257
|
+
async __init__() {
|
|
258
|
+
await this.$$beanBehaviorsHolder.initialize({
|
|
259
|
+
behaviorTag: this.$props.behaviorTag,
|
|
260
|
+
behaviors: () => {
|
|
261
|
+
return this.$props.behaviors;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
render() {
|
|
266
|
+
return this.$$beanBehaviorsHolder.render();
|
|
267
|
+
}
|
|
268
|
+
}, _ControllerBehavior.$propsDefault = {}, _ControllerBehavior.$componentOptions = { inheritAttrs: false }, _ControllerBehavior), _descriptor = _applyDecoratedDescriptor(_class2.prototype, "$$beanBehaviorsHolder", [_dec3, _dec4], {
|
|
269
|
+
configurable: true,
|
|
270
|
+
enumerable: true,
|
|
271
|
+
writable: true,
|
|
272
|
+
initializer: null
|
|
273
|
+
}), _class2)) || _class$2) || _class$2);
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/.metadata/component/behavior.ts
|
|
276
|
+
var ZBehavior = defineComponent((_props) => {
|
|
277
|
+
useController(ControllerBehavior, void 0, void 0);
|
|
278
|
+
return () => {};
|
|
279
|
+
}, prepareComponentOptions(ControllerBehavior.$componentOptions));
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/lib/behavior.ts
|
|
282
|
+
function Behavior(options) {
|
|
283
|
+
return createBeanDecorator("behavior", "new", true, options);
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/bean/behavior.root_.ts
|
|
287
|
+
var _dec$1, _dec2$1, _class$1;
|
|
288
|
+
var BehaviorRoot = (_dec$1 = Behavior(), _dec2$1 = BeanInfo({ module: "a-behavior" }), _dec$1(_class$1 = _dec2$1(_class$1 = class BehaviorRoot extends BeanBehaviorBase {
|
|
289
|
+
constructor(...args) {
|
|
290
|
+
super(...args);
|
|
291
|
+
this.composer = void 0;
|
|
292
|
+
}
|
|
293
|
+
async __init__(options) {
|
|
294
|
+
this.composer = await this.createComposer(options.behaviors);
|
|
295
|
+
}
|
|
296
|
+
__dispose__() {
|
|
297
|
+
disposeInstance(this.composer);
|
|
298
|
+
}
|
|
299
|
+
async onOptionsChange(options) {
|
|
300
|
+
await super.onOptionsChange(options);
|
|
301
|
+
await this.composer.load(options.behaviors);
|
|
302
|
+
}
|
|
303
|
+
render(props, next) {
|
|
304
|
+
return this.composer.render(props, next);
|
|
305
|
+
}
|
|
306
|
+
}) || _class$1) || _class$1);
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/.metadata/index.ts
|
|
309
|
+
/** behaviors: end */
|
|
310
|
+
/** scope: begin */
|
|
311
|
+
var _dec, _dec2, _class;
|
|
312
|
+
var components = { "behavior": ZBehavior };
|
|
313
|
+
var ScopeModuleABehavior = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-behavior" }), _dec(_class = _dec2(_class = class ScopeModuleABehavior extends BeanScopeBase {}) || _class) || _class);
|
|
314
|
+
/** scope: end */
|
|
315
|
+
//#endregion
|
|
316
|
+
export { $UseBehavior, $UseBehaviorTag, BeanBehavior$1 as BeanBehavior, BeanBehaviorBase, BeanBehaviorsHolder, Behavior, BehaviorRoot, ControllerBehavior, ScopeModuleABehavior, ServiceComposer, ZBehavior, components };
|
|
317
|
+
|
|
318
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["BeanControllerBase","SymbolControllerRefDisable","Use","Controller","BeanBehaviorsHolder","ControllerBehavior","_dec","_dec2","__z_BeanInfo","module","_dec3","_dec4","Reflect","metadata","Object","_class","_class2","_ControllerBehavior","constructor","args","_initializerDefineProperty","_descriptor","__init__","$$beanBehaviorsHolder","initialize","behaviorTag","$props","behaviors","render","$propsDefault","$componentOptions","inheritAttrs","_applyDecoratedDescriptor","prototype","configurable","enumerable","writable","initializer"],"sources":["../src/service/composer.ts","../src/bean/bean.behavior.ts","../src/bean/bean.behaviorBase.ts","../src/lib/useBehavior.ts","../src/bean/bean.behaviorsHolder.ts","../src/component/behavior/controller.tsx","../src/.metadata/component/behavior.ts","../src/lib/behavior.ts","../src/bean/behavior.root_.ts","../src/.metadata/index.ts"],"sourcesContent":["import type { VNode } from 'vue';\n\nimport { BeanBase, cast, deepEqual, disposeInstance, Use } from 'zova';\nimport { IOnionItem, IOnionSlice, Service, SysOnion, TypeComposer } from 'zova-module-a-bean';\n\nimport type { BeanBehaviorBase } from '../bean/bean.behaviorBase.js';\nimport type { IBehaviorRecord, IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';\n\nconst SymbolSliceOptionsOriginal = Symbol('SymbolSliceOptionsOriginal');\n\n@Service()\nexport class ServiceComposer extends BeanBase {\n private _composer: TypeComposer;\n private _onionSlicesOriginal?: IOnionSlice<IDecoratorBehaviorOptions, keyof IBehaviorRecord, BeanBehaviorBase>[];\n\n @Use()\n $$sysOnion: SysOnion;\n\n protected async __init__(behaviors: IBehaviors) {\n await this.load(behaviors);\n }\n\n protected __dispose__() {\n if (this._onionSlicesOriginal) {\n for (const onionSlice of this._onionSlicesOriginal) {\n disposeInstance(onionSlice.beanInstance);\n }\n }\n }\n\n public async load(behaviors: IBehaviors) {\n await this.$renderFreezeScope(async () => {\n await this._loadInner(behaviors);\n });\n }\n\n private async _loadInner(behaviors: IBehaviors) {\n // onionItems\n const onionItems = this._prepareOnionItems(behaviors);\n // load onions\n const onionSlices = await this.$$sysOnion.behavior.loadOnions<BeanBehaviorBase>(onionItems);\n // create behaviors\n for (const onionSlice of onionSlices) {\n const onionSliceOriginal = this._onionSlicesOriginal?.find(item => item.beanFullName === onionSlice.beanFullName);\n if (onionSliceOriginal) {\n onionSlice.beanInstance = onionSliceOriginal.beanInstance;\n if (!deepEqual(onionSliceOriginal[SymbolSliceOptionsOriginal], onionSlice.options)) {\n await cast(onionSlice.beanInstance).onOptionsChange(onionSlice.options);\n }\n } else {\n onionSlice.beanInstance = await this.bean._newBean(onionSlice.beanFullName as any, true, onionSlice.options);\n }\n onionSlice[SymbolSliceOptionsOriginal] = onionSlice.options;\n }\n // dispose original behaviors\n if (this._onionSlicesOriginal) {\n for (const onionSlice of this._onionSlicesOriginal) {\n const exists = onionSlices.find(item => item.beanFullName === onionSlice.beanFullName);\n if (!exists) {\n disposeInstance(onionSlice.beanInstance);\n }\n }\n }\n // save\n this._onionSlicesOriginal = onionSlices;\n // compose\n this._composer = this.$$sysOnion.behavior.compose(onionSlices, (onionSlice, props: any, next) => {\n const beanInstance = cast<BeanBehaviorBase>(onionSlice.beanInstance);\n return cast(beanInstance).render(props, next as any);\n });\n }\n\n public render<PROPS_INPUT, PROPS_OUTPUT = PROPS_INPUT>(props: PROPS_INPUT, next: NextBehavior<PROPS_OUTPUT>): VNode {\n return this._composer(props, next);\n }\n\n private _prepareOnionItems(behaviors: IBehaviors) {\n const onionItems: IOnionItem<IDecoratorBehaviorOptions, keyof IBehaviorRecord>[] = [];\n return this._prepareOnionItemsInner(onionItems, behaviors);\n }\n\n private _prepareOnionItemsInner(onionItems: IOnionItem<IDecoratorBehaviorOptions, keyof IBehaviorRecord>[], behaviors: IBehaviors) {\n const behaviors2 = Array.isArray(behaviors) ? behaviors : [behaviors];\n for (const behaviorItem of behaviors2) {\n if (typeof behaviorItem === 'string') {\n onionItems.push({ name: behaviorItem as unknown as keyof IBehaviorRecord, options: undefined });\n } else if (Array.isArray(behaviorItem)) {\n this._prepareOnionItemsInner(onionItems, behaviorItem);\n } else if (typeof behaviorItem === 'object') {\n for (const key in behaviorItem) {\n let options = behaviorItem[key];\n if (options === false) continue;\n if (options === true) options = undefined;\n onionItems.push({ name: key as unknown as keyof IBehaviorRecord, options });\n }\n }\n }\n return onionItems;\n }\n}\n","import { BeanBase } from 'zova';\nimport { Bean } from 'zova-module-a-bean';\n\nimport type { IBehaviors } from '../types/behavior.js';\n\nimport { ServiceComposer } from '../service/composer.js';\n\n@Bean()\nexport class BeanBehavior extends BeanBase {\n public async createComposer(behaviors: IBehaviors): Promise<ServiceComposer> {\n return await this.bean._newBean(ServiceComposer, true, behaviors);\n }\n}\n","import type { VNode } from 'vue';\n\nimport { BeanBase, Use, Virtual } from 'zova';\nimport { Bean } from 'zova-module-a-bean';\n\nimport type { ServiceComposer } from '../service/composer.js';\nimport type { IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';\nimport type { IBehaviorTag } from '../types/behavior.js';\nimport type { BeanBehavior } from './bean.behavior.js';\n\n@Bean()\n@Virtual()\nexport class BeanBehaviorBase<\n OPTIONS extends IDecoratorBehaviorOptions = IDecoratorBehaviorOptions,\n PROPS_INPUT = unknown,\n PROPS_OUTPUT = PROPS_INPUT,\n> extends BeanBase {\n protected $options: OPTIONS;\n\n @Use({ injectionScope: 'host' })\n $$beanBehavior: BeanBehavior;\n\n @Use({ injectionScope: 'host' })\n $$behaviorTag: IBehaviorTag;\n\n constructor(options: OPTIONS) {\n super();\n this.$options = options;\n }\n\n protected async onOptionsChange(options: OPTIONS) {\n this.$options = options;\n }\n\n protected async createComposer(behaviors: IBehaviors): Promise<ServiceComposer> {\n return await this.$$beanBehavior.createComposer(behaviors);\n }\n\n protected render(_props: PROPS_INPUT, next: NextBehavior<PROPS_OUTPUT>): VNode {\n return next();\n }\n}\n","import type { Component } from 'vue';\n\nimport type { IBehaviorItem, IBehaviorRecord } from '../types/behavior.js';\n\nexport function $UseBehavior<T extends keyof IBehaviorRecord>(behaviorName: T, options?: Partial<IBehaviorRecord[T]>): IBehaviorItem {\n return { [behaviorName]: options };\n}\n\nexport function $UseBehaviorTag(component: string | Component) {\n return {\n component,\n name: typeof component === 'string' ? component : undefined,\n };\n}\n","import { createVNode, toRaw } from 'vue';\nimport { BeanBase, deepEqual, disposeInstance, Use } from 'zova';\nimport { Bean } from 'zova-module-a-bean';\nimport { Log } from 'zova-module-a-logger';\n\nimport type { IBehaviors, IBehaviorTag } from '../types/behavior.js';\n\nimport { $UseBehavior } from '../lib/useBehavior.js';\nimport { ServiceComposer } from '../service/composer.js';\nimport { BeanBehavior } from './bean.behavior.js';\n\nexport interface IBehaviorsHolderOptions {\n behaviors: IBehaviors | (() => IBehaviors);\n behaviorTag: IBehaviorTag;\n}\n\n@Bean()\nexport class BeanBehaviorsHolder extends BeanBase {\n public options: IBehaviorsHolderOptions;\n private composer: ServiceComposer;\n\n @Use()\n $$beanBehavior: BeanBehavior;\n\n public async initialize(options: IBehaviorsHolderOptions) {\n this.options = options;\n this.bean._setBean('$$behaviorTag', this.options.behaviorTag);\n // composer\n this.composer = await this.$$beanBehavior.createComposer(this._getBehaviorRoot());\n // watch\n const behaviors = this.options.behaviors;\n if (typeof behaviors === 'function') {\n this.$watch(behaviors, async (newValue, oldValue) => {\n if (deepEqual(newValue, oldValue)) return;\n await this.composer.load(this._getBehaviorRoot(newValue));\n });\n }\n }\n\n protected __dispose__() {\n disposeInstance(this.composer);\n }\n\n private _getBehaviors() {\n let behaviors = this.options.behaviors;\n if (typeof behaviors === 'function') {\n behaviors = behaviors();\n }\n return behaviors;\n }\n\n @Log({ args: false, childName: 'behavior', level: 'debug' })\n private _getBehaviorRoot(behaviors?: IBehaviors) {\n if (!behaviors) {\n behaviors = this._getBehaviors();\n }\n return $UseBehavior('a-behavior:root' as never, { behaviors } as any);\n }\n\n public render(vNodeDefault?: Function, propsCustom?: {}) {\n const parent = this.ctx.instance;\n const { props, children } = parent.vnode;\n // props\n const propsNew = Object.assign({}, propsCustom ?? props) as any;\n delete propsNew.behaviorTag;\n delete propsNew.behaviors;\n // render\n return this.composer.render(propsNew, propsNew => {\n if (vNodeDefault) return vNodeDefault(propsNew);\n return createVNode(toRaw(this.options.behaviorTag.component), propsNew, children);\n });\n // // ensure inner component inherits the async wrapper's ref owner\n // vnode.ref = parent.vnode.ref;\n // // pass the custom element callback on to the inner comp\n // // and remove it from the async wrapper\n // cast(vnode).ce = cast(parent.vnode).ce;\n // // delete cast(parent.vnode).ce;\n // // ok\n // return vnode;\n }\n}\n","import type { IComponentOptions } from 'zova';\n\nimport { BeanControllerBase, SymbolControllerRefDisable, Use } from 'zova';\nimport { Controller } from 'zova-module-a-bean';\n\nimport type { IBehaviors, IBehaviorTag } from '../../types/behavior.js';\n\nimport { BeanBehaviorsHolder } from '../../bean/bean.behaviorsHolder.js';\n\nexport interface ControllerBehaviorProps {\n behaviorTag: IBehaviorTag;\n behaviors: IBehaviors;\n}\n\n@Controller()\nexport class ControllerBehavior extends BeanControllerBase {\n static $propsDefault = {};\n static $componentOptions: IComponentOptions = { inheritAttrs: false };\n protected [SymbolControllerRefDisable]: boolean = true;\n\n @Use()\n $$beanBehaviorsHolder: BeanBehaviorsHolder;\n\n protected async __init__() {\n await this.$$beanBehaviorsHolder.initialize({\n behaviorTag: this.$props.behaviorTag,\n behaviors: () => {\n return this.$props.behaviors;\n },\n });\n }\n\n protected render() {\n return this.$$beanBehaviorsHolder.render();\n }\n}\n","import type { TypeControllerInnerProps } from 'zova';\n\nimport { defineComponent } from 'vue';\nimport { prepareComponentOptions, useController } from 'zova';\n\nimport type { ControllerBehaviorProps } from '../../component/behavior/controller.jsx';\n\nimport { ControllerBehavior } from '../../component/behavior/controller.jsx';\nexport type TypeControllerBehaviorPublicProps = {\n controllerRef?: (ref: ControllerBehavior) => void;\n} & ControllerBehaviorProps;\n\ntype ControllerInnerProps = TypeControllerInnerProps<ControllerBehaviorProps, keyof typeof ControllerBehavior.$propsDefault>;\ndeclare module 'zova-module-a-behavior' {\n export interface ControllerBehavior {\n $props: ControllerInnerProps;\n }\n}\n\nexport const ZBehavior = defineComponent((_props: TypeControllerBehaviorPublicProps) => {\n useController(ControllerBehavior, undefined, undefined);\n return () => {};\n}, prepareComponentOptions(ControllerBehavior.$componentOptions));\n","import { createBeanDecorator } from 'zova';\n\nimport type { IDecoratorBehaviorOptions } from '../types/behavior.js';\n\nexport function Behavior<T extends IDecoratorBehaviorOptions>(options?: T): ClassDecorator {\n return createBeanDecorator('behavior', 'new', true, options);\n}\n","import type { VNode } from 'vue';\n\nimport { disposeInstance } from 'zova';\n\nimport type { ServiceComposer } from '../service/composer.js';\nimport type { IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';\n\nimport { Behavior } from '../lib/behavior.js';\nimport { BeanBehaviorBase } from './bean.behaviorBase.js';\n\nexport interface IBehaviorPropsInputRoot {}\n\nexport interface IBehaviorPropsOutputRoot {}\n\nexport interface IBehaviorOptionsRoot extends IDecoratorBehaviorOptions {\n behaviors: IBehaviors;\n}\n\n@Behavior<IBehaviorOptionsRoot>()\nexport class BehaviorRoot extends BeanBehaviorBase<IBehaviorOptionsRoot, IBehaviorPropsInputRoot, IBehaviorPropsOutputRoot> {\n private composer: ServiceComposer;\n\n protected async __init__(options: IBehaviorOptionsRoot) {\n this.composer = await this.createComposer(options.behaviors);\n }\n\n protected __dispose__() {\n disposeInstance(this.composer);\n }\n\n protected async onOptionsChange(options: IBehaviorOptionsRoot) {\n await super.onOptionsChange(options);\n await this.composer.load(options.behaviors);\n }\n\n protected render(props: IBehaviorPropsInputRoot, next: NextBehavior<IBehaviorPropsOutputRoot>): VNode {\n return this.composer.render(props, next);\n }\n}\n","// eslint-disable\n/** bean: begin */\nexport * from '../bean/bean.behavior.js';\nexport * from '../bean/bean.behaviorBase.js';\nexport * from '../bean/bean.behaviorsHolder.js';\n\nimport 'zova';\ndeclare module 'zova' {\n \n \n}\ndeclare module 'zova-module-a-behavior' {\n \n export interface BeanBehavior {\n /** @internal */\n get scope(): ScopeModuleABehavior;\n }\n\n export interface BeanBehavior {\n get $beanFullName(): 'a-behavior.bean.behavior';\n get $onionName(): 'a-behavior:behavior';\n \n }\n\n export interface BeanBehaviorsHolder {\n /** @internal */\n get scope(): ScopeModuleABehavior;\n }\n\n export interface BeanBehaviorsHolder {\n get $beanFullName(): 'a-behavior.bean.behaviorsHolder';\n get $onionName(): 'a-behavior:behaviorsHolder';\n \n } \n}\n/** bean: end */\n/** bean: begin */\nimport { BeanBehavior } from '../bean/bean.behavior.js';\nimport { BeanBehaviorBase } from '../bean/bean.behaviorBase.js';\nimport { BeanBehaviorsHolder } from '../bean/bean.behaviorsHolder.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordGeneral {\n 'a-behavior.bean.behavior': BeanBehavior;\n'a-behavior.bean.behaviorBase': BeanBehaviorBase;\n'a-behavior.bean.behaviorsHolder': BeanBehaviorsHolder;\n }\n}\n/** bean: end */\n/** service: begin */\nexport * from '../service/composer.js';\n\nimport 'zova-module-a-bean';\ndeclare module 'zova-module-a-bean' {\n \n export interface IServiceRecord {\n 'a-behavior:composer': never;\n }\n\n \n}\ndeclare module 'zova-module-a-behavior' {\n \n export interface ServiceComposer {\n /** @internal */\n get scope(): ScopeModuleABehavior;\n }\n\n export interface ServiceComposer {\n get $beanFullName(): 'a-behavior.service.composer';\n get $onionName(): 'a-behavior:composer';\n \n } \n}\n/** service: end */\n/** service: begin */\nimport { ServiceComposer } from '../service/composer.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordGeneral {\n 'a-behavior.service.composer': ServiceComposer;\n }\n}\n/** service: end */\n/** controller: begin */\nexport * from '../component/behavior/controller.jsx';\n\nimport 'zova';\ndeclare module 'zova' {\n \n \n}\ndeclare module 'zova-module-a-behavior' {\n \n export interface ControllerBehavior {\n /** @internal */\n get scope(): ScopeModuleABehavior;\n } \n}\n/** controller: end */\n/** controller: begin */\nimport { ControllerBehavior } from '../component/behavior/controller.jsx';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordLocal {\n 'a-behavior.controller.behavior': ControllerBehavior;\n }\n}\n/** controller: end */\n\n/** components: begin */\nexport * from './component/behavior.js';\nimport { ZBehavior } from './component/behavior.js';\nexport const components = {\n 'behavior': ZBehavior,\n};\nimport 'zova';\ndeclare module 'zova' {\nexport interface IComponentRecord {\n 'a-behavior:behavior': ControllerBehavior;\n}\nexport interface IZovaComponentRecord {\n 'a-behavior:behavior': typeof ZBehavior;\n}\n}\n/** components: end */\n/** behavior: begin */\nexport * from '../bean/behavior.root_.js';\n\nimport 'zova-module-a-behavior';\ndeclare module 'zova-module-a-behavior' {\n \n \n}\ndeclare module 'zova-module-a-behavior' {\n \n}\n/** behavior: end */\n/** behaviors: begin */\nimport 'vue';\nimport 'vue/jsx-runtime';\n\ndeclare module 'vue' {\n export interface InputHTMLAttributes {\n \n }\n}\n\ndeclare module 'vue/jsx-runtime' {\n namespace JSX {\n // need define class/style in IntrinsicAttributes\n export interface IntrinsicAttributes {\n \n }\n }\n}\n/** behaviors: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleABehavior extends BeanScopeBase {}\n\nexport interface ScopeModuleABehavior {\n util: BeanScopeUtil;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-behavior': ScopeModuleABehavior;\n }\n \n \n\n \n\n \n}\n \n/** scope: end */\n"],"mappings":";;;;;;;;AAAA,IAAA,QAAO,SAAO,SAAQ,SAAS,UAAC,WAAA;;;;;;;;;AAEhC,SAAS,4BAA0B,GAAC,GAAA,GAAA,GAAA,GAAA;CAAgB,IAAI,IAAG,EAAA;AAAK,QAAM,OAAA,KAAA,EAAA,CAAA,QAAA,SAAA,GAAA;AAAA,IAAA,KAAA,EAAA;GAAA,EAAA,EAAA,aAAA,CAAA,CAAA,EAAA,YAAA,EAAA,eAAA,CAAA,CAAA,EAAA,eAAA,WAAA,KAAA,EAAA,iBAAA,EAAA,WAAA,CAAA,IAAA,IA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AAA;CAAA,CAAA,EAAArB,SAAA,IAAAD,SAAA,IAAAA;;;ACdvE,IAAS,YAAA,iBAAyB,WAAgB;;AAElD,cAAc;;;;;ACHd,QAAO,oBAAO,YAA2B,OAAO,MAAG,QAAM;;;;ACFzD,IAAA,QAAO,SAAO;AAKd,IAAW,gBAAe,SAAA,UAAA,EAAA,UAA2B,SAAc,EAAA,QAAA,cAEnE,CAAA,EAAA,OAAS,WAAS,QAAM,WAAS,MAAA,qBAAY,iBAAA;CAC7C,YAAS,GAAA,MAAA;;AAET,OAAO,WAAU,KAAA;;CAEjB,MAAO,SAAU,SAAA;;;CAGf,cAAW;AACb,kBAAA,KAAA,SAAA;;CAEC,MAAA,gBAAS,SAAsB;AAChC,QAAO,MAAM,gBAAa,QAAQ;AAChC,QAAQ,KAAA,SAAU,KAAA,QAAe,UAAA;;CAEjC,OAAA,OAAU,MAAM;AACd,SAAK,KAAA,SAAgB,OAAM,OAAA,KAAA;;;;;;;ACvB/B,IAAG,MAAO,OAAA;AAkCV,IAAA,aAAA,EACE,YAAY,WACb;AAcD,IAAS,wBAA0B,OAAG,OAAA,EAAA,QAAA,SAAA,EAAA,QAAA,cAEtC,CAAA,EAAA,KAAQ,SAAK,MAAS,SAAK,MAAA,6BAAA,cAAA,GAAA,IAAA,OAAA,IAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default async function (options) {
|
|
2
|
+
const { moduleName, globFiles } = options;
|
|
3
|
+
if (globFiles.length === 0)
|
|
4
|
+
return '';
|
|
5
|
+
const contentRecords = [];
|
|
6
|
+
for (const { beanName, beanNameCapitalize, isIgnore } of globFiles) {
|
|
7
|
+
if (isIgnore)
|
|
8
|
+
continue;
|
|
9
|
+
const behaviorAttrName = _combineBehaviorAttrName(moduleName, beanName);
|
|
10
|
+
contentRecords.push(`'${behaviorAttrName}'?: IBehaviorOptions${beanNameCapitalize} | '' | boolean;`);
|
|
11
|
+
}
|
|
12
|
+
// combine
|
|
13
|
+
const content = `/** behaviors: begin */
|
|
14
|
+
import 'vue';
|
|
15
|
+
import 'vue/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
declare module 'vue' {
|
|
18
|
+
export interface InputHTMLAttributes {
|
|
19
|
+
${contentRecords.join('\n')}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module 'vue/jsx-runtime' {
|
|
24
|
+
namespace JSX {
|
|
25
|
+
// need define class/style in IntrinsicAttributes
|
|
26
|
+
export interface IntrinsicAttributes {
|
|
27
|
+
${contentRecords.join('\n')}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** behaviors: end */
|
|
32
|
+
`;
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
// bs-providerId-moduleName-beanName
|
|
36
|
+
function _combineBehaviorAttrName(moduleName, beanName) {
|
|
37
|
+
const parts = ['bs'];
|
|
38
|
+
if (!moduleName.startsWith('a-')) {
|
|
39
|
+
parts.push(moduleName);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const moduleNameShort = moduleName.substring('a-'.length);
|
|
43
|
+
if (!beanName.startsWith(moduleNameShort)) {
|
|
44
|
+
parts.push(moduleNameShort);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
parts.push(beanName);
|
|
48
|
+
return parts.join('-');
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-behavior",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Zova Module"
|
|
7
|
+
],
|
|
8
|
+
"author": "",
|
|
9
|
+
"files": [
|
|
10
|
+
"cli",
|
|
11
|
+
"dist",
|
|
12
|
+
"mock",
|
|
13
|
+
"rest",
|
|
14
|
+
"src",
|
|
15
|
+
"icons",
|
|
16
|
+
"assets",
|
|
17
|
+
"dist-cli"
|
|
18
|
+
],
|
|
4
19
|
"type": "module",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"access": "public"
|
|
7
|
-
},
|
|
8
20
|
"exports": {
|
|
9
21
|
".": {
|
|
10
22
|
"types": [
|
|
11
23
|
"./src/index.ts",
|
|
12
24
|
"./dist/index.d.ts"
|
|
13
25
|
],
|
|
14
|
-
"
|
|
15
|
-
"import": "./dist/index.js",
|
|
16
|
-
"default": "./src/index.ts"
|
|
26
|
+
"default": "./dist/index.js"
|
|
17
27
|
},
|
|
18
|
-
"
|
|
28
|
+
"./*": "./*"
|
|
19
29
|
},
|
|
20
|
-
"description": "",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"static",
|
|
24
|
-
"typings"
|
|
25
|
-
],
|
|
26
30
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
+
"clean": "rimraf dist dist-cli tsconfig.build.tsbuildinfo tsconfig.cli.tsbuildinfo",
|
|
32
|
+
"tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap && tsc -p tsconfig.cli.json",
|
|
33
|
+
"prepublishOnly": "npm run tsc:publish",
|
|
34
|
+
"prepack": "clean-package",
|
|
35
|
+
"postpack": "clean-package restore && npm run clean"
|
|
31
36
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
"title": "a-behavior",
|
|
38
|
+
"zovaModule": {
|
|
39
|
+
"onions": {
|
|
40
|
+
"behavior": {
|
|
41
|
+
"optionsGlobalInterfaceName": "IDecoratorBehaviorOptions",
|
|
42
|
+
"optionsGlobalInterfaceFrom": "zova-module-a-behavior",
|
|
43
|
+
"boilerplate": "behavior/boilerplate",
|
|
44
|
+
"metadataCustom": "behavior/metadata/generate.ts"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "bf1ceb4582381c74ba41ccf11b89d3b9e7b73628"
|
|
37
49
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';
|
|
2
|
+
|
|
3
|
+
import type { ControllerBehaviorProps } from '../../src/component/behavior/controller.jsx';
|
|
4
|
+
|
|
5
|
+
type TypeControllerBehaviorPublicProps = TypeRenderComponentJsxPropsPublic & ControllerBehaviorProps;
|
|
6
|
+
export function ZZBehavior(_props: TypeControllerBehaviorPublicProps) {
|
|
7
|
+
return 'a-behavior:behavior';
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './component/behavior.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 { ControllerBehaviorProps } from '../../component/behavior/controller.jsx';
|
|
7
|
+
|
|
8
|
+
import { ControllerBehavior } from '../../component/behavior/controller.jsx';
|
|
9
|
+
export type TypeControllerBehaviorPublicProps = {
|
|
10
|
+
controllerRef?: (ref: ControllerBehavior) => void;
|
|
11
|
+
} & ControllerBehaviorProps;
|
|
12
|
+
|
|
13
|
+
type ControllerInnerProps = TypeControllerInnerProps<ControllerBehaviorProps, keyof typeof ControllerBehavior.$propsDefault>;
|
|
14
|
+
declare module 'zova-module-a-behavior' {
|
|
15
|
+
export interface ControllerBehavior {
|
|
16
|
+
$props: ControllerInnerProps;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ZBehavior = defineComponent((_props: TypeControllerBehaviorPublicProps) => {
|
|
21
|
+
useController(ControllerBehavior, undefined, undefined);
|
|
22
|
+
return () => {};
|
|
23
|
+
}, prepareComponentOptions(ControllerBehavior.$componentOptions));
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// eslint-disable
|
|
2
|
+
/** bean: begin */
|
|
3
|
+
export * from '../bean/bean.behavior.js';
|
|
4
|
+
export * from '../bean/bean.behaviorBase.js';
|
|
5
|
+
export * from '../bean/bean.behaviorsHolder.js';
|
|
6
|
+
|
|
7
|
+
import 'zova';
|
|
8
|
+
declare module 'zova' {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
declare module 'zova-module-a-behavior' {
|
|
13
|
+
|
|
14
|
+
export interface BeanBehavior {
|
|
15
|
+
/** @internal */
|
|
16
|
+
get scope(): ScopeModuleABehavior;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BeanBehavior {
|
|
20
|
+
get $beanFullName(): 'a-behavior.bean.behavior';
|
|
21
|
+
get $onionName(): 'a-behavior:behavior';
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface BeanBehaviorsHolder {
|
|
26
|
+
/** @internal */
|
|
27
|
+
get scope(): ScopeModuleABehavior;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface BeanBehaviorsHolder {
|
|
31
|
+
get $beanFullName(): 'a-behavior.bean.behaviorsHolder';
|
|
32
|
+
get $onionName(): 'a-behavior:behaviorsHolder';
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** bean: end */
|
|
37
|
+
/** bean: begin */
|
|
38
|
+
import { BeanBehavior } from '../bean/bean.behavior.js';
|
|
39
|
+
import { BeanBehaviorBase } from '../bean/bean.behaviorBase.js';
|
|
40
|
+
import { BeanBehaviorsHolder } from '../bean/bean.behaviorsHolder.js';
|
|
41
|
+
import 'zova';
|
|
42
|
+
declare module 'zova' {
|
|
43
|
+
export interface IBeanRecordGeneral {
|
|
44
|
+
'a-behavior.bean.behavior': BeanBehavior;
|
|
45
|
+
'a-behavior.bean.behaviorBase': BeanBehaviorBase;
|
|
46
|
+
'a-behavior.bean.behaviorsHolder': BeanBehaviorsHolder;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** bean: end */
|
|
50
|
+
/** service: begin */
|
|
51
|
+
export * from '../service/composer.js';
|
|
52
|
+
|
|
53
|
+
import 'zova-module-a-bean';
|
|
54
|
+
declare module 'zova-module-a-bean' {
|
|
55
|
+
|
|
56
|
+
export interface IServiceRecord {
|
|
57
|
+
'a-behavior:composer': never;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
declare module 'zova-module-a-behavior' {
|
|
63
|
+
|
|
64
|
+
export interface ServiceComposer {
|
|
65
|
+
/** @internal */
|
|
66
|
+
get scope(): ScopeModuleABehavior;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ServiceComposer {
|
|
70
|
+
get $beanFullName(): 'a-behavior.service.composer';
|
|
71
|
+
get $onionName(): 'a-behavior:composer';
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** service: end */
|
|
76
|
+
/** service: begin */
|
|
77
|
+
import { ServiceComposer } from '../service/composer.js';
|
|
78
|
+
import 'zova';
|
|
79
|
+
declare module 'zova' {
|
|
80
|
+
export interface IBeanRecordGeneral {
|
|
81
|
+
'a-behavior.service.composer': ServiceComposer;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** service: end */
|
|
85
|
+
/** controller: begin */
|
|
86
|
+
export * from '../component/behavior/controller.jsx';
|
|
87
|
+
|
|
88
|
+
import 'zova';
|
|
89
|
+
declare module 'zova' {
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
declare module 'zova-module-a-behavior' {
|
|
94
|
+
|
|
95
|
+
export interface ControllerBehavior {
|
|
96
|
+
/** @internal */
|
|
97
|
+
get scope(): ScopeModuleABehavior;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** controller: end */
|
|
101
|
+
/** controller: begin */
|
|
102
|
+
import { ControllerBehavior } from '../component/behavior/controller.jsx';
|
|
103
|
+
import 'zova';
|
|
104
|
+
declare module 'zova' {
|
|
105
|
+
export interface IBeanRecordLocal {
|
|
106
|
+
'a-behavior.controller.behavior': ControllerBehavior;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** controller: end */
|
|
110
|
+
|
|
111
|
+
/** components: begin */
|
|
112
|
+
export * from './component/behavior.js';
|
|
113
|
+
import { ZBehavior } from './component/behavior.js';
|
|
114
|
+
export const components = {
|
|
115
|
+
'behavior': ZBehavior,
|
|
116
|
+
};
|
|
117
|
+
import 'zova';
|
|
118
|
+
declare module 'zova' {
|
|
119
|
+
export interface IComponentRecord {
|
|
120
|
+
'a-behavior:behavior': ControllerBehavior;
|
|
121
|
+
}
|
|
122
|
+
export interface IZovaComponentRecord {
|
|
123
|
+
'a-behavior:behavior': typeof ZBehavior;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** components: end */
|
|
127
|
+
/** behavior: begin */
|
|
128
|
+
export * from '../bean/behavior.root_.js';
|
|
129
|
+
|
|
130
|
+
import 'zova-module-a-behavior';
|
|
131
|
+
declare module 'zova-module-a-behavior' {
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
declare module 'zova-module-a-behavior' {
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
/** behavior: end */
|
|
139
|
+
/** behaviors: begin */
|
|
140
|
+
import 'vue';
|
|
141
|
+
import 'vue/jsx-runtime';
|
|
142
|
+
|
|
143
|
+
declare module 'vue' {
|
|
144
|
+
export interface InputHTMLAttributes {
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare module 'vue/jsx-runtime' {
|
|
150
|
+
namespace JSX {
|
|
151
|
+
// need define class/style in IntrinsicAttributes
|
|
152
|
+
export interface IntrinsicAttributes {
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** behaviors: end */
|
|
158
|
+
/** scope: begin */
|
|
159
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'zova';
|
|
160
|
+
import { Scope } from 'zova-module-a-bean';
|
|
161
|
+
|
|
162
|
+
@Scope()
|
|
163
|
+
export class ScopeModuleABehavior extends BeanScopeBase {}
|
|
164
|
+
|
|
165
|
+
export interface ScopeModuleABehavior {
|
|
166
|
+
util: BeanScopeUtil;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
import 'zova';
|
|
170
|
+
declare module 'zova' {
|
|
171
|
+
export interface IBeanScopeRecord {
|
|
172
|
+
'a-behavior': ScopeModuleABehavior;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** scope: end */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BeanBase } from 'zova';
|
|
2
|
+
import { Bean } from 'zova-module-a-bean';
|
|
3
|
+
|
|
4
|
+
import type { IBehaviors } from '../types/behavior.js';
|
|
5
|
+
|
|
6
|
+
import { ServiceComposer } from '../service/composer.js';
|
|
7
|
+
|
|
8
|
+
@Bean()
|
|
9
|
+
export class BeanBehavior extends BeanBase {
|
|
10
|
+
public async createComposer(behaviors: IBehaviors): Promise<ServiceComposer> {
|
|
11
|
+
return await this.bean._newBean(ServiceComposer, true, behaviors);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { BeanBase, Use, Virtual } from 'zova';
|
|
4
|
+
import { Bean } from 'zova-module-a-bean';
|
|
5
|
+
|
|
6
|
+
import type { ServiceComposer } from '../service/composer.js';
|
|
7
|
+
import type { IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';
|
|
8
|
+
import type { IBehaviorTag } from '../types/behavior.js';
|
|
9
|
+
import type { BeanBehavior } from './bean.behavior.js';
|
|
10
|
+
|
|
11
|
+
@Bean()
|
|
12
|
+
@Virtual()
|
|
13
|
+
export class BeanBehaviorBase<
|
|
14
|
+
OPTIONS extends IDecoratorBehaviorOptions = IDecoratorBehaviorOptions,
|
|
15
|
+
PROPS_INPUT = unknown,
|
|
16
|
+
PROPS_OUTPUT = PROPS_INPUT,
|
|
17
|
+
> extends BeanBase {
|
|
18
|
+
protected $options: OPTIONS;
|
|
19
|
+
|
|
20
|
+
@Use({ injectionScope: 'host' })
|
|
21
|
+
$$beanBehavior: BeanBehavior;
|
|
22
|
+
|
|
23
|
+
@Use({ injectionScope: 'host' })
|
|
24
|
+
$$behaviorTag: IBehaviorTag;
|
|
25
|
+
|
|
26
|
+
constructor(options: OPTIONS) {
|
|
27
|
+
super();
|
|
28
|
+
this.$options = options;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async onOptionsChange(options: OPTIONS) {
|
|
32
|
+
this.$options = options;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected async createComposer(behaviors: IBehaviors): Promise<ServiceComposer> {
|
|
36
|
+
return await this.$$beanBehavior.createComposer(behaviors);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected render(_props: PROPS_INPUT, next: NextBehavior<PROPS_OUTPUT>): VNode {
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createVNode, toRaw } from 'vue';
|
|
2
|
+
import { BeanBase, deepEqual, disposeInstance, Use } from 'zova';
|
|
3
|
+
import { Bean } from 'zova-module-a-bean';
|
|
4
|
+
import { Log } from 'zova-module-a-logger';
|
|
5
|
+
|
|
6
|
+
import type { IBehaviors, IBehaviorTag } from '../types/behavior.js';
|
|
7
|
+
|
|
8
|
+
import { $UseBehavior } from '../lib/useBehavior.js';
|
|
9
|
+
import { ServiceComposer } from '../service/composer.js';
|
|
10
|
+
import { BeanBehavior } from './bean.behavior.js';
|
|
11
|
+
|
|
12
|
+
export interface IBehaviorsHolderOptions {
|
|
13
|
+
behaviors: IBehaviors | (() => IBehaviors);
|
|
14
|
+
behaviorTag: IBehaviorTag;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Bean()
|
|
18
|
+
export class BeanBehaviorsHolder extends BeanBase {
|
|
19
|
+
public options: IBehaviorsHolderOptions;
|
|
20
|
+
private composer: ServiceComposer;
|
|
21
|
+
|
|
22
|
+
@Use()
|
|
23
|
+
$$beanBehavior: BeanBehavior;
|
|
24
|
+
|
|
25
|
+
public async initialize(options: IBehaviorsHolderOptions) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.bean._setBean('$$behaviorTag', this.options.behaviorTag);
|
|
28
|
+
// composer
|
|
29
|
+
this.composer = await this.$$beanBehavior.createComposer(this._getBehaviorRoot());
|
|
30
|
+
// watch
|
|
31
|
+
const behaviors = this.options.behaviors;
|
|
32
|
+
if (typeof behaviors === 'function') {
|
|
33
|
+
this.$watch(behaviors, async (newValue, oldValue) => {
|
|
34
|
+
if (deepEqual(newValue, oldValue)) return;
|
|
35
|
+
await this.composer.load(this._getBehaviorRoot(newValue));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected __dispose__() {
|
|
41
|
+
disposeInstance(this.composer);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private _getBehaviors() {
|
|
45
|
+
let behaviors = this.options.behaviors;
|
|
46
|
+
if (typeof behaviors === 'function') {
|
|
47
|
+
behaviors = behaviors();
|
|
48
|
+
}
|
|
49
|
+
return behaviors;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Log({ args: false, childName: 'behavior', level: 'debug' })
|
|
53
|
+
private _getBehaviorRoot(behaviors?: IBehaviors) {
|
|
54
|
+
if (!behaviors) {
|
|
55
|
+
behaviors = this._getBehaviors();
|
|
56
|
+
}
|
|
57
|
+
return $UseBehavior('a-behavior:root' as never, { behaviors } as any);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public render(vNodeDefault?: Function, propsCustom?: {}) {
|
|
61
|
+
const parent = this.ctx.instance;
|
|
62
|
+
const { props, children } = parent.vnode;
|
|
63
|
+
// props
|
|
64
|
+
const propsNew = Object.assign({}, propsCustom ?? props) as any;
|
|
65
|
+
delete propsNew.behaviorTag;
|
|
66
|
+
delete propsNew.behaviors;
|
|
67
|
+
// render
|
|
68
|
+
return this.composer.render(propsNew, propsNew => {
|
|
69
|
+
if (vNodeDefault) return vNodeDefault(propsNew);
|
|
70
|
+
return createVNode(toRaw(this.options.behaviorTag.component), propsNew, children);
|
|
71
|
+
});
|
|
72
|
+
// // ensure inner component inherits the async wrapper's ref owner
|
|
73
|
+
// vnode.ref = parent.vnode.ref;
|
|
74
|
+
// // pass the custom element callback on to the inner comp
|
|
75
|
+
// // and remove it from the async wrapper
|
|
76
|
+
// cast(vnode).ce = cast(parent.vnode).ce;
|
|
77
|
+
// // delete cast(parent.vnode).ce;
|
|
78
|
+
// // ok
|
|
79
|
+
// return vnode;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { disposeInstance } from 'zova';
|
|
4
|
+
|
|
5
|
+
import type { ServiceComposer } from '../service/composer.js';
|
|
6
|
+
import type { IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';
|
|
7
|
+
|
|
8
|
+
import { Behavior } from '../lib/behavior.js';
|
|
9
|
+
import { BeanBehaviorBase } from './bean.behaviorBase.js';
|
|
10
|
+
|
|
11
|
+
export interface IBehaviorPropsInputRoot {}
|
|
12
|
+
|
|
13
|
+
export interface IBehaviorPropsOutputRoot {}
|
|
14
|
+
|
|
15
|
+
export interface IBehaviorOptionsRoot extends IDecoratorBehaviorOptions {
|
|
16
|
+
behaviors: IBehaviors;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Behavior<IBehaviorOptionsRoot>()
|
|
20
|
+
export class BehaviorRoot extends BeanBehaviorBase<IBehaviorOptionsRoot, IBehaviorPropsInputRoot, IBehaviorPropsOutputRoot> {
|
|
21
|
+
private composer: ServiceComposer;
|
|
22
|
+
|
|
23
|
+
protected async __init__(options: IBehaviorOptionsRoot) {
|
|
24
|
+
this.composer = await this.createComposer(options.behaviors);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected __dispose__() {
|
|
28
|
+
disposeInstance(this.composer);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async onOptionsChange(options: IBehaviorOptionsRoot) {
|
|
32
|
+
await super.onOptionsChange(options);
|
|
33
|
+
await this.composer.load(options.behaviors);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected render(props: IBehaviorPropsInputRoot, next: NextBehavior<IBehaviorPropsOutputRoot>): VNode {
|
|
37
|
+
return this.composer.render(props, next);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IComponentOptions } from 'zova';
|
|
2
|
+
|
|
3
|
+
import { BeanControllerBase, SymbolControllerRefDisable, Use } from 'zova';
|
|
4
|
+
import { Controller } from 'zova-module-a-bean';
|
|
5
|
+
|
|
6
|
+
import type { IBehaviors, IBehaviorTag } from '../../types/behavior.js';
|
|
7
|
+
|
|
8
|
+
import { BeanBehaviorsHolder } from '../../bean/bean.behaviorsHolder.js';
|
|
9
|
+
|
|
10
|
+
export interface ControllerBehaviorProps {
|
|
11
|
+
behaviorTag: IBehaviorTag;
|
|
12
|
+
behaviors: IBehaviors;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Controller()
|
|
16
|
+
export class ControllerBehavior extends BeanControllerBase {
|
|
17
|
+
static $propsDefault = {};
|
|
18
|
+
static $componentOptions: IComponentOptions = { inheritAttrs: false };
|
|
19
|
+
protected [SymbolControllerRefDisable]: boolean = true;
|
|
20
|
+
|
|
21
|
+
@Use()
|
|
22
|
+
$$beanBehaviorsHolder: BeanBehaviorsHolder;
|
|
23
|
+
|
|
24
|
+
protected async __init__() {
|
|
25
|
+
await this.$$beanBehaviorsHolder.initialize({
|
|
26
|
+
behaviorTag: this.$props.behaviorTag,
|
|
27
|
+
behaviors: () => {
|
|
28
|
+
return this.$props.behaviors;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected render() {
|
|
34
|
+
return this.$$beanBehaviorsHolder.render();
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createBeanDecorator } from 'zova';
|
|
2
|
+
|
|
3
|
+
import type { IDecoratorBehaviorOptions } from '../types/behavior.js';
|
|
4
|
+
|
|
5
|
+
export function Behavior<T extends IDecoratorBehaviorOptions>(options?: T): ClassDecorator {
|
|
6
|
+
return createBeanDecorator('behavior', 'new', true, options);
|
|
7
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Component } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { IBehaviorItem, IBehaviorRecord } from '../types/behavior.js';
|
|
4
|
+
|
|
5
|
+
export function $UseBehavior<T extends keyof IBehaviorRecord>(behaviorName: T, options?: Partial<IBehaviorRecord[T]>): IBehaviorItem {
|
|
6
|
+
return { [behaviorName]: options };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function $UseBehaviorTag(component: string | Component) {
|
|
10
|
+
return {
|
|
11
|
+
component,
|
|
12
|
+
name: typeof component === 'string' ? component : undefined,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { BeanBase, cast, deepEqual, disposeInstance, Use } from 'zova';
|
|
4
|
+
import { IOnionItem, IOnionSlice, Service, SysOnion, TypeComposer } from 'zova-module-a-bean';
|
|
5
|
+
|
|
6
|
+
import type { BeanBehaviorBase } from '../bean/bean.behaviorBase.js';
|
|
7
|
+
import type { IBehaviorRecord, IBehaviors, IDecoratorBehaviorOptions, NextBehavior } from '../types/behavior.js';
|
|
8
|
+
|
|
9
|
+
const SymbolSliceOptionsOriginal = Symbol('SymbolSliceOptionsOriginal');
|
|
10
|
+
|
|
11
|
+
@Service()
|
|
12
|
+
export class ServiceComposer extends BeanBase {
|
|
13
|
+
private _composer: TypeComposer;
|
|
14
|
+
private _onionSlicesOriginal?: IOnionSlice<IDecoratorBehaviorOptions, keyof IBehaviorRecord, BeanBehaviorBase>[];
|
|
15
|
+
|
|
16
|
+
@Use()
|
|
17
|
+
$$sysOnion: SysOnion;
|
|
18
|
+
|
|
19
|
+
protected async __init__(behaviors: IBehaviors) {
|
|
20
|
+
await this.load(behaviors);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected __dispose__() {
|
|
24
|
+
if (this._onionSlicesOriginal) {
|
|
25
|
+
for (const onionSlice of this._onionSlicesOriginal) {
|
|
26
|
+
disposeInstance(onionSlice.beanInstance);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async load(behaviors: IBehaviors) {
|
|
32
|
+
await this.$renderFreezeScope(async () => {
|
|
33
|
+
await this._loadInner(behaviors);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private async _loadInner(behaviors: IBehaviors) {
|
|
38
|
+
// onionItems
|
|
39
|
+
const onionItems = this._prepareOnionItems(behaviors);
|
|
40
|
+
// load onions
|
|
41
|
+
const onionSlices = await this.$$sysOnion.behavior.loadOnions<BeanBehaviorBase>(onionItems);
|
|
42
|
+
// create behaviors
|
|
43
|
+
for (const onionSlice of onionSlices) {
|
|
44
|
+
const onionSliceOriginal = this._onionSlicesOriginal?.find(item => item.beanFullName === onionSlice.beanFullName);
|
|
45
|
+
if (onionSliceOriginal) {
|
|
46
|
+
onionSlice.beanInstance = onionSliceOriginal.beanInstance;
|
|
47
|
+
if (!deepEqual(onionSliceOriginal[SymbolSliceOptionsOriginal], onionSlice.options)) {
|
|
48
|
+
await cast(onionSlice.beanInstance).onOptionsChange(onionSlice.options);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
onionSlice.beanInstance = await this.bean._newBean(onionSlice.beanFullName as any, true, onionSlice.options);
|
|
52
|
+
}
|
|
53
|
+
onionSlice[SymbolSliceOptionsOriginal] = onionSlice.options;
|
|
54
|
+
}
|
|
55
|
+
// dispose original behaviors
|
|
56
|
+
if (this._onionSlicesOriginal) {
|
|
57
|
+
for (const onionSlice of this._onionSlicesOriginal) {
|
|
58
|
+
const exists = onionSlices.find(item => item.beanFullName === onionSlice.beanFullName);
|
|
59
|
+
if (!exists) {
|
|
60
|
+
disposeInstance(onionSlice.beanInstance);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// save
|
|
65
|
+
this._onionSlicesOriginal = onionSlices;
|
|
66
|
+
// compose
|
|
67
|
+
this._composer = this.$$sysOnion.behavior.compose(onionSlices, (onionSlice, props: any, next) => {
|
|
68
|
+
const beanInstance = cast<BeanBehaviorBase>(onionSlice.beanInstance);
|
|
69
|
+
return cast(beanInstance).render(props, next as any);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public render<PROPS_INPUT, PROPS_OUTPUT = PROPS_INPUT>(props: PROPS_INPUT, next: NextBehavior<PROPS_OUTPUT>): VNode {
|
|
74
|
+
return this._composer(props, next);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private _prepareOnionItems(behaviors: IBehaviors) {
|
|
78
|
+
const onionItems: IOnionItem<IDecoratorBehaviorOptions, keyof IBehaviorRecord>[] = [];
|
|
79
|
+
return this._prepareOnionItemsInner(onionItems, behaviors);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _prepareOnionItemsInner(onionItems: IOnionItem<IDecoratorBehaviorOptions, keyof IBehaviorRecord>[], behaviors: IBehaviors) {
|
|
83
|
+
const behaviors2 = Array.isArray(behaviors) ? behaviors : [behaviors];
|
|
84
|
+
for (const behaviorItem of behaviors2) {
|
|
85
|
+
if (typeof behaviorItem === 'string') {
|
|
86
|
+
onionItems.push({ name: behaviorItem as unknown as keyof IBehaviorRecord, options: undefined });
|
|
87
|
+
} else if (Array.isArray(behaviorItem)) {
|
|
88
|
+
this._prepareOnionItemsInner(onionItems, behaviorItem);
|
|
89
|
+
} else if (typeof behaviorItem === 'object') {
|
|
90
|
+
for (const key in behaviorItem) {
|
|
91
|
+
let options = behaviorItem[key];
|
|
92
|
+
if (options === false) continue;
|
|
93
|
+
if (options === true) options = undefined;
|
|
94
|
+
onionItems.push({ name: key as unknown as keyof IBehaviorRecord, options });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return onionItems;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Component, VNode } from 'vue';
|
|
2
|
+
import type { OmitNever } from 'zova';
|
|
3
|
+
import type { IOnionOptionsEnable, ServiceOnion } from 'zova-module-a-bean';
|
|
4
|
+
|
|
5
|
+
import 'vue';
|
|
6
|
+
import 'vue/jsx-runtime';
|
|
7
|
+
import '@vue/runtime-dom';
|
|
8
|
+
|
|
9
|
+
export type NextBehavior<PROPS_OUTPUT = unknown> = (props?: PROPS_OUTPUT) => VNode;
|
|
10
|
+
|
|
11
|
+
export interface IBehaviorTag {
|
|
12
|
+
component: string | Component;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type IBehaviorItem = {
|
|
17
|
+
[prop in keyof IBehaviorRecord]?: Partial<IBehaviorRecord[prop]>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type IBehaviors = keyof IBehaviorRecord | IBehaviorItem | (keyof IBehaviorRecord | IBehaviorItem)[];
|
|
21
|
+
|
|
22
|
+
export interface IBehaviorRecord {}
|
|
23
|
+
|
|
24
|
+
export interface IDecoratorBehaviorOptions extends IOnionOptionsEnable {}
|
|
25
|
+
|
|
26
|
+
export type TypeBehaviorRecordSelector<PREFIX extends string> = {
|
|
27
|
+
[K in keyof IBehaviorRecord as K extends `${string}:${PREFIX}${string}` ? K : never]: IBehaviorRecord[K];
|
|
28
|
+
};
|
|
29
|
+
export type TypeBehaviorRecordSelectorKeys<PREFIX extends string> = keyof TypeBehaviorRecordSelector<PREFIX>;
|
|
30
|
+
|
|
31
|
+
export type TypeBehaviorRecordSelectorStrict<PREFIX extends string> = {
|
|
32
|
+
[K in keyof IBehaviorRecord as K extends `${string}:${PREFIX}` ? K : never]: IBehaviorRecord[K];
|
|
33
|
+
};
|
|
34
|
+
export type TypeBehaviorRecordSelectorKeysStrict<PREFIX extends string> = keyof TypeBehaviorRecordSelectorStrict<PREFIX>;
|
|
35
|
+
|
|
36
|
+
declare module 'zova-module-a-bean' {
|
|
37
|
+
export interface SysOnion {
|
|
38
|
+
behavior: ServiceOnion<IDecoratorBehaviorOptions, keyof IBehaviorRecord>;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare module 'zova' {
|
|
43
|
+
export interface ConfigOnions {
|
|
44
|
+
behavior: OmitNever<IBehaviorRecord>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IBeanSceneRecord {
|
|
48
|
+
behavior: never;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ILoggerChildRecord {
|
|
52
|
+
behavior: never;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module 'vue' {
|
|
57
|
+
export interface InputHTMLAttributes {
|
|
58
|
+
behaviors?: IBehaviors;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare module 'vue/jsx-runtime' {
|
|
63
|
+
namespace JSX {
|
|
64
|
+
// need define class/style in IntrinsicAttributes
|
|
65
|
+
export interface IntrinsicAttributes {
|
|
66
|
+
bs_all?: IBehaviors;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare module '@vue/runtime-dom' {
|
|
72
|
+
export interface HTMLAttributes {
|
|
73
|
+
bs_all?: IBehaviors;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './behavior.js';
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# @cabloy/set
|