@leafer-in/editor 1.9.2 → 1.9.4
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 +37 -18
- package/dist/editor.esm.js +38 -19
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +37 -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 +28 -9
- package/src/decorator/data.ts +4 -2
- package/src/display/EditBox.ts +1 -1
- package/src/helper/EditDataHelper.ts +5 -5
- package/src/tool/TransformTool.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.4",
|
|
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.4",
|
|
38
|
+
"@leafer-ui/core": "^1.9.4",
|
|
39
|
+
"@leafer-in/resize": "^1.9.4",
|
|
40
|
+
"@leafer-ui/interface": "^1.9.4",
|
|
41
|
+
"@leafer-in/interface": "^1.9.4"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -141,11 +141,22 @@ export class Editor extends Group implements IEditor {
|
|
|
141
141
|
this.unloadEditTool()
|
|
142
142
|
|
|
143
143
|
if (this.editing) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
+
}
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
|
|
@@ -274,13 +285,21 @@ export class Editor extends Group implements IEditor {
|
|
|
274
285
|
if (target && select) this.target = target
|
|
275
286
|
|
|
276
287
|
if (this.single) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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]) {
|
|
280
299
|
this.editTool.unload()
|
|
281
300
|
this.innerEditing = true
|
|
282
301
|
this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this)
|
|
283
|
-
this.innerEditor.editTarget =
|
|
302
|
+
this.innerEditor.editTarget = target
|
|
284
303
|
|
|
285
304
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN)
|
|
286
305
|
this.innerEditor.load()
|
package/src/decorator/data.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IFunction, ILeaf, IObject, IUI, } from '@leafer-ui/interface'
|
|
2
|
+
import { defineKey, isNull, isArray, isObject, isUndefined } from '@leafer-ui/draw'
|
|
3
|
+
|
|
2
4
|
import { IEditor } from '@leafer-in/interface'
|
|
3
|
-
import { defineKey, isNull, isArray, isObject } from '@leafer-ui/draw'
|
|
4
5
|
|
|
5
6
|
import { EditorEvent } from '../event/EditorEvent'
|
|
6
7
|
|
|
@@ -45,7 +46,7 @@ export function mergeConfigAttr() {
|
|
|
45
46
|
return (target: IEditor, key: string) => {
|
|
46
47
|
defineKey(target, key, {
|
|
47
48
|
get() {
|
|
48
|
-
const { config, element, dragPoint, editBox } = this, mergeConfig = { ...config } // 实时合并,后期可优化
|
|
49
|
+
const { config, element, dragPoint, editBox, app } = this, mergeConfig = { ...config } // 实时合并,后期可优化
|
|
49
50
|
if (element && element.editConfig) Object.assign(mergeConfig, element.editConfig) // 元素上的配置
|
|
50
51
|
if (editBox.config) Object.assign(mergeConfig, editBox.config) // EditBox 上的配置
|
|
51
52
|
if (dragPoint) {
|
|
@@ -56,6 +57,7 @@ export function mergeConfigAttr() {
|
|
|
56
57
|
isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true)
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
if (isUndefined(mergeConfig.dragLimitAnimate)) mergeConfig.dragLimitAnimate = app && app.config.pointer.dragLimitAnimate
|
|
59
61
|
return (this as IObject).mergedConfig = mergeConfig
|
|
60
62
|
}
|
|
61
63
|
} as ThisType<IEditor>)
|
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.moving) this.transformTool.onMove(e)
|
|
310
|
+
if (this.moving && this.mergeConfig.dragLimitAnimate && this.target.dragBounds) this.transformTool.onMove(e)
|
|
311
311
|
|
|
312
312
|
this.dragPoint = null
|
|
313
313
|
this.resetDoing()
|
|
@@ -6,7 +6,7 @@ import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer
|
|
|
6
6
|
|
|
7
7
|
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = Direction9
|
|
8
8
|
const { toPoint } = AroundHelper
|
|
9
|
-
const { within } = MathHelper
|
|
9
|
+
const { within, sign } = MathHelper
|
|
10
10
|
|
|
11
11
|
export const EditDataHelper = {
|
|
12
12
|
|
|
@@ -25,8 +25,8 @@ export const EditDataHelper = {
|
|
|
25
25
|
// 获取已经改变的比例
|
|
26
26
|
const originChangedScaleX = target.scaleX / startBounds.scaleX
|
|
27
27
|
const originChangedScaleY = target.scaleY / startBounds.scaleY
|
|
28
|
-
const signX = originChangedScaleX
|
|
29
|
-
const signY = originChangedScaleY
|
|
28
|
+
const signX = sign(originChangedScaleX)
|
|
29
|
+
const signY = sign(originChangedScaleY)
|
|
30
30
|
|
|
31
31
|
const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width
|
|
32
32
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height
|
|
@@ -142,8 +142,8 @@ export const EditDataHelper = {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// 防止小于1px
|
|
145
|
-
if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1) scaleX = (scaleX
|
|
146
|
-
if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1) scaleY = (scaleY
|
|
145
|
+
if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1) scaleX = sign(scaleX) / worldBoxBounds.width
|
|
146
|
+
if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1) scaleY = sign(scaleY) / worldBoxBounds.height
|
|
147
147
|
|
|
148
148
|
if (lockRatio && scaleX !== scaleY) scaleY = scaleX = Math.min(scaleX, scaleY)
|
|
149
149
|
|
|
@@ -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, isString, isNumber
|
|
2
|
+
import { MathHelper, Matrix, LeafHelper, AroundHelper, isObject, isString, isNumber } 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,10 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
23
23
|
|
|
24
24
|
public onMove(e: DragEvent | MoveEvent): void {
|
|
25
25
|
|
|
26
|
-
const { target, mergeConfig, dragStartData
|
|
26
|
+
const { target, mergeConfig, dragStartData } = this.editBox
|
|
27
27
|
|
|
28
28
|
let move: IPointData, { dragLimitAnimate } = mergeConfig
|
|
29
29
|
|
|
30
|
-
if (isUndefined(dragLimitAnimate)) dragLimitAnimate = app && app.config.pointer.dragLimitAnimate
|
|
31
|
-
|
|
32
30
|
const isMoveEnd = e.type === MoveEvent.END || e.type === DragEvent.END
|
|
33
31
|
const axisDrag = isString(target.draggable)
|
|
34
32
|
const checkLimitMove = !dragLimitAnimate || isMoveEnd || axisDrag
|