@leafer-in/editor 1.0.4 → 1.0.6

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.
@@ -4,11 +4,11 @@ import { Bounds } from '@leafer-ui/draw'
4
4
  import { IEditor } from '@leafer-in/interface'
5
5
 
6
6
 
7
- export function simulate(editor: IEditor) {
8
- const { simulateTarget, leafList: targetList } = editor
9
- const { x, y, width, height } = new Bounds().setListWithFn(targetList.list, (leaf: ILeaf) => leaf.worldBoxBounds)
7
+ const bounds = new Bounds()
10
8
 
11
- const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer as IGroup // follow zoomLayer zoom / move
12
- const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world
13
- simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY })
9
+ export function simulate(editor: IEditor) {
10
+ const { simulateTarget, list } = editor
11
+ const { zoomLayer } = list[0].leafer.zoomLayer as IGroup // follow zoomLayer zoom / move
12
+ simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf: ILeaf) => leaf.getBounds('box', 'page')).get()))
13
+ zoomLayer.add(simulateTarget)
14
14
  }
@@ -12,6 +12,7 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
12
12
  if (target) {
13
13
  editor.leafList = target instanceof LeafList ? target : new LeafList(target instanceof Array ? target : target as IUI)
14
14
  } else {
15
+ editor.simulateTarget.remove()
15
16
  editor.leafList.reset()
16
17
  editor.closeInnerEditor()
17
18
  }
