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