@leafer-ui/app 1.0.0-beta.12 → 1.0.0-beta.16

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer-ui/app",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "@leafer-ui/app",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
8
9
  "files": [
9
- "src"
10
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,13 +22,13 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/core": "1.0.0-beta.12",
23
- "@leafer-ui/display": "1.0.0-beta.12",
24
- "@leafer-ui/type": "1.0.0-beta.12",
25
- "@leafer-ui/data": "1.0.0-beta.12"
25
+ "@leafer/core": "1.0.0-beta.16",
26
+ "@leafer-ui/display": "1.0.0-beta.16",
27
+ "@leafer-ui/type": "1.0.0-beta.16",
28
+ "@leafer-ui/data": "1.0.0-beta.16"
26
29
  },
27
30
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-beta.12",
29
- "@leafer-ui/interface": "1.0.0-beta.12"
31
+ "@leafer/interface": "1.0.0-beta.16",
32
+ "@leafer-ui/interface": "1.0.0-beta.16"
30
33
  }
31
34
  }
package/src/App.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, IFunction } from '@leafer/interface'
2
- import { DataHelper, Debug, LayoutEvent, Platform, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
1
+ import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, ILeafer } from '@leafer/interface'
2
+ import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
3
3
 
4
4
  import { Leafer } from './Leafer'
5
5
 
@@ -11,7 +11,7 @@ export class App extends Leafer implements IApp {
11
11
 
12
12
  public get isApp(): boolean { return true }
13
13
 
14
- public children: Leafer[] = []
14
+ declare public children: Leafer[]
15
15
 
16
16
  public realCanvas: boolean
17
17
 
@@ -28,11 +28,7 @@ export class App extends Leafer implements IApp {
28
28
  this.watcher.disable()
29
29
  this.layouter.disable()
30
30
 
31
- this.__eventIds.push(
32
- this.on_(PropertyEvent.CHANGE, () => {
33
- if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('blendMode') })
34
- })
35
- )
31
+ this.__eventIds.push(this.on_(PropertyEvent.CHANGE, this.__onPropertyChange, this))
36
32
  }
37
33
 
38
34
  public start(): void {
@@ -52,28 +48,36 @@ export class App extends Leafer implements IApp {
52
48
  }
53
49
 
54
50
  public add(leafer: Leafer): void {
55
- if (!leafer.view) leafer.init(this.__getChildConfig(leafer.userConfig), this)
51
+ if (!leafer.view) {
52
+ if (this.realCanvas && !this.canvas.bounds) { // wait miniapp select canvas
53
+ setTimeout(() => this.add(leafer), 10)
54
+ return
55
+ }
56
+ leafer.init(this.__getChildConfig(leafer.userConfig), this)
57
+ }
58
+
56
59
  super.add(leafer)
60
+ this.__listenChildEvents(leafer)
61
+ }
62
+
63
+ protected __onPropertyChange(): void {
64
+ if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('surface') })
65
+ }
57
66
 
58
- leafer.once(LayoutEvent.END, () => {
59
- if (!this.ready && this.children.every(child => child.ready)) this.__onReady()
60
- })
67
+ protected __onCreated(): void {
68
+ this.created = this.children.every(child => child.created)
69
+ }
61
70
 
62
- leafer.once(RenderEvent.END, () => {
63
- if (!this.viewReady && this.children.every(child => child.viewReady)) this.__onViewReady()
64
- })
71
+ protected __onReady(): void {
72
+ if (this.children.every(child => child.ready)) super.__onReady()
73
+ }
65
74
 
66
- if (this.realCanvas) {
67
- this.__eventIds.push(
68
- leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this),
69
- )
70
- }
75
+ protected __onViewReady(): void {
76
+ if (this.children.every(child => child.viewReady)) super.__onViewReady()
71
77
  }
72
78
 
73
- public waitViewLoaded(fun: IFunction): void {
74
- const wait = () => { if (this.children.every(item => item.viewLoaded)) Platform.requestRender(fun) }
75
- this.children.forEach(leafer => { leafer.waitViewLoaded(wait) })
76
- if (!this.running) this.start()
79
+ protected __checkViewCompleted(): boolean {
80
+ return this.children.every(item => item.viewCompleted)
77
81
  }
78
82
 
79
83
  protected __onChildRenderEnd(e: RenderEvent): void {
@@ -106,4 +110,11 @@ export class App extends Leafer implements IApp {
106
110
  return config
107
111
  }
108
112
 
113
+ protected __listenChildEvents(leafer: ILeafer): void {
114
+ leafer.once(LayoutEvent.END, () => this.__onReady())
115
+ leafer.once(RenderEvent.START, () => this.__onCreated())
116
+ leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e))
117
+ if (this.realCanvas) this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this))
118
+ }
119
+
109
120
  }
