@leafer/decorator 1.0.0-alpha.9 → 1.0.0-bate
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 +1 -1
- package/src/data.ts +79 -56
- package/src/define.ts +35 -0
- package/src/index.ts +2 -2
- package/src/rewrite.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/decorator",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-bate",
|
|
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-
|
|
23
|
-
"@leafer/debug": "1.0.0-
|
|
22
|
+
"@leafer/platform": "1.0.0-bate",
|
|
23
|
+
"@leafer/debug": "1.0.0-bate"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-
|
|
26
|
+
"@leafer/interface": "1.0.0-bate"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/class.ts
CHANGED
package/src/data.ts
CHANGED
|
@@ -1,155 +1,175 @@
|
|
|
1
1
|
import { ILeafData, ILeaf, IObject, __Value } from '@leafer/interface'
|
|
2
2
|
import { defineKey, getDescriptor } from './object'
|
|
3
|
+
import { Debug } from '@leafer/debug'
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
// name
|
|
5
7
|
|
|
6
8
|
export function aliasType(name: string) {
|
|
7
9
|
return (target: ILeaf, key: string) => {
|
|
8
10
|
defineKey(target, key, {
|
|
9
|
-
get() { return this.
|
|
11
|
+
get() { return this.__getAttr(name) },
|
|
10
12
|
set(value: __Value) {
|
|
11
|
-
this.
|
|
13
|
+
this.__setAttr(name, value)
|
|
12
14
|
}
|
|
13
15
|
})
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: __Value, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
|
|
20
|
+
const defaultDescriptor: IObject & ThisType<ILeaf> = {
|
|
21
|
+
get() { return this.__getAttr(key) },
|
|
22
|
+
set(value: __Value) { this.__setAttr(key, value) },
|
|
23
|
+
configurable: true,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}
|
|
26
|
+
defineKey(target, key, Object.assign(defaultDescriptor, mergeDescriptor || {}))
|
|
27
|
+
defineDataProcessor(target, key, defaultValue)
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
export function dataType(defaultValue?: __Value) {
|
|
18
31
|
return (target: ILeaf, key: string) => {
|
|
19
|
-
|
|
20
|
-
get() { return this.__get(key) },
|
|
21
|
-
set(value: __Value) {
|
|
22
|
-
this.__set(key, value)
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
defineDataProcessor(target, key, defaultValue)
|
|
32
|
+
defineLeafAttr(target, key, defaultValue)
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export function positionType(defaultValue?: __Value) {
|
|
30
37
|
return (target: ILeaf, key: string) => {
|
|
31
|
-
|
|
32
|
-
get() { return this.__get(key) },
|
|
38
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
33
39
|
set(value: __Value) {
|
|
34
|
-
this.
|
|
40
|
+
this.__setAttr(key, value)
|
|
35
41
|
this.__layout.positionChanged || this.__layout.positionChange()
|
|
36
42
|
}
|
|
37
43
|
})
|
|
38
|
-
defineDataProcessor(target, key, defaultValue)
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
export function scaleType(defaultValue?: __Value) {
|
|
43
48
|
return (target: ILeaf, key: string) => {
|
|
44
|
-
|
|
45
|
-
get() { return this.__get(key) },
|
|
49
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
46
50
|
set(value: __Value) {
|
|
47
|
-
this.
|
|
51
|
+
this.__setAttr(key, value)
|
|
48
52
|
this.__layout.scaleChanged || this.__layout.scaleChange()
|
|
49
53
|
}
|
|
50
54
|
})
|
|
51
|
-
defineDataProcessor(target, key, defaultValue)
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
|
|
55
59
|
export function rotationType(defaultValue?: __Value) {
|
|
56
60
|
return (target: ILeaf, key: string) => {
|
|
57
|
-
|
|
58
|
-
get() { return this.__get(key) },
|
|
61
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
59
62
|
set(value: __Value) {
|
|
60
|
-
this.
|
|
63
|
+
this.__setAttr(key, value)
|
|
61
64
|
this.__layout.rotationChanged || this.__layout.rotationChange()
|
|
62
65
|
|
|
63
66
|
}
|
|
64
67
|
})
|
|
65
|
-
defineDataProcessor(target, key, defaultValue)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export function boundsType(defaultValue?: __Value) {
|
|
70
72
|
return (target: ILeaf, key: string) => {
|
|
71
|
-
|
|
72
|
-
get() { return this.__get(key) },
|
|
73
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
73
74
|
set(value: __Value) {
|
|
74
|
-
this.
|
|
75
|
-
this.__layout.
|
|
75
|
+
this.__setAttr(key, value)
|
|
76
|
+
this.__layout.boxChanged || this.__layout.boxChange()
|
|
76
77
|
}
|
|
77
78
|
})
|
|
78
|
-
defineDataProcessor(target, key, defaultValue)
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export const pathType = boundsType
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
export function
|
|
85
|
+
export function affectStrokeBoundsType(defaultValue?: __Value) {
|
|
86
86
|
return (target: ILeaf, key: string) => {
|
|
87
|
-
|
|
88
|
-
get() { return this.__get(key) },
|
|
87
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
89
88
|
set(value: __Value) {
|
|
90
|
-
this.
|
|
91
|
-
this.__layout.
|
|
89
|
+
this.__setAttr(key, value)
|
|
90
|
+
this.__layout.strokeChanged || this.__layout.strokeChange()
|
|
92
91
|
}
|
|
93
92
|
})
|
|
94
|
-
defineDataProcessor(target, key, defaultValue)
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
|
|
96
|
+
export const strokeType = affectStrokeBoundsType
|
|
97
|
+
|
|
98
98
|
export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
99
99
|
return (target: ILeaf, key: string) => {
|
|
100
|
-
|
|
101
|
-
get() { return this.__get(key) },
|
|
100
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
102
101
|
set(value: __Value) {
|
|
103
|
-
this.
|
|
104
|
-
this.__layout.
|
|
102
|
+
this.__setAttr(key, value)
|
|
103
|
+
this.__layout.renderChanged || this.__layout.renderChange()
|
|
105
104
|
}
|
|
106
105
|
})
|
|
107
|
-
defineDataProcessor(target, key, defaultValue)
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
export function surfaceType(defaultValue?: __Value) {
|
|
112
110
|
return (target: ILeaf, key: string) => {
|
|
113
|
-
|
|
114
|
-
get() { return this.__get(key) },
|
|
111
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
115
112
|
set(value: __Value) {
|
|
116
|
-
this.
|
|
113
|
+
this.__setAttr(key, value)
|
|
117
114
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
118
115
|
}
|
|
119
116
|
})
|
|
120
|
-
defineDataProcessor(target, key, defaultValue)
|
|
121
117
|
}
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
export function opacityType(defaultValue?: __Value) {
|
|
125
121
|
return (target: ILeaf, key: string) => {
|
|
126
|
-
|
|
127
|
-
get() { return this.__get(key) },
|
|
122
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
128
123
|
set(value: __Value) {
|
|
129
|
-
this.
|
|
124
|
+
this.__setAttr(key, value)
|
|
130
125
|
this.__layout.opacityChanged || this.__layout.opacityChange()
|
|
131
126
|
}
|
|
132
127
|
})
|
|
133
|
-
defineDataProcessor(target, key, defaultValue)
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
export function sortType(defaultValue?: __Value) {
|
|
138
132
|
return (target: ILeaf, key: string) => {
|
|
139
|
-
|
|
140
|
-
get() { return this.__get(key) },
|
|
133
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
141
134
|
set(value: __Value) {
|
|
142
|
-
this.
|
|
135
|
+
this.__setAttr(key, value)
|
|
143
136
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
144
137
|
|
|
145
138
|
if (this.parent) {
|
|
146
139
|
this.parent.__layout.childrenSortChanged = true
|
|
147
140
|
} else {
|
|
148
|
-
this.
|
|
141
|
+
this.waitParent(() => { this.parent.__layout.childrenSortChanged = true })
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function maskType(defaultValue?: __Value) {
|
|
149
|
+
return (target: ILeaf, key: string) => {
|
|
150
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
151
|
+
set(value: boolean) {
|
|
152
|
+
this.__setAttr(key, value)
|
|
153
|
+
this.__layout.boxChanged || this.__layout.boxChange()
|
|
154
|
+
|
|
155
|
+
if (this.parent) {
|
|
156
|
+
this.parent.__updateMask(value)
|
|
157
|
+
} else {
|
|
158
|
+
this.waitParent(() => { this.parent.__updateMask(value) })
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
161
|
})
|
|
152
|
-
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function hitType(defaultValue?: __Value) {
|
|
166
|
+
return (target: ILeaf, key: string) => {
|
|
167
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
168
|
+
set(value: __Value) {
|
|
169
|
+
this.__setAttr(key, value)
|
|
170
|
+
if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
|
|
171
|
+
}
|
|
172
|
+
})
|
|
153
173
|
}
|
|
154
174
|
}
|
|
155
175
|
|
|
@@ -179,8 +199,12 @@ function getSetMethodName(key: string): string {
|
|
|
179
199
|
return 'set' + key.charAt(0).toUpperCase() + key.slice(1)
|
|
180
200
|
}
|
|
181
201
|
|
|
202
|
+
export function setDefaultValue(target: IObject, key: string, defaultValue: __Value): void {
|
|
203
|
+
defineDataProcessor(target.prototype, key, defaultValue)
|
|
204
|
+
}
|
|
205
|
+
|
|
182
206
|
// define leaf.__[key] getter/setter
|
|
183
|
-
export function defineDataProcessor(target: ILeaf, key: string, defaultValue
|
|
207
|
+
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: __Value): void {
|
|
184
208
|
|
|
185
209
|
const data = target.__DataProcessor.prototype as ILeafData
|
|
186
210
|
const computedKey = '_' + key
|
|
@@ -193,17 +217,16 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue: __
|
|
|
193
217
|
},
|
|
194
218
|
set(value: __Value) {
|
|
195
219
|
this[computedKey] = value
|
|
196
|
-
}
|
|
220
|
+
},
|
|
221
|
+
configurable: true,
|
|
222
|
+
enumerable: true
|
|
197
223
|
}
|
|
198
224
|
|
|
199
225
|
if (defaultValue === undefined) property.get = function () { return this[computedKey] }
|
|
200
226
|
|
|
201
227
|
const descriptor = getDescriptor(data, key)
|
|
202
228
|
|
|
203
|
-
if (descriptor)
|
|
204
|
-
if (descriptor.set) property.set = descriptor.set // use custom set
|
|
205
|
-
if (descriptor.get) property.get = descriptor.get // use custom get
|
|
206
|
-
}
|
|
229
|
+
if (descriptor && descriptor.set) property.set = descriptor.set // use custom set
|
|
207
230
|
|
|
208
231
|
if (data[setMethodName]) {
|
|
209
232
|
property.set = data[setMethodName] // use custom setKey(value)
|
package/src/define.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ILeaf, IObject, __Value } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
import * as types from './data'
|
|
4
|
+
|
|
5
|
+
interface IDataTypeFunction {
|
|
6
|
+
(target: ILeaf, key: string): void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface IDataTypeDecorator {
|
|
10
|
+
(...arg: any): IDataTypeFunction
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface IDataTypeDecoratorMap {
|
|
14
|
+
[key: string]: IDataTypeDecorator
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const DataTypeDecorator = {
|
|
18
|
+
|
|
19
|
+
list: {} as IDataTypeDecoratorMap,
|
|
20
|
+
|
|
21
|
+
register(name: string, decorator: IDataTypeDecorator): void {
|
|
22
|
+
this.list[name] = decorator
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
get(name: string): IDataTypeDecorator {
|
|
26
|
+
const decorator = this.list[name]
|
|
27
|
+
return decorator
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Object.keys(types).forEach(key => {
|
|
32
|
+
if (key.includes('Type')) {
|
|
33
|
+
DataTypeDecorator.register(key, (types as IObject)[key] as IDataTypeDecorator)
|
|
34
|
+
}
|
|
35
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { aliasType, dataType, positionType, boundsType,
|
|
1
|
+
export { aliasType, defineLeafAttr, dataType, positionType, boundsType, affectStrokeBoundsType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, sortType, maskType, hitType, pathType, dataProcessor, layoutProcessor, setDefaultValue, defineDataProcessor } from './data'
|
|
2
2
|
export { useModule, rewrite, rewriteAble } from './rewrite'
|
|
3
3
|
export { defineKey, getDescriptor } from './object'
|
|
4
|
-
export { registerUI,
|
|
4
|
+
export { registerUI, registerUIEvent } from './class'
|
package/src/rewrite.ts
CHANGED
|
@@ -42,11 +42,11 @@ setTimeout(() => doRewrite(true))
|
|
|
42
42
|
|
|
43
43
|
// class
|
|
44
44
|
|
|
45
|
-
export function useModule(module: IObject) {
|
|
45
|
+
export function useModule(module: IObject, exclude?: string[]) {
|
|
46
46
|
return (target: IObject) => {
|
|
47
47
|
const names = module.prototype ? getNames(module.prototype) : Object.keys(module)
|
|
48
48
|
names.forEach(name => {
|
|
49
|
-
if (!excludeNames.includes(name)) {
|
|
49
|
+
if (!excludeNames.includes(name) && (!exclude || !exclude.includes(name))) {
|
|
50
50
|
if (module.prototype) {
|
|
51
51
|
const d = getDescriptor(module.prototype, name)
|
|
52
52
|
if (d.writable) target.prototype[name] = module.prototype[name]
|