@leafer/display-module 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.
- package/package.json +6 -6
- package/src/LeafBounds.ts +1 -0
- package/src/LeafDataProxy.ts +15 -4
- package/src/LeafEventer.ts +4 -152
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "@leafer/display-module",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/helper": "1.0.
|
|
26
|
-
"@leafer/event": "1.0.
|
|
27
|
-
"@leafer/math": "1.0.
|
|
28
|
-
"@leafer/debug": "1.0.
|
|
25
|
+
"@leafer/helper": "1.0.3",
|
|
26
|
+
"@leafer/event": "1.0.3",
|
|
27
|
+
"@leafer/math": "1.0.3",
|
|
28
|
+
"@leafer/debug": "1.0.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@leafer/interface": "1.0.
|
|
31
|
+
"@leafer/interface": "1.0.3"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/LeafBounds.ts
CHANGED
|
@@ -98,6 +98,7 @@ export const LeafBounds: ILeafBoundsModule = {
|
|
|
98
98
|
},
|
|
99
99
|
|
|
100
100
|
__updateLocalBoxBounds(): void {
|
|
101
|
+
if (this.__hasMotionPath) this.__updateMotionPath()
|
|
101
102
|
if (this.__hasAutoLayout) this.__updateAutoLayout() // origin / around / flow
|
|
102
103
|
toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
|
|
103
104
|
},
|
package/src/LeafDataProxy.ts
CHANGED
|
@@ -18,8 +18,8 @@ export const LeafDataProxy: ILeafDataProxyModule = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if (typeof newValue === 'object' || oldValue !== newValue) {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
this.__realSetAttr(name, newValue)
|
|
23
23
|
|
|
24
24
|
const { CHANGE } = PropertyEvent
|
|
25
25
|
const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue)
|
|
@@ -31,18 +31,29 @@ export const LeafDataProxy: ILeafDataProxyModule = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
this.leafer.emitEvent(event)
|
|
34
|
+
|
|
34
35
|
return true
|
|
35
36
|
} else {
|
|
36
37
|
return false
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
} else {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
this.__realSetAttr(name, newValue)
|
|
43
|
+
|
|
42
44
|
return true
|
|
45
|
+
|
|
43
46
|
}
|
|
44
47
|
},
|
|
45
48
|
|
|
49
|
+
__realSetAttr(name: string, newValue: IValue): void {
|
|
50
|
+
const data = this.__ as IObject
|
|
51
|
+
data[name] = newValue
|
|
52
|
+
if (this.__proxyData) this.setProxyAttr(name, newValue)
|
|
53
|
+
if (data.normalStyle) this.lockNormalStyle || data.normalStyle[name] === undefined || (data.normalStyle[name] = newValue)
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
|
|
46
57
|
__getAttr(name: string): IValue {
|
|
47
58
|
if (this.__proxyData) return this.getProxyAttr(name)
|
|
48
59
|
return this.__.__get(name)
|
package/src/LeafEventer.ts
CHANGED
|
@@ -1,154 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ILeafEventerModule } from '@leafer/interface'
|
|
2
|
+
import { Eventer } from '@leafer/event'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const { on, on_, off, off_, once, emit, emitEvent, hasEvent, destroy } = Eventer.prototype
|
|
5
5
|
|
|
6
|
-
export const LeafEventer: ILeafEventerModule = {
|
|
7
|
-
|
|
8
|
-
on(type: string | string[], listener: IEventListener, options?: IEventOption): void {
|
|
9
|
-
let capture: boolean, once: boolean
|
|
10
|
-
if (options) {
|
|
11
|
-
if (options === 'once') {
|
|
12
|
-
once = true
|
|
13
|
-
} else if (typeof options === 'boolean') {
|
|
14
|
-
capture = options
|
|
15
|
-
} else {
|
|
16
|
-
capture = options.capture
|
|
17
|
-
once = options.once
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let events: IEventListenerItem[]
|
|
22
|
-
const map = __getListenerMap(this, capture, true)
|
|
23
|
-
const typeList = typeof type === 'string' ? type.split(' ') : type
|
|
24
|
-
const item = once ? { listener, once } : { listener }
|
|
25
|
-
|
|
26
|
-
typeList.forEach(type => {
|
|
27
|
-
if (type) {
|
|
28
|
-
events = map[type]
|
|
29
|
-
if (events) {
|
|
30
|
-
if (events.findIndex(item => item.listener === listener) === -1) events.push(item)
|
|
31
|
-
} else {
|
|
32
|
-
map[type] = [item]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
off(type?: string | string[], listener?: IEventListener, options?: IEventOption): void {
|
|
39
|
-
if (type) {
|
|
40
|
-
|
|
41
|
-
const typeList = typeof type === 'string' ? type.split(' ') : type
|
|
42
|
-
|
|
43
|
-
if (listener) {
|
|
44
|
-
|
|
45
|
-
let capture: boolean
|
|
46
|
-
if (options) capture = typeof options === 'boolean' ? options : (options === 'once' ? false : options.capture)
|
|
47
|
-
|
|
48
|
-
let events: IEventListenerItem[], index: number
|
|
49
|
-
const map = __getListenerMap(this, capture)
|
|
50
|
-
|
|
51
|
-
typeList.forEach(type => {
|
|
52
|
-
if (type) {
|
|
53
|
-
events = map[type]
|
|
54
|
-
if (events) {
|
|
55
|
-
index = events.findIndex(item => item.listener === listener)
|
|
56
|
-
if (index > -1) events.splice(index, 1)
|
|
57
|
-
if (!events.length) delete map[type]
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
} else {
|
|
63
|
-
|
|
64
|
-
// off type
|
|
65
|
-
const { __bubbleMap: b, __captureMap: c } = this
|
|
66
|
-
typeList.forEach(type => {
|
|
67
|
-
if (b) delete b[type]
|
|
68
|
-
if (c) delete c[type]
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
|
|
75
|
-
this.__bubbleMap = this.__captureMap = undefined // off all
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventOption): IEventListenerId {
|
|
82
|
-
if (bind) listener = listener.bind(bind)
|
|
83
|
-
this.on(type, listener, options)
|
|
84
|
-
return { type, current: this, listener, options }
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
off_(id: IEventListenerId | IEventListenerId[]): void {
|
|
88
|
-
if (!id) return
|
|
89
|
-
const list = id instanceof Array ? id : [id]
|
|
90
|
-
list.forEach(item => item.current.off(item.type, item.listener, item.options))
|
|
91
|
-
list.length = 0
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
once(type: string | string[], listener: IEventListener, capture?: boolean): void {
|
|
95
|
-
this.on(type, listener, { once: true, capture })
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
emit(type: string, event?: IEvent | IObject, capture?: boolean): void {
|
|
99
|
-
if (!event && EventCreator.has(type)) event = EventCreator.get(type, { type, target: this, current: this } as IEvent)
|
|
100
|
-
|
|
101
|
-
const map = __getListenerMap(this, capture)
|
|
102
|
-
const list = map[type]
|
|
103
|
-
if (list) {
|
|
104
|
-
let item: IEventListenerItem
|
|
105
|
-
for (let i = 0, len = list.length; i < len; i++) {
|
|
106
|
-
item = list[i]
|
|
107
|
-
item.listener(event)
|
|
108
|
-
if (item.once) {
|
|
109
|
-
this.off(type, item.listener, capture)
|
|
110
|
-
i--, len--
|
|
111
|
-
}
|
|
112
|
-
if (event && (event as IEvent).isStopNow) break
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
this.syncEventer && this.syncEventer.emitEvent(event, capture)
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
emitEvent(event: IEvent, capture?: boolean): void {
|
|
120
|
-
event.current = this
|
|
121
|
-
this.emit(event.type, event, capture)
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
hasEvent(type: string, capture?: boolean): boolean {
|
|
125
|
-
if (this.syncEventer && this.syncEventer.hasEvent(type, capture)) return true
|
|
126
|
-
|
|
127
|
-
const { __bubbleMap: b, __captureMap: c } = this
|
|
128
|
-
const hasB = b && b[type], hasC = c && c[type]
|
|
129
|
-
return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB))
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function __getListenerMap(eventer: IEventTarget, capture?: boolean, create?: boolean): IEventListenerMap {
|
|
135
|
-
if (capture) {
|
|
136
|
-
|
|
137
|
-
const { __captureMap: c } = eventer
|
|
138
|
-
if (c) {
|
|
139
|
-
return c
|
|
140
|
-
} else {
|
|
141
|
-
return create ? eventer.__captureMap = {} : empty
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
} else {
|
|
145
|
-
|
|
146
|
-
const { __bubbleMap: b } = eventer
|
|
147
|
-
if (b) {
|
|
148
|
-
return b
|
|
149
|
-
} else {
|
|
150
|
-
return create ? eventer.__bubbleMap = {} : empty
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
}
|
|
6
|
+
export const LeafEventer: ILeafEventerModule = { on, on_, off, off_, once, emit, emitEvent, hasEvent, destroyEventer: destroy }
|