package/src/Leafer.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITransformEventData, ITimer, __Value, IObject, IControl } from '@leafer/interface'
2
- import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor, Platform, PluginManager, AnimateEvent } from '@leafer/core'
2
+ import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor, PluginManager, WaitHelper, WatchEvent } from '@leafer/core'
3
3
 
4
- import { ILeaferInputData, ILeaferData, IFunction } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction, IUIInputData } from '@leafer-ui/interface'
5
5
  import { LeaferTypeCreator } from '@leafer-ui/type'
6
6
  import { LeaferData } from '@leafer-ui/data'
7
7
  import { Group } from '@leafer-ui/display'
@@ -17,19 +17,21 @@ export class Leafer extends Group implements ILeafer {
17
17
  public get __tag() { return 'Leafer' }
18
18
 
19
19
  @dataProcessor(LeaferData)
20
- public __: ILeaferData
20
+ declare public __: ILeaferData
21
21
 
22
22
  @boundsType()
23
23
  public pixelRatio: number
24
24
 
25
25
  public get isApp(): boolean { return false }
26
+ public get app(): ILeafer { return this.parent || this }
26
27
 
27
- public parent?: App
28
+ declare public parent?: App
28
29
 
29
30
  public running: boolean
31
+ public created: boolean
30
32
  public ready: boolean
31
33
  public viewReady: boolean
32
- public get viewLoaded(): boolean { return this.viewReady && !this.watcher.changed && ImageManager.isComplete }
34
+ public viewCompleted: boolean
33
35
 
34
36
  public view: unknown
35
37
 
@@ -61,6 +63,7 @@ export class Leafer extends Group implements ILeafer {
61
63
  max: 256
62
64
  },
63
65
  move: {
66
+ holdSpaceKey: true,
64
67
  dragOut: true,
65
68
  autoDistance: 2
66
69
  }
@@ -72,6 +75,11 @@ export class Leafer extends Group implements ILeafer {
72
75
  protected __startTimer: ITimer
73
76
  protected __controllers: IControl[] = []
74
77
 
78
+ protected __readyWait: IFunction[] = []
79
+ protected __viewReadyWait: IFunction[] = []
80
+ protected __viewCompletedWait: IFunction[] = []
81
+ public __nextRenderWait: IFunction[] = []
82
+
75
83
  constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
76
84
  super(data)
77
85
  this.userConfig = userConfig
@@ -125,6 +133,16 @@ export class Leafer extends Group implements ILeafer {
125
133
  PluginManager.onLeafer(this)
126
134
  }
127
135
 
136
+ public set(data: IUIInputData): void {
137
+ if (!this.children) {
138
+ setTimeout(() => {
139
+ super.set(data)
140
+ })
141
+ } else {
142
+ super.set(data)
143
+ }
144
+ }
145
+
128
146
  public start(): void {
129
147
  clearTimeout(this.__startTimer)
130
148
  if (!this.running && this.canvas) {
@@ -158,6 +176,10 @@ export class Leafer extends Group implements ILeafer {
158
176
  if (this.viewReady) this.renderer.update()
159
177
  }
160
178
 
179
+ public updateCursor(): void {
180
+ if (this.interaction) this.interaction.updateCursor()
181
+ }
182
+
161
183
  protected __doResize(size: IScreenSizeData): void {
162
184
  if (!this.canvas || this.canvas.isSameSize(size)) return
163
185
  const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs) as IScreenSizeData
@@ -192,19 +214,6 @@ export class Leafer extends Group implements ILeafer {
192
214
  this.moveLayer = moveLayer || zoomLayer
193
215
  }
194
216
 
195
- public waitViewLoaded(fun: IFunction): void {
196
- let id: IEventListenerId
197
- const check = () => {
198
- if (this.viewLoaded) {
199
- if (id) this.off_(id)
200
- Platform.requestRender(fun)
201
- }
202
- }
203
- if (!this.running) this.start()
204
- check()
205
- if (!this.viewLoaded) id = this.on_(AnimateEvent.FRAME, check)
206
- }
207
-
208
217
  protected __checkAutoLayout(config: ILeaferConfig): void {
209
218
  if (!config.width || !config.height) {
210
219
  this.autoLayout = new AutoBounds(config)
@@ -246,18 +255,74 @@ export class Leafer extends Group implements ILeafer {
246
255
  }
247
256
  }
248
257
 
258
+ protected __onCreated(): void {
259
+ this.created = true
260
+ }
261
+
249
262
  protected __onReady(): void {
250
263
  if (this.ready) return
251
264
  this.ready = true
252
265
  this.emitLeafer(LeaferEvent.BEFORE_READY)
253
266
  this.emitLeafer(LeaferEvent.READY)
254
267
  this.emitLeafer(LeaferEvent.AFTER_READY)
268
+ WaitHelper.run(this.__readyWait)
255
269
  }
256
270
 
257
271
  protected __onViewReady(): void {
258
272
  if (this.viewReady) return
259
273
  this.viewReady = true
260
274
  this.emitLeafer(LeaferEvent.VIEW_READY)
275
+ WaitHelper.run(this.__viewReadyWait)
276
+ }
277
+
278
+ protected __onRenderEnd(_e: RenderEvent): void {
279
+ if (!this.viewReady) this.__onViewReady()
280
+ const completed = this.__checkViewCompleted()
281
+ if (completed) this.__onViewCompleted()
282
+ this.viewCompleted = completed
283
+ WaitHelper.run(this.__nextRenderWait)
284
+ }
285
+
286
+ protected __checkViewCompleted(): boolean {
287
+ return this.viewReady && !this.watcher.changed && ImageManager.isComplete
288
+ }
289
+
290
+ protected __onViewCompleted(): void {
291
+ if (!this.viewCompleted) {
292
+ this.emitLeafer(LeaferEvent.VIEW_COMPLETED)
293
+ WaitHelper.run(this.__viewCompletedWait)
294
+ }
295
+ }
296
+
297
+ protected __onWatchData(): void {
298
+ if (this.watcher.childrenChanged && this.interaction) {
299
+ this.nextRender(() => this.interaction.updateCursor())
300
+ }
301
+ }
302
+
303
+ public waitReady(item: IFunction): void {
304
+ this.ready ? item() : this.__readyWait.push(item)
305
+ }
306
+
307
+ public waitViewReady(item: IFunction): void {
308
+ this.viewReady ? item() : this.__viewReadyWait.push(item)
309
+ }
310
+
311
+ public waitViewCompleted(item: IFunction): void {
312
+ if (this.viewCompleted) {
313
+ item()
314
+ } else {
315
+ this.__viewCompletedWait.push(item)
316
+ if (!this.running) this.start()
317
+ }
318
+ }
319
+
320
+ public nextRender(item: IFunction): void {
321
+ if (this.watcher && !this.watcher.changed) {
322
+ item()
323
+ } else {
324
+ this.__nextRenderWait.push(item)
325
+ }
261
326
  }
262
327
 
263
328
  protected __checkUpdateLayout(): void {
@@ -272,8 +337,12 @@ export class Leafer extends Group implements ILeafer {
272
337
  const runId = Run.start('FirstCreate ' + this.innerName)
273
338
  this.once(LeaferEvent.START, () => Run.end(runId))
274
339
  this.once(LayoutEvent.END, () => this.__onReady())
275
- this.once(RenderEvent.END, () => this.__onViewReady())
276
- this.on(LayoutEvent.CHECK_UPDATE, () => this.__checkUpdateLayout())
340
+ this.once(RenderEvent.START, () => this.__onCreated())
341
+ this.__eventIds.push(
342
+ this.on_(WatchEvent.DATA, this.__onWatchData, this),
343
+ this.on_(RenderEvent.END, this.__onRenderEnd, this),
344
+ this.on_(LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this)
345
+ )
277
346
  }
278
347
 
279
348
  protected __removeListenEvents(): void {
@@ -302,7 +371,8 @@ export class Leafer extends Group implements ILeafer {
302
371
 
303
372
  this.canvas.destroy()
304
373
 
305
- this.config.view = this.userConfig.view = this.view = null
374
+ this.config.view = this.view = null
375
+ if (this.userConfig) this.userConfig.view = null
306
376
 
307
377
  super.destroy()
308
378
 
@@ -311,7 +381,7 @@ export class Leafer extends Group implements ILeafer {
311
381
  debug.error(e)
312
382
  }
313
383
  }
314
- }, 0)
384
+ })
315
385
 
316
386
  }
317
387
  }
@@ -0,0 +1,101 @@
1
+ import { IApp, ILeaferConfig, ILeaferCanvas, IRenderOptions, IResizeEvent, ILeafer, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaf, ITransformEventData, IAutoBounds, IEventListenerId, ITimer, IControl, IScreenSizeData, __Value } from '@leafer/interface';
2
+ import { RenderEvent } from '@leafer/core';
3
+ import { ILeaferData, IFunction, ILeaferInputData, IUIInputData } from '@leafer-ui/interface';
4
+ import { Group } from '@leafer-ui/display';
5
+
6
+ declare class App extends Leafer implements IApp {
7
+ get __tag(): string;
8
+ get isApp(): boolean;
9
+ children: Leafer[];
10
+ realCanvas: boolean;
11
+ protected __setApp(): void;
12
+ start(): void;
13
+ stop(): void;
14
+ addLeafer(merge?: ILeaferConfig): Leafer;
15
+ add(leafer: Leafer): void;
16
+ protected __onPropertyChange(): void;
17
+ protected __onCreated(): void;
18
+ protected __onReady(): void;
19
+ protected __onViewReady(): void;
20
+ protected __checkViewCompleted(): boolean;
21
+ protected __onChildRenderEnd(e: RenderEvent): void;
22
+ __render(canvas: ILeaferCanvas, _options: IRenderOptions): void;
23
+ __onResize(event: IResizeEvent): void;
24
+ protected __checkUpdateLayout(): void;
25
+ protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig;
26
+ protected __listenChildEvents(leafer: ILeafer): void;
27
+ }
28
+
29
+ declare class Leafer extends Group implements ILeafer {
30
+ get __tag(): string;
31
+ __: ILeaferData;
32
+ pixelRatio: number;
33
+ get isApp(): boolean;
34
+ get app(): ILeafer;
35
+ parent?: App;
36
+ running: boolean;
37
+ created: boolean;
38
+ ready: boolean;
39
+ viewReady: boolean;
40
+ viewCompleted: boolean;
41
+ view: unknown;
42
+ canvas: ILeaferCanvas;
43
+ renderer: IRenderer;
44
+ watcher: IWatcher;
45
+ layouter: ILayouter;
46
+ selector?: ISelector;
47
+ interaction?: IInteraction;
48
+ canvasManager: ICanvasManager;
49
+ hitCanvasManager?: IHitCanvasManager;
50
+ zoomLayer: ILeaf;
51
+ moveLayer: ILeaf;
52
+ transformData?: ITransformEventData;
53
+ userConfig: ILeaferConfig;
54
+ config: ILeaferConfig;
55
+ autoLayout?: IAutoBounds;
56
+ __eventIds: IEventListenerId[];
57
+ protected __startTimer: ITimer;
58
+ protected __controllers: IControl[];
59
+ protected __readyWait: IFunction[];
60
+ protected __viewReadyWait: IFunction[];
61
+ protected __viewCompletedWait: IFunction[];
62
+ __renderWait: IFunction[];
63
+ constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData);
64
+ init(userConfig?: ILeaferConfig, parentApp?: IApp): void;
65
+ set(data: IUIInputData): void;
66
+ start(): void;
67
+ stop(): void;
68
+ resize(size: IScreenSizeData): void;
69
+ forceLayout(): void;
70
+ forceFullRender(): void;
71
+ updateCursor(): void;
72
+ protected __doResize(size: IScreenSizeData): void;
73
+ protected __onResize(event: IResizeEvent): void;
74
+ protected __setApp(): void;
75
+ protected __bindApp(app: IApp): void;
76
+ __setLeafer(leafer: ILeafer): void;
77
+ setZoomLayer(zoomLayer: ILeaf, moveLayer?: ILeaf): void;
78
+ protected __checkAutoLayout(config: ILeaferConfig): void;
79
+ __setAttr(attrName: string, newValue: __Value): void;
80
+ __getAttr(attrName: string): __Value;
81
+ protected __changeCanvasSize(attrName: string, newValue: number): void;
82
+ protected __changeFill(newValue: string): void;
83
+ protected __onCreated(): void;
84
+ protected __onReady(): void;
85
+ protected __onViewReady(): void;
86
+ protected __onRenderEnd(_e: RenderEvent): void;
87
+ protected __checkViewCompleted(): boolean;
88
+ protected __onViewCompleted(): void;
89
+ protected __onWatchData(): void;
90
+ waitReady(item: IFunction): void;
91
+ waitViewReady(item: IFunction): void;
92
+ waitViewCompleted(item: IFunction): void;
93
+ waitRender(item: IFunction): void;
94
+ protected __checkUpdateLayout(): void;
95
+ protected emitLeafer(type: string): void;
96
+ protected __listenEvents(): void;
97
+ protected __removeListenEvents(): void;
98
+ destroy(): void;
99
+ }
100
+
101
+ export { App, Leafer };