@leafer/event 1.8.0 → 1.9.1

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/event",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "@leafer/event",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,12 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/decorator": "1.8.0",
26
- "@leafer/math": "1.8.0",
27
- "@leafer/platform": "1.8.0"
25
+ "@leafer/decorator": "1.9.1",
26
+ "@leafer/math": "1.9.1",
27
+ "@leafer/data": "1.9.1",
28
+ "@leafer/platform": "1.9.1"
28
29
  },
29
30
  "devDependencies": {
30
- "@leafer/interface": "1.8.0"
31
+ "@leafer/interface": "1.9.1"
31
32
  }
32
33
  }
package/src/Eventer.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IEventListener, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, IEventOption, IEventer, IEventParamsMap, InnerId, IEventParams, IFunction } from '@leafer/interface'
2
2
  import { EventCreator } from '@leafer/platform'
3
+ import { isArray, isObject, isString, isUndefined } from '@leafer/data'
3
4
 
4
5
  import { BoundsEvent, boundsEventMap } from './BoundsEvent'
5
6
 
@@ -27,8 +28,8 @@ export class Eventer implements IEventer {
27
28
 
28
29
  if (!listener) {
29
30
  let event: IFunction | [IFunction, IEventOption]
30
- if (type instanceof Array) (type as IEventParams[]).forEach(item => this.on(item[0], item[1], item[2]))
31
- else for (let key in type as IEventParamsMap) (event = (type as IEventParamsMap)[key]) instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event)
31
+ if (isArray(type)) (type as IEventParams[]).forEach(item => this.on(item[0], item[1], item[2]))
32
+ else for (let key in type as IEventParamsMap) isArray(event = (type as IEventParamsMap)[key]) ? this.on(key, event[0], event[1]) : this.on(key, event)
32
33
  return
33
34
  }
34
35
 
