@leafer/decorator 1.0.0-alpha.7 → 1.0.0-alpha.9
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/package.json +4 -4
- package/src/class.ts +8 -6
- package/src/data.ts +135 -125
- package/src/index.ts +4 -4
- package/src/rewrite.ts +14 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/decorator",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "@leafer/decorator",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/platform": "1.0.0-alpha.
|
|
23
|
-
"@leafer/debug": "1.0.0-alpha.
|
|
22
|
+
"@leafer/platform": "1.0.0-alpha.9",
|
|
23
|
+
"@leafer/debug": "1.0.0-alpha.9"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
26
|
+
"@leafer/interface": "1.0.0-alpha.9"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/class.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { IObject } from '@leafer/interface'
|
|
2
2
|
import { EventCreator, UICreator } from '@leafer/platform'
|
|
3
3
|
|
|
4
|
-
export function registerUI() {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export function registerUI() {
|
|
5
|
+
return (target: IObject) => {
|
|
6
|
+
UICreator.register(target)
|
|
7
|
+
}
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export function registerEvent() {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export function registerEvent() {
|
|
11
|
+
return (target: IObject) => {
|
|
12
|
+
EventCreator.register(target)
|
|
13
|
+
}
|
|
12
14
|
}
|
package/src/data.ts
CHANGED
|
@@ -3,163 +3,173 @@ import { defineKey, getDescriptor } from './object'
|
|
|
3
3
|
|
|
4
4
|
// name
|
|
5
5
|
|
|
6
|
-
export function aliasType(name: string) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export function aliasType(name: string) {
|
|
7
|
+
return (target: ILeaf, key: string) => {
|
|
8
|
+
defineKey(target, key, {
|
|
9
|
+
get() { return this.__get(name) },
|
|
10
|
+
set(value: __Value) {
|
|
11
|
+
this.__set(name, value)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function dataType(defaultValue?: __Value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export function dataType(defaultValue?: __Value) {
|
|
18
|
+
return (target: ILeaf, key: string) => {
|
|
19
|
+
defineKey(target, key, {
|
|
20
|
+
get() { return this.__get(key) },
|
|
21
|
+
set(value: __Value) {
|
|
22
|
+
this.__set(key, value)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
defineDataProcessor(target, key, defaultValue)
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
export function positionType(defaultValue?: __Value) {
|
|
30
|
+
return (target: ILeaf, key: string) => {
|
|
31
|
+
defineKey(target, key, {
|
|
32
|
+
get() { return this.__get(key) },
|
|
33
|
+
set(value: __Value) {
|
|
34
|
+
this.__set(key, value)
|
|
35
|
+
this.__layout.positionChanged || this.__layout.positionChange()
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
defineDataProcessor(target, key, defaultValue)
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
export function scaleType(defaultValue?: __Value) {
|
|
43
|
+
return (target: ILeaf, key: string) => {
|
|
44
|
+
defineKey(target, key, {
|
|
45
|
+
get() { return this.__get(key) },
|
|
46
|
+
set(value: __Value) {
|
|
47
|
+
this.__set(key, value)
|
|
48
|
+
this.__layout.scaleChanged || this.__layout.scaleChange()
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
defineDataProcessor(target, key, defaultValue)
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
export function rotationType(defaultValue?: __Value) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
export function rotationType(defaultValue?: __Value) {
|
|
56
|
+
return (target: ILeaf, key: string) => {
|
|
57
|
+
defineKey(target, key, {
|
|
58
|
+
get() { return this.__get(key) },
|
|
59
|
+
set(value: __Value) {
|
|
60
|
+
this.__set(key, value)
|
|
61
|
+
this.__layout.rotationChanged || this.__layout.rotationChange()
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
defineDataProcessor(target, key, defaultValue)
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
export function boundsType(defaultValue?: __Value) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
export function boundsType(defaultValue?: __Value) {
|
|
70
|
+
return (target: ILeaf, key: string) => {
|
|
71
|
+
defineKey(target, key, {
|
|
72
|
+
get() { return this.__get(key) },
|
|
73
|
+
set(value: __Value) {
|
|
74
|
+
this.__set(key, value)
|
|
75
|
+
this.__layout.boxBoundsChanged || this.__layout.boxBoundsChange()
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
defineDataProcessor(target, key, defaultValue)
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
export const pathType = boundsType
|
|
79
|
-
export const pathType__ = boundsType__
|
|
80
83
|
|
|
81
84
|
|
|
82
|
-
export function affectEventBoundsType(defaultValue?: __Value) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
export function affectEventBoundsType(defaultValue?: __Value) {
|
|
86
|
+
return (target: ILeaf, key: string) => {
|
|
87
|
+
defineKey(target, key, {
|
|
88
|
+
get() { return this.__get(key) },
|
|
89
|
+
set(value: __Value) {
|
|
90
|
+
this.__set(key, value)
|
|
91
|
+
this.__layout.eventBoundsChanged || this.__layout.eventBoundsChange()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
defineDataProcessor(target, key, defaultValue)
|
|
95
|
+
}
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
99
|
+
return (target: ILeaf, key: string) => {
|
|
100
|
+
defineKey(target, key, {
|
|
101
|
+
get() { return this.__get(key) },
|
|
102
|
+
set(value: __Value) {
|
|
103
|
+
this.__set(key, value)
|
|
104
|
+
this.__layout.renderBoundsChanged || this.__layout.renderBoundsChange()
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
defineDataProcessor(target, key, defaultValue)
|
|
108
|
+
}
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
export function surfaceType(defaultValue?: __Value) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
export function surfaceType(defaultValue?: __Value) {
|
|
112
|
+
return (target: ILeaf, key: string) => {
|
|
113
|
+
defineKey(target, key, {
|
|
114
|
+
get() { return this.__get(key) },
|
|
115
|
+
set(value: __Value) {
|
|
116
|
+
this.__set(key, value)
|
|
117
|
+
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
defineDataProcessor(target, key, defaultValue)
|
|
121
|
+
}
|
|
116
122
|
}
|
|
117
123
|
|
|
118
|
-
export function opacityType(defaultValue?: __Value) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
export function opacityType(defaultValue?: __Value) {
|
|
125
|
+
return (target: ILeaf, key: string) => {
|
|
126
|
+
defineKey(target, key, {
|
|
127
|
+
get() { return this.__get(key) },
|
|
128
|
+
set(value: __Value) {
|
|
129
|
+
this.root ? this.__set(key, value) : this.__[key] = value
|
|
130
|
+
this.__layout.opacityChanged || this.__layout.opacityChange()
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
defineDataProcessor(target, key, defaultValue)
|
|
134
|
+
}
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
export function sortType(defaultValue?: __Value) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
export function sortType(defaultValue?: __Value) {
|
|
138
|
+
return (target: ILeaf, key: string) => {
|
|
139
|
+
defineKey(target, key, {
|
|
140
|
+
get() { return this.__get(key) },
|
|
141
|
+
set(value: __Value) {
|
|
142
|
+
this.__set(key, value)
|
|
143
|
+
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
144
|
+
|
|
145
|
+
if (this.parent) {
|
|
146
|
+
this.parent.__layout.childrenSortChanged = true
|
|
147
|
+
} else {
|
|
148
|
+
this.__addParentWait(() => { this.parent.__layout.childrenSortChanged = true })
|
|
149
|
+
}
|
|
142
150
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
})
|
|
152
|
+
defineDataProcessor(target, key, defaultValue)
|
|
153
|
+
}
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
|
|
149
157
|
// get
|
|
150
158
|
|
|
151
|
-
export function dataProcessor(processor: IObject) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
export function dataProcessor(processor: IObject) {
|
|
160
|
+
return (target: ILeaf, _key: string) => {
|
|
161
|
+
defineKey(target, '__DataProcessor', {
|
|
162
|
+
get() { return processor }
|
|
163
|
+
})
|
|
164
|
+
}
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
export function layoutProcessor(processor: IObject) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
export function layoutProcessor(processor: IObject) {
|
|
168
|
+
return (target: ILeaf, _key: string) => {
|
|
169
|
+
defineKey(target, '__LayoutProcessor', {
|
|
170
|
+
get() { return processor }
|
|
171
|
+
})
|
|
172
|
+
}
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { aliasType, dataType, positionType, boundsType, affectEventBoundsType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, sortType, pathType, dataProcessor, layoutProcessor, defineDataProcessor } from './data'
|
|
2
|
+
export { useModule, rewrite, rewriteAble } from './rewrite'
|
|
3
|
+
export { defineKey, getDescriptor } from './object'
|
|
4
|
+
export { registerUI, registerEvent } from './class'
|
package/src/rewrite.ts
CHANGED
|
@@ -42,17 +42,18 @@ setTimeout(() => doRewrite(true))
|
|
|
42
42
|
|
|
43
43
|
// class
|
|
44
44
|
|
|
45
|
-
export function useModule(module: IObject) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
export function useModule(module: IObject) {
|
|
46
|
+
return (target: IObject) => {
|
|
47
|
+
const names = module.prototype ? getNames(module.prototype) : Object.keys(module)
|
|
48
|
+
names.forEach(name => {
|
|
49
|
+
if (!excludeNames.includes(name)) {
|
|
50
|
+
if (module.prototype) {
|
|
51
|
+
const d = getDescriptor(module.prototype, name)
|
|
52
|
+
if (d.writable) target.prototype[name] = module.prototype[name]
|
|
53
|
+
} else {
|
|
54
|
+
target.prototype[name] = module[name]
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|