@leafer-in/editor 1.9.10 → 1.9.12

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-in/editor",
3
- "version": "1.9.10",
3
+ "version": "1.9.12",
4
4
  "description": "@leafer-in/editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.9.10",
38
- "@leafer-ui/core": "^1.9.10",
39
- "@leafer-in/resize": "^1.9.10",
40
- "@leafer-ui/interface": "^1.9.10",
41
- "@leafer-in/interface": "^1.9.10"
37
+ "@leafer-ui/draw": "^1.9.12",
38
+ "@leafer-ui/core": "^1.9.12",
39
+ "@leafer-in/resize": "^1.9.12",
40
+ "@leafer-ui/interface": "^1.9.12",
41
+ "@leafer-in/interface": "^1.9.12"
42
42
  }
43
43
  }
package/src/Editor.ts CHANGED
@@ -287,7 +287,7 @@ export class Editor extends Group implements IEditor {
287
287
 
288
288
  public emitGroupEvent(type: string, group?: IGroup): void {
289
289
  const event = new EditorGroupEvent(type, { editTarget: group })
290
- if (!group || !group.syncEventer) this.emitEvent(event) // 单选时,元素会自动将事件传递给 editor,避免重复触发
290
+ this.emitEvent(event)
291
291
  if (group) group.emitEvent(event)
292
292
  }
293
293
 
@@ -340,7 +340,7 @@ export class Editor extends Group implements IEditor {
340
340
  public emitInnerEvent(type: string): void {
341
341
  const { innerEditor } = this, { editTarget } = innerEditor
342
342
  const event = new InnerEditorEvent(type, { editTarget, innerEditor })
343
- if (!editTarget.syncEventer) this.emitEvent(event) // 单选时,元素会自动将事件传递给 editor,避免重复触发
343
+ this.emitEvent(event)
344
344
  editTarget.emitEvent(event)
345
345
  }
346
346
 
@@ -62,7 +62,7 @@ export class EditBox extends Group implements IEditBox {
62
62
  public get flippedY(): boolean { return this.scaleY < 0 }
63
63
  public get flippedOne(): boolean { return this.scaleX * this.scaleY < 0 }
64
64
 
65
- public get canUse(): boolean { return (this.app && this.visible && this.view.visible) as boolean } // 编辑框是否处于激活状态
65
+ public get canUse(): boolean { return this.app && this.editor.editing } // 编辑框是否处于激活状态
66
66
  public get canGesture(): boolean { // 是否支持手势
67
67
  if (!this.canUse) return false
68
68
  const { moveable, resizeable, rotateable } = this.mergeConfig
@@ -148,6 +148,7 @@ export class EditBox extends Group implements IEditBox {
148
148
  updateMoveCursor(this)
149
149
  }
150
150
 
151
+ // 必须来自 editor.update(),需同步更新编辑工具
151
152
  public update(): void {
152
153
  const { editor } = this
153
154
  const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true)
@@ -329,29 +330,25 @@ export class EditBox extends Group implements IEditBox {
329
330
  // 操作事件共用
330
331
 
331
332
  public onTransformStart(e: IUIEvent): void {
332
- if (this.canUse) {
333
- if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
334
- if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
335
-
336
- const { dragStartData, target } = this
337
- dragStartData.x = e.x
338
- dragStartData.y = e.y
339
- dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
340
- dragStartData.point = { x: target.x, y: target.y } // 用于移动
341
- dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
342
- dragStartData.rotation = target.rotation // 用于旋转
343
- }
333
+ if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
334
+ if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
335
+
336
+ const { dragStartData, target } = this
337
+ dragStartData.x = e.x
338
+ dragStartData.y = e.y
339
+ dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
340
+ dragStartData.point = { x: target.x, y: target.y } // 用于移动
341
+ dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
342
+ dragStartData.rotation = target.rotation // 用于旋转
344
343
  }
345
344
 
346
345
  public onTransformEnd(e: IUIEvent): void {
347
- if (this.canUse) {
348
- if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e)
349
- if (this.resizing) ResizeEvent.resizingKeys = null
346
+ if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e)
347
+ if (this.resizing) ResizeEvent.resizingKeys = null
350
348
 
351
- this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false
352
- this.editor.opacity = 1
353
- this.update() // 移动端手势操作hideOnMove移动需强制更新一次
354
- }
349
+ this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false
350
+ this.editor.opacity = 1
351
+ this.editor.update() // 移动端手势操作hideOnMove移动需强制更新一次
355
352
  }
356
353
 
357
354
  // 手势控制元素
@@ -386,6 +383,14 @@ export class EditBox extends Group implements IEditBox {
386
383
  }
387
384
  }
388
385
 
386
+ public onGestureStart(e: IUIEvent): void {
387
+ if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformStart(e)
388
+ }
389
+
390
+ public onGestureEnd(e: IUIEvent): void {
391
+ if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformEnd(e)
392
+ }
393
+
389
394
  // 键盘
390
395
 
391
396
  public isHoldRotateKey(e: IUIEvent): boolean { // 按住ctrl在控制点上变旋转功能
@@ -482,11 +487,12 @@ export class EditBox extends Group implements IEditBox {
482
487
  [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
483
488
  [KeyEvent.DOWN, this.onArrow, this],
484
489
 
485
- [[MoveEvent.START, MoveEvent.BEFORE_MOVE], this.onMove, this, true],
486
- [[ZoomEvent.START, ZoomEvent.BEFORE_ZOOM], this.onScale, this, true],
487
- [[RotateEvent.START, RotateEvent.BEFORE_ROTATE], this.onRotate, this, true],
490
+ [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
491
+ [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
492
+ [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
488
493
 
489
- [[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onTransformEnd, this],
494
+ [[MoveEvent.START, ZoomEvent.START, RotateEvent.START], this.onGestureStart, this],
495
+ [[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onGestureEnd, this],
490
496
  ])
491
497
  )
492
498
  })
package/types/index.d.ts CHANGED
@@ -190,6 +190,8 @@ declare class EditBox extends Group implements IEditBox {
190
190
  onMove(e: MoveEvent): void;
191
191
  onScale(e: ZoomEvent): void;
192
192
  onRotate(e: RotateEvent): void;
193
+ onGestureStart(e: IUIEvent): void;
194
+ onGestureEnd(e: IUIEvent): void;
193
195
  isHoldRotateKey(e: IUIEvent): boolean;
194
196
  protected onKey(e: KeyEvent): void;
195
197
  onArrow(e: IKeyEvent): void;