@leafer/decorator 1.0.0-rc.1 → 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 +4 -4
- package/src/data.ts +58 -54
- package/src/define.ts +1 -1
- package/src/index.ts +1 -1
- package/types/index.d.ts +21 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/decorator",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"description": "@leafer/decorator",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/platform": "1.0.0-rc.
|
|
26
|
-
"@leafer/debug": "1.0.0-rc.
|
|
25
|
+
"@leafer/platform": "1.0.0-rc.10",
|
|
26
|
+
"@leafer/debug": "1.0.0-rc.10"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.10"
|
|
30
30
|
}
|
|
31
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,13 +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()
|
|
77
|
-
if (this.
|
|
79
|
+
if (this.__hasAutoLayout) this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
78
80
|
}
|
|
79
81
|
})
|
|
80
82
|
}
|
|
@@ -83,10 +85,10 @@ export function boundsType(defaultValue?: __Value) {
|
|
|
83
85
|
export const pathType = boundsType
|
|
84
86
|
|
|
85
87
|
|
|
86
|
-
export function affectStrokeBoundsType(defaultValue?:
|
|
88
|
+
export function affectStrokeBoundsType(defaultValue?: IValue) {
|
|
87
89
|
return (target: ILeaf, key: string) => {
|
|
88
90
|
defineLeafAttr(target, key, defaultValue, {
|
|
89
|
-
set(value:
|
|
91
|
+
set(value: IValue) {
|
|
90
92
|
this.__setAttr(key, value)
|
|
91
93
|
this.__layout.strokeChanged || this.__layout.strokeChange()
|
|
92
94
|
}
|
|
@@ -96,10 +98,10 @@ export function affectStrokeBoundsType(defaultValue?: __Value) {
|
|
|
96
98
|
|
|
97
99
|
export const strokeType = affectStrokeBoundsType
|
|
98
100
|
|
|
99
|
-
export function affectRenderBoundsType(defaultValue?:
|
|
101
|
+
export function affectRenderBoundsType(defaultValue?: IValue) {
|
|
100
102
|
return (target: ILeaf, key: string) => {
|
|
101
103
|
defineLeafAttr(target, key, defaultValue, {
|
|
102
|
-
set(value:
|
|
104
|
+
set(value: IValue) {
|
|
103
105
|
this.__setAttr(key, value)
|
|
104
106
|
this.__layout.renderChanged || this.__layout.renderChange()
|
|
105
107
|
}
|
|
@@ -107,10 +109,10 @@ export function affectRenderBoundsType(defaultValue?: __Value) {
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
export function surfaceType(defaultValue?:
|
|
112
|
+
export function surfaceType(defaultValue?: IValue) {
|
|
111
113
|
return (target: ILeaf, key: string) => {
|
|
112
114
|
defineLeafAttr(target, key, defaultValue, {
|
|
113
|
-
set(value:
|
|
115
|
+
set(value: IValue) {
|
|
114
116
|
this.__setAttr(key, value)
|
|
115
117
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
116
118
|
}
|
|
@@ -118,10 +120,10 @@ export function surfaceType(defaultValue?: __Value) {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
export function opacityType(defaultValue?:
|
|
123
|
+
export function opacityType(defaultValue?: IValue) {
|
|
122
124
|
return (target: ILeaf, key: string) => {
|
|
123
125
|
defineLeafAttr(target, key, defaultValue, {
|
|
124
|
-
set(value:
|
|
126
|
+
set(value: IValue) {
|
|
125
127
|
this.__setAttr(key, value)
|
|
126
128
|
this.__layout.opacityChanged || this.__layout.opacityChange()
|
|
127
129
|
}
|
|
@@ -129,10 +131,10 @@ export function opacityType(defaultValue?: __Value) {
|
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
export function sortType(defaultValue?:
|
|
134
|
+
export function sortType(defaultValue?: IValue) {
|
|
133
135
|
return (target: ILeaf, key: string) => {
|
|
134
136
|
defineLeafAttr(target, key, defaultValue, {
|
|
135
|
-
set(value:
|
|
137
|
+
set(value: IValue) {
|
|
136
138
|
this.__setAttr(key, value)
|
|
137
139
|
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
138
140
|
this.waitParent(() => { this.parent.__layout.childrenSortChange() })
|
|
@@ -141,7 +143,7 @@ export function sortType(defaultValue?: __Value) {
|
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
export function maskType(defaultValue?:
|
|
146
|
+
export function maskType(defaultValue?: IValue) {
|
|
145
147
|
return (target: ILeaf, key: string) => {
|
|
146
148
|
defineLeafAttr(target, key, defaultValue, {
|
|
147
149
|
set(value: boolean) {
|
|
@@ -153,7 +155,7 @@ export function maskType(defaultValue?: __Value) {
|
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
export function eraserType(defaultValue?:
|
|
158
|
+
export function eraserType(defaultValue?: IValue) {
|
|
157
159
|
return (target: ILeaf, key: string) => {
|
|
158
160
|
defineLeafAttr(target, key, defaultValue, {
|
|
159
161
|
set(value: boolean) {
|
|
@@ -164,10 +166,10 @@ export function eraserType(defaultValue?: __Value) {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
export function hitType(defaultValue?:
|
|
169
|
+
export function hitType(defaultValue?: IValue) {
|
|
168
170
|
return (target: ILeaf, key: string) => {
|
|
169
171
|
defineLeafAttr(target, key, defaultValue, {
|
|
170
|
-
set(value:
|
|
172
|
+
set(value: IValue) {
|
|
171
173
|
this.__setAttr(key, value)
|
|
172
174
|
if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
|
|
173
175
|
if (this.leafer) this.leafer.updateCursor()
|
|
@@ -176,10 +178,10 @@ export function hitType(defaultValue?: __Value) {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
|
|
179
|
-
export function cursorType(defaultValue?:
|
|
181
|
+
export function cursorType(defaultValue?: IValue) {
|
|
180
182
|
return (target: ILeaf, key: string) => {
|
|
181
183
|
defineLeafAttr(target, key, defaultValue, {
|
|
182
|
-
set(value:
|
|
184
|
+
set(value: IValue) {
|
|
183
185
|
this.__setAttr(key, value)
|
|
184
186
|
if (this.leafer) this.leafer.updateCursor()
|
|
185
187
|
}
|
|
@@ -191,7 +193,7 @@ export function cursorType(defaultValue?: __Value) {
|
|
|
191
193
|
// get
|
|
192
194
|
|
|
193
195
|
export function dataProcessor(processor: IObject) {
|
|
194
|
-
return (target:
|
|
196
|
+
return (target: IObject, _key?: string) => {
|
|
195
197
|
defineKey(target, '__DataProcessor', {
|
|
196
198
|
get() { return processor }
|
|
197
199
|
})
|
|
@@ -199,7 +201,7 @@ export function dataProcessor(processor: IObject) {
|
|
|
199
201
|
}
|
|
200
202
|
|
|
201
203
|
export function layoutProcessor(processor: IObject) {
|
|
202
|
-
return (target:
|
|
204
|
+
return (target: IObject, _key?: string) => {
|
|
203
205
|
defineKey(target, '__LayoutProcessor', {
|
|
204
206
|
get() { return processor }
|
|
205
207
|
})
|
|
@@ -213,24 +215,21 @@ function getSetMethodName(key: string): string {
|
|
|
213
215
|
return 'set' + key.charAt(0).toUpperCase() + key.slice(1)
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
export function setDefaultValue(target: IObject, key: string, defaultValue: __Value): void {
|
|
217
|
-
defineDataProcessor(target.prototype, key, defaultValue)
|
|
218
|
-
}
|
|
219
218
|
|
|
220
219
|
// define leaf.__[key] getter/setter
|
|
221
|
-
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?:
|
|
220
|
+
export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue): void {
|
|
222
221
|
|
|
223
|
-
const data = target.__DataProcessor.prototype
|
|
222
|
+
const data = target.__DataProcessor.prototype
|
|
224
223
|
const computedKey = '_' + key
|
|
225
224
|
const setMethodName = getSetMethodName(key)
|
|
226
225
|
|
|
227
226
|
const property: IObject & ThisType<ILeafData> = {
|
|
228
227
|
get() {
|
|
229
|
-
const v = this[computedKey]
|
|
228
|
+
const v = (this as IObject)[computedKey]
|
|
230
229
|
return v === undefined ? defaultValue : v
|
|
231
230
|
},
|
|
232
|
-
set(value:
|
|
233
|
-
this[computedKey] = value
|
|
231
|
+
set(value: IValue) {
|
|
232
|
+
(this as IObject)[computedKey] = value
|
|
234
233
|
},
|
|
235
234
|
configurable: true,
|
|
236
235
|
enumerable: true
|
|
@@ -250,12 +249,17 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: _
|
|
|
250
249
|
}
|
|
251
250
|
}
|
|
252
251
|
|
|
253
|
-
|
|
252
|
+
// find parent proto
|
|
253
|
+
let descriptor, find = data
|
|
254
|
+
while (!descriptor && find) {
|
|
255
|
+
descriptor = getDescriptor(find, key)
|
|
256
|
+
find = find.__proto__
|
|
257
|
+
}
|
|
254
258
|
|
|
255
|
-
if (descriptor && descriptor.set) property.set = descriptor.set // use
|
|
259
|
+
if (descriptor && descriptor.set) property.set = descriptor.set // use exist set
|
|
256
260
|
|
|
257
261
|
if (data[setMethodName]) {
|
|
258
|
-
property.set = data[setMethodName] //
|
|
262
|
+
property.set = data[setMethodName] // first use custom setKey(value)
|
|
259
263
|
delete data[setMethodName]
|
|
260
264
|
}
|
|
261
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
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { ILeaf,
|
|
1
|
+
import { ILeaf, IValue, IObject, IFunction } from '@leafer/interface';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function scaleType(defaultValue?:
|
|
8
|
-
declare function rotationType(defaultValue?:
|
|
9
|
-
declare function boundsType(defaultValue?:
|
|
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
10
|
declare const pathType: typeof boundsType;
|
|
11
|
-
declare function affectStrokeBoundsType(defaultValue?:
|
|
11
|
+
declare function affectStrokeBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
12
12
|
declare const strokeType: typeof affectStrokeBoundsType;
|
|
13
|
-
declare function affectRenderBoundsType(defaultValue?:
|
|
14
|
-
declare function surfaceType(defaultValue?:
|
|
15
|
-
declare function opacityType(defaultValue?:
|
|
16
|
-
declare function sortType(defaultValue?:
|
|
17
|
-
declare function maskType(defaultValue?:
|
|
18
|
-
declare function eraserType(defaultValue?:
|
|
19
|
-
declare function hitType(defaultValue?:
|
|
20
|
-
declare function cursorType(defaultValue?:
|
|
21
|
-
declare function dataProcessor(processor: IObject): (target:
|
|
22
|
-
declare function layoutProcessor(processor: IObject): (target:
|
|
23
|
-
declare function
|
|
24
|
-
declare function defineDataProcessor(target: ILeaf, key: string, defaultValue?: __Value): void;
|
|
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;
|
|
25
24
|
|
|
26
25
|
declare function rewrite(method: IFunction): (target: IObject, key: string) => void;
|
|
27
26
|
declare function rewriteAble(): (_target: IObject) => void;
|
|
@@ -33,4 +32,4 @@ declare function getDescriptor(object: IObject, name: string): PropertyDescripto
|
|
|
33
32
|
declare function registerUI(): (target: IObject) => void;
|
|
34
33
|
declare function registerUIEvent(): (target: IObject) => void;
|
|
35
34
|
|
|
36
|
-
export { affectRenderBoundsType, affectStrokeBoundsType,
|
|
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 };
|