@leafer/platform 1.0.0-alpha.21 → 1.0.0-alpha.23

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/platform",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "@leafer/platform",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,9 +19,9 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/debug": "1.0.0-alpha.21"
22
+ "@leafer/debug": "1.0.0-alpha.23"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.21"
25
+ "@leafer/interface": "1.0.0-alpha.23"
26
26
  }
27
27
  }
@@ -1,17 +1,5 @@
1
- import { ICreator, IObject, IEvent, ILeaf } from '@leafer/interface'
2
-
3
- import { EventCreator } from './EventCreator'
4
- import { UICreator } from './UICreator'
5
-
1
+ import { ICreator } from '@leafer/interface'
6
2
 
7
3
  export const Creator: ICreator = {
8
4
 
9
- ui(tag: string, data?: IObject): ILeaf {
10
- return UICreator.get(tag, data)
11
- },
12
-
13
- event(type: string, ...params: unknown[]): IEvent {
14
- return EventCreator.get(type, ...params)
15
- }
16
-
17
5
  }
@@ -6,20 +6,31 @@ const debug = Debug.get('EventCreator')
6
6
 
7
7
  export const EventCreator = {
8
8
 
9
- typeList: {} as IObject,
9
+ nameList: {} as IObject,
10
10
 
11
11
  register(Event: IObject): void {
12
- let type: string
12
+ let name: string
13
13
  Object.keys(Event).forEach(key => {
14
- type = Event[key]
15
- if (typeof type === 'string') typeList[type] ? debug.error('register the repeat EventType: ', type) : typeList[type] = Event
14
+ name = Event[key]
15
+ if (typeof name === 'string') nameList[name] ? debug.error('register the repeat EventType: ', name) : nameList[name] = Event
16
16
  })
17
17
  },
18
18
 
19
+ changeName(oldName: string, newName: string): void {
20
+ const Event = nameList[oldName]
21
+ if (Event) {
22
+ const constName = Object.keys(Event).find(key => Event[key] === oldName)
23
+ if (constName) {
24
+ Event[constName] = newName
25
+ nameList[newName] = Event
26
+ }
27
+ }
28
+ },
29
+
19
30
  get(type: string, ...params: unknown[]): IEvent {
20
- return new typeList[type](...params)
31
+ return new nameList[type](...params)
21
32
  }
22
33
 
23
34
  }
24
35
 
25
- const { typeList } = EventCreator
36
+ const { nameList } = EventCreator
@@ -9,7 +9,7 @@ export const UICreator = {
9
9
  list: {} as IObject,
10
10
 
11
11
  register(UI: IObject): void {
12
- const { tag } = UI.prototype as ILeaf
12
+ const { __tag: tag } = UI.prototype as ILeaf
13
13
  if (list[tag]) {
14
14
  debug.error('register the repeat UI: ', tag)
15
15
  } else {
@@ -17,8 +17,15 @@ export const UICreator = {
17
17
  }
18
18
  },
19
19
 
20
- get(tag: string, data: IObject): ILeaf {
21
- return new list[tag](data)
20
+ get(tag: string, data: IObject, x?: number, y?: number, width?: number, height?: number): ILeaf {
21
+ const ui = new list[tag](data)
22
+ if (x !== undefined) {
23
+ ui.x = x
24
+ if (y) ui.y = y
25
+ if (width) ui.width = width
26
+ if (height) ui.height = height
27
+ }
28
+ return ui
22
29
  }
23
30
 
24
31
  }