@leafer-in/editor 1.9.1 → 1.9.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/dist/editor.cjs +50 -18
- package/dist/editor.esm.js +50 -18
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +50 -18
- 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 +35 -12
- package/src/display/EditBox.ts +7 -2
- package/src/helper/EditorHelper.ts +1 -1
- package/src/tool/TransformTool.ts +9 -6
- package/types/index.d.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
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.9.
|
|
38
|
-
"@leafer-ui/core": "^1.9.
|
|
39
|
-
"@leafer-in/resize": "^1.9.
|
|
40
|
-
"@leafer-ui/interface": "^1.9.
|
|
41
|
-
"@leafer-in/interface": "^1.9.
|
|
37
|
+
"@leafer-ui/draw": "^1.9.3",
|
|
38
|
+
"@leafer-ui/core": "^1.9.3",
|
|
39
|
+
"@leafer-in/resize": "^1.9.3",
|
|
40
|
+
"@leafer-ui/interface": "^1.9.3",
|
|
41
|
+
"@leafer-in/interface": "^1.9.3"
|
|
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, isString } from '@leafer-ui/draw'
|
|
2
|
+
import { Group, DataHelper, LeafList, RenderEvent, LeafHelper, Direction9, Plugin, isString, PropertyEvent } 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'
|
|
@@ -78,6 +78,7 @@ export class Editor extends Group implements IEditor {
|
|
|
78
78
|
public selector: EditSelect = new EditSelect(this)
|
|
79
79
|
public editMask: EditMask = new EditMask(this)
|
|
80
80
|
|
|
81
|
+
public get targetLeafer() { const first = this.list[0]; return first && first.leafer }
|
|
81
82
|
public targetChanged: boolean
|
|
82
83
|
public targetEventIds: IEventListenerId[] = []
|
|
83
84
|
|
|
@@ -140,11 +141,22 @@ export class Editor extends Group implements IEditor {
|
|
|
140
141
|
this.unloadEditTool()
|
|
141
142
|
|
|
142
143
|
if (this.editing) {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
const target = this.element
|
|
145
|
+
let name = target.editOuter || 'EditTool'
|
|
146
|
+
|
|
147
|
+
const { beforeEditOuter } = this.mergeConfig
|
|
148
|
+
if (beforeEditOuter) {
|
|
149
|
+
const check = beforeEditOuter({ target, name })
|
|
150
|
+
if (isString(check)) name = check
|
|
151
|
+
else if (check === false) return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (EditToolCreator.list[name]) {
|
|
155
|
+
const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this)
|
|
156
|
+
this.editBox.load()
|
|
157
|
+
tool.load()
|
|
158
|
+
this.update()
|
|
159
|
+
}
|
|
148
160
|
}
|
|
149
161
|
}
|
|
150
162
|
|
|
@@ -273,18 +285,25 @@ export class Editor extends Group implements IEditor {
|
|
|
273
285
|
if (target && select) this.target = target
|
|
274
286
|
|
|
275
287
|
if (this.single) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
288
|
+
if (!target) target = this.element
|
|
289
|
+
if (!name) name = target.editInner
|
|
290
|
+
|
|
291
|
+
const { beforeEditInner } = this.mergeConfig
|
|
292
|
+
if (beforeEditInner) {
|
|
293
|
+
const check = beforeEditInner({ target, name })
|
|
294
|
+
if (isString(check)) name = check
|
|
295
|
+
else if (check === false) return
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (EditToolCreator.list[name]) {
|
|
279
299
|
this.editTool.unload()
|
|
280
300
|
this.innerEditing = true
|
|
281
301
|
this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this)
|
|
282
|
-
this.innerEditor.editTarget =
|
|
302
|
+
this.innerEditor.editTarget = target
|
|
283
303
|
|
|
284
304
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN)
|
|
285
305
|
this.innerEditor.load()
|
|
286
306
|
this.emitInnerEvent(InnerEditorEvent.OPEN)
|
|
287
|
-
console.log('hello')
|
|
288
307
|
}
|
|
289
308
|
}
|
|
290
309
|
}
|
|
@@ -345,14 +364,18 @@ export class Editor extends Group implements IEditor {
|
|
|
345
364
|
if (this.targetChanged) this.update()
|
|
346
365
|
}
|
|
347
366
|
|
|
367
|
+
protected onChildScroll(): void {
|
|
368
|
+
if (this.multiple) this.updateEditBox()
|
|
369
|
+
}
|
|
348
370
|
|
|
349
371
|
// event
|
|
350
372
|
|
|
351
373
|
public listenTargetEvents(): void {
|
|
352
374
|
if (!this.targetEventIds.length) {
|
|
353
|
-
const { app, leafer, editMask } = this
|
|
375
|
+
const { app, leafer, targetLeafer, editMask } = this
|
|
354
376
|
this.targetEventIds = [
|
|
355
377
|
leafer.on_(RenderEvent.START, this.onRenderStart, this),
|
|
378
|
+
targetLeafer && targetLeafer.on_(PropertyEvent.SCROLL, this.onChildScroll, this),
|
|
356
379
|
app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this)
|
|
357
380
|
]
|
|
358
381
|
if (editMask.visible) editMask.forceRender()
|
package/src/display/EditBox.ts
CHANGED
|
@@ -307,7 +307,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
protected onDragEnd(e: DragEvent): void {
|
|
310
|
-
if (this.
|
|
310
|
+
if (this.moving) this.transformTool.onMove(e)
|
|
311
311
|
|
|
312
312
|
this.dragPoint = null
|
|
313
313
|
this.resetDoing()
|
|
@@ -347,6 +347,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
public onMoveEnd(e: MoveEvent): void {
|
|
351
|
+
if (this.moving) this.transformTool.onMove(e)
|
|
352
|
+
this.resetDoing()
|
|
353
|
+
}
|
|
354
|
+
|
|
350
355
|
public onScale(e: ZoomEvent): void {
|
|
351
356
|
if (this.canGesture) {
|
|
352
357
|
e.stop()
|
|
@@ -468,7 +473,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
468
473
|
[MoveEvent.BEFORE_MOVE, this.onMove, this, true],
|
|
469
474
|
[ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
|
|
470
475
|
[RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
|
|
471
|
-
[MoveEvent.END, this.
|
|
476
|
+
[MoveEvent.END, this.onMoveEnd, this],
|
|
472
477
|
[ZoomEvent.END, this.resetDoing, this],
|
|
473
478
|
[RotateEvent.END, this.resetDoing, this],
|
|
474
479
|
])
|
|
@@ -22,7 +22,7 @@ export const EditorHelper = {
|
|
|
22
22
|
list.sort(order)
|
|
23
23
|
|
|
24
24
|
const matrx = new Matrix(element.worldTransform)
|
|
25
|
-
matrx.divideParent(parent.
|
|
25
|
+
matrx.divideParent(parent.scrollWorldTransform)
|
|
26
26
|
group.setTransform(matrx)
|
|
27
27
|
group.editable = true
|
|
28
28
|
group.hitChildren = false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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'
|
|
2
|
+
import { MathHelper, Matrix, LeafHelper, AroundHelper, isObject, isString, 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'
|
|
@@ -26,10 +26,12 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
26
26
|
const { target, mergeConfig, dragStartData, app } = this.editBox
|
|
27
27
|
|
|
28
28
|
let move: IPointData, { dragLimitAnimate } = mergeConfig
|
|
29
|
+
|
|
29
30
|
if (isUndefined(dragLimitAnimate)) dragLimitAnimate = app && app.config.pointer.dragLimitAnimate
|
|
30
31
|
|
|
31
|
-
const isMoveEnd = e.type ===
|
|
32
|
-
const
|
|
32
|
+
const isMoveEnd = e.type === MoveEvent.END || e.type === DragEvent.END
|
|
33
|
+
const axisDrag = isString(target.draggable)
|
|
34
|
+
const checkLimitMove = !dragLimitAnimate || isMoveEnd || axisDrag
|
|
33
35
|
|
|
34
36
|
if (e instanceof MoveEvent) {
|
|
35
37
|
|
|
@@ -49,9 +51,10 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
49
51
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if (move.x || move.y) {
|
|
55
|
+
if (dragLimitAnimate && !axisDrag && isMoveEnd) LeafHelper.animateMove(this as unknown as IUI, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : 0.3) // 是否进行动画
|
|
56
|
+
else this.move(move)
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
public onScale(e: DragEvent | ZoomEvent): void {
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _leafer_ui_interface from '@leafer-ui/interface';
|
|
1
2
|
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
3
|
import { Group, UI, Direction9, Box, Event } from '@leafer-ui/draw';
|
|
3
4
|
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
|
|
@@ -80,6 +81,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
80
81
|
editToolList: IObject;
|
|
81
82
|
selector: EditSelect;
|
|
82
83
|
editMask: EditMask;
|
|
84
|
+
get targetLeafer(): _leafer_ui_interface.ILeafer;
|
|
83
85
|
targetChanged: boolean;
|
|
84
86
|
targetEventIds: IEventListenerId[];
|
|
85
87
|
constructor(userConfig?: IEditorConfig, data?: IGroupInputData);
|
|
@@ -123,6 +125,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
123
125
|
toBottom(): void;
|
|
124
126
|
protected onAppRenderStart(app: IApp): void;
|
|
125
127
|
protected onRenderStart(): void;
|
|
128
|
+
protected onChildScroll(): void;
|
|
126
129
|
listenTargetEvents(): void;
|
|
127
130
|
removeTargetEvents(): void;
|
|
128
131
|
destroy(): void;
|
|
@@ -180,6 +183,7 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
180
183
|
protected onDrag(e: DragEvent): void;
|
|
181
184
|
protected resetDoing(): void;
|
|
182
185
|
onMove(e: MoveEvent): void;
|
|
186
|
+
onMoveEnd(e: MoveEvent): void;
|
|
183
187
|
onScale(e: ZoomEvent): void;
|
|
184
188
|
onRotate(e: RotateEvent): void;
|
|
185
189
|
isHoldRotateKey(e: IUIEvent): boolean;
|