@leafer-in/editor 1.9.6 → 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/dist/editor.cjs +51 -29
- package/dist/editor.esm.js +51 -29
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +50 -28
- 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 +19 -3
- package/src/decorator/data.ts +9 -4
- package/src/display/EditBox.ts +29 -28
- package/src/editor/cursor.ts +10 -4
- package/types/index.d.ts +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.9.
|
|
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.
|
|
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.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
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 } from '@leafer-ui/draw'
|
|
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
|
-
|
|
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 {
|
package/src/decorator/data.ts
CHANGED
|
@@ -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
|
-
|
|
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 (
|
|
28
|
+
if (t.single) t.element.syncEventer = null // 重置 EditBox.load() 设置
|
|
24
29
|
|
|
25
|
-
const { beforeSelect } =
|
|
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:
|
|
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)
|
package/src/display/EditBox.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData,
|
|
2
|
-
import { Group,
|
|
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:
|
|
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 {
|
|
163
|
-
const {
|
|
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.
|
|
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 (
|
|
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 {
|
|
315
|
-
if (
|
|
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
|
-
|
|
444
|
-
[
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
])
|
package/src/editor/cursor.ts
CHANGED
|
@@ -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
|
-
|
|
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')
|
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,
|
|
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:
|
|
146
|
+
rect: IEditPoint;
|
|
144
147
|
circle: IEditPoint;
|
|
145
148
|
buttons: IGroup;
|
|
146
149
|
resizePoints: IEditPoint[];
|