@leafer-in/editor 1.9.5 → 1.9.7

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.9.5",
3
+ "version": "1.9.7",
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.5",
38
- "@leafer-ui/core": "^1.9.5",
39
- "@leafer-in/resize": "^1.9.5",
40
- "@leafer-ui/interface": "^1.9.5",
41
- "@leafer-in/interface": "^1.9.5"
37
+ "@leafer-ui/draw": "^1.9.7",
38
+ "@leafer-ui/core": "^1.9.7",
39
+ "@leafer-in/resize": "^1.9.7",
40
+ "@leafer-ui/interface": "^1.9.7",
41
+ "@leafer-in/interface": "^1.9.7"
42
42
  }
43
43
  }
package/src/Editor.ts CHANGED
@@ -1,5 +1,5 @@
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, PropertyEvent } from '@leafer-ui/draw'
1
+ import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup, IObject, IAlign, IAxis, IFunction, IMatrix, IApp, ILeaferMode } from '@leafer-ui/interface'
2
+ import { Group, DataHelper, LeafList, RenderEvent, LeafHelper, Direction9, Plugin, isString, PropertyEvent, LeaferEvent, isArray } 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'
@@ -29,11 +29,13 @@ export class Editor extends Group implements IEditor {
29
29
  readonly mergeConfig: IEditorConfig
30
30
  readonly mergedConfig: IEditorConfig
31
31
 
32
+ @targetAttr(onTarget)
33
+ public target?: IUI | IUI[]
34
+
32
35
  @targetAttr(onHover)
33
36
  public hoverTarget?: IUI
34
37
 
35
- @targetAttr(onTarget)
36
- public target?: IUI | IUI[]
38
+ public dimTarget?: IGroup | IGroup[] // 需要淡化的容器
37
39
 
38
40
  // 列表
39
41
 
@@ -121,6 +123,20 @@ export class Editor extends Group implements IEditor {
121
123
  this.hasItem(item) ? this.removeItem(item) : this.addItem(item)
122
124
  }
123
125
 
126
+ // 淡化 / 突出
127
+
128
+ public setDimOthers(value: boolean | number, attrName: 'bright' | 'dim' = 'dim', list?: IUI[]): void {
129
+ if (!list) {
130
+ const { dimTarget, targetLeafer } = this
131
+ list = dimTarget ? (isArray(dimTarget) ? dimTarget : [dimTarget]) : [targetLeafer]
132
+ }
133
+ if (list[0] && list[0][attrName] !== (value || false)) list.forEach(item => DataHelper.stintSet(item, attrName, value))
134
+ }
135
+
136
+ public setBright(value: boolean): void {
137
+ this.setDimOthers(value, 'bright', this.list)
138
+ }
139
+
124
140
  // update
125
141
 
126
142
  public update(): void {
@@ -376,7 +392,8 @@ export class Editor extends Group implements IEditor {
376
392
  this.targetEventIds = [
377
393
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
378
394
  targetLeafer && targetLeafer.on_(PropertyEvent.SCROLL, this.onChildScroll, this),
379
- app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this)
395
+ app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this),
396
+ app.on_(LeaferEvent.UPDATE_MODE, (data: { mode: ILeaferMode }) => { if (data.mode && data.mode !== 'normal') this.cancel() })
380
397
  ]
381
398
  if (editMask.visible) editMask.forceRender()
382
399
  }
