@leafer/decorator 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +5 -4
  2. package/src/data.ts +26 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/decorator",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "@leafer/decorator",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/platform": "1.0.2",
26
- "@leafer/debug": "1.0.2"
25
+ "@leafer/platform": "1.0.3",
26
+ "@leafer/data": "1.0.3",
27
+ "@leafer/debug": "1.0.3"
27
28
  },
28
29
  "devDependencies": {
29
- "@leafer/interface": "1.0.2"
30
+ "@leafer/interface": "1.0.3"
30
31
  }
31
32
  }
package/src/data.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn } from '@leafer/interface'
2
- import { defineKey, getDescriptor } from './object'
2
+ import { DataHelper } from '@leafer/data'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
5
+ import { defineKey, getDescriptor } from './object'
6
+
5
7
 
6
8
  // name
7
9
 
@@ -41,7 +43,7 @@ export function autoLayoutType(defaultValue?: IValue) {
41
43
  set(value: IValue) {
42
44
  if (this.__setAttr(key, value)) {
43
45
  this.__layout.matrixChanged || this.__layout.matrixChange()
44
- this.__hasAutoLayout = !!value
46
+ this.__hasAutoLayout = !!(this.origin || this.around || this.flow)
45
47
  if (!this.__local) this.__layout.createLocal()
46
48
  }
47
49
  }
@@ -146,14 +148,23 @@ export function visibleType(defaultValue?: IValue) {
146
148
  return decorateLeafAttr(defaultValue, (key: string) => attr({
147
149
  set(value: IValue) {
148
150
  const oldValue = this.visible
149
- if (this.__setAttr(key, value)) {
150
- this.__layout.opacityChanged || this.__layout.opacityChange()
151
- if (oldValue === 0 || value === 0) doBoundsType(this) // 0 = display: none
151
+ if (oldValue === true && value === 0) {
152
+ if (this.animationOut) return this.__runAnimation('out', () => doVisible(this, key, value, oldValue)) // hide
153
+ } else if (oldValue === 0 && value === true) {
154
+ if (this.animation) this.__runAnimation('in') // show
152
155
  }
156
+ doVisible(this, key, value, oldValue)
153
157
  }
154
158
  }))
155
159
  }
156
160
 
161
+ function doVisible(leaf: ILeaf, key: string, value: IValue, oldValue: IValue): void {
162
+ if (leaf.__setAttr(key, value)) {
163
+ leaf.__layout.opacityChanged || leaf.__layout.opacityChange()
164
+ if (oldValue === 0 || value === 0) doBoundsType(leaf) // 0 = display: none
165
+ }
166
+ }
167
+
157
168
  export function sortType(defaultValue?: IValue) {
158
169
  return decorateLeafAttr(defaultValue, (key: string) => attr({
159
170
  set(value: IValue) {
@@ -251,7 +262,16 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
251
262
 
252
263
  if (defaultValue === undefined) {
253
264
  property.get = function () { return this[computedKey] }
254
- } else if (key === 'width') {
265
+ } else if (typeof defaultValue === 'object') {
266
+ const { clone } = DataHelper
267
+ property.get = function () {
268
+ let v = this[computedKey]
269
+ if (v === undefined) this[computedKey] = v = clone(defaultValue)
270
+ return v
271
+ }
272
+ }
273
+
274
+ if (key === 'width') {
255
275
  property.get = function () {
256
276
  const v = this[computedKey]
257
277
  if (v === undefined) {