@leafer-in/editor 1.0.0-rc.20 → 1.0.0-rc.22
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.esm.js +472 -296
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +501 -323
- package/dist/editor.min.js +1 -1
- package/package.json +5 -7
- package/src/Editor.ts +115 -26
- package/src/config.ts +1 -0
- package/src/decorator/data.ts +1 -1
- package/src/display/EditBox.ts +126 -70
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +42 -36
- package/src/display/SelectArea.ts +1 -1
- package/src/display/Stroker.ts +5 -5
- package/src/editor/cursor.ts +4 -4
- package/src/editor/simulate.ts +1 -1
- package/src/editor/target.ts +4 -2
- package/src/event/EditorEvent.ts +1 -1
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/helper/EditDataHelper.ts +8 -11
- package/src/helper/EditSelectHelper.ts +1 -1
- package/src/helper/EditorHelper.ts +1 -1
- package/src/index.ts +29 -6
- package/src/tool/EditTool.ts +36 -12
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +64 -0
- package/src/tool/LineEditTool.ts +8 -8
- package/types/index.d.ts +96 -42
- package/src/tool/index.ts +0 -21
package/src/display/EditBox.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IRect, IAround, IEventListenerId, IBoundsData,
|
|
2
|
-
import { Group,
|
|
1
|
+
import { IRect, IAround, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData } from '@leafer-ui/interface'
|
|
2
|
+
import { Group, Box, AroundHelper, Direction9 } from '@leafer-ui/draw'
|
|
3
|
+
import { DragEvent, PointerEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
|
-
import { IEditBox, IEditor,
|
|
5
|
+
import { IEditBox, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
|
|
5
6
|
|
|
6
7
|
import { updateCursor, updateMoveCursor } from '../editor/cursor'
|
|
7
8
|
import { EditorEvent } from '../event/EditorEvent'
|
|
@@ -17,6 +18,8 @@ export class EditBox extends Group implements IEditBox {
|
|
|
17
18
|
public dragging: boolean
|
|
18
19
|
public moving: boolean
|
|
19
20
|
|
|
21
|
+
public view: IGroup = new Group() // 放置默认编辑工具控制点
|
|
22
|
+
|
|
20
23
|
public rect: IBox = new Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 }) // target rect
|
|
21
24
|
public circle: IEditPoint = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 }) // rotate point
|
|
22
25
|
|
|
@@ -46,7 +49,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
46
49
|
|
|
47
50
|
public create() {
|
|
48
51
|
let rotatePoint: IEditPoint, resizeLine: IEditPoint, resizePoint: IEditPoint
|
|
49
|
-
const { resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this
|
|
52
|
+
const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this
|
|
50
53
|
const arounds: IAround[] = [{ x: 1, y: 1 }, { x: 0.5, y: 1 }, { x: 0, y: 1 }, { x: 0, y: 0.5 }, { x: 0, y: 0 }, { x: 0.5, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 0.5 }]
|
|
51
54
|
|
|
52
55
|
for (let i = 0; i < 8; i++) {
|
|
@@ -60,7 +63,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
60
63
|
this.listenPointEvents(resizeLine, 'resize', i)
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
resizePoint = new EditPoint({ name: 'resize-point',
|
|
66
|
+
resizePoint = new EditPoint({ name: 'resize-point', hitRadius: 5 })
|
|
64
67
|
resizePoints.push(resizePoint)
|
|
65
68
|
this.listenPointEvents(resizePoint, 'resize', i)
|
|
66
69
|
}
|
|
@@ -68,73 +71,98 @@ export class EditBox extends Group implements IEditBox {
|
|
|
68
71
|
buttons.add(circle)
|
|
69
72
|
this.listenPointEvents(circle, 'rotate', 2)
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints)
|
|
75
|
+
this.add(view)
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const {
|
|
78
|
-
const { width, height } = bounds
|
|
79
|
-
const { rect, circle, resizePoints, rotatePoints, resizeLines } = this
|
|
80
|
-
const { middlePoint, resizeable, rotateable, stroke, strokeWidth, hideOnSmall } = config
|
|
78
|
+
public load(): void {
|
|
79
|
+
const { mergeConfig, element, single } = this.editor
|
|
80
|
+
const { rect, circle, resizePoints } = this
|
|
81
|
+
const { stroke, strokeWidth, moveable } = mergeConfig
|
|
81
82
|
|
|
82
83
|
const pointsStyle = this.getPointsStyle()
|
|
83
84
|
const middlePointsStyle = this.getMiddlePointsStyle()
|
|
84
|
-
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10
|
|
85
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize)
|
|
86
|
-
|
|
87
|
-
this.visible = list[0] && !list[0].locked // check locked
|
|
88
85
|
|
|
89
|
-
let
|
|
86
|
+
let resizeP: IRect
|
|
90
87
|
|
|
91
88
|
for (let i = 0; i < 8; i++) {
|
|
89
|
+
resizeP = resizePoints[i]
|
|
90
|
+
resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]))
|
|
91
|
+
if (!(i % 2)) resizeP.rotation = (i / 2) * 90
|
|
92
|
+
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
resizeP = resizePoints[i], rotateP = rotatePoints[i], resizeL = resizeLines[Math.floor(i / 2)]
|
|
96
|
-
resizeP.set(style)
|
|
97
|
-
resizeP.set(point), rotateP.set(point), resizeL.set(point)
|
|
94
|
+
// rotate
|
|
95
|
+
circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]))
|
|
98
96
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
// rect
|
|
98
|
+
rect.set({ stroke, strokeWidth, ...(mergeConfig.rect || {}) })
|
|
99
|
+
rect.hittable = !single && moveable
|
|
102
100
|
|
|
103
|
-
|
|
101
|
+
// 编辑框作为底部虚拟元素, 在 onSelect 方法移除
|
|
102
|
+
element.syncEventer = (single && moveable) ? rect : null
|
|
103
|
+
this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
this.visible = !element.locked
|
|
106
|
+
}
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
public update(bounds: IBoundsData): void {
|
|
109
|
+
if (this.view.worldOpacity) {
|
|
110
|
+
const { mergeConfig } = this.editor
|
|
111
|
+
const { width, height } = bounds
|
|
112
|
+
const { rect, circle, resizePoints, rotatePoints, resizeLines } = this
|
|
113
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig
|
|
114
|
+
|
|
115
|
+
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10
|
|
116
|
+
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize)
|
|
117
|
+
|
|
118
|
+
let point = {} as IPointData, rotateP: IRect, resizeP: IRect, resizeL: IRect
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < 8; i++) {
|
|
121
|
+
|
|
122
|
+
AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point)
|
|
123
|
+
resizeP = resizePoints[i]
|
|
124
|
+
rotateP = rotatePoints[i]
|
|
125
|
+
resizeL = resizeLines[Math.floor(i / 2)]
|
|
126
|
+
resizeP.set(point)
|
|
127
|
+
rotateP.set(point)
|
|
128
|
+
resizeL.set(point)
|
|
129
|
+
|
|
130
|
+
// visible
|
|
131
|
+
resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable)
|
|
132
|
+
rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint
|
|
133
|
+
|
|
134
|
+
if (i % 2) { // top, right, bottom, left
|
|
135
|
+
|
|
136
|
+
resizeP.visible = rotateP.visible = showPoints && !!middlePoint
|
|
137
|
+
|
|
138
|
+
if (((i + 1) / 2) % 2) { // top, bottom
|
|
139
|
+
resizeL.width = width
|
|
140
|
+
if (resizeP.width > width - 30) resizeP.visible = false
|
|
141
|
+
} else {
|
|
142
|
+
resizeL.height = height
|
|
143
|
+
resizeP.rotation = 90
|
|
144
|
+
if (resizeP.width > height - 30) resizeP.visible = false
|
|
145
|
+
}
|
|
114
146
|
}
|
|
115
|
-
} else {
|
|
116
|
-
resizeP.rotation = (i / 2) * 90
|
|
117
|
-
}
|
|
118
147
|
|
|
119
|
-
|
|
148
|
+
}
|
|
120
149
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
circle.set(this.getPointStyle(config.rotatePoint || pointsStyle[0]))
|
|
150
|
+
// rotate
|
|
151
|
+
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint
|
|
124
152
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
rect.set({ ...bounds, visible: true })
|
|
128
|
-
rect.hittable = config.moveable
|
|
153
|
+
// rect
|
|
154
|
+
rect.set({ ...bounds, visible: true })
|
|
129
155
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
// buttons
|
|
157
|
+
const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1)
|
|
158
|
+
this.buttons.visible = buttonVisible
|
|
159
|
+
if (buttonVisible) this.layoutButtons()
|
|
160
|
+
}
|
|
133
161
|
}
|
|
134
162
|
|
|
135
163
|
protected layoutButtons(): void {
|
|
136
164
|
const { buttons, resizePoints } = this
|
|
137
|
-
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.
|
|
165
|
+
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.mergeConfig
|
|
138
166
|
|
|
139
167
|
const { flippedX, flippedY } = this
|
|
140
168
|
let index = fourDirection.indexOf(buttonsDirection)
|
|
@@ -166,44 +194,55 @@ export class EditBox extends Group implements IEditBox {
|
|
|
166
194
|
|
|
167
195
|
}
|
|
168
196
|
|
|
169
|
-
public
|
|
170
|
-
|
|
171
|
-
|
|
197
|
+
public unload(): void {
|
|
198
|
+
this.visible = false
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
public getPointStyle(userStyle?: IBoxInputData): IBoxInputData {
|
|
203
|
+
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig
|
|
204
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius } as IBoxInputData
|
|
172
205
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle
|
|
173
206
|
}
|
|
174
207
|
|
|
175
|
-
public getPointsStyle():
|
|
176
|
-
const { point } = this.editor.
|
|
208
|
+
public getPointsStyle(): IBoxInputData[] {
|
|
209
|
+
const { point } = this.editor.mergeConfig
|
|
177
210
|
return point instanceof Array ? point : [point]
|
|
178
211
|
}
|
|
179
212
|
|
|
180
|
-
public getMiddlePointsStyle():
|
|
181
|
-
const { middlePoint } = this.editor.
|
|
213
|
+
public getMiddlePointsStyle(): IBoxInputData[] {
|
|
214
|
+
const { middlePoint } = this.editor.mergeConfig
|
|
182
215
|
return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle())
|
|
183
216
|
}
|
|
184
217
|
|
|
218
|
+
protected onSelect(e: EditorEvent): void {
|
|
219
|
+
if (e.oldList.length === 1) e.oldList[0].syncEventer = this.app.interaction.bottomList = null
|
|
220
|
+
}
|
|
221
|
+
|
|
185
222
|
// drag
|
|
186
223
|
|
|
187
224
|
protected onDragStart(e: DragEvent): void {
|
|
188
225
|
this.dragging = true
|
|
189
|
-
if (e.
|
|
226
|
+
if (e.current.name === 'rect') {
|
|
227
|
+
const { editor } = this
|
|
190
228
|
this.moving = true
|
|
191
|
-
|
|
229
|
+
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y }
|
|
230
|
+
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1 // move
|
|
192
231
|
}
|
|
193
232
|
}
|
|
194
233
|
|
|
195
234
|
protected onDragEnd(e: DragEvent): void {
|
|
196
235
|
this.dragging = false
|
|
197
236
|
this.moving = false
|
|
198
|
-
if (e.
|
|
237
|
+
if (e.current.name === 'rect') this.editor.opacity = 1 // move
|
|
199
238
|
|
|
200
239
|
}
|
|
201
240
|
|
|
202
241
|
protected onDrag(e: DragEvent): void {
|
|
203
242
|
const { editor } = this
|
|
204
243
|
const point = this.enterPoint = e.current as IEditPoint
|
|
205
|
-
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.
|
|
206
|
-
if (editor.
|
|
244
|
+
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
|
|
245
|
+
if (editor.mergeConfig.rotateable) editor.onRotate(e)
|
|
207
246
|
} else {
|
|
208
247
|
editor.onScale(e)
|
|
209
248
|
}
|
|
@@ -211,7 +250,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
211
250
|
}
|
|
212
251
|
|
|
213
252
|
public onArrow(e: IKeyEvent): void {
|
|
214
|
-
if (this.editor.
|
|
253
|
+
if (this.editor.editing && this.editor.mergeConfig.keyEvent) {
|
|
215
254
|
const move = { x: 0, y: 0 }
|
|
216
255
|
const distance = e.shiftKey ? 10 : 1
|
|
217
256
|
switch (e.code) {
|
|
@@ -227,18 +266,34 @@ export class EditBox extends Group implements IEditBox {
|
|
|
227
266
|
case 'ArrowRight':
|
|
228
267
|
move.x = distance
|
|
229
268
|
}
|
|
230
|
-
|
|
269
|
+
this.editor.move(move)
|
|
231
270
|
}
|
|
232
271
|
}
|
|
233
272
|
|
|
234
|
-
|
|
273
|
+
|
|
274
|
+
protected onDoubleTap(e: PointerEvent): void {
|
|
275
|
+
if (this.editor.mergeConfig.openInner === 'double') this.openInner(e)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
protected onLongPress(e: PointerEvent): void {
|
|
279
|
+
if (this.editor.mergeConfig.openInner === 'long') this.openInner(e)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
protected openInner(e: PointerEvent): void {
|
|
235
283
|
const { editor } = this
|
|
236
|
-
if (editor.single
|
|
237
|
-
|
|
284
|
+
if (editor.single) {
|
|
285
|
+
const { element } = editor
|
|
286
|
+
if (element.isBranch) {
|
|
287
|
+
editor.openGroup(element as IGroup)
|
|
288
|
+
editor.target = editor.selector.findDeepOne(e)
|
|
289
|
+
} else {
|
|
290
|
+
editor.openInnerEditor()
|
|
291
|
+
}
|
|
238
292
|
}
|
|
239
293
|
}
|
|
240
294
|
|
|
241
|
-
|
|
295
|
+
|
|
296
|
+
public listenPointEvents(point: IEditPoint, type: IEditPointType, direction: Direction9): void {
|
|
242
297
|
const { editor } = this
|
|
243
298
|
point.direction = direction
|
|
244
299
|
point.pointType = type
|
|
@@ -252,12 +307,13 @@ export class EditBox extends Group implements IEditBox {
|
|
|
252
307
|
protected __listenEvents(): void {
|
|
253
308
|
const { rect, editor } = this
|
|
254
309
|
this.__eventIds = [
|
|
255
|
-
editor.on_(EditorEvent.SELECT,
|
|
310
|
+
editor.on_(EditorEvent.SELECT, this.onSelect, this),
|
|
256
311
|
rect.on_(DragEvent.START, this.onDragStart, this),
|
|
257
312
|
rect.on_(DragEvent.DRAG, editor.onMove, editor),
|
|
258
313
|
rect.on_(DragEvent.END, this.onDragEnd, this),
|
|
259
314
|
rect.on_(PointerEvent.ENTER, () => updateMoveCursor(editor)),
|
|
260
|
-
rect.on_(PointerEvent.
|
|
315
|
+
rect.on_(PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
|
|
316
|
+
rect.on_(PointerEvent.LONG_PRESS, this.onLongPress, this)
|
|
261
317
|
]
|
|
262
318
|
}
|
|
263
319
|
|
package/src/display/EditPoint.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Box } from '@leafer-ui/
|
|
1
|
+
import { Box, Direction9 } from '@leafer-ui/draw'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IEditPoint, IEditPointType } from '@leafer-in/interface'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class EditPoint extends Box implements IEditPoint {
|
|
7
|
-
public direction:
|
|
7
|
+
public direction: Direction9
|
|
8
8
|
public pointType: IEditPointType
|
|
9
9
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IBounds, ILeaf, ILeafList, IUI, IEventListenerId } from '@leafer-ui/interface'
|
|
2
|
-
import { Bounds,
|
|
1
|
+
import { IBounds, ILeaf, ILeafList, IUI, IEventListenerId, IPointerEvent } from '@leafer-ui/interface'
|
|
2
|
+
import { Bounds, LeafList, Group } from '@leafer-ui/draw'
|
|
3
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
5
|
import { IEditSelect, IEditor, ISelectArea, IStroker } from '@leafer-in/interface'
|
|
5
6
|
|
|
@@ -16,7 +17,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
16
17
|
public editor: IEditor
|
|
17
18
|
|
|
18
19
|
public get dragging(): boolean { return !!this.originList }
|
|
19
|
-
public get running(): boolean { return this.editor.hittable &&
|
|
20
|
+
public get running(): boolean { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector }
|
|
20
21
|
public get isMoveMode(): boolean { return this.app && this.app.interaction.moveMode }
|
|
21
22
|
|
|
22
23
|
public hoverStroker: IStroker = new Stroker()
|
|
@@ -26,7 +27,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
26
27
|
public selectArea: ISelectArea = new SelectArea()
|
|
27
28
|
|
|
28
29
|
protected originList: ILeafList
|
|
29
|
-
protected
|
|
30
|
+
protected needRemoveItem: IUI
|
|
30
31
|
|
|
31
32
|
protected __eventIds: IEventListenerId[] = []
|
|
32
33
|
|
|
@@ -43,8 +44,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
43
44
|
protected onHover(): void {
|
|
44
45
|
const { editor } = this
|
|
45
46
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
46
|
-
const { stroke, strokeWidth, hover } = editor.
|
|
47
|
-
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth })
|
|
47
|
+
const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig
|
|
48
|
+
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth, ...(hoverStyle || {}) })
|
|
48
49
|
} else {
|
|
49
50
|
this.hoverStroker.target = null
|
|
50
51
|
}
|
|
@@ -52,7 +53,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
52
53
|
|
|
53
54
|
protected onSelect(): void {
|
|
54
55
|
if (this.running) {
|
|
55
|
-
const { config, list } = this.editor
|
|
56
|
+
const { mergeConfig: config, list } = this.editor
|
|
56
57
|
const { stroke, strokeWidth } = config
|
|
57
58
|
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) })
|
|
58
59
|
this.hoverStroker.target = null
|
|
@@ -60,7 +61,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
public update(): void {
|
|
63
|
-
if (this.
|
|
64
|
+
if (this.targetStroker.target) this.targetStroker.forceUpdate()
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// move / down
|
|
@@ -68,7 +69,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
68
69
|
protected onPointerMove(e: PointerEvent): void {
|
|
69
70
|
const { app, editor } = this
|
|
70
71
|
if (this.running && !this.isMoveMode && app.config.pointer.hover && !app.interaction.dragging) {
|
|
71
|
-
const find =
|
|
72
|
+
const find = this.findUI(e)
|
|
72
73
|
editor.hoverTarget = editor.hasItem(find) ? null : find
|
|
73
74
|
} if (this.isMoveMode) {
|
|
74
75
|
editor.hoverTarget = null // move.dragEmpty
|
|
@@ -76,45 +77,38 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
protected onBeforeDown(e: PointerEvent): void {
|
|
79
|
-
const { select } = this.editor.
|
|
80
|
-
if (select === 'press') this.checkAndSelect(e
|
|
80
|
+
const { select } = this.editor.mergeConfig
|
|
81
|
+
if (select === 'press') this.checkAndSelect(e)
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
protected onTap(e: PointerEvent): void {
|
|
84
85
|
const { editor } = this
|
|
85
|
-
const { select
|
|
86
|
+
const { select } = editor.mergeConfig
|
|
86
87
|
if (select === 'tap') this.checkAndSelect(e)
|
|
87
88
|
|
|
88
|
-
if (this.
|
|
89
|
-
|
|
90
|
-
if (find) editor.shiftItem(find)
|
|
91
|
-
else if (!e.shiftKey && continuousSelect) editor.target = null
|
|
89
|
+
if (this.needRemoveItem) {
|
|
90
|
+
editor.removeItem(this.needRemoveItem)
|
|
92
91
|
} else if (this.isMoveMode) {
|
|
93
92
|
editor.target = null // move.dragEmpty
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
this.lastDownLeaf = null
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
protected checkAndSelect(e: PointerEvent
|
|
100
|
-
|
|
97
|
+
protected checkAndSelect(e: PointerEvent): void { // pointer.down or tap
|
|
98
|
+
this.needRemoveItem = null
|
|
99
|
+
|
|
100
|
+
if (this.allowSelect(e)) {
|
|
101
101
|
const { editor } = this
|
|
102
|
-
const find = this.
|
|
102
|
+
const find = this.findUI(e)
|
|
103
103
|
|
|
104
104
|
if (find) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
editor.
|
|
105
|
+
if (this.isMultipleSelect(e)) {
|
|
106
|
+
if (editor.hasItem(find)) this.needRemoveItem = find // 等待tap事件再实际移除
|
|
107
|
+
else editor.addItem(find)
|
|
108
108
|
} else {
|
|
109
109
|
editor.target = find
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
// change down data
|
|
113
|
-
if (isDownType) {
|
|
114
|
-
editor.updateLayout()
|
|
115
|
-
if (!find.locked) this.app.interaction.updateDownData(e, { findList: [editor.editBox.rect] }, editor.config.dualEvent)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
112
|
} else if (this.allow(e.target)) {
|
|
119
113
|
|
|
120
114
|
if (!e.shiftKey) editor.target = null
|
|
@@ -126,14 +120,14 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
126
120
|
// drag
|
|
127
121
|
|
|
128
122
|
protected onDragStart(e: DragEvent): void {
|
|
129
|
-
if (this.
|
|
123
|
+
if (this.allowDrag(e)) {
|
|
130
124
|
const { editor } = this
|
|
131
|
-
const { stroke,
|
|
125
|
+
const { stroke, area } = editor.mergeConfig
|
|
132
126
|
const { x, y } = e.getInner(this)
|
|
133
127
|
|
|
134
128
|
this.bounds.set(x, y)
|
|
135
129
|
|
|
136
|
-
this.selectArea.setStyle({ visible: true, stroke,
|
|
130
|
+
this.selectArea.setStyle({ visible: true, stroke, x, y }, area)
|
|
137
131
|
this.selectArea.setBounds(this.bounds.get())
|
|
138
132
|
|
|
139
133
|
this.originList = editor.leafList.clone()
|
|
@@ -196,18 +190,30 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
196
190
|
}
|
|
197
191
|
|
|
198
192
|
protected allowDrag(e: DragEvent) {
|
|
199
|
-
if (this.editor.
|
|
200
|
-
return (!this.editor.
|
|
193
|
+
if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
|
|
194
|
+
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path))
|
|
201
195
|
} else {
|
|
202
196
|
return false
|
|
203
197
|
}
|
|
204
198
|
}
|
|
205
199
|
|
|
206
|
-
protected
|
|
200
|
+
protected allowSelect(e: IPointerEvent): boolean {
|
|
201
|
+
return this.running && !this.isMoveMode && !e.middle
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public findDeepOne(e: PointerEvent): IUI {
|
|
207
205
|
const options = { exclude: new LeafList(this.editor.editBox.rect) }
|
|
208
206
|
return findOne(e.target.leafer.interaction.findPath(e, options)) as IUI
|
|
209
207
|
}
|
|
210
208
|
|
|
209
|
+
public findUI(e: PointerEvent): IUI {
|
|
210
|
+
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public isMultipleSelect(e: IPointerEvent): boolean {
|
|
214
|
+
return e.shiftKey || this.editor.mergeConfig.continuousSelect
|
|
215
|
+
}
|
|
216
|
+
|
|
211
217
|
protected __listenEvents(): void {
|
|
212
218
|
const { editor } = this
|
|
213
219
|
editor.waitLeafer(() => {
|
|
@@ -242,7 +248,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
242
248
|
}
|
|
243
249
|
|
|
244
250
|
public destroy(): void {
|
|
245
|
-
this.editor = this.originList = this.
|
|
251
|
+
this.editor = this.originList = this.needRemoveItem = null
|
|
246
252
|
this.__removeListenEvents()
|
|
247
253
|
super.destroy()
|
|
248
254
|
}
|
package/src/display/Stroker.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IUI, ILeaferCanvas, IRenderOptions, IRectInputData } from '@leafer-ui/interface'
|
|
2
|
-
import { Paint, UI, MatrixHelper } from '@leafer-ui/
|
|
2
|
+
import { Paint, UI, MatrixHelper } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IStroker } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -24,8 +24,7 @@ export class Stroker extends UI implements IStroker {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public setTarget(target: IUI | IUI[], style: IRectInputData): void {
|
|
27
|
-
|
|
28
|
-
this.set({ stroke, strokeWidth })
|
|
27
|
+
this.set(style)
|
|
29
28
|
this.target = target
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -34,7 +33,7 @@ export class Stroker extends UI implements IStroker {
|
|
|
34
33
|
if (list.length) {
|
|
35
34
|
|
|
36
35
|
let leaf: IUI
|
|
37
|
-
const { stroke, strokeWidth } = this.__
|
|
36
|
+
const { stroke, strokeWidth, fill } = this.__
|
|
38
37
|
const { bounds } = options
|
|
39
38
|
|
|
40
39
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -73,7 +72,8 @@ export class Stroker extends UI implements IStroker {
|
|
|
73
72
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX)
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas)
|
|
75
|
+
if (stroke) typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas)
|
|
76
|
+
if (fill) typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas)
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
package/src/editor/cursor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IObject, IUIEvent } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
3
|
import { IEditor } from '@leafer-in/interface'
|
|
4
|
-
import { MathHelper } from '@leafer-ui/
|
|
4
|
+
import { MathHelper } from '@leafer-ui/draw'
|
|
5
5
|
|
|
6
6
|
import { EditDataHelper } from '../helper/EditDataHelper'
|
|
7
7
|
|
|
@@ -10,11 +10,11 @@ const cacheCursors: IObject = {}
|
|
|
10
10
|
|
|
11
11
|
export function updateCursor(editor: IEditor, e: IUIEvent): void {
|
|
12
12
|
const { editBox } = editor, point = editBox.enterPoint
|
|
13
|
-
if (!point || !editor.
|
|
13
|
+
if (!point || !editor.editing || !editBox.visible) return
|
|
14
14
|
if (point.name === 'circle') return // 独立旋转按钮
|
|
15
15
|
|
|
16
16
|
let { rotation } = editBox
|
|
17
|
-
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.
|
|
17
|
+
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig
|
|
18
18
|
const { pointType } = point, { flippedX, flippedY } = editBox
|
|
19
19
|
|
|
20
20
|
let showResize = pointType === 'resize'
|
|
@@ -36,7 +36,7 @@ export function updateCursor(editor: IEditor, e: IUIEvent): void {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function updateMoveCursor(editor: IEditor): void {
|
|
39
|
-
editor.editBox.rect.cursor = editor.
|
|
39
|
+
editor.editBox.rect.cursor = editor.mergeConfig.moveCursor
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
|
package/src/editor/simulate.ts
CHANGED
package/src/editor/target.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeafList } from '@leafer-ui/
|
|
1
|
+
import { LeafList } from '@leafer-ui/draw'
|
|
2
2
|
|
|
3
3
|
import { IEditor, IUI } from '@leafer-in/interface'
|
|
4
4
|
|
|
@@ -16,8 +16,9 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }))
|
|
19
|
+
editor.checkOpenedGroups()
|
|
19
20
|
|
|
20
|
-
if (editor.
|
|
21
|
+
if (editor.editing) {
|
|
21
22
|
editor.waitLeafer(() => {
|
|
22
23
|
if (editor.multiple) simulate(editor)
|
|
23
24
|
updateMoveCursor(editor)
|
|
@@ -26,6 +27,7 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
26
27
|
editor.listenTargetEvents()
|
|
27
28
|
})
|
|
28
29
|
} else {
|
|
30
|
+
editor.updateEditTool()
|
|
29
31
|
editor.removeTargetEvents()
|
|
30
32
|
}
|
|
31
33
|
}
|
package/src/event/EditorEvent.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAround, IDragEvent, IMatrixData } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IEditorScaleEvent } from '@leafer-in/interface'
|
|
4
|
+
import { Direction9 } from '@leafer-ui/draw'
|
|
4
5
|
|
|
5
6
|
import { EditorEvent } from './EditorEvent'
|
|
6
7
|
|
|
@@ -16,7 +17,7 @@ export class EditorScaleEvent extends EditorEvent implements IEditorScaleEvent {
|
|
|
16
17
|
|
|
17
18
|
readonly drag: IDragEvent
|
|
18
19
|
|
|
19
|
-
readonly direction:
|
|
20
|
+
readonly direction: Direction9
|
|
20
21
|
readonly lockRatio: boolean
|
|
21
22
|
readonly around: IAround
|
|
22
23
|
|