@@ -15,14 +15,19 @@ export function targetAttr(fn: IFunction) {
15
15
  const old = (this as IObject)[privateKey]
16
16
  if (old !== value) {
17
17
 
18
- if ((this as IEditor).config) { // Editor
18
+ const t = this as IEditor
19
+
20
+ if (t.config) { // Editor
19
21
 
20
22
  const isSelect = key === 'target'
21
23
  if (isSelect) {
24
+ t.setDimOthers(false)
25
+ t.setBright(false)
26
+
22
27
  if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
23
- if ((this as IEditor).single) (this as IEditor).element.syncEventer = null // 重置 EditBox.load() 设置
28
+ if (t.single) t.element.syncEventer = null // 重置 EditBox.load() 设置
24
29
 
25
- const { beforeSelect } = (this as IEditor).config
30
+ const { beforeSelect } = t.config
26
31
  if (beforeSelect) {
27
32
  const check = beforeSelect({ target: value })
28
33
  if (isObject(check)) value = check
@@ -31,7 +36,7 @@ export function targetAttr(fn: IFunction) {
31
36
  }
32
37
 
33
38
  const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER
34
- if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, { editor: this as IEditor, value: value as IUI, oldValue: old }))
39
+ if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, { editor: t, value: value as IUI, oldValue: old }))
35
40
  }
36
41
 
37
42
  (this as IObject)[privateKey] = value, fn(this, old)
@@ -1,5 +1,5 @@
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'
1
+ import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, ITransformTool, IUIEvent, IEditPointInputData } from '@leafer-ui/interface'
2
+ import { Group, 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'
@@ -25,7 +25,7 @@ export class EditBox extends Group implements IEditBox {
25
25
 
26
26
  public view: IGroup = new Group() // 放置默认编辑工具控制点
27
27
 
28
- public rect: IBox = new Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 }) // target rect
28
+ public rect: IEditPoint = new EditPoint({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 }) // target rect
29
29
  public circle: IEditPoint = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 }) // rotate point
30
30
  public buttons: IGroup = new Group({ around: 'center', hitSelf: false, visible: 0 })
31
31
 
@@ -101,6 +101,7 @@ export class EditBox extends Group implements IEditBox {
101
101
  }
102
102
 
103
103
  this.listenPointEvents(circle, 'rotate', 2)
104
+ this.listenPointEvents(rect, 'move', 8) // center
104
105
 
105
106
  view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints)
106
107
  this.add(view)
@@ -108,8 +109,8 @@ export class EditBox extends Group implements IEditBox {
108
109
 
109
110
 
110
111
  public load(): void {
111
- const { target, mergeConfig, single, rect, circle, resizePoints } = this
112
- const { stroke, strokeWidth } = mergeConfig
112
+ const { target, mergeConfig, single, rect, circle, resizePoints, resizeLines } = this
113
+ const { stroke, strokeWidth, resizeLine } = mergeConfig
113
114
 
114
115
  const pointsStyle = this.getPointsStyle()
115
116
  const middlePointsStyle = this.getMiddlePointsStyle()
@@ -122,6 +123,7 @@ export class EditBox extends Group implements IEditBox {
122
123
  resizeP = resizePoints[i]
123
124
  resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]))
124
125
  resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90
126
+ if (i % 2) resizeLines[(i - 1) / 2].set({ pointType: 'resize', rotation: (i - 1) / 2 * 90, ...(resizeLine || {}) } as IEditPointInputData)
125
127
  }
126
128
 
127
129
  // rotate