@@ -46,7 +47,7 @@ export class Eventer implements IEventer {
46
47
 
47
48
  let events: IEventListenerItem[]
48
49
  const map = __getListenerMap(this, capture, true)
49
- const typeList = typeof type === 'string' ? type.split(' ') : type as string[]
50
+ const typeList = isString(type) ? type.split(' ') : type as string[]
50
51
  const item = once ? { listener, once } : { listener }
51
52
 
52
53
  typeList.forEach(type => {
@@ -66,7 +67,7 @@ export class Eventer implements IEventer {
66
67
  public off(type?: string | string[], listener?: IEventListener, options?: IEventOption): void {
67
68
  if (type) {
68
69
 
69
- const typeList = typeof type === 'string' ? type.split(' ') : type
70
+ const typeList = isString(type) ? type.split(' ') : type
70
71
 
71
72
  if (listener) {
72
73
 
@@ -108,24 +109,24 @@ export class Eventer implements IEventer {
108
109
  }
109
110
 
110
111
  public on_(type: string | string[] | IEventParams[], listener?: IEventListener, bind?: IObject, options?: IEventOption): IEventListenerId {
111
- if (!listener) (type instanceof Array) && (type as IEventParams[]).forEach(item => this.on(item[0], item[2] ? item[1] = item[1].bind(item[2]) : item[1], item[3]))
112
+ if (!listener) isArray(type) && (type as IEventParams[]).forEach(item => this.on(item[0], item[2] ? item[1] = item[1].bind(item[2]) : item[1], item[3]))
112
113
  else this.on(type, bind ? listener = listener.bind(bind) : listener, options)
113
114
  return { type, current: this as any, listener, options }
114
115
  }
115
116
 
116
117
  public off_(id: IEventListenerId | IEventListenerId[]): void {
117
118
  if (!id) return
118
- const list = id instanceof Array ? id : [id]
119
+ const list = isArray(id) ? id : [id]
119
120
  list.forEach(item => {
120
- if (!item.listener) (item.type instanceof Array) && (item.type as IEventParams[]).forEach(v => item.current.off(v[0], v[1], v[3]))
121
+ if (!item.listener) isArray(item.type) && (item.type as IEventParams[]).forEach(v => item.current.off(v[0], v[1], v[3]))
121
122
  else item.current.off(item.type as string | string[], item.listener, item.options)
122
123
  })
123
124
  list.length = 0
124
125
  }
125
126
 
126
127
  public once(type: string | string[] | IEventParams[], listener?: IEventListener, captureOrBind?: boolean | IObject, capture?: boolean): void {
127
- if (!listener) return (type instanceof Array) && (type as IEventParams[]).forEach(item => this.once(item[0], item[1], item[2], item[3]))
128
- if (typeof captureOrBind === 'object') listener = listener.bind(captureOrBind)
128
+ if (!listener) return isArray(type) && (type as IEventParams[]).forEach(item => this.once(item[0], item[1], item[2], item[3]))
129
+ if (isObject(captureOrBind)) listener = listener.bind(captureOrBind)
129
130
  else capture = captureOrBind
130
131
  this.on(type, listener, { once: true, capture })
131
132
  }
@@ -162,7 +163,7 @@ export class Eventer implements IEventer {
162
163
 
163
164
  const { __bubbleMap: b, __captureMap: c } = this
164
165
  const hasB = b && b[type], hasC = c && c[type]
165
- return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB))
166
+ return !!(isUndefined(capture) ? (hasB || hasC) : (capture ? hasC : hasB))
166
167
  }
167
168
 
168
169
  public destroy(): void {
@@ -1,4 +1,4 @@
1
- import { ILeaferEvent } from '@leafer/interface'
1
+ import { ILeaferEvent, IStringMap } from '@leafer/interface'
2
2
 
3
3
  import { Event } from './Event'
4
4
 
@@ -20,4 +20,23 @@ export class LeaferEvent extends Event implements ILeaferEvent {
20
20
 
21
21
  static END = 'leafer.end'
22
22
 
23
+ // 变换操作
24
+ static TRANSFORM = 'leafer.transform'
25
+ static MOVE = 'leafer.move'
26
+ static SCALE = 'leafer.scale'
27
+ static ROTATE = 'leafer.rotate'
28
+ static SKEW = 'leafer.skew'
29
+ }
30
+
31
+
32
+ const { MOVE, SCALE, ROTATE, SKEW } = LeaferEvent
33
+
34
+ export const leaferTransformAttrMap: IStringMap = {
35
+ x: MOVE,
36
+ y: MOVE,
37
+ scaleX: SCALE,
38
+ scaleY: SCALE,
39
+ rotation: ROTATE,
40
+ skewX: SKEW,
41
+ skewY: SKEW
23
42
  }
@@ -1,4 +1,5 @@
1
1
  import { ILeaf, INumberMap, IResizeEvent, IScreenSizeData } from '@leafer/interface'
2
+ import { isObject, isUndefined } from '@leafer/data'
2
3
 
3
4
  import { Event } from './Event'
4
5
 
@@ -31,7 +32,7 @@ export class ResizeEvent extends Event implements IResizeEvent {
31
32
  readonly old: IScreenSizeData
32
33
 
33
34
  constructor(size: IScreenSizeData | string, oldSize?: IScreenSizeData) {
34
- if (typeof size === 'object') {
35
+ if (isObject(size)) {
35
36
  super(ResizeEvent.RESIZE)
36
37
  Object.assign(this, size)
37
38
  } else {
@@ -41,7 +42,7 @@ export class ResizeEvent extends Event implements IResizeEvent {
41
42
  }
42
43
 
43
44
  static isResizing(leaf: ILeaf): boolean {
44
- return this.resizingKeys && this.resizingKeys[leaf.innerId] !== undefined
45
+ return this.resizingKeys && !isUndefined(this.resizingKeys[leaf.innerId])
45
46
  }
46
47
 
47
48
  }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ export { ResizeEvent } from './ResizeEvent'
6
6
  export { WatchEvent } from './WatchEvent'
7
7
  export { LayoutEvent } from './LayoutEvent'
8
8
  export { RenderEvent } from './RenderEvent'
9
- export { LeaferEvent } from './LeaferEvent'
9
+ export { LeaferEvent, leaferTransformAttrMap } from './LeaferEvent'
10
10
 
11
11
  export { Event } from './Event'
12
12
  export { Eventer } from './Eventer'
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IEvent, IObject, IEventTarget, IChildEvent, ILeaf, IPropertyEvent, IImageEvent, ILeaferImage, IBoundsEvent, IResizeEvent, INumberMap, IScreenSizeData, IWatchEvent, IWatchEventData, ILayoutEvent, ILayoutBlockData, IRenderEvent, IBounds, IRenderOptions, ILeaferEvent, IEventer, InnerId, IEventListenerMap, IEventParamsMap, IEventParams, IEventListener, IEventOption, IEventListenerId } from '@leafer/interface';
1
+ import { IEvent, IObject, IEventTarget, IChildEvent, ILeaf, IPropertyEvent, IImageEvent, ILeaferImage, IBoundsEvent, IResizeEvent, INumberMap, IScreenSizeData, IWatchEvent, IWatchEventData, ILayoutEvent, ILayoutBlockData, IRenderEvent, IBounds, IRenderOptions, ILeaferEvent, IStringMap, IEventer, InnerId, IEventListenerMap, IEventParamsMap, IEventParams, IEventListener, IEventOption, IEventListenerId } from '@leafer/interface';
2
2
 
3
3
  declare class Event implements IEvent {
4
4
  readonly origin: IObject;
@@ -119,7 +119,13 @@ declare class LeaferEvent extends Event implements ILeaferEvent {
119
119
  static STOP: string;
120
120
  static RESTART: string;
121
121
  static END: string;
122
+ static TRANSFORM: string;
123
+ static MOVE: string;
124
+ static SCALE: string;
125
+ static ROTATE: string;
126
+ static SKEW: string;
122
127
  }
128
+ declare const leaferTransformAttrMap: IStringMap;
123
129
 
124
130
  declare class Eventer implements IEventer {
125
131
  readonly innerId: InnerId;
@@ -140,4 +146,4 @@ declare class Eventer implements IEventer {
140
146
  destroy(): void;
141
147
  }
142
148
 
143
- export { BoundsEvent, ChildEvent, Event, Eventer, ImageEvent, LayoutEvent, LeaferEvent, PropertyEvent, RenderEvent, ResizeEvent, WatchEvent };
149
+ export { BoundsEvent, ChildEvent, Event, Eventer, ImageEvent, LayoutEvent, LeaferEvent, PropertyEvent, RenderEvent, ResizeEvent, WatchEvent, leaferTransformAttrMap };