@leafer-in/editor 1.0.0-rc.9 → 1.0.1
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/dist/editor.cjs +2008 -0
- package/dist/editor.esm.js +1197 -458
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +1235 -487
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -7
- package/src/Editor.ts +268 -76
- package/src/config.ts +14 -4
- package/src/decorator/data.ts +1 -1
- package/src/display/EditBox.ts +164 -81
- package/src/display/EditMask.ts +37 -0
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +84 -49
- package/src/display/SelectArea.ts +1 -1
- package/src/display/Stroker.ts +24 -21
- package/src/editor/cursor.ts +29 -38
- package/src/editor/simulate.ts +2 -2
- package/src/editor/target.ts +4 -2
- package/src/event/EditorEvent.ts +8 -1
- package/src/event/EditorGroupEvent.ts +23 -0
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/event/InnerEditorEvent.ts +23 -0
- package/src/helper/EditDataHelper.ts +112 -41
- package/src/helper/EditSelectHelper.ts +5 -4
- package/src/helper/EditorHelper.ts +11 -4
- package/src/index.ts +29 -5
- package/src/svg.ts +54 -0
- package/src/tool/EditTool.ts +51 -22
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +68 -0
- package/src/tool/LineEditTool.ts +94 -38
- package/types/index.d.ts +157 -52
- package/src/tool/index.ts +0 -21
package/src/Editor.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Rect,
|
|
1
|
+
import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup, IObject, IAlign, IAxis, IFunction, ILayoutBoundsData } from '@leafer-ui/interface'
|
|
2
|
+
import { Group, Rect, DataHelper, MathHelper, LeafList, Matrix, RenderEvent, LeafHelper } from '@leafer-ui/draw'
|
|
3
|
+
import { DragEvent, RotateEvent, KeyEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
|
-
import { IEditBox, IEditPoint, IEditor, IEditorConfig, IEditTool, IEditorScaleEvent } from '@leafer-in/interface'
|
|
5
|
+
import { IEditBox, IEditPoint, IEditor, IEditorConfig, IEditTool, IEditorScaleEvent, IInnerEditor } from '@leafer-in/interface'
|
|
5
6
|
|
|
6
7
|
import { EditorMoveEvent } from './event/EditorMoveEvent'
|
|
7
8
|
import { EditorScaleEvent } from './event/EditorScaleEvent'
|
|
@@ -10,44 +11,71 @@ import { EditorSkewEvent } from './event/EditorSkewEvent'
|
|
|
10
11
|
|
|
11
12
|
import { EditSelect } from './display/EditSelect'
|
|
12
13
|
import { EditBox } from './display/EditBox'
|
|
14
|
+
import { EditMask } from './display/EditMask'
|
|
13
15
|
|
|
14
16
|
import { config } from './config'
|
|
15
|
-
import { getEditTool } from './tool'
|
|
16
17
|
|
|
17
18
|
import { onTarget, onHover } from './editor/target'
|
|
18
19
|
import { targetAttr } from './decorator/data'
|
|
19
20
|
import { EditorHelper } from './helper/EditorHelper'
|
|
20
21
|
import { EditDataHelper } from './helper/EditDataHelper'
|
|
22
|
+
import { simulate } from './editor/simulate'
|
|
21
23
|
import { updateCursor } from './editor/cursor'
|
|
24
|
+
import { EditToolCreator } from './tool/EditToolCreator'
|
|
25
|
+
import { InnerEditorEvent } from './event/InnerEditorEvent'
|
|
26
|
+
import { EditorGroupEvent } from './event/EditorGroupEvent'
|
|
22
27
|
|
|
23
28
|
|
|
24
29
|
export class Editor extends Group implements IEditor {
|
|
25
30
|
|
|
26
31
|
public config = config
|
|
27
32
|
|
|
33
|
+
public get mergeConfig(): IEditorConfig {
|
|
34
|
+
const { element, config } = this
|
|
35
|
+
return this.single && element.editConfig ? { ...config, ...element.editConfig } : config // 实时合并,后期可优化
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
@targetAttr(onHover)
|
|
29
|
-
public hoverTarget
|
|
39
|
+
public hoverTarget?: IUI
|
|
30
40
|
|
|
31
41
|
@targetAttr(onTarget)
|
|
32
|
-
public target
|
|
42
|
+
public target?: IUI | IUI[]
|
|
43
|
+
|
|
44
|
+
// 列表
|
|
33
45
|
|
|
34
|
-
public leafList: ILeafList = new LeafList() // from target
|
|
35
46
|
public get list(): IUI[] { return this.leafList.list as IUI[] }
|
|
47
|
+
public leafList: ILeafList = new LeafList() // from target
|
|
48
|
+
public openedGroupList: ILeafList = new LeafList()
|
|
49
|
+
|
|
50
|
+
// 状态
|
|
51
|
+
|
|
52
|
+
public get editing(): boolean { return !!this.list.length }
|
|
53
|
+
public innerEditing: boolean
|
|
54
|
+
public get groupOpening(): boolean { return !!this.openedGroupList.length }
|
|
36
55
|
|
|
37
|
-
public get hasTarget(): boolean { return !!this.list.length }
|
|
38
56
|
public get multiple(): boolean { return this.list.length > 1 }
|
|
39
57
|
public get single(): boolean { return this.list.length === 1 }
|
|
40
58
|
|
|
59
|
+
public get dragging(): boolean { return this.editBox.dragging }
|
|
60
|
+
|
|
61
|
+
// 组件
|
|
62
|
+
|
|
41
63
|
public get element() { return this.multiple ? this.simulateTarget : this.list[0] as IUI }
|
|
42
64
|
public simulateTarget: IUI = new Rect({ visible: false })
|
|
43
65
|
|
|
44
66
|
public editBox: IEditBox = new EditBox(this)
|
|
45
67
|
public get buttons() { return this.editBox.buttons }
|
|
46
68
|
|
|
47
|
-
public editTool
|
|
69
|
+
public editTool?: IEditTool
|
|
70
|
+
|
|
71
|
+
public innerEditor?: IInnerEditor
|
|
72
|
+
public editToolList: IObject = {}
|
|
73
|
+
|
|
48
74
|
public selector: EditSelect = new EditSelect(this)
|
|
75
|
+
public editMask: EditMask = new EditMask(this)
|
|
49
76
|
|
|
50
|
-
public
|
|
77
|
+
public dragStartPoint: IPointData
|
|
78
|
+
public dragStartBounds: ILayoutBoundsData
|
|
51
79
|
|
|
52
80
|
public targetEventIds: IEventListenerId[] = []
|
|
53
81
|
|
|
@@ -55,7 +83,17 @@ export class Editor extends Group implements IEditor {
|
|
|
55
83
|
constructor(userConfig?: IEditorConfig, data?: IGroupInputData) {
|
|
56
84
|
super(data)
|
|
57
85
|
if (userConfig) this.config = DataHelper.default(userConfig, this.config)
|
|
58
|
-
this.addMany(this.selector, this.editBox)
|
|
86
|
+
this.addMany(this.editMask, this.selector, this.editBox)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// select
|
|
90
|
+
|
|
91
|
+
public select(target: IUI | IUI[]): void {
|
|
92
|
+
this.target = target
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public cancel(): void {
|
|
96
|
+
this.target = null
|
|
59
97
|
}
|
|
60
98
|
|
|
61
99
|
// item
|
|
@@ -79,83 +117,130 @@ export class Editor extends Group implements IEditor {
|
|
|
79
117
|
// update
|
|
80
118
|
|
|
81
119
|
public update(): void {
|
|
82
|
-
if (this.
|
|
83
|
-
this.
|
|
120
|
+
if (this.editing) {
|
|
121
|
+
if (this.innerEditing) this.innerEditor.update()
|
|
122
|
+
this.editTool.update()
|
|
84
123
|
this.selector.update()
|
|
85
124
|
}
|
|
86
125
|
}
|
|
87
126
|
|
|
127
|
+
public updateEditBox(): void {
|
|
128
|
+
if (this.multiple) simulate(this)
|
|
129
|
+
this.update()
|
|
130
|
+
}
|
|
131
|
+
|
|
88
132
|
public updateEditTool(): void {
|
|
89
|
-
|
|
133
|
+
const tool = this.editTool
|
|
134
|
+
if (tool) {
|
|
135
|
+
this.editBox.unload()
|
|
136
|
+
tool.unload()
|
|
137
|
+
this.editTool = null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (this.editing) {
|
|
141
|
+
const tag = this.single ? this.list[0].editOuter as string : 'EditTool'
|
|
142
|
+
this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this)
|
|
143
|
+
this.editBox.load()
|
|
144
|
+
this.editTool.load()
|
|
145
|
+
}
|
|
90
146
|
}
|
|
91
147
|
|
|
148
|
+
|
|
92
149
|
// get
|
|
93
150
|
|
|
94
|
-
public getEditSize(
|
|
95
|
-
|
|
96
|
-
return editSize === 'auto' ? ui.editSize : editSize
|
|
151
|
+
public getEditSize(_ui: IUI): IEditSize {
|
|
152
|
+
return this.mergeConfig.editSize
|
|
97
153
|
}
|
|
98
154
|
|
|
99
155
|
// operate
|
|
100
156
|
|
|
101
|
-
public onMove(e: DragEvent): void {
|
|
102
|
-
|
|
157
|
+
public onMove(e: DragEvent | MoveEvent): void {
|
|
158
|
+
|
|
159
|
+
if (e instanceof MoveEvent) {
|
|
160
|
+
|
|
161
|
+
if (e.moveType !== 'drag') {
|
|
162
|
+
const { moveable, resizeable } = this.mergeConfig
|
|
163
|
+
const move = e.getLocalMove(this.element)
|
|
164
|
+
if (moveable === 'move') e.stop(), this.move(move.x, move.y)
|
|
165
|
+
else if (resizeable === 'zoom') e.stop()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
} else {
|
|
169
|
+
|
|
170
|
+
const total = { x: e.totalX, y: e.totalY }
|
|
171
|
+
|
|
172
|
+
if (e.shiftKey) {
|
|
173
|
+
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0
|
|
174
|
+
else total.x = 0
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.move(DragEvent.getValidMove(this.element, this.dragStartPoint, total))
|
|
103
178
|
|
|
104
|
-
if (e.shiftKey) {
|
|
105
|
-
if (Math.abs(move.x) > Math.abs(move.y)) move.y = 0
|
|
106
|
-
else move.x = 0
|
|
107
179
|
}
|
|
108
180
|
|
|
109
|
-
this.move(move.x, move.y)
|
|
110
181
|
}
|
|
111
182
|
|
|
112
|
-
public onScale(e: DragEvent): void {
|
|
183
|
+
public onScale(e: DragEvent | ZoomEvent): void {
|
|
113
184
|
const { element } = this
|
|
114
|
-
|
|
185
|
+
let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig
|
|
115
186
|
|
|
116
|
-
|
|
117
|
-
if (e.shiftKey) lockRatio = true
|
|
187
|
+
if (e instanceof ZoomEvent) {
|
|
118
188
|
|
|
119
|
-
|
|
189
|
+
if (resizeable === 'zoom') e.stop(), this.scaleOf(element.getInnerPoint(e), e.scale, e.scale)
|
|
120
190
|
|
|
121
|
-
if (this.editTool.onScaleWithDrag) {
|
|
122
|
-
data.drag = e
|
|
123
|
-
this.scaleWithDrag(data)
|
|
124
191
|
} else {
|
|
125
|
-
|
|
192
|
+
|
|
193
|
+
const { direction } = e.current as IEditPoint
|
|
194
|
+
|
|
195
|
+
if (e.shiftKey || element.lockRatio) lockRatio = true
|
|
196
|
+
|
|
197
|
+
const data = EditDataHelper.getScaleData(element, this.dragStartBounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale')
|
|
198
|
+
|
|
199
|
+
if (this.editTool.onScaleWithDrag) {
|
|
200
|
+
data.drag = e
|
|
201
|
+
this.scaleWithDrag(data)
|
|
202
|
+
} else {
|
|
203
|
+
this.scaleOf(data.origin, data.scaleX, data.scaleY)
|
|
204
|
+
}
|
|
205
|
+
|
|
126
206
|
}
|
|
127
207
|
|
|
128
208
|
}
|
|
129
209
|
|
|
130
210
|
public onRotate(e: DragEvent | RotateEvent): void {
|
|
131
|
-
const { skewable, around, rotateGap } = this.
|
|
211
|
+
const { skewable, rotateable, around, rotateGap } = this.mergeConfig
|
|
132
212
|
const { direction, name } = e.current as IEditPoint
|
|
133
213
|
if (skewable && name === 'resize-line') return this.onSkew(e as DragEvent)
|
|
134
214
|
|
|
135
|
-
const { element
|
|
215
|
+
const { element } = this
|
|
136
216
|
let origin: IPointData, rotation: number
|
|
137
217
|
|
|
138
218
|
if (e instanceof RotateEvent) {
|
|
139
|
-
|
|
219
|
+
|
|
220
|
+
if (rotateable === 'rotate') e.stop(), rotation = e.rotation, origin = element.getInnerPoint(e)
|
|
221
|
+
else return
|
|
222
|
+
|
|
140
223
|
} else {
|
|
224
|
+
|
|
141
225
|
const last = { x: e.x - e.moveX, y: e.y - e.moveY }
|
|
142
|
-
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (around || 'center'))
|
|
226
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'))
|
|
143
227
|
rotation = data.rotation
|
|
144
228
|
origin = data.origin
|
|
229
|
+
|
|
145
230
|
}
|
|
146
231
|
|
|
147
232
|
rotation = MathHelper.getGapRotation(rotation, rotateGap, element.rotation)
|
|
148
233
|
if (!rotation) return
|
|
149
234
|
|
|
150
|
-
if (
|
|
235
|
+
if (element.scaleX * element.scaleY < 0) rotation = -rotation // flippedOne
|
|
151
236
|
|
|
152
|
-
this.rotateOf(origin, rotation)
|
|
237
|
+
this.rotateOf(origin, MathHelper.float(rotation, 2))
|
|
153
238
|
}
|
|
154
239
|
|
|
155
240
|
|
|
156
241
|
public onSkew(e: DragEvent): void {
|
|
157
242
|
const { element } = this
|
|
158
|
-
const { around } = this.
|
|
243
|
+
const { around } = this.mergeConfig
|
|
159
244
|
|
|
160
245
|
const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, (e.current as IEditPoint).direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey))
|
|
161
246
|
if (!skewX && !skewY) return
|
|
@@ -166,9 +251,11 @@ export class Editor extends Group implements IEditor {
|
|
|
166
251
|
|
|
167
252
|
// transform
|
|
168
253
|
|
|
169
|
-
public move(x: number, y
|
|
254
|
+
public move(x: number | IPointData, y = 0): void {
|
|
255
|
+
if (!this.mergeConfig.moveable || this.element.locked) return
|
|
256
|
+
|
|
170
257
|
const { element } = this
|
|
171
|
-
const world = element.getWorldPointByLocal({ x, y }, null, true)
|
|
258
|
+
const world = element.getWorldPointByLocal(typeof x === 'object' ? { ...x } : { x, y }, null, true)
|
|
172
259
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y })
|
|
173
260
|
|
|
174
261
|
this.editTool.onMove(event)
|
|
@@ -178,77 +265,177 @@ export class Editor extends Group implements IEditor {
|
|
|
178
265
|
}
|
|
179
266
|
|
|
180
267
|
public scaleWithDrag(data: IEditorScaleEvent): void {
|
|
268
|
+
if (!this.mergeConfig.resizeable || this.element.locked) return
|
|
269
|
+
|
|
181
270
|
const { element } = this
|
|
182
|
-
const
|
|
183
|
-
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { ...data, target: element, editor: this, worldOrigin })
|
|
271
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { ...data, target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) })
|
|
184
272
|
|
|
185
273
|
this.editTool.onScaleWithDrag(event)
|
|
186
274
|
this.emitEvent(event)
|
|
187
275
|
}
|
|
188
276
|
|
|
189
|
-
public scaleOf(origin: IPointData, scaleX: number, scaleY = scaleX, _resize?: boolean): void {
|
|
190
|
-
const { element } = this
|
|
191
|
-
const worldOrigin = element.getWorldPoint(origin)
|
|
192
|
-
|
|
193
|
-
let transform: Matrix
|
|
194
277
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
element.scaleOf(origin, scaleX, scaleY)
|
|
198
|
-
transform = new Matrix(element.localTransform).divide(childMatrix)
|
|
199
|
-
}
|
|
278
|
+
override scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY = scaleX, _resize?: boolean): void {
|
|
279
|
+
if (!this.mergeConfig.resizeable || this.element.locked) return
|
|
200
280
|
|
|
281
|
+
const { element } = this
|
|
282
|
+
const worldOrigin = this.getWorldOrigin(origin)
|
|
283
|
+
const transform = this.multiple && this.getChangedTransform(() => element.scaleOf(origin, scaleX, scaleY))
|
|
201
284
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform })
|
|
202
285
|
|
|
203
286
|
this.editTool.onScale(event)
|
|
204
287
|
this.emitEvent(event)
|
|
205
288
|
}
|
|
206
289
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const worldOrigin = element.getWorldPoint(origin)
|
|
290
|
+
override flip(axis: IAxis): void {
|
|
291
|
+
if (this.element.locked) return
|
|
210
292
|
|
|
211
|
-
const
|
|
293
|
+
const { element } = this
|
|
294
|
+
const worldOrigin = this.getWorldOrigin('center')
|
|
295
|
+
const transform = this.multiple ? this.getChangedTransform(() => element.flip(axis)) : new Matrix(LeafHelper.getFlipTransform(element, axis))
|
|
296
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform })
|
|
212
297
|
|
|
213
|
-
this.editTool.
|
|
298
|
+
this.editTool.onScale(event)
|
|
214
299
|
this.emitEvent(event)
|
|
215
|
-
|
|
216
|
-
if (this.multiple) element.rotateOf(origin, rotation)
|
|
217
300
|
}
|
|
218
301
|
|
|
219
|
-
|
|
302
|
+
override rotateOf(origin: IPointData | IAlign, rotation: number): void {
|
|
303
|
+
if (!this.mergeConfig.rotateable || this.element.locked) return
|
|
304
|
+
|
|
220
305
|
const { element } = this
|
|
221
|
-
const worldOrigin =
|
|
306
|
+
const worldOrigin = this.getWorldOrigin(origin)
|
|
307
|
+
const transform = this.multiple && this.getChangedTransform(() => element.rotateOf(origin, rotation))
|
|
308
|
+
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform })
|
|
222
309
|
|
|
223
|
-
|
|
310
|
+
this.editTool.onRotate(event)
|
|
311
|
+
this.emitEvent(event)
|
|
312
|
+
}
|
|
224
313
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
element.skewOf(origin, skewX, skewY)
|
|
228
|
-
transform = new Matrix(element.localTransform).divide(childMatrix)
|
|
229
|
-
}
|
|
314
|
+
override skewOf(origin: IPointData | IAlign, skewX: number, skewY = 0, _resize?: boolean): void {
|
|
315
|
+
if (!this.mergeConfig.skewable || this.element.locked) return
|
|
230
316
|
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
317
|
+
const { element } = this
|
|
318
|
+
const worldOrigin = this.getWorldOrigin(origin)
|
|
319
|
+
const transform = this.multiple && this.getChangedTransform(() => element.skewOf(origin, skewX, skewY))
|
|
320
|
+
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform })
|
|
234
321
|
|
|
235
322
|
this.editTool.onSkew(event)
|
|
236
323
|
this.emitEvent(event)
|
|
237
324
|
}
|
|
238
325
|
|
|
326
|
+
|
|
327
|
+
protected getWorldOrigin(origin: IPointData | IAlign): IPointData {
|
|
328
|
+
return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin))
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
protected getChangedTransform(func: IFunction): Matrix {
|
|
332
|
+
const { element } = this
|
|
333
|
+
const oldMatrix = new Matrix(element.worldTransform)
|
|
334
|
+
func()
|
|
335
|
+
return new Matrix(element.worldTransform).divide(oldMatrix) // world change transform
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
|
|
239
339
|
// group
|
|
240
340
|
|
|
241
|
-
public group(
|
|
242
|
-
if (this.multiple)
|
|
341
|
+
public group(userGroup?: IGroup | IGroupInputData): IGroup {
|
|
342
|
+
if (this.multiple) {
|
|
343
|
+
this.target = EditorHelper.group(this.list, this.element, userGroup)
|
|
344
|
+
this.emitGroupEvent(EditorGroupEvent.GROUP, this.target as IGroup)
|
|
345
|
+
}
|
|
243
346
|
return this.target as IGroup
|
|
244
347
|
}
|
|
245
348
|
|
|
246
|
-
|
|
247
349
|
public ungroup(): IUI[] {
|
|
248
|
-
|
|
350
|
+
const { list } = this
|
|
351
|
+
if (list.length) {
|
|
352
|
+
list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.BEFORE_UNGROUP, item as IGroup))
|
|
353
|
+
this.target = EditorHelper.ungroup(list)
|
|
354
|
+
list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.UNGROUP, item as IGroup))
|
|
355
|
+
}
|
|
249
356
|
return this.list
|
|
250
357
|
}
|
|
251
358
|
|
|
359
|
+
public openGroup(group: IGroup): void {
|
|
360
|
+
this.openedGroupList.add(group)
|
|
361
|
+
group.hitChildren = true
|
|
362
|
+
this.emitGroupEvent(EditorGroupEvent.OPEN, group)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
public closeGroup(group: IGroup): void {
|
|
366
|
+
this.openedGroupList.remove(group)
|
|
367
|
+
group.hitChildren = false
|
|
368
|
+
this.emitGroupEvent(EditorGroupEvent.CLOSE, group)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
public checkOpenedGroups(): void {
|
|
372
|
+
const opened = this.openedGroupList
|
|
373
|
+
if (opened.length) {
|
|
374
|
+
let { list } = opened
|
|
375
|
+
if (this.editing) list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item))
|
|
376
|
+
list.forEach(item => this.closeGroup(item as IGroup))
|
|
377
|
+
}
|
|
378
|
+
if (this.editing && !this.selector.dragging) this.checkDeepSelect()
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
public checkDeepSelect(): void {
|
|
382
|
+
let parent: IGroup, { list } = this
|
|
383
|
+
for (let i = 0; i < list.length; i++) {
|
|
384
|
+
parent = list[i].parent
|
|
385
|
+
while (parent && !parent.hitChildren) {
|
|
386
|
+
this.openGroup(parent)
|
|
387
|
+
parent = parent.parent
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public emitGroupEvent(type: string, group: IGroup): void {
|
|
393
|
+
const event = new EditorGroupEvent(type, { editTarget: group })
|
|
394
|
+
this.emitEvent(event)
|
|
395
|
+
group.emitEvent(event)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// inner
|
|
399
|
+
|
|
400
|
+
public openInnerEditor(target?: IUI): void {
|
|
401
|
+
if (target) this.target = target
|
|
402
|
+
if (this.single) {
|
|
403
|
+
const editTarget = this.element
|
|
404
|
+
const tag = editTarget.editInner
|
|
405
|
+
if (tag && EditToolCreator.list[tag]) {
|
|
406
|
+
this.editTool.unload()
|
|
407
|
+
this.innerEditing = true
|
|
408
|
+
this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this)
|
|
409
|
+
this.innerEditor.editTarget = editTarget
|
|
410
|
+
|
|
411
|
+
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN)
|
|
412
|
+
this.innerEditor.load()
|
|
413
|
+
this.emitInnerEvent(InnerEditorEvent.OPEN)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
public closeInnerEditor(): void {
|
|
419
|
+
if (this.innerEditing) {
|
|
420
|
+
this.innerEditing = false
|
|
421
|
+
|
|
422
|
+
this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE)
|
|
423
|
+
this.innerEditor.unload()
|
|
424
|
+
this.emitInnerEvent(InnerEditorEvent.CLOSE)
|
|
425
|
+
|
|
426
|
+
this.editTool.load()
|
|
427
|
+
this.innerEditor = null
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
public emitInnerEvent(type: string): void {
|
|
432
|
+
const { innerEditor } = this
|
|
433
|
+
const { editTarget } = innerEditor
|
|
434
|
+
const event = new InnerEditorEvent(type, { editTarget, innerEditor })
|
|
435
|
+
this.emitEvent(event)
|
|
436
|
+
editTarget.emitEvent(event)
|
|
437
|
+
}
|
|
438
|
+
|
|
252
439
|
// lock
|
|
253
440
|
|
|
254
441
|
public lock(): void {
|
|
@@ -283,6 +470,9 @@ export class Editor extends Group implements IEditor {
|
|
|
283
470
|
if (!this.targetEventIds.length) {
|
|
284
471
|
const { leafer } = this.list[0]
|
|
285
472
|
this.targetEventIds = [
|
|
473
|
+
this.app.on_(MoveEvent.BEFORE_MOVE, this.onMove, this, true),
|
|
474
|
+
this.app.on_(ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
|
|
475
|
+
this.app.on_(RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
|
|
286
476
|
leafer.on_(RenderEvent.START, this.update, this),
|
|
287
477
|
leafer.on_([KeyEvent.HOLD, KeyEvent.UP], (e: KeyEvent) => { updateCursor(this, e) }),
|
|
288
478
|
leafer.on_(KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
|
|
@@ -301,7 +491,9 @@ export class Editor extends Group implements IEditor {
|
|
|
301
491
|
public destroy(): void {
|
|
302
492
|
if (!this.destroyed) {
|
|
303
493
|
this.simulateTarget.destroy()
|
|
304
|
-
|
|
494
|
+
Object.values(this.editToolList).forEach(item => item.destroy())
|
|
495
|
+
this.editToolList = {}
|
|
496
|
+
this.target = this.hoverTarget = this.simulateTarget = this.editTool = this.innerEditor = null
|
|
305
497
|
super.destroy()
|
|
306
498
|
}
|
|
307
499
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { IEditorConfig } from '@leafer-in/interface'
|
|
2
|
+
import { resizeSVG, rotateSVG, skewSVG } from './svg'
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
export const config: IEditorConfig = {
|
|
4
|
-
editSize: '
|
|
6
|
+
editSize: 'size',
|
|
7
|
+
keyEvent: true,
|
|
5
8
|
|
|
6
9
|
stroke: '#836DFF',
|
|
7
10
|
strokeWidth: 2,
|
|
8
11
|
|
|
9
12
|
pointFill: '#FFFFFF',
|
|
10
|
-
pointSize:
|
|
13
|
+
pointSize: 10,
|
|
11
14
|
pointRadius: 16,
|
|
12
15
|
|
|
13
16
|
rotateGap: 45,
|
|
@@ -15,15 +18,22 @@ export const config: IEditorConfig = {
|
|
|
15
18
|
buttonsDirection: 'bottom',
|
|
16
19
|
buttonsMargin: 12,
|
|
17
20
|
|
|
21
|
+
hideOnSmall: true,
|
|
22
|
+
|
|
18
23
|
moveCursor: 'move',
|
|
19
|
-
resizeCursor:
|
|
20
|
-
rotateCursor:
|
|
24
|
+
resizeCursor: { url: resizeSVG, x: 12, y: 12 },
|
|
25
|
+
rotateCursor: { url: rotateSVG, x: 12, y: 12 },
|
|
26
|
+
skewCursor: { url: skewSVG, x: 12, y: 12 },
|
|
21
27
|
|
|
22
28
|
selector: true,
|
|
23
29
|
hover: true,
|
|
30
|
+
select: 'press',
|
|
31
|
+
openInner: 'double',
|
|
24
32
|
boxSelect: true,
|
|
25
33
|
|
|
34
|
+
moveable: true,
|
|
26
35
|
resizeable: true,
|
|
36
|
+
flipable: true,
|
|
27
37
|
rotateable: true,
|
|
28
38
|
skewable: true
|
|
29
39
|
}
|
package/src/decorator/data.ts
CHANGED