@leafer/decorator 1.0.0-alpha.23 → 1.0.0-alpha.31
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/data.ts +34 -14
- package/src/define.ts +35 -0
- package/src/index.ts +1 -1
- 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-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.31",
|
|
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.31",
|
|
23
|
+
"@leafer/debug": "1.0.0-alpha.31"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
26
|
+
"@leafer/interface": "1.0.0-alpha.31"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/data.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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
|
|
|
@@ -14,11 +16,12 @@ export function aliasType(name: string) {
|
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
export function defineLeafAttr(target: ILeaf, key: string, defaultValue: __Value, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
|
|
19
|
+
export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: __Value, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
|
|
19
20
|
const defaultDescriptor: IObject & ThisType<ILeaf> = {
|
|
20
21
|
get() { return this.__getAttr(key) },
|
|
21
|
-
set(value: __Value) { this.__setAttr(key, value) }
|
|
22
|
+
set(value: __Value) { this.__setAttr(key, value) },
|
|
23
|
+
configurable: true,
|
|
24
|
+
enumerable: true
|
|
22
25
|
}
|
|
23
26
|
defineKey(target, key, Object.assign(defaultDescriptor, mergeDescriptor || {}))
|
|
24
27
|
defineDataProcessor(target, key, defaultValue)
|
|
@@ -52,6 +55,7 @@ export function scaleType(defaultValue?: __Value) {
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
|
|
55
59
|
export function rotationType(defaultValue?: __Value) {
|
|
56
60
|
return (target: ILeaf, key: string) => {
|
|
57
61
|
defineLeafAttr(target, key, defaultValue, {
|
|
@@ -78,7 +82,7 @@ export function boundsType(defaultValue?: __Value) {
|
|
|
78
82
|
export const pathType = boundsType
|
|
79
83
|
|
|
80
84
|
|
|
81
|
-
export function
|
|
85
|
+
export function affectStrokeBoundsType(defaultValue?: __Value) {
|
|
82
86
|
return (target: ILeaf, key: string) => {
|
|
83
87
|
defineLeafAttr(target, key, defaultValue, {
|
|
84
88
|
set(value: __Value) {
|
|
@@ -89,6 +93,8 @@ export function affectEventBoundsType(defaultValue?: __Value) {
|
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
96
|
+
export const strokeType = affectStrokeBoundsType
|
|
97
|
+
|
|
92
98
|
export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
93
99
|
return (target: ILeaf, key: string) => {
|
|
94
100
|
defineLeafAttr(target, key, defaultValue, {
|
|
@@ -132,7 +138,7 @@ export function sortType(defaultValue?: __Value) {
|
|
|
132
138
|
if (this.parent) {
|
|
133
139
|
this.parent.__layout.childrenSortChanged = true
|
|
134
140
|
} else {
|
|
135
|
-
this.
|
|
141
|
+
this.waitParent(() => { this.parent.__layout.childrenSortChanged = true })
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
})
|
|
@@ -142,20 +148,31 @@ export function sortType(defaultValue?: __Value) {
|
|
|
142
148
|
export function maskType(defaultValue?: __Value) {
|
|
143
149
|
return (target: ILeaf, key: string) => {
|
|
144
150
|
defineLeafAttr(target, key, defaultValue, {
|
|
145
|
-
set(value:
|
|
151
|
+
set(value: boolean) {
|
|
146
152
|
this.__setAttr(key, value)
|
|
147
153
|
this.__layout.boxBoundsChanged || this.__layout.boxBoundsChange()
|
|
148
154
|
|
|
149
155
|
if (this.parent) {
|
|
150
|
-
this.parent.
|
|
156
|
+
this.parent.__updateMask(value)
|
|
151
157
|
} else {
|
|
152
|
-
this.
|
|
158
|
+
this.waitParent(() => { this.parent.__updateMask(value) })
|
|
153
159
|
}
|
|
154
160
|
}
|
|
155
161
|
})
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
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
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
159
176
|
|
|
160
177
|
// get
|
|
161
178
|
|
|
@@ -182,8 +199,12 @@ function getSetMethodName(key: string): string {
|
|
|
182
199
|
return 'set' + key.charAt(0).toUpperCase() + key.slice(1)
|
|
183
200
|
}
|
|
184
201
|
|
|
202
|
+
export function setDefaultValue(target: IObject, key: string, defaultValue: __Value): void {
|
|
203
|
+
defineDataProcessor(target.prototype, key, defaultValue)
|
|
204
|
+
}
|
|
205
|
+
|
|
185
206
|
// define leaf.__[key] getter/setter
|
|
186
|
-
export function defineDataProcessor(target: ILeaf, key: string, defaultValue
|
|
207
|
+
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: __Value): void {
|
|
187
208
|
|
|
188
209
|
const data = target.__DataProcessor.prototype as ILeafData
|
|
189
210
|
const computedKey = '_' + key
|
|
@@ -196,17 +217,16 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue: __
|
|
|
196
217
|
},
|
|
197
218
|
set(value: __Value) {
|
|
198
219
|
this[computedKey] = value
|
|
199
|
-
}
|
|
220
|
+
},
|
|
221
|
+
configurable: true,
|
|
222
|
+
enumerable: true
|
|
200
223
|
}
|
|
201
224
|
|
|
202
225
|
if (defaultValue === undefined) property.get = function () { return this[computedKey] }
|
|
203
226
|
|
|
204
227
|
const descriptor = getDescriptor(data, key)
|
|
205
228
|
|
|
206
|
-
if (descriptor)
|
|
207
|
-
if (descriptor.set) property.set = descriptor.set // use custom set
|
|
208
|
-
if (descriptor.get) property.get = descriptor.get // use custom get
|
|
209
|
-
}
|
|
229
|
+
if (descriptor && descriptor.set) property.set = descriptor.set // use custom set
|
|
210
230
|
|
|
211
231
|
if (data[setMethodName]) {
|
|
212
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, defineLeafAttr, 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
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]
|