@leafer-in/editor 1.5.1 → 1.5.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 +87 -31
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +87 -31
- package/dist/editor.esm.js.map +1 -1
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +87 -31
- package/dist/editor.js.map +1 -1
- 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 +5 -5
- package/src/Editor.ts +46 -18
- package/src/config.ts +1 -0
- package/src/decorator/data.ts +20 -4
- package/src/display/EditBox.ts +1 -0
- package/src/display/EditSelect.ts +4 -2
- package/src/editor/cursor.ts +1 -1
- package/src/editor/target.ts +2 -11
- package/src/helper/EditDataHelper.ts +4 -0
- package/src/helper/EditorHelper.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
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.5.
|
|
38
|
-
"@leafer-in/resize": "^1.5.
|
|
39
|
-
"@leafer-ui/interface": "^1.5.
|
|
40
|
-
"@leafer-in/interface": "^1.5.
|
|
37
|
+
"@leafer-ui/core": "^1.5.3",
|
|
38
|
+
"@leafer-in/resize": "^1.5.3",
|
|
39
|
+
"@leafer-ui/interface": "^1.5.3",
|
|
40
|
+
"@leafer-in/interface": "^1.5.3"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -168,7 +168,6 @@ export class Editor extends Group implements IEditor {
|
|
|
168
168
|
// operate
|
|
169
169
|
|
|
170
170
|
public onMove(e: DragEvent | MoveEvent): void {
|
|
171
|
-
|
|
172
171
|
if (e instanceof MoveEvent) {
|
|
173
172
|
|
|
174
173
|
if (e.moveType !== 'drag') {
|
|
@@ -190,7 +189,6 @@ export class Editor extends Group implements IEditor {
|
|
|
190
189
|
this.move(DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total))
|
|
191
190
|
|
|
192
191
|
}
|
|
193
|
-
|
|
194
192
|
}
|
|
195
193
|
|
|
196
194
|
public onScale(e: DragEvent | ZoomEvent): void {
|
|
@@ -217,7 +215,6 @@ export class Editor extends Group implements IEditor {
|
|
|
217
215
|
}
|
|
218
216
|
|
|
219
217
|
}
|
|
220
|
-
|
|
221
218
|
}
|
|
222
219
|
|
|
223
220
|
public onRotate(e: DragEvent | RotateEvent): void {
|
|
@@ -267,12 +264,19 @@ export class Editor extends Group implements IEditor {
|
|
|
267
264
|
// transform
|
|
268
265
|
|
|
269
266
|
public move(x: number | IPointData, y = 0): void {
|
|
270
|
-
const { element } = this
|
|
271
267
|
if (!this.checkTransform('moveable')) return
|
|
268
|
+
if (typeof x === 'object') y = x.y, x = x.x
|
|
272
269
|
|
|
273
|
-
const
|
|
274
|
-
if (
|
|
275
|
-
|
|
270
|
+
const { element: target } = this, { beforeMove } = this.mergeConfig
|
|
271
|
+
if (beforeMove) {
|
|
272
|
+
const check = beforeMove({ target, x, y })
|
|
273
|
+
if (typeof check === 'object') x = check.x, y = check.y
|
|
274
|
+
else if (check === false) return
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const world = target.getWorldPointByLocal({ x, y }, null, true)
|
|
278
|
+
if (this.multiple) target.safeChange(() => target.move(x, y))
|
|
279
|
+
const data: IEditorMoveEvent = { target, editor: this, moveX: world.x, moveY: world.y }
|
|
276
280
|
|
|
277
281
|
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data))
|
|
278
282
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data)
|
|
@@ -283,8 +287,14 @@ export class Editor extends Group implements IEditor {
|
|
|
283
287
|
public scaleWithDrag(data: IEditorScaleEvent): void {
|
|
284
288
|
if (!this.checkTransform('resizeable')) return
|
|
285
289
|
|
|
286
|
-
const { element } = this
|
|
287
|
-
|
|
290
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig
|
|
291
|
+
if (beforeScale) {
|
|
292
|
+
const { origin, scaleX, scaleY, drag } = data
|
|
293
|
+
const check = beforeScale({ target, drag, origin, scaleX, scaleY })
|
|
294
|
+
if (check === false) return
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
data = { ...data, target, editor: this, worldOrigin: target.getWorldPoint(data.origin) }
|
|
288
298
|
|
|
289
299
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data))
|
|
290
300
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data)
|
|
@@ -296,10 +306,16 @@ export class Editor extends Group implements IEditor {
|
|
|
296
306
|
override scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY = scaleX, _resize?: boolean): void {
|
|
297
307
|
if (!this.checkTransform('resizeable')) return
|
|
298
308
|
|
|
299
|
-
const { element } = this
|
|
309
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig
|
|
310
|
+
if (beforeScale) {
|
|
311
|
+
const check = beforeScale({ target, origin, scaleX, scaleY })
|
|
312
|
+
if (typeof check === 'object') scaleX = check.scaleX, scaleY = check.scaleY
|
|
313
|
+
else if (check === false) return
|
|
314
|
+
}
|
|
315
|
+
|
|
300
316
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
301
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
302
|
-
const data: IEditorScaleEvent = { target
|
|
317
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)))
|
|
318
|
+
const data: IEditorScaleEvent = { target, editor: this, worldOrigin, scaleX, scaleY, transform }
|
|
303
319
|
|
|
304
320
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data))
|
|
305
321
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data)
|
|
@@ -324,10 +340,16 @@ export class Editor extends Group implements IEditor {
|
|
|
324
340
|
override rotateOf(origin: IPointData | IAlign, rotation: number): void {
|
|
325
341
|
if (!this.checkTransform('rotateable')) return
|
|
326
342
|
|
|
327
|
-
const { element } = this
|
|
343
|
+
const { element: target } = this, { beforeRotate } = this.mergeConfig
|
|
344
|
+
if (beforeRotate) {
|
|
345
|
+
const check = beforeRotate({ target, origin, rotation })
|
|
346
|
+
if (typeof check === 'number') rotation = check
|
|
347
|
+
else if (check === false) return
|
|
348
|
+
}
|
|
349
|
+
|
|
328
350
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
329
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
330
|
-
const data: IEditorRotateEvent = { target
|
|
351
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)))
|
|
352
|
+
const data: IEditorRotateEvent = { target, editor: this, worldOrigin, rotation, transform }
|
|
331
353
|
|
|
332
354
|
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data))
|
|
333
355
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data)
|
|
@@ -338,10 +360,16 @@ export class Editor extends Group implements IEditor {
|
|
|
338
360
|
override skewOf(origin: IPointData | IAlign, skewX: number, skewY = 0, _resize?: boolean): void {
|
|
339
361
|
if (!this.checkTransform('skewable')) return
|
|
340
362
|
|
|
341
|
-
const { element } = this
|
|
363
|
+
const { element: target } = this, { beforeSkew } = this.mergeConfig
|
|
364
|
+
if (beforeSkew) {
|
|
365
|
+
const check = beforeSkew({ target, origin, skewX, skewY })
|
|
366
|
+
if (typeof check === 'object') skewX = check.skewX, skewY = check.skewY
|
|
367
|
+
else if (check === false) return
|
|
368
|
+
}
|
|
369
|
+
|
|
342
370
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
343
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
344
|
-
const data: IEditorSkewEvent = { target
|
|
371
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)))
|
|
372
|
+
const data: IEditorSkewEvent = { target, editor: this, worldOrigin, skewX, skewY, transform }
|
|
345
373
|
|
|
346
374
|
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data))
|
|
347
375
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data)
|
package/src/config.ts
CHANGED
package/src/decorator/data.ts
CHANGED
|
@@ -5,17 +5,33 @@ import { defineKey } from '@leafer-ui/draw'
|
|
|
5
5
|
import { EditorEvent } from '../event/EditorEvent'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
export function targetAttr(fn: IFunction) {
|
|
10
9
|
return (target: ILeaf, key: string) => {
|
|
11
10
|
const privateKey = '_' + key
|
|
12
11
|
defineKey(target, key, {
|
|
13
12
|
get() { return (this as IObject)[privateKey] },
|
|
14
|
-
set(value:
|
|
13
|
+
set(value: IUI | IUI[]) {
|
|
15
14
|
const old = (this as IObject)[privateKey]
|
|
16
15
|
if (old !== value) {
|
|
17
|
-
|
|
18
|
-
if (
|
|
16
|
+
|
|
17
|
+
if ((this as IEditor).config) { // Editor
|
|
18
|
+
|
|
19
|
+
const isSelect = key === 'target'
|
|
20
|
+
if (isSelect) {
|
|
21
|
+
if (value instanceof Array && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
|
|
22
|
+
|
|
23
|
+
const { beforeSelect } = (this as IEditor).config
|
|
24
|
+
if (beforeSelect) {
|
|
25
|
+
const check = beforeSelect({ target: value })
|
|
26
|
+
if (typeof check === 'object') value = check
|
|
27
|
+
else if (check === false) return
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER
|
|
32
|
+
if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, { editor: this as IEditor, value: value as IUI, oldValue: old }))
|
|
33
|
+
}
|
|
34
|
+
|
|
19
35
|
(this as IObject)[privateKey] = value, fn(this, old)
|
|
20
36
|
}
|
|
21
37
|
}
|
package/src/display/EditBox.ts
CHANGED
|
@@ -264,6 +264,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
264
264
|
const { pointType } = this.enterPoint = e.current as IEditPoint
|
|
265
265
|
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) editor.onRotate(e)
|
|
266
266
|
if (pointType.includes('resize')) editor.onScale(e)
|
|
267
|
+
if (pointType === 'skew') editor.onSkew(e)
|
|
267
268
|
updateCursor(editor, e)
|
|
268
269
|
}
|
|
269
270
|
|
|
@@ -207,7 +207,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
protected allowDrag(e: DragEvent) {
|
|
210
|
-
|
|
210
|
+
const { boxSelect, multipleSelect } = this.editor.mergeConfig
|
|
211
|
+
if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
|
|
211
212
|
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path))
|
|
212
213
|
} else {
|
|
213
214
|
return false
|
|
@@ -228,7 +229,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
public isMultipleSelect(e: IPointerEvent): boolean {
|
|
231
|
-
|
|
232
|
+
const { multipleSelect, continuousSelect } = this.editor.mergeConfig
|
|
233
|
+
return multipleSelect && (e.shiftKey || continuousSelect)
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
protected __listenEvents(): void {
|
package/src/editor/cursor.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function updateCursor(editor: IEditor, e: IUIEvent): void {
|
|
|
23
23
|
|
|
24
24
|
let showResize = pointType.includes('resize')
|
|
25
25
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable)) showResize = false
|
|
26
|
-
const showSkew = skewable && !showResize && point.name === 'resize-line'
|
|
26
|
+
const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew')
|
|
27
27
|
|
|
28
28
|
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor)
|
|
29
29
|
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45
|
package/src/editor/target.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LeafList } from '@leafer-ui/draw'
|
|
2
2
|
|
|
3
|
-
import { IEditor,
|
|
3
|
+
import { IEditor, IUI } from '@leafer-in/interface'
|
|
4
4
|
|
|
5
5
|
import { simulate } from './simulate'
|
|
6
6
|
import { updateMoveCursor } from './cursor'
|
|
@@ -10,11 +10,7 @@ import { EditorEvent } from '../event/EditorEvent'
|
|
|
10
10
|
export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
11
11
|
const { target } = editor
|
|
12
12
|
if (target) {
|
|
13
|
-
|
|
14
|
-
if (!list.every(checkEditable)) { // 过滤不合格的元素
|
|
15
|
-
editor.target = list.filter(checkEditable) as IUI[]
|
|
16
|
-
return
|
|
17
|
-
}
|
|
13
|
+
editor.leafList = target instanceof LeafList ? target : new LeafList(target)
|
|
18
14
|
if (editor.multiple) simulate(editor) // 更新模拟元素
|
|
19
15
|
} else {
|
|
20
16
|
editor.simulateTarget.remove()
|
|
@@ -41,9 +37,4 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
41
37
|
|
|
42
38
|
export function onHover(editor: IEditor, oldValue: IUI): void {
|
|
43
39
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function checkEditable(item: ILeaf): boolean {
|
|
48
|
-
return item.editable && !item.locked
|
|
49
40
|
}
|
|
@@ -174,21 +174,25 @@ export const EditDataHelper = {
|
|
|
174
174
|
|
|
175
175
|
switch (direction) {
|
|
176
176
|
case top:
|
|
177
|
+
case topLeft:
|
|
177
178
|
last = { x: 0.5, y: 0 }
|
|
178
179
|
align = 'bottom'
|
|
179
180
|
skewX = 1
|
|
180
181
|
break
|
|
181
182
|
case bottom:
|
|
183
|
+
case bottomRight:
|
|
182
184
|
last = { x: 0.5, y: 1 }
|
|
183
185
|
align = 'top'
|
|
184
186
|
skewX = 1
|
|
185
187
|
break
|
|
186
188
|
case left:
|
|
189
|
+
case bottomLeft:
|
|
187
190
|
last = { x: 0, y: 0.5 }
|
|
188
191
|
align = 'right'
|
|
189
192
|
skewY = 1
|
|
190
193
|
break
|
|
191
194
|
case right:
|
|
195
|
+
case topRight:
|
|
192
196
|
last = { x: 1, y: 0.5 }
|
|
193
197
|
align = 'left'
|
|
194
198
|
skewY = 1
|
|
@@ -40,13 +40,14 @@ export const EditorHelper = {
|
|
|
40
40
|
|
|
41
41
|
app.lockLayout()
|
|
42
42
|
list.forEach(leaf => {
|
|
43
|
-
if (leaf.isBranch
|
|
43
|
+
if (leaf.isBranch) {
|
|
44
44
|
const { parent, children } = leaf
|
|
45
45
|
while (children.length) {
|
|
46
46
|
ungroupList.push(children[0])
|
|
47
47
|
children[0].dropTo(parent, parent.children.indexOf(leaf))
|
|
48
48
|
}
|
|
49
|
-
leaf.
|
|
49
|
+
if (leaf.isBranchLeaf) ungroupList.push(leaf)
|
|
50
|
+
else leaf.remove()
|
|
50
51
|
} else {
|
|
51
52
|
ungroupList.push(leaf)
|
|
52
53
|
}
|