@leafer-in/editor 1.4.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/editor",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "@leafer-in/editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/core": "^1.4.0",
38
- "@leafer-in/resize": "^1.4.0",
39
- "@leafer-ui/interface": "^1.4.0",
40
- "@leafer-in/interface": "^1.4.0"
37
+ "@leafer-ui/core": "^1.4.1",
38
+ "@leafer-in/resize": "^1.4.1",
39
+ "@leafer-ui/interface": "^1.4.1",
40
+ "@leafer-in/interface": "^1.4.1"
41
41
  }
42
42
  }
package/src/Editor.ts CHANGED
@@ -258,9 +258,10 @@ export class Editor extends Group implements IEditor {
258
258
  // transform
259
259
 
260
260
  public move(x: number | IPointData, y = 0): void {
261
+ const { element } = this
261
262
  if (!this.checkTransform('moveable')) return
262
263
 
263
- const { element } = this
264
+
264
265
  const world = element.getWorldPointByLocal(typeof x === 'object' ? { ...x } : { x, y }, null, true)
265
266
  if (this.multiple) element.safeChange(() => element.move(x, y))
266
267
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y })
@@ -1,5 +1,5 @@
1
1
  import { IBoundsData, IPointData, IAround, IAlign, IUI, ILayoutBoundsData } from '@leafer-ui/interface'
2
- import { AroundHelper, MathHelper, PointHelper, Direction9 } from '@leafer-ui/draw'
2
+ import { AroundHelper, MathHelper, PointHelper, BoundsHelper, Bounds, Direction9 } from '@leafer-ui/draw'
3
3
 
4
4
  import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
5
5
 
@@ -13,7 +13,7 @@ export const EditDataHelper = {
13
13
  getScaleData(element: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMove: IPointData, lockRatio: boolean | 'corner', around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent {
14
14
  let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1
15
15
 
16
- const { boxBounds, widthRange, heightRange } = element
16
+ const { boxBounds, widthRange, heightRange, dragBounds } = element
17
17
  const { width, height } = startBounds
18
18
 
19
19
  if (around) {
@@ -116,6 +116,21 @@ export const EditDataHelper = {
116
116
  if (scaleY < 0) scaleY = 1 / boxBounds.height / worldTransform.scaleY
117
117
  }
118
118
 
119
+ // 检查限制
120
+
121
+ toPoint(around || align, boxBounds, origin, true)
122
+
123
+ if (dragBounds) {
124
+ const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds
125
+ const localBounds = new Bounds(element.__localBoxBounds)
126
+ localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY)
127
+
128
+ if (!BoundsHelper.includes(allowBounds, localBounds)) {
129
+ const realBounds = localBounds.getIntersect(allowBounds)
130
+ scaleX *= realBounds.width / localBounds.width
131
+ scaleY *= realBounds.height / localBounds.height // 后续需优化带旋转的场景
132
+ }
133
+ }
119
134
 
120
135
  if (widthRange) {
121
136
  const nowWidth = boxBounds.width * element.scaleX
@@ -127,9 +142,6 @@ export const EditDataHelper = {
127
142
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight
128
143
  }
129
144
 
130
-
131
- toPoint(around || align, boxBounds, origin, true)
132
-
133
145
  return { origin, scaleX, scaleY, direction, lockRatio, around }
134
146
  },
135
147