@leafer/platform 1.0.0-alpha.7 → 1.0.0-bate
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 +3 -3
- package/src/Platform.ts +2 -1
- package/src/creator/Creator.ts +1 -13
- package/src/creator/EventCreator.ts +17 -6
- package/src/creator/UICreator.ts +11 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/platform",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-bate",
|
|
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-
|
|
22
|
+
"@leafer/debug": "1.0.0-bate"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-
|
|
25
|
+
"@leafer/interface": "1.0.0-bate"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/Platform.ts
CHANGED
package/src/creator/Creator.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { ICreator
|
|
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
|
-
|
|
9
|
+
nameList: {} as IObject,
|
|
10
10
|
|
|
11
11
|
register(Event: IObject): void {
|
|
12
|
-
let
|
|
12
|
+
let name: string
|
|
13
13
|
Object.keys(Event).forEach(key => {
|
|
14
|
-
|
|
15
|
-
if (typeof
|
|
14
|
+
name = Event[key]
|
|
15
|
+
if (typeof name === 'string') nameList[name] ? debug.error('repeat: ', 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
|
|
31
|
+
return new nameList[type](...params)
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
const {
|
|
36
|
+
const { nameList } = EventCreator
|
package/src/creator/UICreator.ts
CHANGED
|
@@ -9,16 +9,23 @@ 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
|
-
debug.error('
|
|
14
|
+
debug.error('repeat:', tag)
|
|
15
15
|
} else {
|
|
16
16
|
list[tag] = UI
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
|
|
20
|
-
get(tag: string, data: IObject): ILeaf {
|
|
21
|
-
|
|
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
|
}
|