@@ -40,7 +40,7 @@ export const EditorHelper = {
40
40
 
41
41
  app.lockLayout()
42
42
  list.forEach(leaf => {
43
- if (leaf.isBranch) {
43
+ if (leaf.isBranch && !leaf.isBranchLeaf) {
44
44
  const { parent, children } = leaf
45
45
  while (children.length) {
46
46
  ungroupList.push(children[0])
package/src/index.ts CHANGED
@@ -27,12 +27,27 @@ export { EditDataHelper } from './helper/EditDataHelper'
27
27
  export { EditSelectHelper } from './helper/EditSelectHelper'
28
28
 
29
29
  import { IEditor, IEditorConfig, IEditToolFunction, IEditorConfigFunction } from '@leafer-in/interface'
30
- import { Creator, UI, defineKey } from '@leafer-ui/draw'
30
+ import { Creator, UI, Text, defineKey } from '@leafer-ui/draw'
31
31
 
32
32
  import { Editor } from './Editor'
33
33
 
34
+
34
35
  Creator.editor = function (options?: IEditorConfig): IEditor { return new Editor(options) }
35
36
 
37
+
38
+ defineKey(UI.prototype, 'editOuter', {
39
+ get(): string { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool' }
40
+ })
41
+
42
+ defineKey(UI.prototype, 'editInner', {
43
+ get(): string { return 'PathEditor' }
44
+ })
45
+
46
+ defineKey(Text.prototype, 'editInner', {
47
+ get(): string { return 'TextEditor' }
48
+ })
49
+
50
+
36
51
  UI.setEditConfig = function (config: IEditorConfig | IEditorConfigFunction): void {
37
52
  defineKey(this.prototype, 'editConfig', {
38
53
  get(): IEditorConfig { return typeof config === 'function' ? config(this) : config }
@@ -81,11 +81,7 @@ export class EditTool extends InnerEditor implements IEditTool {
81
81
 
82
82
  public update(): void {
83
83
  const { editor, editBox } = this
84
-
85
- const { simulateTarget, element } = editor
86
- if (editor.multiple) simulateTarget.parent.updateLayout()
87
-
88
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true)
84
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true)
89
85
  editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
90
86
  editBox.update({ x: 0, y: 0, width, height })
91
87
  this.onUpdate()
@@ -7,7 +7,7 @@ import { registerEditTool } from './EditToolCreator'
7
7
 
8
8
 
9
9
  const { left, right } = Direction9
10
- const { move, copy } = PointHelper
10
+ const { move, copy, toNumberPoints } = PointHelper
11
11
 
12
12
  @registerEditTool()
13
13
  export class LineEditTool extends EditTool {
@@ -65,13 +65,7 @@ export class LineEditTool extends EditTool {
65
65
 
66
66
  getInnerMove(ui: IUI, event: IDragEvent, lockRatio: boolean | 'corner'): IPointData {
67
67
  const movePoint = event.getInnerMove(ui)
68
- if (lockRatio) {
69
- if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
70
- movePoint.y = 0
71
- } else {
72
- movePoint.x = 0
73
- }
74
- }
68
+ if (lockRatio) Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0
75
69
  return movePoint
76
70
  }
77
71
 
@@ -82,7 +76,8 @@ export class LineEditTool extends EditTool {
82
76
  }
83
77
  }
84
78
 
85
- getFromToByPoints(points: number[]): IFromToData {
79
+ getFromToByPoints(originPoints: number[] | IPointData[]): IFromToData {
80
+ const points = toNumberPoints(originPoints)
86
81
  return {
87
82
  from: { x: points[0], y: points[1] },
88
83
  to: { x: points[2], y: points[3] }
package/types/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from '@leafer-in/resize';
2
- import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IObject, IGroup, IPointData, ILayoutBoundsData, IGroupInputData, IEditSize, IAlign, IAxis, IBox, IBoundsData, IEditorConfig as IEditorConfig$1, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
3
- import { Group, UI, Direction9, Matrix, Event, Box, Answer } from '@leafer-ui/draw';
2
+ import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IObject, IGroup, IPointData, ILayoutBoundsData, IGroupInputData, IEditSize, IAlign, IAxis, IMatrix, IBox, IBoundsData, IEditorConfig as IEditorConfig$1, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
3
+ import { Group, UI, Direction9, Event, Box, Answer } from '@leafer-ui/draw';
4
4
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core';
5
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, 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';
5
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, 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';
6
6
 
7
7
  declare class EditSelect extends Group implements IEditSelect {
8
8
  editor: IEditor;
@@ -52,8 +52,9 @@ declare class Editor extends Group implements IEditor {
52
52
  get mergeConfig(): IEditorConfig;
53
53
  hoverTarget?: IUI;
54
54
  target?: IUI | IUI[];
55
- get list(): IUI[];
56
55
  leafList: ILeafList;
56
+ get list(): IUI[];
57
+ get dragHoverExclude(): IUI[];
57
58
  openedGroupList: ILeafList;
58
59
  get editing(): boolean;
59
60
  innerEditing: boolean;
@@ -62,8 +63,9 @@ declare class Editor extends Group implements IEditor {
62
63
  get multiple(): boolean;
63
64
  get single(): boolean;
64
65
  get dragging(): boolean;
65
- get element(): IUI;
66
- simulateTarget: IUI;
66
+ get moving(): boolean;
67
+ get element(): ISimulateElement;
68
+ simulateTarget: ISimulateElement;
67
69
  editBox: IEditBox;
68
70
  get buttons(): IGroup;
69
71
  editTool?: IEditTool;
@@ -95,8 +97,9 @@ declare class Editor extends Group implements IEditor {
95
97
  flip(axis: IAxis): void;
96
98
  rotateOf(origin: IPointData | IAlign, rotation: number): void;
97
99
  skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, _resize?: boolean): void;
100
+ checkTransform(type: 'moveable' | 'resizeable' | 'rotateable' | 'skewable'): boolean;
98
101
  protected getWorldOrigin(origin: IPointData | IAlign): IPointData;
99
- protected getChangedTransform(func: IFunction): Matrix;
102
+ protected getChangedTransform(func: IFunction): IMatrix;
100
103
  group(userGroup?: IGroup | IGroupInputData): IGroup;
101
104
  ungroup(): IUI[];
102
105
  openGroup(group: IGroup): void;
@@ -104,7 +107,7 @@ declare class Editor extends Group implements IEditor {
104
107
  checkOpenedGroups(): void;
105
108
  checkDeepSelect(): void;
106
109
  emitGroupEvent(type: string, group: IGroup): void;
107
- openInnerEditor(target?: IUI): void;
110
+ openInnerEditor(target?: IUI, select?: boolean): void;
108
111
  closeInnerEditor(): void;
109
112
  emitInnerEvent(type: string): void;
110
113
  lock(): void;
@@ -294,7 +297,7 @@ declare class LineEditTool extends EditTool {
294
297
  onScaleWithDrag(e: IEditorScaleEvent): void;
295
298
  getInnerMove(ui: IUI$1, event: IDragEvent$1, lockRatio: boolean | 'corner'): IPointData$1;
296
299
  getFromToByPath(path: IPathCommandData): IFromToData;
297
- getFromToByPoints(points: number[]): IFromToData;
300
+ getFromToByPoints(originPoints: number[] | IPointData$1[]): IFromToData;
298
301
  dragPoint(fromPoint: IPointData$1, toPoint: IPointData$1, isDragFrom: boolean, around: IAround$1, movePoint: IPointData$1): void;
299
302
  onSkew(_e: IEditorSkewEvent): void;
300
303
  onUpdate(): void;