@leafer-ui/app 1.0.0-rc.5 → 1.0.0-rc.7

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-ui/app",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.7",
4
4
  "description": "@leafer-ui/app",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,13 +22,13 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.5",
26
- "@leafer-ui/display": "1.0.0-rc.5",
27
- "@leafer-ui/type": "1.0.0-rc.5",
28
- "@leafer-ui/data": "1.0.0-rc.5"
25
+ "@leafer/core": "1.0.0-rc.7",
26
+ "@leafer-ui/display": "1.0.0-rc.7",
27
+ "@leafer-ui/type": "1.0.0-rc.7",
28
+ "@leafer-ui/data": "1.0.0-rc.7"
29
29
  },
30
30
  "devDependencies": {
31
- "@leafer/interface": "1.0.0-rc.5",
32
- "@leafer-ui/interface": "1.0.0-rc.5"
31
+ "@leafer/interface": "1.0.0-rc.7",
32
+ "@leafer-ui/interface": "1.0.0-rc.7"
33
33
  }
34
34
  }
package/src/App.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, ILeafer } from '@leafer/interface'
2
- import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
1
+ import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, ILeaferBase } from '@leafer/interface'
2
+ import { Creator, DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
3
+
4
+ import { IApp, IAppConfig, IAppInputData, IEditorBase, ILeafer } from '@leafer-ui/interface'
3
5
 
4
6
  import { Leafer } from './Leafer'
5
7
 
@@ -11,10 +13,28 @@ export class App extends Leafer implements IApp {
11
13
 
12
14
  public get isApp(): boolean { return true }
13
15
 
14
- declare public children: Leafer[]
16
+ declare public children: ILeafer[]
15
17
 
16
18
  public realCanvas: boolean
17
19
 
20
+ public ground?: ILeafer
21
+ public tree?: ILeafer
22
+ public sky?: ILeafer
23
+
24
+ constructor(userConfig?: IAppConfig, data?: IAppInputData) {
25
+ super(userConfig, data)
26
+ if (userConfig) {
27
+ const { ground, tree, sky, editor } = userConfig
28
+ if (ground) this.ground = this.addLeafer(ground)
29
+ if (tree || editor) this.tree = this.addLeafer(tree)
30
+ if (sky || editor) this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false })
31
+ if (editor) {
32
+ this.editor = Creator.editor(editor) as IEditorBase
33
+ this.sky.add(this.editor)
34
+ }
35
+ }
36
+ }
37
+
18
38
  protected __setApp(): void {
19
39
  const { canvas } = this
20
40
  const { realCanvas, view } = this.config
@@ -33,21 +53,31 @@ export class App extends Leafer implements IApp {
33
53
 
34
54
  public start(): void {
35
55
  super.start()
36
- this.children.forEach(leafer => { leafer.start() })
56
+ this.children.forEach(leafer => leafer.start())
37
57
  }
38
58
 
39
59
  public stop(): void {
40
- this.children.forEach(leafer => { leafer.stop() })
60
+ this.children.forEach(leafer => leafer.stop())
41
61
  super.stop()
42
62
  }
43
63
 
64
+ public unlockLayout(): void {
65
+ super.unlockLayout()
66
+ this.children.forEach(leafer => leafer.unlockLayout())
67
+ }
68
+
69
+ public lockLayout(): void {
70
+ super.lockLayout()
71
+ this.children.forEach(leafer => leafer.lockLayout())
72
+ }
73
+
44
74
  public addLeafer(merge?: ILeaferConfig): Leafer {
45
75
  const leafer = new Leafer(merge)
46
76
  this.add(leafer)
47
77
  return leafer
48
78
  }
49
79
 
50
- public add(leafer: Leafer): void {
80
+ public add(leafer: ILeafer): void {
51
81
  if (!leafer.view) {
52
82
  if (this.realCanvas && !this.canvas.bounds) { // wait miniapp select canvas
53
83
  setTimeout(() => this.add(leafer), 10)
@@ -61,7 +91,7 @@ export class App extends Leafer implements IApp {
61
91
  }
62
92
 
63
93
  protected __onPropertyChange(): void {
64
- if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('surface') })
94
+ if (Debug.showHitView) this.children.forEach(leafer => leafer.forceUpdate('surface'))
65
95
  }
66
96
 
67
97
  protected __onCreated(): void {
@@ -86,16 +116,16 @@ export class App extends Leafer implements IApp {
86
116
  }
87
117
 
88
118
  public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
89
- this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas) })
119
+ this.children.forEach(leafer => canvas.copyWorld(leafer.canvas))
90
120
  }
91
121
 
92
122
  public __onResize(event: IResizeEvent): void {
93
- this.children.forEach(leafer => { leafer.resize(event) })
123
+ this.children.forEach(leafer => leafer.resize(event))
94
124
  super.__onResize(event)
95
125
  }
96
126
 
97
127
  protected __checkUpdateLayout(): void {
98
- this.children.forEach(leafer => { leafer.__layout.checkUpdate() })
128
+ this.children.forEach(leafer => leafer.__layout.update())
99
129
  }
100
130
 
101
131
  protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
@@ -110,7 +140,7 @@ export class App extends Leafer implements IApp {
110
140
  return config
111
141
  }
112
142
 
113
- protected __listenChildEvents(leafer: ILeafer): void {
143
+ protected __listenChildEvents(leafer: ILeaferBase): void {
114
144
  leafer.once(LayoutEvent.END, () => this.__onReady())
115
145
  leafer.once(RenderEvent.START, () => this.__onCreated())
116
146
  leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e))
package/src/Leafer.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITimer, __Value, IObject, IControl, IPointData } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITimer, IValue, IObject, IControl, IPointData } from '@leafer/interface'
2
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, IUIInputData } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction, IUIInputData, ILeafer, IGroup, IApp, IEditorBase } 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'
8
8
 
