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