@leafer-ui/app 1.0.0-alpha.1 → 1.0.0-alpha.10
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 +8 -7
- package/src/App.ts +86 -0
- package/src/Leafer.ts +34 -37
- package/src/index.ts +1 -1
- package/src/SuperLeafer.ts +0 -68
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/app",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
4
4
|
"description": "@leafer-ui/app",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "https://github.com/leaferjs/ui.git"
|
|
@@ -13,16 +15,15 @@
|
|
|
13
15
|
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/app",
|
|
14
16
|
"bugs": "https://github.com/leaferjs/ui/issues",
|
|
15
17
|
"keywords": [
|
|
16
|
-
"leaferui",
|
|
17
18
|
"leafer-ui",
|
|
18
19
|
"leaferjs"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@leafer/core": "1.0.0-alpha.
|
|
22
|
-
"@leafer-ui/display": "1.0.0-alpha.
|
|
22
|
+
"@leafer/core": "1.0.0-alpha.10",
|
|
23
|
+
"@leafer-ui/display": "1.0.0-alpha.10"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
"@leafer/interface": "1.0.0-alpha.10",
|
|
27
|
+
"@leafer-ui/interface": "1.0.0-alpha.10"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/src/App.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions } from '@leafer/interface'
|
|
2
|
+
import { DataHelper, LayoutEvent, RenderEvent } from '@leafer/core'
|
|
3
|
+
|
|
4
|
+
import { IGroup } from '@leafer-ui/interface'
|
|
5
|
+
|
|
6
|
+
import { Leafer } from './Leafer'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class App extends Leafer implements IGroup {
|
|
10
|
+
|
|
11
|
+
public get isApp(): boolean { return true }
|
|
12
|
+
|
|
13
|
+
public children: Leafer[] = []
|
|
14
|
+
|
|
15
|
+
constructor(userConfig?: ILeaferConfig) {
|
|
16
|
+
super(userConfig)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public start(): void {
|
|
20
|
+
this.children.forEach(leafer => { leafer.start() })
|
|
21
|
+
this.renderer.start()
|
|
22
|
+
this.running = true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public stop(): void {
|
|
26
|
+
this.children.forEach(leafer => { leafer.stop() })
|
|
27
|
+
this.renderer.stop()
|
|
28
|
+
this.running = false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
32
|
+
const leafer = new Leafer(this.__getChildConfig(merge), this)
|
|
33
|
+
this.add(leafer)
|
|
34
|
+
|
|
35
|
+
const { renderer } = this
|
|
36
|
+
|
|
37
|
+
this.__eventIds.push(
|
|
38
|
+
leafer.on__(LayoutEvent.END, this.__onChildLayoutEnd, this),
|
|
39
|
+
leafer.on__(RenderEvent.END, renderer.update, renderer),
|
|
40
|
+
this.on__(LayoutEvent.REQUEST, renderer.mergeBlocks, renderer),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return leafer
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected __onChildLayoutEnd(event: LayoutEvent): void {
|
|
47
|
+
const { renderer } = this
|
|
48
|
+
if ((event.current as Leafer).config.usePartRender) {
|
|
49
|
+
event.data.map(item => renderer.addBlock(item.updatedBounds))
|
|
50
|
+
} else {
|
|
51
|
+
renderer.addBlock(renderer.canvas.bounds)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
|
|
56
|
+
this.children.forEach(leafer => { canvas.copy(leafer.canvas) })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public __onResize(event: IResizeEvent): void {
|
|
60
|
+
this.emitEvent(event)
|
|
61
|
+
this.children.forEach(leafer => { leafer.resize(event) })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
65
|
+
let old = { ...this.config }
|
|
66
|
+
userConfig = userConfig ? DataHelper.default(userConfig, old) : old
|
|
67
|
+
userConfig.view = null
|
|
68
|
+
if (this.autoLayout) {
|
|
69
|
+
userConfig.width = this.width
|
|
70
|
+
userConfig.height = this.height
|
|
71
|
+
userConfig.pixelRatio = this.pixelRatio
|
|
72
|
+
}
|
|
73
|
+
return userConfig
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public destory(): void {
|
|
77
|
+
super.destory()
|
|
78
|
+
|
|
79
|
+
const { children } = this
|
|
80
|
+
if (children.length) {
|
|
81
|
+
children.forEach(leafer => leafer.destory())
|
|
82
|
+
children.length = 0
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
package/src/Leafer.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ICreator, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IImageManager, IAutoBounds, IScreenSizeData, IResizeEvent, IObject, ILeaf, IEventListenerId, ITransformEventData } from '@leafer/interface'
|
|
2
|
+
import { AutoBounds, LayoutEvent, ResizeEvent, MoveEvent, ZoomEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, LeafHelper, Creator, Run } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { Group } from '@leafer-ui/display'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { App } from './App'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
@registerUI()
|
|
10
9
|
export class Leafer extends Group implements ILeafer {
|
|
11
10
|
|
|
12
11
|
public creator: ICreator
|
|
13
12
|
|
|
14
|
-
public get
|
|
13
|
+
public get isApp(): boolean { return false }
|
|
15
14
|
|
|
16
|
-
public parent?:
|
|
15
|
+
public parent?: App
|
|
17
16
|
|
|
18
17
|
public running: boolean
|
|
19
18
|
|
|
@@ -56,45 +55,42 @@ export class Leafer extends Group implements ILeafer {
|
|
|
56
55
|
|
|
57
56
|
protected __eventIds: IEventListenerId[] = []
|
|
58
57
|
|
|
59
|
-
constructor(userConfig?: ILeaferConfig,
|
|
58
|
+
constructor(userConfig?: ILeaferConfig, app?: IApp) {
|
|
60
59
|
super()
|
|
61
60
|
|
|
62
|
-
this.creator = Creator
|
|
63
|
-
|
|
64
|
-
const { config } = this
|
|
65
|
-
|
|
66
61
|
this.__setAsLeafer()
|
|
67
62
|
this.__setConfig(userConfig)
|
|
68
63
|
|
|
64
|
+
const { config } = this
|
|
65
|
+
this.creator = Creator
|
|
66
|
+
|
|
69
67
|
// render
|
|
70
68
|
this.canvas = Creator.canvas(config)
|
|
71
69
|
this.renderer = Creator.renderer(this, this.canvas, config)
|
|
72
70
|
|
|
73
71
|
// layout
|
|
74
|
-
if (this.
|
|
72
|
+
if (this.isApp) {
|
|
75
73
|
this.__level = 1
|
|
76
74
|
} else {
|
|
77
|
-
|
|
78
75
|
this.watcher = Creator.watcher(this)
|
|
79
76
|
this.layouter = Creator.layouter(this)
|
|
80
|
-
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
this.__checkAutoLayout(config)
|
|
84
80
|
|
|
85
81
|
// interaction / manager
|
|
86
|
-
if (
|
|
82
|
+
if (app) {
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
app.selector?.defaultPath.unshift(this)
|
|
89
85
|
|
|
90
|
-
this.selector =
|
|
91
|
-
this.interaction =
|
|
86
|
+
this.selector = app.selector
|
|
87
|
+
this.interaction = app.interaction
|
|
92
88
|
|
|
93
|
-
this.canvasManager =
|
|
94
|
-
this.hitCanvasManager =
|
|
95
|
-
this.imageManager =
|
|
89
|
+
this.canvasManager = app.canvasManager
|
|
90
|
+
this.hitCanvasManager = app.hitCanvasManager
|
|
91
|
+
this.imageManager = app.imageManager
|
|
96
92
|
|
|
97
|
-
if (
|
|
93
|
+
if (app.running) setTimeout(this.start.bind(this))
|
|
98
94
|
|
|
99
95
|
} else {
|
|
100
96
|
|
|
@@ -104,7 +100,7 @@ export class Leafer extends Group implements ILeafer {
|
|
|
104
100
|
this.canvasManager = new CanvasManager(this)
|
|
105
101
|
this.hitCanvasManager = new HitCanvasManager(this)
|
|
106
102
|
this.imageManager = new ImageManager(this, config)
|
|
107
|
-
|
|
103
|
+
Run.start('FullCreate')
|
|
108
104
|
if (config.start) setTimeout(this.start.bind(this))
|
|
109
105
|
|
|
110
106
|
}
|
|
@@ -135,6 +131,7 @@ export class Leafer extends Group implements ILeafer {
|
|
|
135
131
|
|
|
136
132
|
public start(): void {
|
|
137
133
|
if (!this.running) {
|
|
134
|
+
Run.endOfName('FullCreate')
|
|
138
135
|
this.__interactiveWindow()
|
|
139
136
|
this.interaction?.start()
|
|
140
137
|
this.renderer.start()
|
|
@@ -159,8 +156,8 @@ export class Leafer extends Group implements ILeafer {
|
|
|
159
156
|
if (move) {
|
|
160
157
|
const { MOVE } = MoveEvent
|
|
161
158
|
const { ZOOM } = ZoomEvent
|
|
162
|
-
if (!this.hasEvent(MOVE)) this.__eventIds.push(this.on__(MOVE, (e: MoveEvent) => { LeafHelper.
|
|
163
|
-
if (zoom && !this.hasEvent(ZOOM)) this.__eventIds.push(this.on__(ZOOM, (e: ZoomEvent) => { LeafHelper.
|
|
159
|
+
if (!this.hasEvent(MOVE)) this.__eventIds.push(this.on__(MOVE, (e: MoveEvent) => { LeafHelper.moveOfWorld(this, e.moveX, e.moveY) }))
|
|
160
|
+
if (zoom && !this.hasEvent(ZOOM)) this.__eventIds.push(this.on__(ZOOM, (e: ZoomEvent) => { LeafHelper.zoomOfWorld(this, e.scale, e) }))
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
163
|
|
|
@@ -197,24 +194,24 @@ export class Leafer extends Group implements ILeafer {
|
|
|
197
194
|
}
|
|
198
195
|
|
|
199
196
|
this.canvas.destroy()
|
|
200
|
-
this.canvas =
|
|
197
|
+
this.canvas = null
|
|
201
198
|
|
|
202
|
-
this.creator =
|
|
203
|
-
this.config =
|
|
199
|
+
this.creator = null
|
|
200
|
+
this.config = null
|
|
204
201
|
|
|
205
|
-
this.interaction =
|
|
206
|
-
this.selector =
|
|
202
|
+
this.interaction = null
|
|
203
|
+
this.selector = null
|
|
207
204
|
|
|
208
205
|
|
|
209
|
-
this.renderer =
|
|
210
|
-
this.watcher =
|
|
211
|
-
this.layouter =
|
|
206
|
+
this.renderer = null
|
|
207
|
+
this.watcher = null
|
|
208
|
+
this.layouter = null
|
|
212
209
|
|
|
213
|
-
this.canvasManager =
|
|
214
|
-
this.hitCanvasManager =
|
|
215
|
-
this.imageManager =
|
|
210
|
+
this.canvasManager = null
|
|
211
|
+
this.hitCanvasManager = null
|
|
212
|
+
this.imageManager = null
|
|
216
213
|
|
|
217
|
-
this.zoomLayer =
|
|
214
|
+
this.zoomLayer = null
|
|
218
215
|
this.moveLayer = undefined
|
|
219
216
|
|
|
220
217
|
this.parent = undefined
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Leafer } from './Leafer'
|
|
2
|
-
export {
|
|
2
|
+
export { App } from './App'
|
package/src/SuperLeafer.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions } from '@leafer/interface'
|
|
2
|
-
import { registerUI, DataHelper, RenderEvent } from '@leafer/core'
|
|
3
|
-
|
|
4
|
-
import { IGroup } from '@leafer-ui/interface'
|
|
5
|
-
|
|
6
|
-
import { Leafer } from './Leafer'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@registerUI()
|
|
10
|
-
export class SuperLeafer extends Leafer implements IGroup {
|
|
11
|
-
|
|
12
|
-
public get isSupperLeafer(): boolean { return true }
|
|
13
|
-
|
|
14
|
-
public children: Leafer[] = []
|
|
15
|
-
|
|
16
|
-
public start(): void {
|
|
17
|
-
if (!this.running) {
|
|
18
|
-
this.children.forEach(leafer => { leafer.start() })
|
|
19
|
-
this.running = false
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public stop(): void {
|
|
24
|
-
if (this.running) {
|
|
25
|
-
this.children.forEach(leafer => { leafer.stop() })
|
|
26
|
-
this.running = false
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
31
|
-
const leafer = new Leafer(this.__getChildConfig(merge), this)
|
|
32
|
-
this.add(leafer)
|
|
33
|
-
this.__eventIds.push(leafer.on__(RenderEvent.END, this.renderer.start, this.renderer))
|
|
34
|
-
return leafer
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public __render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
38
|
-
this.children.forEach(leafer => { canvas.copy(leafer.canvas) })
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public __onResize(event: IResizeEvent): void {
|
|
42
|
-
this.emitEvent(event)
|
|
43
|
-
this.children.forEach(leafer => { leafer.resize(event) })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
47
|
-
let old = { ...this.config }
|
|
48
|
-
userConfig = userConfig ? DataHelper.default(userConfig, old) : old
|
|
49
|
-
userConfig.view = undefined
|
|
50
|
-
if (this.autoLayout) {
|
|
51
|
-
userConfig.width = this.width
|
|
52
|
-
userConfig.height = this.height
|
|
53
|
-
userConfig.pixelRatio = this.pixelRatio
|
|
54
|
-
}
|
|
55
|
-
return userConfig
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public destory(): void {
|
|
59
|
-
if (this.children.length) {
|
|
60
|
-
super.destory()
|
|
61
|
-
this.children.forEach(leafer => {
|
|
62
|
-
leafer.destory()
|
|
63
|
-
})
|
|
64
|
-
this.children.length = 0
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|