9
- import { App } from './App'
10
-
11
9
 
12
10
  const debug = Debug.get('Leafer')
13
11
 
@@ -25,13 +23,14 @@ export class Leafer extends Group implements ILeafer {
25
23
  public get isApp(): boolean { return false }
26
24
  public get app(): ILeafer { return this.parent || this }
27
25
 
28
- declare public parent?: App
26
+ declare public parent?: IApp
29
27
 
30
28
  public running: boolean
31
29
  public created: boolean
32
30
  public ready: boolean
33
31
  public viewReady: boolean
34
32
  public viewCompleted: boolean
33
+ public get layoutLocked() { return !this.layouter.running }
35
34
 
36
35
  public view: unknown
37
36
 
@@ -48,7 +47,10 @@ export class Leafer extends Group implements ILeafer {
48
47
  public canvasManager: ICanvasManager
49
48
  public hitCanvasManager?: IHitCanvasManager
50
49
 
51
- public zoomLayer: ILeaf = this
50
+ // plugin
51
+ public editor: IEditorBase
52
+
53
+ public zoomLayer: IGroup = this
52
54
 
53
55
  public userConfig: ILeaferConfig
54
56
  public config: ILeaferConfig = {
@@ -163,15 +165,21 @@ export class Leafer extends Group implements ILeafer {
163
165
  }
164
166
  }
165
167
 
168
+ public unlockLayout(): void {
169
+ this.layouter.start()
170
+ this.updateLayout()
171
+ }
172
+
173
+ public lockLayout(): void {
174
+ this.updateLayout()
175
+ this.layouter.stop()
176
+ }
177
+
166
178
  public resize(size: IScreenSizeData): void {
167
179
  const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs)
168
180
  Object.keys(data).forEach(key => (this as any)[key] = data[key])
169
181
  }
170
182
 
171
- public forceLayout(): void {
172
- this.__layout.checkUpdate(true)
173
- }
174
-
175
183
  public forceFullRender(): void {
176
184
  this.renderer.addBlock(this.canvas.bounds)
177
185
  if (this.viewReady) this.renderer.update()
@@ -211,7 +219,7 @@ export class Leafer extends Group implements ILeafer {
211
219
  }
212
220
 
213
221
  public setZoomLayer(zoomLayer: ILeaf): void {
214
- this.zoomLayer = zoomLayer
222
+ this.zoomLayer = zoomLayer as IGroup
215
223
  }
216
224
 
217
225
  protected __checkAutoLayout(config: ILeaferConfig): void {
@@ -221,7 +229,7 @@ export class Leafer extends Group implements ILeafer {
221
229
  }
222
230
  }
223
231
 
224
- public __setAttr(attrName: string, newValue: __Value): void {
232
+ public __setAttr(attrName: string, newValue: IValue): void {
225
233
  if (this.canvas) {
226
234
  if (canvasSizeAttrs.includes(attrName)) {
227
235
  this.__changeCanvasSize(attrName, newValue as number)
@@ -234,7 +242,7 @@ export class Leafer extends Group implements ILeafer {
234
242
  super.__setAttr(attrName, newValue)
235
243
  }
236
244
 
237
- public __getAttr(attrName: string): __Value {
245
+ public __getAttr(attrName: string): IValue {
238
246
  if (this.canvas && canvasSizeAttrs.includes(attrName)) return this.canvas[attrName]
239
247
  return super.__getAttr(attrName)
240
248
  }
@@ -326,7 +334,7 @@ export class Leafer extends Group implements ILeafer {
326
334
  }
327
335
 
328
336
  protected __checkUpdateLayout(): void {
329
- this.__layout.checkUpdate()
337
+ this.__layout.update()
330
338
  }
331
339
 
332
340
  protected emitLeafer(type: string): void {
package/types/index.d.ts CHANGED
@@ -1,43 +1,21 @@
1
- import { IApp, ILeaferConfig, ILeaferCanvas, IRenderOptions, IResizeEvent, ILeafer, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaf, IAutoBounds, IPointData, IEventListenerId, ITimer, IControl, IScreenSizeData, __Value } from '@leafer/interface';
1
+ import { ILeaferCanvas, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IPointData, IEventListenerId, ITimer, IControl, IScreenSizeData, IResizeEvent, ILeaf, IValue, IRenderOptions, ILeaferBase } from '@leafer/interface';
2
2
  import { RenderEvent } from '@leafer/core';
3
- import { ILeaferData, IFunction, ILeaferInputData, IUIInputData } from '@leafer-ui/interface';
3
+ import { ILeafer, ILeaferData, IApp, IEditorBase, IGroup, IFunction, ILeaferInputData, IUIInputData, IAppConfig, IAppInputData } from '@leafer-ui/interface';
4
4
  import { Group } from '@leafer-ui/display';
5
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
6
  declare class Leafer extends Group implements ILeafer {
30
7
  get __tag(): string;
31
8
  __: ILeaferData;
32
9
  pixelRatio: number;
33
10
  get isApp(): boolean;
34
11
  get app(): ILeafer;
35
- parent?: App;
12
+ parent?: IApp;
36
13
  running: boolean;
37
14
  created: boolean;
38
15
  ready: boolean;
39
16
  viewReady: boolean;
40
17
  viewCompleted: boolean;
18
+ get layoutLocked(): boolean;
41
19
  view: unknown;
42
20
  canvas: ILeaferCanvas;
43
21
  renderer: IRenderer;
@@ -47,7 +25,8 @@ declare class Leafer extends Group implements ILeafer {
47
25
  interaction?: IInteraction;
48
26
  canvasManager: ICanvasManager;
49
27
  hitCanvasManager?: IHitCanvasManager;
50
- zoomLayer: ILeaf;
28
+ editor: IEditorBase;
29
+ zoomLayer: IGroup;
51
30
  userConfig: ILeaferConfig;
52
31
  config: ILeaferConfig;
53
32
  autoLayout?: IAutoBounds;
@@ -65,8 +44,9 @@ declare class Leafer extends Group implements ILeafer {
65
44
  set(data: IUIInputData): void;
66
45
  start(): void;
67
46
  stop(): void;
47
+ unlockLayout(): void;
48
+ lockLayout(): void;
68
49
  resize(size: IScreenSizeData): void;
69
- forceLayout(): void;
70
50
  forceFullRender(): void;
71
51
  updateCursor(): void;
72
52
  protected __doResize(size: IScreenSizeData): void;
@@ -76,8 +56,8 @@ declare class Leafer extends Group implements ILeafer {
76
56
  __setLeafer(leafer: ILeafer): void;
77
57
  setZoomLayer(zoomLayer: ILeaf): void;
78
58
  protected __checkAutoLayout(config: ILeaferConfig): void;
79
- __setAttr(attrName: string, newValue: __Value): void;
80
- __getAttr(attrName: string): __Value;
59
+ __setAttr(attrName: string, newValue: IValue): void;
60
+ __getAttr(attrName: string): IValue;
81
61
  protected __changeCanvasSize(attrName: string, newValue: number): void;
82
62
  protected __changeFill(newValue: string): void;
83
63
  protected __onCreated(): void;
@@ -98,4 +78,33 @@ declare class Leafer extends Group implements ILeafer {
98
78
  destroy(): void;
99
79
  }
100
80
 
81
+ declare class App extends Leafer implements IApp {
82
+ get __tag(): string;
83
+ get isApp(): boolean;
84
+ children: ILeafer[];
85
+ realCanvas: boolean;
86
+ ground?: ILeafer;
87
+ tree?: ILeafer;
88
+ sky?: ILeafer;
89
+ constructor(userConfig?: IAppConfig, data?: IAppInputData);
90
+ protected __setApp(): void;
91
+ start(): void;
92
+ stop(): void;
93
+ unlockLayout(): void;
94
+ lockLayout(): void;
95
+ addLeafer(merge?: ILeaferConfig): Leafer;
96
+ add(leafer: ILeafer): void;
97
+ protected __onPropertyChange(): void;
98
+ protected __onCreated(): void;
99
+ protected __onReady(): void;
100
+ protected __onViewReady(): void;
101
+ protected __checkViewCompleted(): boolean;
102
+ protected __onChildRenderEnd(e: RenderEvent): void;
103
+ __render(canvas: ILeaferCanvas, _options: IRenderOptions): void;
104
+ __onResize(event: IResizeEvent): void;
105
+ protected __checkUpdateLayout(): void;
106
+ protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig;
107
+ protected __listenChildEvents(leafer: ILeaferBase): void;
108
+ }
109
+
101
110
  export { App, Leafer };