@leafer-in/editor 1.6.1 → 1.6.3

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.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "@leafer-in/editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/core": "^1.6.1",
38
- "@leafer-in/resize": "^1.6.1",
39
- "@leafer-ui/interface": "^1.6.1",
40
- "@leafer-in/interface": "^1.6.1"
37
+ "@leafer-ui/core": "^1.6.3",
38
+ "@leafer-in/resize": "^1.6.3",
39
+ "@leafer-ui/interface": "^1.6.3",
40
+ "@leafer-in/interface": "^1.6.3"
41
41
  }
42
42
  }
package/src/Editor.ts CHANGED
@@ -536,12 +536,17 @@ export class Editor extends Group implements IEditor {
536
536
  const { app, leafer, editBox, editMask } = this
537
537
  this.targetEventIds = [
538
538
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
539
- app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this),
540
- app.on_(MoveEvent.BEFORE_MOVE, this.onMove, this, true),
541
- app.on_(ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
542
- app.on_(RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
543
- app.on_([KeyEvent.HOLD, KeyEvent.UP], this.onKey, this),
544
- app.on_(KeyEvent.DOWN, editBox.onArrow, editBox)
539
+
540
+ app.on_([
541
+ [RenderEvent.CHILD_START, this.onAppRenderStart, this],
542
+
543
+ [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
544
+ [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
545
+ [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
546
+
547
+ [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
548
+ [KeyEvent.DOWN, editBox.onArrow, editBox]
549
+ ])
545
550
  ]
546
551
  if (editMask.visible) editMask.forceRender()
547
552
  }
@@ -551,7 +556,6 @@ export class Editor extends Group implements IEditor {
551
556
  const { targetEventIds, editMask } = this
552
557
  if (targetEventIds.length) {
553
558
  this.off_(targetEventIds)
554
- targetEventIds.length = 0
555
559
  if (editMask.visible) editMask.forceRender()
556
560
  }
557
561
  }
@@ -1,4 +1,4 @@
1
- import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData } from '@leafer-ui/interface'
1
+ import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, IEventParams } from '@leafer-ui/interface'
2
2
  import { Group, Box, Text, AroundHelper, Direction9, ResizeEvent } from '@leafer-ui/draw'
3
3
  import { DragEvent, PointerEvent } from '@leafer-ui/core'
4
4
 
@@ -330,31 +330,36 @@ export class EditBox extends Group implements IEditBox {
330
330
  const { editor } = this
331
331
  point.direction = direction
332
332
  point.pointType = type
333
- point.on_(DragEvent.START, this.onDragStart, this)
334
- point.on_(DragEvent.DRAG, this.onDrag, this)
335
- point.on_(DragEvent.END, this.onDragEnd, this)
336
- point.on_(PointerEvent.LEAVE, () => this.enterPoint = null)
337
- if (point.name !== 'circle') point.on_(PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e) })
333
+
334
+ const events: IEventParams[] = [
335
+ [DragEvent.START, this.onDragStart, this],
336
+ [DragEvent.DRAG, this.onDrag, this],
337
+ [DragEvent.END, this.onDragEnd, this],
338
+ [PointerEvent.LEAVE, () => { this.enterPoint = null }],
339
+ ]
340
+ if (point.name !== 'circle') events.push([PointerEvent.ENTER, (e: PointerEvent) => { this.enterPoint = point, updateCursor(editor, e) }])
341
+ this.__eventIds.push(point.on_(events))
338
342
  }
339
343
 
340
344
  protected __listenEvents(): void {
341
345
  const { rect, editor } = this
342
- this.__eventIds = [
346
+ this.__eventIds.push(
343
347
  editor.on_(EditorEvent.SELECT, this.onSelect, this),
344
348
 
345
- rect.on_(DragEvent.START, this.onDragStart, this),
346
- rect.on_(DragEvent.DRAG, editor.onMove, editor),
347
- rect.on_(DragEvent.END, this.onDragEnd, this),
349
+ rect.on_([
350
+ [DragEvent.START, this.onDragStart, this],
351
+ [DragEvent.DRAG, editor.onMove, editor],
352
+ [DragEvent.END, this.onDragEnd, this],
348
353
 
349
- rect.on_(PointerEvent.ENTER, () => updateMoveCursor(editor)),
350
- rect.on_(PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
351
- rect.on_(PointerEvent.LONG_PRESS, this.onLongPress, this)
352
- ]
354
+ [PointerEvent.ENTER, () => updateMoveCursor(editor)],
355
+ [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
356
+ [PointerEvent.LONG_PRESS, this.onLongPress, this]
357
+ ])
358
+ )
353
359
  }
354
360
 
355
361
  protected __removeListenEvents(): void {
356
362
  this.off_(this.__eventIds)
357
- this.__eventIds.length = 0
358
363
  }
359
364
 
360
365
  public destroy(): void {
@@ -1,9 +1,16 @@
1
1
  import { Box, Direction9 } from '@leafer-ui/draw'
2
2
 
3
- import { IEditPoint, IEditPointType } from '@leafer-in/interface'
3
+ import { IEditPoint, IEditPointInputData, IEditPointType } from '@leafer-in/interface'
4
4
 
5
5
 
6
6
  export class EditPoint extends Box implements IEditPoint {
7
+
7
8
  public direction: Direction9
8
9
  public pointType: IEditPointType
10
+
11
+ constructor(data: IEditPointInputData) {
12
+ super(data)
13
+ this.useFastShadow = true
14
+ }
15
+
9
16
  }
@@ -241,29 +241,30 @@ export class EditSelect extends Group implements IEditSelect {
241
241
  app.selector.proxy = editor
242
242
 
243
243
  this.__eventIds = [
244
- editor.on_(EditorEvent.HOVER, this.onHover, this),
245
- editor.on_(EditorEvent.SELECT, this.onSelect, this),
246
-
247
- app.on_(PointerEvent.MOVE, this.onPointerMove, this),
248
- app.on_(PointerEvent.BEFORE_DOWN, this.onBeforeDown, this),
249
- app.on_(PointerEvent.TAP, this.onTap, this),
250
-
251
- app.on_(DragEvent.START, this.onDragStart, this, true), // 采用捕获事件,需要比EditBox中的dragStart早触发
252
- app.on_(DragEvent.DRAG, this.onDrag, this),
253
- app.on_(DragEvent.END, this.onDragEnd, this),
254
-
255
- app.on_(MoveEvent.MOVE, this.onAutoMove, this),
256
- app.on_([ZoomEvent.ZOOM, MoveEvent.MOVE], () => { this.editor.hoverTarget = null }),
244
+ editor.on_([
245
+ [EditorEvent.HOVER, this.onHover, this],
246
+ [EditorEvent.SELECT, this.onSelect, this]
247
+ ]),
248
+
249
+ app.on_([
250
+ [PointerEvent.MOVE, this.onPointerMove, this],
251
+ [PointerEvent.BEFORE_DOWN, this.onBeforeDown, this],
252
+ [PointerEvent.TAP, this.onTap, this],
253
+
254
+ [DragEvent.START, this.onDragStart, this, true], // 采用捕获事件,需要比EditBox中的dragStart早触发
255
+ [DragEvent.DRAG, this.onDrag, this],
256
+ [DragEvent.END, this.onDragEnd, this],
257
+
258
+ [MoveEvent.MOVE, this.onAutoMove, this],
259
+ [[ZoomEvent.ZOOM, MoveEvent.MOVE], () => { this.editor.hoverTarget = null }],
260
+ ])
257
261
  ]
258
262
 
259
263
  })
260
264
  }
261
265
 
262
266
  protected __removeListenEvents(): void {
263
- if (this.__eventIds) {
264
- this.off_(this.__eventIds)
265
- this.__eventIds.length = 0
266
- }
267
+ this.off_(this.__eventIds)
267
268
  }
268
269
 
269
270
  public destroy(): void {
@@ -78,8 +78,9 @@ export const EditDataHelper = {
78
78
  }
79
79
 
80
80
  if (lockRatio) {
81
- const unlockSide = lockRatio === 'corner' && direction % 2
82
- if (!unlockSide) {
81
+ if (lockRatio === 'corner' && direction % 2) {
82
+ lockRatio = false
83
+ } else {
83
84
  let scale: number
84
85
  switch (direction) {
85
86
  case top:
@@ -92,7 +93,6 @@ export const EditDataHelper = {
92
93
  break
93
94
  default:
94
95
  scale = Math.sqrt(Math.abs(scaleX * scaleY))
95
-
96
96
  }
97
97
  scaleX = scaleX < 0 ? -scale : scale
98
98
  scaleY = scaleY < 0 ? -scale : scale
package/src/index.ts CHANGED
@@ -25,7 +25,7 @@ export { EditDataHelper } from './helper/EditDataHelper'
25
25
  export { EditSelectHelper } from './helper/EditSelectHelper'
26
26
 
27
27
 
28
- import { IEditor, IEditorConfig, IEditToolFunction, IEditorConfigFunction } from '@leafer-in/interface'
28
+ import { IEditor, IEditorConfig, IEditToolFunction, IEditorConfigFunction, IApp } from '@leafer-in/interface'
29
29
  import { Creator, UI, Group, Text, Box, dataType, Plugin } from '@leafer-ui/draw'
30
30
 
31
31
  import '@leafer-in/resize'
@@ -36,7 +36,11 @@ import { Editor } from './Editor'
36
36
  Plugin.add('editor', 'resize')
37
37
 
38
38
 
39
- Creator.editor = function (options?: IEditorConfig): IEditor { return new Editor(options) }
39
+ Creator.editor = function (options?: IEditorConfig, app?: IApp): IEditor {
40
+ const editor = new Editor(options)
41
+ if (app) app.sky.add(app.editor = editor)
42
+ return editor
43
+ }
40
44
 
41
45
  Box.addAttr('textBox', false, dataType)
42
46
 
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IBox, IEditorDragStartData, IBoundsData, IEditorConfig as IEditorConfig$1, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, ILayoutBoundsData } from '@leafer-ui/interface';
2
2
  import { Group, UI, Direction9, Event, Box } from '@leafer-ui/draw';
3
3
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
4
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
4
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPointType, IEditPointInputData, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
5
5
 
6
6
  declare class EditSelect extends Group implements IEditSelect {
7
7
  editor: IEditor;
@@ -186,6 +186,7 @@ declare class EditBox extends Group implements IEditBox {
186
186
  declare class EditPoint extends Box implements IEditPoint {
187
187
  direction: Direction9;
188
188
  pointType: IEditPointType;
189
+ constructor(data: IEditPointInputData);
189
190
  }
190
191
 
191
192
  declare class SelectArea extends Group implements ISelectArea {