@leafer/decorator 1.6.7 → 1.8.0

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.6.7",
3
+ "version": "1.8.0",
4
4
  "description": "@leafer/decorator",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/platform": "1.6.7",
26
- "@leafer/data": "1.6.7",
27
- "@leafer/debug": "1.6.7"
25
+ "@leafer/platform": "1.8.0",
26
+ "@leafer/data": "1.8.0",
27
+ "@leafer/debug": "1.8.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.6.7"
30
+ "@leafer/interface": "1.8.0"
31
31
  }
32
32
  }
package/src/data.ts CHANGED
@@ -2,7 +2,7 @@ import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescri
2
2
  import { DataHelper, isEmptyData } from '@leafer/data'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
5
- import { defineKey, getDescriptor } from './object'
5
+ import { defineKey, getDescriptor, createDescriptor } from './object'
6
6
 
7
7
 
8
8
  // name
@@ -104,10 +104,13 @@ export function pathInputType(defaultValue?: IValue) {
104
104
  export const pathType = boundsType
105
105
 
106
106
 
107
- export function affectStrokeBoundsType(defaultValue?: IValue) {
107
+ export function affectStrokeBoundsType(defaultValue?: IValue, useStroke?: boolean) {
108
108
  return decorateLeafAttr(defaultValue, (key: string) => attr({
109
109
  set(value: IValue) {
110
- this.__setAttr(key, value) && doStrokeType(this)
110
+ if (this.__setAttr(key, value)) {
111
+ doStrokeType(this)
112
+ if (useStroke) this.__.__useStroke = true
113
+ }
111
114
  }
112
115
  }))
113
116
  }
@@ -261,15 +264,7 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
261
264
  const computedKey = '_' + key
262
265
  const setMethodName = getSetMethodName(key)
263
266
 
264
- const property: IObject & ThisType<ILeafData> = {
265
- get() {
266
- const v = (this as IObject)[computedKey]
267
- return v === undefined ? defaultValue : v
268
- },
269
- set(value: IValue) {
270
- (this as IObject)[computedKey] = value
271
- }
272
- }
267
+ const property: IObject & ThisType<ILeafData> = createDescriptor(key, defaultValue)
273
268
 
274
269
  if (defaultValue === undefined) {
275
270
  property.get = function () { return this[computedKey] }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { defineLeafAttr, decorateLeafAttr, attr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, hitType, pathType, pathInputType, cursorType, dataProcessor, layoutProcessor, defineDataProcessor } from './data'
2
2
  export { useModule, rewrite, rewriteAble } from './rewrite'
3
- export { defineKey, getDescriptor } from './object'
3
+ export { defineKey, getDescriptor, createDescriptor } from './object'
4
4
  export { registerUI, registerUIEvent } from './class'
package/src/object.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IObject } from '@leafer/interface'
1
+ import { IObject, IValue } from '@leafer/interface'
2
2
 
3
3
  export function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void {
4
4
  if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true
@@ -9,6 +9,14 @@ export function getDescriptor(object: IObject, name: string) {
9
9
  return Object.getOwnPropertyDescriptor(object, name)
10
10
  }
11
11
 
12
+ export function createDescriptor(key: string, defaultValue?: IValue) {
13
+ const privateKey = '_' + key
14
+ return {
15
+ get() { const v = (this as IObject)[privateKey]; return v === undefined ? defaultValue : v },
16
+ set(value: IValue) { (this as IObject)[privateKey] = value }
17
+ }
18
+ }
19
+
12
20
  export function getNames(object: IObject): string[] {
13
21
  return Object.getOwnPropertyNames(object)
14
22
  }
package/types/index.d.ts CHANGED
@@ -13,7 +13,7 @@ declare function naturalBoundsType(defaultValue?: IValue): (target: ILeaf, key:
13
13
  declare function doBoundsType(leaf: ILeaf): void;
14
14
  declare function pathInputType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
15
15
  declare const pathType: typeof boundsType;
16
- declare function affectStrokeBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
16
+ declare function affectStrokeBoundsType(defaultValue?: IValue, useStroke?: boolean): (target: ILeaf, key: string) => void;
17
17
  declare function doStrokeType(leaf: ILeaf): void;
18
18
  declare const strokeType: typeof affectStrokeBoundsType;
19
19
  declare function affectRenderBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
@@ -35,8 +35,12 @@ declare function useModule(module: IObject, exclude?: string[]): (target: IObjec
35
35
 
36
36
  declare function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void;
37
37
  declare function getDescriptor(object: IObject, name: string): PropertyDescriptor;
38
+ declare function createDescriptor(key: string, defaultValue?: IValue): {
39
+ get(): any;
40
+ set(value: IValue): void;
41
+ };
38
42
 
39
43
  declare function registerUI(): (target: IObject) => void;
40
44
  declare function registerUIEvent(): (target: IObject) => void;
41
45
 
42
- export { affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule, visibleType };
46
+ export { affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule, visibleType };