@@ -159,12 +161,15 @@ export class EditBox extends Group implements IEditBox {
159
161
 
160
162
 
161
163
  public updateBounds(bounds: IBoundsData): void {
162
- const { editMask } = this.editor
163
- const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this
164
- const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread, hideRotatePoints, hideResizeLines } = mergeConfig
164
+ const { editor, mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this
165
+ const { editMask } = editor
166
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, dimOthers, bright, spread, hideRotatePoints, hideResizeLines } = mergeConfig
165
167
 
166
168
  editMask.visible = mask ? true : 0
167
169
 
170
+ editor.setDimOthers(dimOthers)
171
+ editor.setBright(!!dimOthers || bright)
172
+
168
173
  if (spread) BoundsHelper.spread(bounds, spread)
169
174
 
170
175
  if (this.view.worldOpacity) {
@@ -195,10 +200,10 @@ export class EditBox extends Group implements IEditBox {
195
200
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint
196
201
 
197
202
  if (((i + 1) / 2) % 2) { // top, bottom
198
- resizeL.width = width
203
+ resizeL.width = width + resizeL.height
199
204
  if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false
200
205
  } else {
201
- resizeL.height = height
206
+ resizeL.width = height + resizeL.height
202
207
  if (hideOnSmall && resizeP.width * 2 > height) resizeP.visible = false
203
208
  }
204
209
  }
@@ -286,7 +291,7 @@ export class EditBox extends Group implements IEditBox {
286
291
  const { editor, dragStartData } = this, { target } = this, { moveable, resizeable, rotateable, skewable, hideOnMove } = this.mergeConfig
287
292
 
288
293
  // 确定模式
289
- if (point.name === 'rect') {
294
+ if (pointType === 'move') {
290
295
  moveable && (this.moving = true)
291
296
  editor.opacity = hideOnMove ? 0 : 1 // move
292
297
  } else {
@@ -311,8 +316,8 @@ export class EditBox extends Group implements IEditBox {
311
316
 
312
317
  this.dragPoint = null
313
318
  this.resetDoing()
314
- const { name, pointType } = e.current as IEditPoint
315
- if (name === 'rect') this.editor.opacity = 1 // move
319
+ const { pointType } = e.current as IEditPoint
320
+ if (pointType === 'move') this.editor.opacity = 1 // move
316
321
  if (pointType && pointType.includes('resize')) ResizeEvent.resizingKeys = null
317
322
  }
318
323
 
@@ -320,15 +325,14 @@ export class EditBox extends Group implements IEditBox {
320
325
  const { transformTool, moving, resizing, rotating, skewing } = this
321
326
  if (moving) {
322
327
  transformTool.onMove(e)
323
- updateMoveCursor(this)
324
328
  } else if (resizing || rotating || skewing) {
325
329
  const point = e.current as IEditPoint
326
330
  if (point.pointType) this.enterPoint = point// 防止变化
327
331
  if (rotating) transformTool.onRotate(e)
328
332
  if (resizing) transformTool.onScale(e)
329
333
  if (skewing) transformTool.onSkew(e)
330
- updatePointCursor(this, e)
331
334
  }
335
+ updatePointCursor(this, e)
332
336
  }
333
337
 
334
338
  protected resetDoing(): void {
@@ -440,14 +444,16 @@ export class EditBox extends Group implements IEditBox {
440
444
  point.direction = direction
441
445
  point.pointType = type
442
446
 
443
- const events: IEventParams[] = [
444
- [DragEvent.START, this.onDragStart, this],
445
- [DragEvent.DRAG, this.onDrag, this],
446
- [DragEvent.END, this.onDragEnd, this],
447
- [PointerEvent.LEAVE, () => { this.enterPoint = null }],
448
- ]
449
- if (point.name !== 'circle') events.push([PointerEvent.ENTER, (e: PointerEvent) => { this.enterPoint = point, updatePointCursor(this, e) }])
450
- this.__eventIds.push(point.on_(events))
447
+ this.__eventIds.push(
448
+ point.on_([
449
+ [DragEvent.START, this.onDragStart, this],
450
+ [DragEvent.DRAG, this.onDrag, this],
451
+ [DragEvent.END, this.onDragEnd, this],
452
+
453
+ [PointerEvent.ENTER, (e: PointerEvent) => { this.enterPoint = point, updatePointCursor(this, e) }],
454
+ [PointerEvent.LEAVE, () => { this.enterPoint = null }]
455
+ ])
456
+ )
451
457
  }
452
458
 
453
459
  protected __listenEvents(): void {
@@ -455,11 +461,6 @@ export class EditBox extends Group implements IEditBox {
455
461
 
456
462
  events.push(
457
463
  rect.on_([
458
- [DragEvent.START, this.onDragStart, this],
459
- [DragEvent.DRAG, this.onDrag, this],
460
- [DragEvent.END, this.onDragEnd, this],
461
-
462
- [PointerEvent.ENTER, () => updateMoveCursor(this)],
463
464
  [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
464
465
  [PointerEvent.LONG_PRESS, this.onLongPress, this]
465
466
  ])
@@ -17,7 +17,7 @@ export class EditSelect extends Group implements IEditSelect {
17
17
  public editor: IEditor
18
18
 
19
19
  public get dragging(): boolean { return !!this.originList }
20
- public get running(): boolean { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector }
20
+ public get running(): boolean { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector && this.app.mode === 'normal' }
21
21
  public get isMoveMode(): boolean { return this.app && this.app.interaction.moveMode }
22
22
 
23
23
  public hoverStroker: IStroker = new Stroker()
@@ -11,15 +11,21 @@ const cacheCursors: IObject = {}
11
11
  export function updatePointCursor(editBox: IEditBox, e: IUIEvent): void {
12
12
  const { enterPoint: point, dragging, skewing, resizing, flippedX, flippedY } = editBox
13
13
  if (!point || !editBox.editor.editing || !editBox.canUse) return
14
+ if (point.name === 'rect') return updateMoveCursor(editBox) // rect 移动元素
14
15
  if (point.name === 'circle') return // 独立旋转按钮
15
- if (point.pointType === 'button') { // 普通按钮
16
+
17
+ let { rotation } = editBox
18
+ const { pointType } = point, { moveCursor, resizeCursor, rotateCursor, skewCursor, moveable, resizeable, rotateable, skewable } = editBox.mergeConfig
19
+
20
+ if (pointType === 'move') { // 移动类型
21
+ point.cursor = moveCursor
22
+ if (!moveable) point.visible = false
23
+ return
24
+ } else if (pointType === 'button') { // 普通按钮
16
25
  if (!point.cursor) point.cursor = 'pointer'
17
26
  return
18
27
  }
19
28
 
20
- let { rotation } = editBox
21
- const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig
22
-
23
29
  let showResize = pointType.includes('resize')
24
30
  if (showResize && rotateable && (editBox.isHoldRotateKey(e) || !resizeable)) showResize = false
25
31
  const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew')
@@ -1,5 +1,5 @@
1
1
  import { IBoundsData, IPointData, IAround, IAlign, IUI, ILayoutBoundsData } from '@leafer-ui/interface'
2
- import { AroundHelper, MathHelper, PointHelper, BoundsHelper, Bounds, Direction9 } from '@leafer-ui/draw'
2
+ import { AroundHelper, MathHelper, PointHelper, Direction9, DragBoundsHelper } from '@leafer-ui/draw'
3
3
 
4
4
  import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
5
5
 
@@ -115,20 +115,10 @@ export const EditDataHelper = {
115
115
  toPoint(around || align, boxBounds, origin, true)
116
116
 
117
117
  if (dragBounds) {
118
- const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds
119
- const childBounds = new Bounds(target.__localBoxBounds)
120
-
121
- if (BoundsHelper.includes(new Bounds(allowBounds).spread(0.1), childBounds)) {
122
-
123
- childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY)
124
-
125
- if (!BoundsHelper.includes(allowBounds, childBounds)) {
126
- const realBounds = childBounds.getIntersect(allowBounds)
127
- const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height
128
- if (useScaleX) scaleX *= fitScaleX
129
- if (useScaleY) scaleY *= fitScaleY // 后续需优化带旋转的场景
130
- }
131
- }
118
+ const scaleData = { x: scaleX, y: scaleY }
119
+ DragBoundsHelper.limitScaleOf(target, origin, scaleData)
120
+ scaleX = scaleData.x
121
+ scaleY = scaleData.y
132
122
  }
133
123
 
134
124
  if (useScaleX && widthRange) {
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _leafer_ui_interface from '@leafer-ui/interface';
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
+ import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData } from '@leafer-ui/interface';
3
3
  import { Group, UI, Direction9, Box, Event } from '@leafer-ui/draw';
4
4
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
5
5
  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';
@@ -53,8 +53,9 @@ declare class Editor extends Group implements IEditor {
53
53
  config: IEditorConfig;
54
54
  readonly mergeConfig: IEditorConfig;
55
55
  readonly mergedConfig: IEditorConfig;
56
- hoverTarget?: IUI;
57
56
  target?: IUI | IUI[];
57
+ hoverTarget?: IUI;
58
+ dimTarget?: IGroup | IGroup[];
58
59
  leafList: ILeafList;
59
60
  get list(): IUI[];
60
61
  get dragHoverExclude(): IUI[];
@@ -91,6 +92,8 @@ declare class Editor extends Group implements IEditor {
91
92
  addItem(item: IUI): void;
92
93
  removeItem(item: IUI): void;
93
94
  shiftItem(item: IUI): void;
95
+ setDimOthers(value: boolean | number, attrName?: 'bright' | 'dim', list?: IUI[]): void;
96
+ setBright(value: boolean): void;
94
97
  update(): void;
95
98
  updateEditBox(): void;
96
99
  updateEditTool(): void;
@@ -140,7 +143,7 @@ declare class EditBox extends Group implements IEditBox {
140
143
  rotating: boolean;
141
144
  skewing: boolean;
142
145
  view: IGroup;
143
- rect: IBox;
146
+ rect: IEditPoint;
144
147
  circle: IEditPoint;
145
148
  buttons: IGroup;
146
149
  resizePoints: IEditPoint[];