@leafer/decorator 1.0.0-beta.9 → 1.0.0-rc.10
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 +8 -5
- package/src/data.ts +69 -52
- package/src/define.ts +1 -1
- package/src/index.ts +1 -1
- package/types/index.d.ts +35 -0
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/decorator",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"description": "@leafer/decorator",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -19,10 +22,10 @@
|
|
|
19
22
|
"leaferjs"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@leafer/platform": "1.0.0-
|
|
23
|
-
"@leafer/debug": "1.0.0-
|
|
25
|
+
"@leafer/platform": "1.0.0-rc.10",
|
|
26
|
+
"@leafer/debug": "1.0.0-rc.10"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.10"
|
|
27
30
|
}
|
|
28
31
|
}
|
package/src/data.ts
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import { ILeafData, ILeaf, IObject,
|
|
1
|
+
import { ILeafData, ILeaf, IObject, IValue } from '@leafer/interface'
|
|
2
2
|
import { defineKey, getDescriptor } from './object'
|
|
3
3
|
import { Debug } from '@leafer/debug'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
// name
|
|
7
7
|
|
|
8
|
-
export function
|
|
9
|
-
return (target: ILeaf, key: string) => {
|
|
10
|
-
defineKey(target, key, {
|
|
11
|
-
get() { return this.__getAttr(name) },
|
|
12
|
-
set(value: __Value) {
|
|
13
|
-
this.__setAttr(name, value)
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: __Value, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
|
|
8
|
+
export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
|
|
20
9
|
const defaultDescriptor: IObject & ThisType<ILeaf> = {
|
|
21
10
|
get() { return this.__getAttr(key) },
|
|
22
|
-
set(value:
|
|
11
|
+
set(value: IValue) { this.__setAttr(key, value) },
|
|
23
12
|
configurable: true,
|
|
24
13
|
enumerable: true
|
|
25
14
|
}
|
|
@@ -27,27 +16,40 @@ export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: __Valu
|
|
|
27
16
|
defineDataProcessor(target, key, defaultValue)
|
|
28
17
|
}
|
|
29
18
|
|
|
30
|
-
export function dataType(defaultValue?:
|
|
19
|
+
export function dataType(defaultValue?: IValue) {
|
|
31
20
|
return (target: ILeaf, key: string) => {
|
|
32
21
|
defineLeafAttr(target, key, defaultValue)
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
export function positionType(defaultValue?:
|
|
25
|
+
export function positionType(defaultValue?: IValue) {
|
|
37
26
|
return (target: ILeaf, key: string) => {
|
|
38
27
|
defineLeafAttr(target, key, defaultValue, {
|
|
39
|
-
set(value:
|
|
28
|
+
set(value: IValue) {
|
|
40
29
|
this.__setAttr(key, value)
|
|
41
|
-
this.__layout.
|
|
30
|
+
this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
42
31
|
}
|
|
43
32
|
})
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
35
|
|
|
47
|
-
export function
|
|
36
|
+
export function autoLayoutType(defaultValue?: IValue) {
|
|
48
37
|
return (target: ILeaf, key: string) => {
|
|
49
38
|
defineLeafAttr(target, key, defaultValue, {
|
|
50
|
-
set(value:
|
|
39
|
+
set(value: IValue) {
|
|
40
|
+
this.__setAttr(key, value)
|
|
41
|
+
this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
42
|
+
this.__hasAutoLayout = !!value
|
|
43
|
+
if (!this.__local) this.__layout.createLocal()
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function scaleType(defaultValue?: IValue) {
|
|
50
|
+
return (target: ILeaf, key: string) => {
|
|
51
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
52
|
+
set(value: IValue) {
|
|
51
53
|
this.__setAttr(key, value)
|
|
52
54
|
this.__layout.scaleChanged || this.__layout.scaleChange()
|
|
53
55
|
}
|
|
@@ -56,10 +58,10 @@ export function scaleType(defaultValue?: __Value) {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
|
|
59
|
-
export function rotationType(defaultValue?:
|
|
61
|
+
export function rotationType(defaultValue?: IValue) {
|
|
60
62
|
return (target: ILeaf, key: string) => {
|
|
61
63
|
defineLeafAttr(target, key, defaultValue, {
|
|
62
|
-
set(value:
|
|
64
|
+
set(value: IValue) {
|
|
63
65
|
this.__setAttr(key, value)
|
|
64
66
|
this.__layout.rotationChanged || this.__layout.rotationChange()
|
|
65
67
|
|
|
@@ -68,12 +70,13 @@ export function rotationType(defaultValue?: __Value) {
|
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
export function boundsType(defaultValue?:
|
|
73
|
+
export function boundsType(defaultValue?: IValue) {
|
|
72
74
|
return (target: ILeaf, key: string) => {
|
|
73
75
|
defineLeafAttr(target, key, defaultValue, {
|
|
74
|
-
set(value:
|
|
76
|
+
set(value: IValue) {
|
|
75
77
|
this.__setAttr(key, value)
|
|
76
78
|
this.__layout.boxChanged || this.__layout.boxChange()
|
|
79
|
+
if (this.__hasAutoLayout) this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
77
80
|
}
|
|
78
81
|
})
|
|
79
82
|
}
|
|
@@ -82,10 +85,10 @@ export function boundsType(defaultValue?: __Value) {
|
|
|
82
85
|
export const pathType = boundsType
|
|
83
86
|
|
|
84
87
|
|
|
85
|
-
export function affectStrokeBoundsType(defaultValue?:
|
|
88
|
+
export function affectStrokeBoundsType(defaultValue?: IValue) {
|
|
86
89
|
return (target: ILeaf, key: string) => {
|
|
87
90
|
defineLeafAttr(target, key, defaultValue, {
|
|
88
|
-
set(value:
|
|
91
|
+
set(value: IValue) {
|
|
89
92
|
this.__setAttr(key, value)
|
|
90
93
|
this.__layout.strokeChanged || this.__layout.strokeChange()
|
|
91
94
|
}
|
|
@@ -95,10 +98,10 @@ export function affectStrokeBoundsType(defaultValue?: __Value) {
|
|
|
95
98
|
|
|
96
99
|
export const strokeType = affectStrokeBoundsType
|
|
97
100
|
|
|
98
|
-
export function affectRenderBoundsType(defaultValue?:
|
|
101
|
+
export function affectRenderBoundsType(defaultValue?: IValue) {
|
|
99
102
|
return (target: ILeaf, key: string) => {
|
|
100
103
|
defineLeafAttr(target, key, defaultValue, {
|
|
101
|
-
set(value:
|
|
104
|
+
set(value: IValue) {
|
|
102
105
|
this.__setAttr(key, value)
|
|
103
106
|
this.__layout.renderChanged || this.__layout.renderChange()
|
|
104
107
|
}
|
|
@@ -106,10 +109,10 @@ export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
export function surfaceType(defaultValue?:
|
|
112
|
+
export function surfaceType(defaultValue?: IValue) {
|
|
110
113
|
return (target: ILeaf, key: string) => {
|
|
111
114
|
defineLeafAttr(target, key, defaultValue, {
|
|
112
|
-
set(value:
|
|
115
|
+
set(value: IValue) {
|
|
113
116
|
this.__setAttr(key, value)
|
|
114
117
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
115
118
|
}
|
|
@@ -117,10 +120,10 @@ export function surfaceType(defaultValue?: __Value) {
|
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
export function opacityType(defaultValue?:
|
|
123
|
+
export function opacityType(defaultValue?: IValue) {
|
|
121
124
|
return (target: ILeaf, key: string) => {
|
|
122
125
|
defineLeafAttr(target, key, defaultValue, {
|
|
123
|
-
set(value:
|
|
126
|
+
set(value: IValue) {
|
|
124
127
|
this.__setAttr(key, value)
|
|
125
128
|
this.__layout.opacityChanged || this.__layout.opacityChange()
|
|
126
129
|
}
|
|
@@ -128,19 +131,19 @@ export function opacityType(defaultValue?: __Value) {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
export function sortType(defaultValue?:
|
|
134
|
+
export function sortType(defaultValue?: IValue) {
|
|
132
135
|
return (target: ILeaf, key: string) => {
|
|
133
136
|
defineLeafAttr(target, key, defaultValue, {
|
|
134
|
-
set(value:
|
|
137
|
+
set(value: IValue) {
|
|
135
138
|
this.__setAttr(key, value)
|
|
136
139
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
137
|
-
this.waitParent(() => { this.parent.__layout.
|
|
140
|
+
this.waitParent(() => { this.parent.__layout.childrenSortChange() })
|
|
138
141
|
}
|
|
139
142
|
})
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
export function maskType(defaultValue?:
|
|
146
|
+
export function maskType(defaultValue?: IValue) {
|
|
144
147
|
return (target: ILeaf, key: string) => {
|
|
145
148
|
defineLeafAttr(target, key, defaultValue, {
|
|
146
149
|
set(value: boolean) {
|
|
@@ -152,7 +155,7 @@ export function maskType(defaultValue?: __Value) {
|
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
|
|
155
|
-
export function eraserType(defaultValue?:
|
|
158
|
+
export function eraserType(defaultValue?: IValue) {
|
|
156
159
|
return (target: ILeaf, key: string) => {
|
|
157
160
|
defineLeafAttr(target, key, defaultValue, {
|
|
158
161
|
set(value: boolean) {
|
|
@@ -163,12 +166,24 @@ export function eraserType(defaultValue?: __Value) {
|
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
export function hitType(defaultValue?:
|
|
169
|
+
export function hitType(defaultValue?: IValue) {
|
|
167
170
|
return (target: ILeaf, key: string) => {
|
|
168
171
|
defineLeafAttr(target, key, defaultValue, {
|
|
169
|
-
set(value:
|
|
172
|
+
set(value: IValue) {
|
|
170
173
|
this.__setAttr(key, value)
|
|
171
174
|
if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
|
|
175
|
+
if (this.leafer) this.leafer.updateCursor()
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function cursorType(defaultValue?: IValue) {
|
|
182
|
+
return (target: ILeaf, key: string) => {
|
|
183
|
+
defineLeafAttr(target, key, defaultValue, {
|
|
184
|
+
set(value: IValue) {
|
|
185
|
+
this.__setAttr(key, value)
|
|
186
|
+
if (this.leafer) this.leafer.updateCursor()
|
|
172
187
|
}
|
|
173
188
|
})
|
|
174
189
|
}
|
|
@@ -178,7 +193,7 @@ export function hitType(defaultValue?: __Value) {
|
|
|
178
193
|
// get
|
|
179
194
|
|
|
180
195
|
export function dataProcessor(processor: IObject) {
|
|
181
|
-
return (target:
|
|
196
|
+
return (target: IObject, _key?: string) => {
|
|
182
197
|
defineKey(target, '__DataProcessor', {
|
|
183
198
|
get() { return processor }
|
|
184
199
|
})
|
|
@@ -186,7 +201,7 @@ export function dataProcessor(processor: IObject) {
|
|
|
186
201
|
}
|
|
187
202
|
|
|
188
203
|
export function layoutProcessor(processor: IObject) {
|
|
189
|
-
return (target:
|
|
204
|
+
return (target: IObject, _key?: string) => {
|
|
190
205
|
defineKey(target, '__LayoutProcessor', {
|
|
191
206
|
get() { return processor }
|
|
192
207
|
})
|
|
@@ -200,24 +215,21 @@ function getSetMethodName(key: string): string {
|
|
|
200
215
|
return 'set' + key.charAt(0).toUpperCase() + key.slice(1)
|
|
201
216
|
}
|
|
202
217
|
|
|
203
|
-
export function setDefaultValue(target: IObject, key: string, defaultValue: __Value): void {
|
|
204
|
-
defineDataProcessor(target.prototype, key, defaultValue)
|
|
205
|
-
}
|
|
206
218
|
|
|
207
219
|
// define leaf.__[key] getter/setter
|
|
208
|
-
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?:
|
|
220
|
+
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue): void {
|
|
209
221
|
|
|
210
|
-
const data = target.__DataProcessor.prototype
|
|
222
|
+
const data = target.__DataProcessor.prototype
|
|
211
223
|
const computedKey = '_' + key
|
|
212
224
|
const setMethodName = getSetMethodName(key)
|
|
213
225
|
|
|
214
226
|
const property: IObject & ThisType<ILeafData> = {
|
|
215
227
|
get() {
|
|
216
|
-
const v = this[computedKey]
|
|
228
|
+
const v = (this as IObject)[computedKey]
|
|
217
229
|
return v === undefined ? defaultValue : v
|
|
218
230
|
},
|
|
219
|
-
set(value:
|
|
220
|
-
this[computedKey] = value
|
|
231
|
+
set(value: IValue) {
|
|
232
|
+
(this as IObject)[computedKey] = value
|
|
221
233
|
},
|
|
222
234
|
configurable: true,
|
|
223
235
|
enumerable: true
|
|
@@ -237,12 +249,17 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: _
|
|
|
237
249
|
}
|
|
238
250
|
}
|
|
239
251
|
|
|
240
|
-
|
|
252
|
+
// find parent proto
|
|
253
|
+
let descriptor, find = data
|
|
254
|
+
while (!descriptor && find) {
|
|
255
|
+
descriptor = getDescriptor(find, key)
|
|
256
|
+
find = find.__proto__
|
|
257
|
+
}
|
|
241
258
|
|
|
242
|
-
if (descriptor && descriptor.set) property.set = descriptor.set // use
|
|
259
|
+
if (descriptor && descriptor.set) property.set = descriptor.set // use exist set
|
|
243
260
|
|
|
244
261
|
if (data[setMethodName]) {
|
|
245
|
-
property.set = data[setMethodName] //
|
|
262
|
+
property.set = data[setMethodName] // first use custom setKey(value)
|
|
246
263
|
delete data[setMethodName]
|
|
247
264
|
}
|
|
248
265
|
|
package/src/define.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { defineLeafAttr, dataType, positionType, autoLayoutType, boundsType, affectStrokeBoundsType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, sortType, maskType, eraserType, hitType, pathType, cursorType, dataProcessor, layoutProcessor, 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/types/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ILeaf, IValue, IObject, IFunction } from '@leafer/interface';
|
|
2
|
+
|
|
3
|
+
declare function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, mergeDescriptor?: IObject & ThisType<ILeaf>): void;
|
|
4
|
+
declare function dataType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
5
|
+
declare function positionType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
6
|
+
declare function autoLayoutType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
7
|
+
declare function scaleType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
8
|
+
declare function rotationType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
9
|
+
declare function boundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
10
|
+
declare const pathType: typeof boundsType;
|
|
11
|
+
declare function affectStrokeBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
12
|
+
declare const strokeType: typeof affectStrokeBoundsType;
|
|
13
|
+
declare function affectRenderBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
14
|
+
declare function surfaceType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
15
|
+
declare function opacityType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
16
|
+
declare function sortType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
17
|
+
declare function maskType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
18
|
+
declare function eraserType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
19
|
+
declare function hitType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
20
|
+
declare function cursorType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
21
|
+
declare function dataProcessor(processor: IObject): (target: IObject, _key?: string) => void;
|
|
22
|
+
declare function layoutProcessor(processor: IObject): (target: IObject, _key?: string) => void;
|
|
23
|
+
declare function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue): void;
|
|
24
|
+
|
|
25
|
+
declare function rewrite(method: IFunction): (target: IObject, key: string) => void;
|
|
26
|
+
declare function rewriteAble(): (_target: IObject) => void;
|
|
27
|
+
declare function useModule(module: IObject, exclude?: string[]): (target: IObject) => void;
|
|
28
|
+
|
|
29
|
+
declare function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>): void;
|
|
30
|
+
declare function getDescriptor(object: IObject, name: string): PropertyDescriptor;
|
|
31
|
+
|
|
32
|
+
declare function registerUI(): (target: IObject) => void;
|
|
33
|
+
declare function registerUIEvent(): (target: IObject) => void;
|
|
34
|
+
|
|
35
|
+
export { affectRenderBoundsType, affectStrokeBoundsType, autoLayoutType, boundsType, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, eraserType, getDescriptor, hitType, layoutProcessor, maskType, opacityType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule };
|