@leafer-in/editor 2.2.10 → 2.3.0

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": "2.2.10",
3
+ "version": "2.3.0",
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": "^2.2.10",
38
- "@leafer-ui/core": "^2.2.10",
39
- "@leafer-in/resize": "^2.2.10",
40
- "@leafer-ui/interface": "^2.2.10",
41
- "@leafer-in/interface": "^2.2.10"
37
+ "@leafer-ui/draw": "^2.3.0",
38
+ "@leafer-ui/core": "^2.3.0",
39
+ "@leafer-in/resize": "^2.3.0",
40
+ "@leafer-ui/interface": "^2.3.0",
41
+ "@leafer-in/interface": "^2.3.0"
42
42
  }
43
43
  }
@@ -1,5 +1,5 @@
1
1
  import { IFunction, ILeaf, IObject, IUI, } from '@leafer-ui/interface'
2
- import { defineKey, isNull, isArray, isObject, isUndefined, DataHelper } from '@leafer-ui/draw'
2
+ import { defineKey, isNull, isArray, isObject, isUndefined, DataHelper, LeafHelper } from '@leafer-ui/draw'
3
3
 
4
4
  import { IEditor, IInnerEditor } from '@leafer-in/interface'
5
5
 
@@ -22,7 +22,24 @@ export function targetAttr(fn: IFunction) {
22
22
 
23
23
  const isSelect = key === 'target'
24
24
  if (isSelect) {
25
- const { beforeSelect } = t.config
25
+ const { beforeSelect, skipNested } = t.config
26
+
27
+ if (isArray(value)) {
28
+ if (skipNested) { // 过滤嵌套关系的元素
29
+ const first = value[0]
30
+ if (value.some(item => item.__level !== first.__level)) {
31
+ value.sort((a, b) => a.__level - b.__level) // 顺序
32
+ const firstLevel = value[0].__level, filterValue: IUI[] = []
33
+ value.forEach(item => { if (!filterValue.length || !filterValue.some(parent => LeafHelper.hasParent(item, parent, firstLevel))) filterValue.push(item) })
34
+ value = filterValue
35
+ }
36
+ }
37
+
38
+ if (value.length > 1 && value.some(item => item.locked || item.editable === 'single')) {
39
+ value = value.filter(item => !(item.locked || item.editable === 'single')) // 锁定、单选元素不能参与多选
40
+ }
41
+ }
42
+
26
43
  if (beforeSelect) {
27
44
  const check = beforeSelect({ target: value })
28
45
  if (isObject(check)) value = check
@@ -31,10 +48,6 @@ export function targetAttr(fn: IFunction) {
31
48
 
32
49
  if (t.hasDimOthers) t.cancelDimOthers()
33
50
 
34
- if (isArray(value) && value.length > 1 && value.some(item => item.locked || item.editable === 'single')) {
35
- value = value.filter(item => !(item.locked || item.editable === 'single')) // 锁定、单选元素不能参与多选
36
- }
37
-
38
51
  if (t.single) {
39
52
  delete t.element.syncEventer // 重置 EditBox.load() 同步事件设置
40
53
  delete t.element.__world.ignorePixelSnap // 重置 EditBox.load() 忽略对齐像素设置
@@ -354,6 +354,7 @@ export class EditBox extends Group implements IEditBox {
354
354
  // alt复制钩子
355
355
  if (e.altKey && onCopy && onCopy() && this.editor.single) this.app.interaction.replaceDownTarget(this.target)
356
356
  moveable && (this.moving = true)
357
+ if (this.moving) this.widgetsMoveStart(e)
357
358
  } else {
358
359
  if (pointType.includes('rotate') || this.isHoldRotateKey(e) || !resizeable) {
359
360
  rotateable && (this.rotating = true)
@@ -370,6 +371,7 @@ export class EditBox extends Group implements IEditBox {
370
371
  const { transformTool, moving, resizing, rotating, skewing } = this
371
372
  if (moving) {
372
373
  transformTool.onMove(e)
374
+ this.widgetsMove(e)
373
375
  } else if (resizing || rotating || skewing) {
374
376
  const point = e.current as IEditPoint
375
377
  if (point.pointType) this.enterPoint = point// 防止变化
@@ -381,6 +383,7 @@ export class EditBox extends Group implements IEditBox {
381
383
  }
382
384
 
383
385
  public onDragEnd(e: DragEvent): void {
386
+ if (this.moving) this.widgetsMoveEnd(e)
384
387
  this.onTransformEnd(e)
385
388
  this.dragPoint = null
386
389
  }
@@ -418,9 +421,9 @@ export class EditBox extends Group implements IEditBox {
418
421
  if (isString(this.mergedConfig.moveable)) {
419
422
  this.gesturing = this.moving = true
420
423
  switch (e.type) {
421
- case MoveEvent.START: this.onTransformStart(e); break
422
- case MoveEvent.END: this.onTransformEnd(e); break
423
- default: this.transformTool.onMove(e)
424
+ case MoveEvent.START: this.onTransformStart(e), this.widgetsMoveStart(e); break
425
+ case MoveEvent.END: this.onTransformEnd(e), this.widgetsMoveEnd(e); break
426
+ default: this.transformTool.onMove(e), this.widgetsMove(e)
424
427
  }
425
428
  }
426
429
  }
@@ -583,6 +586,10 @@ export class EditBox extends Group implements IEditBox {
583
586
  Object.values(EditBox.WidgetList).forEach(item => { this.widgets.push(new item(this)) })
584
587
  }
585
588
 
589
+ public getWidget(name: string): IEditBoxWidget {
590
+ return this.widgets.find(item => item.tag === name)
591
+ }
592
+
586
593
  protected loadWidgets(): void {
587
594
  this.widgets.forEach(item => item.onLoad())
588
595
  }
@@ -595,6 +602,18 @@ export class EditBox extends Group implements IEditBox {
595
602
  this.widgets.forEach(item => item.onUnload())
596
603
  }
597
604
 
605
+ protected widgetsMoveStart(e: DragEvent | MoveEvent): void {
606
+ this.widgets.forEach(item => item.onMove && item.onMoveStart(e))
607
+ }
608
+
609
+ protected widgetsMove(e: DragEvent | MoveEvent): void {
610
+ this.widgets.forEach(item => item.onMove && item.onMove(e))
611
+ }
612
+
613
+ protected widgetsMoveEnd(e: DragEvent | MoveEvent): void {
614
+ this.widgets.forEach(item => item.onMove && item.onMoveEnd(e))
615
+ }
616
+
598
617
  protected destroyWidgets(): void {
599
618
  this.widgets.forEach(item => item.onDestroy())
600
619
  }
@@ -19,8 +19,9 @@ export class EditTool extends InnerEditor implements IEditTool {
19
19
  // 操作
20
20
 
21
21
  public onMove(e: IEditorMoveEvent): void {
22
- if (this.isMotionElement) return this.onMoveMotion(e)
23
- else if (this.isFlowElement) return this.onMoveFlow(e)
22
+ if (this.isMotionElement && this.onMoveMotion(e)) return
23
+ if (this.isFlowElement && this.onMoveFlow(e)) return
24
+
24
25
  const { moveX, moveY, editor } = e
25
26
  const { app, list } = editor
26
27
  app.lockLayout()
@@ -29,6 +30,8 @@ export class EditTool extends InnerEditor implements IEditTool {
29
30
  }
30
31
 
31
32
  public onScale(e: IEditorScaleEvent): void {
33
+ if (this.isFlowElement && this.onScaleFlow(e)) return
34
+
32
35
  const { scaleX, scaleY, transform, worldOrigin, editor } = e
33
36
  const { app, list } = editor
34
37
  app.lockLayout()
@@ -41,6 +44,8 @@ export class EditTool extends InnerEditor implements IEditTool {
41
44
  }
42
45
 
43
46
  public onRotate(e: IEditorRotateEvent): void {
47
+ if (this.isFlowElement && this.onRotateFlow(e)) return
48
+
44
49
  const { rotation, transform, worldOrigin, editor } = e
45
50
  const { app, list } = editor
46
51
  app.lockLayout()
@@ -53,6 +58,8 @@ export class EditTool extends InnerEditor implements IEditTool {
53
58
  }
54
59
 
55
60
  public onSkew(e: IEditorSkewEvent): void {
61
+ if (this.isFlowElement && this.onSkewFlow(e)) return
62
+
56
63
  const { skewX, skewY, transform, worldOrigin, editor } = e
57
64
  const { app, list } = editor
58
65
  app.lockLayout()
@@ -89,6 +96,9 @@ export interface EditTool {
89
96
  readonly isMotionElement?: boolean
90
97
  readonly isFlowElement?: boolean
91
98
 
92
- onMoveMotion(e: IEditorMoveEvent): void
93
- onMoveFlow(e: IEditorMoveEvent): void
99
+ onMoveMotion(e: IEditorMoveEvent): boolean
100
+ onMoveFlow(e: IEditorMoveEvent): boolean
101
+ onScaleFlow(e: IEditorScaleEvent): boolean
102
+ onRotateFlow(e: IEditorRotateEvent): boolean
103
+ onSkewFlow(e: IEditorSkewEvent): boolean
94
104
  }
package/types/index.d.ts CHANGED
@@ -218,9 +218,13 @@ declare class EditBox extends Group implements IEditBox {
218
218
  protected widgets: IEditBoxWidget[];
219
219
  static registerWidget(Widget: IObject): void;
220
220
  protected createWidgets(): void;
221
+ getWidget(name: string): IEditBoxWidget;
221
222
  protected loadWidgets(): void;
222
223
  protected updateWidgets(): void;
223
224
  protected unloadWidgets(): void;
225
+ protected widgetsMoveStart(e: DragEvent | MoveEvent): void;
226
+ protected widgetsMove(e: DragEvent | MoveEvent): void;
227
+ protected widgetsMoveEnd(e: DragEvent | MoveEvent): void;
224
228
  protected destroyWidgets(): void;
225
229
  destroy(): void;
226
230
  }
@@ -386,8 +390,11 @@ declare class EditTool extends InnerEditor implements IEditTool {
386
390
  interface EditTool {
387
391
  readonly isMotionElement?: boolean;
388
392
  readonly isFlowElement?: boolean;
389
- onMoveMotion(e: IEditorMoveEvent): void;
390
- onMoveFlow(e: IEditorMoveEvent): void;
393
+ onMoveMotion(e: IEditorMoveEvent): boolean;
394
+ onMoveFlow(e: IEditorMoveEvent): boolean;
395
+ onScaleFlow(e: IEditorScaleEvent): boolean;
396
+ onRotateFlow(e: IEditorRotateEvent): boolean;
397
+ onSkewFlow(e: IEditorSkewEvent): boolean;
391
398
  }
392
399
 
393
400
  declare class LineEditTool extends EditTool {