@leafer-in/editor 1.8.0 → 1.9.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 +1212 -1022
- package/dist/editor.esm.js +1191 -1020
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +1110 -1051
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +5 -4
- package/src/decorator/data.ts +3 -3
- package/src/display/EditBox.ts +27 -16
- package/src/display/EditSelect.ts +9 -3
- package/src/display/Stroker.ts +4 -4
- package/src/editor/cursor.ts +1 -1
- package/src/event/EditorEvent.ts +2 -2
- package/src/tool/TransformTool.ts +21 -11
- package/types/index.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
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.
|
|
38
|
-
"@leafer-ui/core": "^1.
|
|
39
|
-
"@leafer-in/resize": "^1.
|
|
40
|
-
"@leafer-ui/interface": "^1.
|
|
41
|
-
"@leafer-in/interface": "^1.
|
|
37
|
+
"@leafer-ui/draw": "^1.9.1",
|
|
38
|
+
"@leafer-ui/core": "^1.9.1",
|
|
39
|
+
"@leafer-in/resize": "^1.9.1",
|
|
40
|
+
"@leafer-ui/interface": "^1.9.1",
|
|
41
|
+
"@leafer-in/interface": "^1.9.1"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup, IObject, IAlign, IAxis, IFunction, IMatrix, IApp } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, DataHelper, LeafList, RenderEvent, LeafHelper, Direction9, Plugin } from '@leafer-ui/draw'
|
|
2
|
+
import { Group, DataHelper, LeafList, RenderEvent, LeafHelper, Direction9, Plugin, isString } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, RotateEvent, ZoomEvent, MoveEvent, useModule } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditPoint, IEditor, IEditorConfig, IEditTool, IEditorScaleEvent, IInnerEditor, ISimulateElement } from '@leafer-in/interface'
|
|
@@ -259,7 +259,7 @@ export class Editor extends Group implements IEditor {
|
|
|
259
259
|
|
|
260
260
|
public emitGroupEvent(type: string, group?: IGroup): void {
|
|
261
261
|
const event = new EditorGroupEvent(type, { editTarget: group })
|
|
262
|
-
this.emitEvent(event)
|
|
262
|
+
if (!group || !group.syncEventer) this.emitEvent(event) // 单选时,元素会自动将事件传递给 editor,避免重复触发
|
|
263
263
|
if (group) group.emitEvent(event)
|
|
264
264
|
}
|
|
265
265
|
|
|
@@ -267,7 +267,7 @@ export class Editor extends Group implements IEditor {
|
|
|
267
267
|
|
|
268
268
|
public openInnerEditor(target?: IUI, nameOrSelect?: string | boolean, select?: boolean): void {
|
|
269
269
|
let name: string
|
|
270
|
-
if (
|
|
270
|
+
if (isString(nameOrSelect)) name = nameOrSelect
|
|
271
271
|
else if (!select) select = nameOrSelect
|
|
272
272
|
|
|
273
273
|
if (target && select) this.target = target
|
|
@@ -284,6 +284,7 @@ export class Editor extends Group implements IEditor {
|
|
|
284
284
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN)
|
|
285
285
|
this.innerEditor.load()
|
|
286
286
|
this.emitInnerEvent(InnerEditorEvent.OPEN)
|
|
287
|
+
console.log('hello')
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
}
|
|
@@ -304,7 +305,7 @@ export class Editor extends Group implements IEditor {
|
|
|
304
305
|
public emitInnerEvent(type: string): void {
|
|
305
306
|
const { innerEditor } = this, { editTarget } = innerEditor
|
|
306
307
|
const event = new InnerEditorEvent(type, { editTarget, innerEditor })
|
|
307
|
-
this.emitEvent(event)
|
|
308
|
+
if (!editTarget.syncEventer) this.emitEvent(event) // 单选时,元素会自动将事件传递给 editor,避免重复触发
|
|
308
309
|
editTarget.emitEvent(event)
|
|
309
310
|
}
|
|
310
311
|
|
package/src/decorator/data.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IFunction, ILeaf, IObject, IUI, } from '@leafer-ui/interface'
|
|
2
2
|
import { IEditor } from '@leafer-in/interface'
|
|
3
|
-
import { defineKey, isNull } from '@leafer-ui/draw'
|
|
3
|
+
import { defineKey, isNull, isArray, isObject } from '@leafer-ui/draw'
|
|
4
4
|
|
|
5
5
|
import { EditorEvent } from '../event/EditorEvent'
|
|
6
6
|
|
|
@@ -18,13 +18,13 @@ export function targetAttr(fn: IFunction) {
|
|
|
18
18
|
|
|
19
19
|
const isSelect = key === 'target'
|
|
20
20
|
if (isSelect) {
|
|
21
|
-
if (value
|
|
21
|
+
if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
|
|
22
22
|
if ((this as IEditor).single) (this as IEditor).element.syncEventer = null // 重置 EditBox.load() 设置
|
|
23
23
|
|
|
24
24
|
const { beforeSelect } = (this as IEditor).config
|
|
25
25
|
if (beforeSelect) {
|
|
26
26
|
const check = beforeSelect({ target: value })
|
|
27
|
-
if (
|
|
27
|
+
if (isObject(check)) value = check
|
|
28
28
|
else if (check === false) return
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/display/EditBox.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, IEventParams, ITransformTool } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Box, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper } from '@leafer-ui/draw'
|
|
1
|
+
import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, IEventParams, ITransformTool, IUIEvent } from '@leafer-ui/interface'
|
|
2
|
+
import { Group, Box, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, isArray, isString, isNumber } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, PointerEvent, KeyEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
|
|
@@ -66,7 +66,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
66
66
|
public get canGesture(): boolean { // 是否支持手势
|
|
67
67
|
if (!this.canUse) return false
|
|
68
68
|
const { moveable, resizeable, rotateable } = this.mergeConfig
|
|
69
|
-
return
|
|
69
|
+
return isString(moveable) || isString(resizeable) || isString(rotateable)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
protected __eventIds: IEventListenerId[] = []
|
|
@@ -114,6 +114,8 @@ export class EditBox extends Group implements IEditBox {
|
|
|
114
114
|
const pointsStyle = this.getPointsStyle()
|
|
115
115
|
const middlePointsStyle = this.getMiddlePointsStyle()
|
|
116
116
|
|
|
117
|
+
this.visible = !target.locked
|
|
118
|
+
|
|
117
119
|
let resizeP: IRect
|
|
118
120
|
|
|
119
121
|
for (let i = 0; i < 8; i++) {
|
|
@@ -145,6 +147,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
145
147
|
public update(): void {
|
|
146
148
|
const { editor } = this
|
|
147
149
|
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true)
|
|
150
|
+
this.visible = !this.target.locked
|
|
148
151
|
this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
|
|
149
152
|
this.updateBounds({ x: 0, y: 0, width, height })
|
|
150
153
|
}
|
|
@@ -158,16 +161,15 @@ export class EditBox extends Group implements IEditBox {
|
|
|
158
161
|
public updateBounds(bounds: IBoundsData): void {
|
|
159
162
|
const { editMask } = this.editor
|
|
160
163
|
const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this
|
|
161
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread } = mergeConfig
|
|
164
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread, hideRotatePoints, hideResizeLines } = mergeConfig
|
|
162
165
|
|
|
163
|
-
this.visible = !this.target.locked
|
|
164
166
|
editMask.visible = mask ? true : 0
|
|
165
167
|
|
|
166
168
|
if (spread) BoundsHelper.spread(bounds, spread)
|
|
167
169
|
|
|
168
170
|
if (this.view.worldOpacity) {
|
|
169
171
|
const { width, height } = bounds
|
|
170
|
-
const smallSize =
|
|
172
|
+
const smallSize = isNumber(hideOnSmall) ? hideOnSmall : 10
|
|
171
173
|
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize)
|
|
172
174
|
|
|
173
175
|
let point = {} as IPointData, rotateP: IRect, resizeP: IRect, resizeL: IRect
|
|
@@ -177,17 +179,19 @@ export class EditBox extends Group implements IEditBox {
|
|
|
177
179
|
AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point)
|
|
178
180
|
resizeP = resizePoints[i]
|
|
179
181
|
rotateP = rotatePoints[i]
|
|
180
|
-
resizeL = resizeLines[Math.floor(i / 2)]
|
|
181
182
|
resizeP.set(point)
|
|
182
183
|
rotateP.set(point)
|
|
183
|
-
resizeL.set(point)
|
|
184
184
|
|
|
185
185
|
// visible
|
|
186
|
-
resizeP.visible =
|
|
187
|
-
rotateP.visible = showPoints && rotateable && resizeable && !
|
|
186
|
+
resizeP.visible = showPoints && !!(resizeable || rotateable)
|
|
187
|
+
rotateP.visible = showPoints && rotateable && resizeable && !hideRotatePoints
|
|
188
188
|
|
|
189
189
|
if (i % 2) { // top, right, bottom, left
|
|
190
190
|
|
|
191
|
+
resizeL = resizeLines[(i - 1) / 2]
|
|
192
|
+
resizeL.set(point)
|
|
193
|
+
|
|
194
|
+
resizeL.visible = resizeP.visible && !hideResizeLines
|
|
191
195
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint
|
|
192
196
|
|
|
193
197
|
if (((i + 1) / 2) % 2) { // top, bottom
|
|
@@ -265,12 +269,12 @@ export class EditBox extends Group implements IEditBox {
|
|
|
265
269
|
|
|
266
270
|
public getPointsStyle(): IBoxInputData[] {
|
|
267
271
|
const { point } = this.mergedConfig
|
|
268
|
-
return point
|
|
272
|
+
return isArray(point) ? point : [point]
|
|
269
273
|
}
|
|
270
274
|
|
|
271
275
|
public getMiddlePointsStyle(): IBoxInputData[] {
|
|
272
276
|
const { middlePoint } = this.mergedConfig
|
|
273
|
-
return middlePoint
|
|
277
|
+
return isArray(middlePoint) ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle())
|
|
274
278
|
}
|
|
275
279
|
|
|
276
280
|
|
|
@@ -286,7 +290,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
286
290
|
moveable && (this.moving = true)
|
|
287
291
|
editor.opacity = hideOnMove ? 0 : 1 // move
|
|
288
292
|
} else {
|
|
289
|
-
if (pointType.includes('rotate') ||
|
|
293
|
+
if (pointType.includes('rotate') || this.isHoldRotateKey(e) || !resizeable) {
|
|
290
294
|
rotateable && (this.rotating = true)
|
|
291
295
|
if (pointType === 'resize-rotate') resizeable && (this.resizing = true)
|
|
292
296
|
else if (point.name === 'resize-line') skewable && (this.skewing = true), this.rotating = false
|
|
@@ -303,6 +307,8 @@ export class EditBox extends Group implements IEditBox {
|
|
|
303
307
|
}
|
|
304
308
|
|
|
305
309
|
protected onDragEnd(e: DragEvent): void {
|
|
310
|
+
if (this.mergeConfig.dragLimitAnimate && this.moving) this.transformTool.onMove(e)
|
|
311
|
+
|
|
306
312
|
this.dragPoint = null
|
|
307
313
|
this.resetDoing()
|
|
308
314
|
const { name, pointType } = e.current as IEditPoint
|
|
@@ -334,7 +340,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
334
340
|
public onMove(e: MoveEvent): void {
|
|
335
341
|
if (this.canGesture && e.moveType !== 'drag') {
|
|
336
342
|
e.stop()
|
|
337
|
-
if (
|
|
343
|
+
if (isString(this.mergeConfig.moveable)) {
|
|
338
344
|
this.gesturing = this.moving = true
|
|
339
345
|
this.transformTool.onMove(e)
|
|
340
346
|
}
|
|
@@ -344,7 +350,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
344
350
|
public onScale(e: ZoomEvent): void {
|
|
345
351
|
if (this.canGesture) {
|
|
346
352
|
e.stop()
|
|
347
|
-
if (
|
|
353
|
+
if (isString(this.mergeConfig.resizeable)) {
|
|
348
354
|
this.gesturing = this.resizing = true
|
|
349
355
|
this.transformTool.onScale(e)
|
|
350
356
|
}
|
|
@@ -354,7 +360,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
354
360
|
public onRotate(e: RotateEvent): void {
|
|
355
361
|
if (this.canGesture) {
|
|
356
362
|
e.stop()
|
|
357
|
-
if (
|
|
363
|
+
if (isString(this.mergeConfig.rotateable)) {
|
|
358
364
|
this.gesturing = this.rotating = true
|
|
359
365
|
this.transformTool.onRotate(e)
|
|
360
366
|
}
|
|
@@ -362,6 +368,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
// 键盘
|
|
371
|
+
public isHoldRotateKey(e: IUIEvent): boolean { // 按住ctrl在控制点上变旋转功能
|
|
372
|
+
const { rotateKey } = this.mergedConfig
|
|
373
|
+
if (rotateKey) return e.isHoldKeys(rotateKey)
|
|
374
|
+
return e.metaKey || e.ctrlKey
|
|
375
|
+
}
|
|
365
376
|
|
|
366
377
|
protected onKey(e: KeyEvent): void {
|
|
367
378
|
updatePointCursor(this, e)
|
|
@@ -125,7 +125,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
125
125
|
|
|
126
126
|
} else if (this.allow(e.target)) {
|
|
127
127
|
|
|
128
|
-
if (!e
|
|
128
|
+
if (!this.isHoldMultipleSelectKey(e)) editor.target = null
|
|
129
129
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -209,7 +209,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
209
209
|
protected allowDrag(e: DragEvent) {
|
|
210
210
|
const { boxSelect, multipleSelect } = this.editor.mergeConfig
|
|
211
211
|
if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
|
|
212
|
-
return (!this.editor.editing && this.allow(e.target)) || (e
|
|
212
|
+
return (!this.editor.editing && this.allow(e.target)) || (this.isHoldMultipleSelectKey(e) && !findOne(e.path))
|
|
213
213
|
} else {
|
|
214
214
|
return false
|
|
215
215
|
}
|
|
@@ -230,7 +230,13 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
230
230
|
|
|
231
231
|
public isMultipleSelect(e: IPointerEvent): boolean {
|
|
232
232
|
const { multipleSelect, continuousSelect } = this.editor.mergeConfig
|
|
233
|
-
return multipleSelect && (e
|
|
233
|
+
return multipleSelect && (this.isHoldMultipleSelectKey(e) || continuousSelect)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public isHoldMultipleSelectKey(e: IPointerEvent): boolean {
|
|
237
|
+
const { multipleSelectKey } = this.editor.mergedConfig
|
|
238
|
+
if (multipleSelectKey) return e.isHoldKeys(multipleSelectKey)
|
|
239
|
+
return e.shiftKey
|
|
234
240
|
}
|
|
235
241
|
|
|
236
242
|
protected __listenEvents(): void {
|
package/src/display/Stroker.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IUI, ILeaferCanvas, IRenderOptions, IRectInputData, IMatrixWithOptionHalfData } from '@leafer-ui/interface'
|
|
2
|
-
import { Paint, UI, MatrixHelper, getBoundsData, getMatrixData, BoundsHelper, LeafBoundsHelper } from '@leafer-ui/draw'
|
|
2
|
+
import { Paint, UI, MatrixHelper, getBoundsData, getMatrixData, BoundsHelper, LeafBoundsHelper, isArray, isString } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IStroker } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -84,8 +84,8 @@ export class Stroker extends UI implements IStroker {
|
|
|
84
84
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
if (stroke)
|
|
88
|
-
if (fill)
|
|
87
|
+
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas)
|
|
88
|
+
if (fill) isString(fill) ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas)
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -102,5 +102,5 @@ export class Stroker extends UI implements IStroker {
|
|
|
102
102
|
|
|
103
103
|
function onTarget(stroker: Stroker): void {
|
|
104
104
|
const value = stroker.target
|
|
105
|
-
stroker.list = value ? (value
|
|
105
|
+
stroker.list = value ? (isArray(value) ? value : [value]) : []
|
|
106
106
|
}
|
package/src/editor/cursor.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function updatePointCursor(editBox: IEditBox, e: IUIEvent): void {
|
|
|
21
21
|
const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig
|
|
22
22
|
|
|
23
23
|
let showResize = pointType.includes('resize')
|
|
24
|
-
if (showResize && rotateable && (
|
|
24
|
+
if (showResize && rotateable && (editBox.isHoldRotateKey(e) || !resizeable)) showResize = false
|
|
25
25
|
const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew')
|
|
26
26
|
|
|
27
27
|
const cursor = dragging
|
package/src/event/EditorEvent.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IUI, IPointData } from '@leafer-ui/interface'
|
|
2
|
-
import { Event } from '@leafer-ui/draw'
|
|
2
|
+
import { Event, isArray } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IEditor, IEditorEvent } from '@leafer-in/interface'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
function toList(value: IUI | IUI[]): IUI[] {
|
|
8
|
-
return value ? (value
|
|
8
|
+
return value ? (isArray(value) ? value : [value]) : []
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export class EditorEvent extends Event implements IEditorEvent {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IEvent, IPointData, IAlign, IAxis, IFunction, IMatrix } from '@leafer-ui/interface'
|
|
2
|
-
import { MathHelper, Matrix, LeafHelper, AroundHelper } from '@leafer-ui/draw'
|
|
1
|
+
import { IEvent, IPointData, IAlign, IAxis, IFunction, IMatrix, IUI } from '@leafer-ui/interface'
|
|
2
|
+
import { MathHelper, Matrix, LeafHelper, AroundHelper, isObject, isNumber, isUndefined } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditPoint, IEditTool, IEditorScaleEvent, ISimulateElement, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent } from '@leafer-in/interface'
|
|
@@ -23,12 +23,18 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
23
23
|
|
|
24
24
|
public onMove(e: DragEvent | MoveEvent): void {
|
|
25
25
|
|
|
26
|
-
const { target, dragStartData } = this.editBox
|
|
26
|
+
const { target, mergeConfig, dragStartData, app } = this.editBox
|
|
27
|
+
|
|
28
|
+
let move: IPointData, { dragLimitAnimate } = mergeConfig
|
|
29
|
+
if (isUndefined(dragLimitAnimate)) dragLimitAnimate = app && app.config.pointer.dragLimitAnimate
|
|
30
|
+
|
|
31
|
+
const isMoveEnd = e.type === DragEvent.END || e.type === DragEvent.END
|
|
32
|
+
const checkLimitMove = !dragLimitAnimate || isMoveEnd
|
|
27
33
|
|
|
28
34
|
if (e instanceof MoveEvent) {
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
move = e.getLocalMove(target)
|
|
37
|
+
if (checkLimitMove) DragEvent.limitMove(target, move)
|
|
32
38
|
|
|
33
39
|
} else {
|
|
34
40
|
|
|
@@ -39,9 +45,13 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
39
45
|
else total.x = 0
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
move = DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove)
|
|
43
49
|
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
if (dragLimitAnimate && isMoveEnd) LeafHelper.animateMove(this as unknown as IUI, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : 0.3) // 是否进行动画
|
|
53
|
+
else this.move(move)
|
|
54
|
+
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
public onScale(e: DragEvent | ZoomEvent): void {
|
|
@@ -113,13 +123,13 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
113
123
|
|
|
114
124
|
public move(x: number | IPointData, y = 0): void {
|
|
115
125
|
if (!this.checkTransform('moveable')) return
|
|
116
|
-
if (
|
|
126
|
+
if (isObject(x)) y = x.y, x = x.x
|
|
117
127
|
|
|
118
128
|
const { target, mergeConfig, single, editor } = this.editBox
|
|
119
129
|
const { beforeMove } = mergeConfig
|
|
120
130
|
if (beforeMove) {
|
|
121
131
|
const check = beforeMove({ target, x, y })
|
|
122
|
-
if (
|
|
132
|
+
if (isObject(check)) x = check.x, y = check.y
|
|
123
133
|
else if (check === false) return
|
|
124
134
|
}
|
|
125
135
|
|
|
@@ -160,7 +170,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
160
170
|
const { beforeScale } = mergeConfig
|
|
161
171
|
if (beforeScale) {
|
|
162
172
|
const check = beforeScale({ target, origin, scaleX, scaleY })
|
|
163
|
-
if (
|
|
173
|
+
if (isObject(check)) scaleX = check.scaleX, scaleY = check.scaleY
|
|
164
174
|
else if (check === false) return
|
|
165
175
|
}
|
|
166
176
|
|
|
@@ -197,7 +207,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
197
207
|
const { beforeRotate } = mergeConfig
|
|
198
208
|
if (beforeRotate) {
|
|
199
209
|
const check = beforeRotate({ target, origin, rotation })
|
|
200
|
-
if (
|
|
210
|
+
if (isNumber(check)) rotation = check
|
|
201
211
|
else if (check === false) return
|
|
202
212
|
}
|
|
203
213
|
|
|
@@ -219,7 +229,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
219
229
|
const { beforeSkew } = mergeConfig
|
|
220
230
|
if (beforeSkew) {
|
|
221
231
|
const check = beforeSkew({ target, origin, skewX, skewY })
|
|
222
|
-
if (
|
|
232
|
+
if (isObject(check)) skewX = check.skewX, skewY = check.skewY
|
|
223
233
|
else if (check === false) return
|
|
224
234
|
}
|
|
225
235
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IBox, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData } from '@leafer-ui/interface';
|
|
1
|
+
import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IBox, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData } from '@leafer-ui/interface';
|
|
2
2
|
import { Group, UI, Direction9, Box, Event } from '@leafer-ui/draw';
|
|
3
3
|
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
|
|
4
4
|
import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditPointType, IEditPointInputData, IEditorEvent, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IInnerEditorMode, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
|
|
@@ -34,6 +34,7 @@ declare class EditSelect extends Group implements IEditSelect {
|
|
|
34
34
|
findDeepOne(e: PointerEvent): IUI;
|
|
35
35
|
findUI(e: PointerEvent): IUI;
|
|
36
36
|
isMultipleSelect(e: IPointerEvent): boolean;
|
|
37
|
+
isHoldMultipleSelectKey(e: IPointerEvent): boolean;
|
|
37
38
|
protected __listenEvents(): void;
|
|
38
39
|
protected __removeListenEvents(): void;
|
|
39
40
|
destroy(): void;
|
|
@@ -181,6 +182,7 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
181
182
|
onMove(e: MoveEvent): void;
|
|
182
183
|
onScale(e: ZoomEvent): void;
|
|
183
184
|
onRotate(e: RotateEvent): void;
|
|
185
|
+
isHoldRotateKey(e: IUIEvent): boolean;
|
|
184
186
|
protected onKey(e: KeyEvent): void;
|
|
185
187
|
onArrow(e: IKeyEvent): void;
|
|
186
188
|
protected onDoubleTap(e: PointerEvent): void;
|