@leafer-in/editor 2.2.6 → 2.2.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": "2.2.6",
3
+ "version": "2.2.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": "^2.2.6",
38
- "@leafer-ui/core": "^2.2.6",
39
- "@leafer-in/resize": "^2.2.6",
40
- "@leafer-ui/interface": "^2.2.6",
41
- "@leafer-in/interface": "^2.2.6"
37
+ "@leafer-ui/draw": "^2.2.7",
38
+ "@leafer-ui/core": "^2.2.7",
39
+ "@leafer-in/resize": "^2.2.7",
40
+ "@leafer-ui/interface": "^2.2.7",
41
+ "@leafer-in/interface": "^2.2.7"
42
42
  }
43
43
  }
@@ -114,6 +114,15 @@ export class EditBox extends Group implements IEditBox {
114
114
  this.add(view)
115
115
  }
116
116
 
117
+ public showView(): void {
118
+ this.view.opacity = 1
119
+ this.update()
120
+ }
121
+
122
+ public hideView(): void {
123
+ this.view.opacity = 0
124
+ }
125
+
117
126
  public load(): void {
118
127
  const { target, mergeConfig, single, rect, circle, resizePoints, resizeLines } = this
119
128
  const { stroke, strokeWidth, ignorePixelSnap } = mergeConfig
@@ -152,14 +161,15 @@ export class EditBox extends Group implements IEditBox {
152
161
  // 忽略元素像素对齐,在 target 属性装饰器中重置
153
162
  if (single) DataHelper.stintSet(target.__world, 'ignorePixelSnap', ignorePixelSnap)
154
163
 
155
- updateMoveCursor(this)
164
+ this.updateMoveCursor()
156
165
  this.loadWidgets()
157
166
  }
158
167
 
159
168
  // 必须来自 editor.update(),需同步更新编辑工具
160
169
  public update(): void {
161
- const { editor } = this
162
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true)
170
+ const { editor, target } = this
171
+ if (!target) return
172
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = target.getLayoutBounds('box', editor, true)
163
173
  this.visible = !this.target.locked
164
174
  this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
165
175
  this.updateBounds({ x: 0, y: 0, width, height })
@@ -313,6 +323,17 @@ export class EditBox extends Group implements IEditBox {
313
323
  }
314
324
 
315
325
 
326
+ // 光标
327
+
328
+ public updateMoveCursor(): void {
329
+ updateMoveCursor(this)
330
+ }
331
+
332
+ public updatePointCursor(e: IUIEvent): void {
333
+ updatePointCursor(this, e)
334
+ }
335
+
336
+
316
337
  // drag
317
338
 
318
339
  public onDragStart(e: DragEvent): void {
@@ -348,7 +369,7 @@ export class EditBox extends Group implements IEditBox {
348
369
  if (resizing) transformTool.onScale(e)
349
370
  if (skewing) transformTool.onSkew(e)
350
371
  }
351
- updatePointCursor(this, e)
372
+ this.updatePointCursor(e)
352
373
  }
353
374
 
354
375
  public onDragEnd(e: DragEvent): void {
@@ -434,7 +455,7 @@ export class EditBox extends Group implements IEditBox {
434
455
  }
435
456
 
436
457
  protected onKey(e: KeyEvent): void {
437
- updatePointCursor(this, e)
458
+ this.updatePointCursor(e)
438
459
  }
439
460
 
440
461
  public onArrow(e: IKeyEvent): void {
@@ -504,7 +525,7 @@ export class EditBox extends Group implements IEditBox {
504
525
  [DragEvent.DRAG, this.onDrag, this],
505
526
  [DragEvent.END, this.onDragEnd, this],
506
527
 
507
- [PointerEvent.ENTER, (e: PointerEvent) => { this.enterPoint = point, updatePointCursor(this, e) }],
528
+ [PointerEvent.ENTER, (e: PointerEvent) => { this.enterPoint = point, this.updatePointCursor(e) }],
508
529
  [PointerEvent.LEAVE, () => { this.enterPoint = null }]
509
530
  ])
510
531
  )
@@ -33,7 +33,7 @@ function eachFind(children: IUI[], list: IUI[], bounds: IBounds, mode: 'hit' | '
33
33
  isFind = bounds[mode](child.__layout.boxBounds, child.__world) && data.hitSelf
34
34
 
35
35
  if (child.isBranch) {
36
- if (!data.hitChildren) {
36
+ if (!data.hitChildren || (isFind && child.children.every(item => !item.editable))) {
37
37
  if (isFind) list.push(child)
38
38
  continue
39
39
  }
@@ -16,10 +16,11 @@ export class EditTool extends InnerEditor implements IEditTool {
16
16
 
17
17
  public get tag() { return 'EditTool' }
18
18
 
19
-
20
19
  // 操作
21
20
 
22
21
  public onMove(e: IEditorMoveEvent): void {
22
+ if (this.isMotionElement) return this.onMoveMotion(e)
23
+ else if (this.isFlowElement) return this.onMoveFlow(e)
23
24
  const { moveX, moveY, editor } = e
24
25
  const { app, list } = editor
25
26
  app.lockLayout()
@@ -71,13 +72,25 @@ export class EditTool extends InnerEditor implements IEditTool {
71
72
  }
72
73
 
73
74
  public update(): void {
75
+ this.updateEditBoxConfig()
74
76
  this.editBox.update()
75
77
  this.onUpdate()
76
78
  }
77
79
 
78
80
  public unload(): void {
79
81
  this.editBox.view.visible = false
82
+ this.unloadEditBoxConfig()
80
83
  this.onUnload()
81
84
  }
82
85
 
86
+ }
87
+
88
+
89
+ export interface EditTool {
90
+ // 扩展
91
+ readonly isMotionElement?: boolean
92
+ readonly isFlowElement?: boolean
93
+
94
+ onMoveMotion(e: IEditorMoveEvent): void
95
+ onMoveFlow(e: IEditorMoveEvent): void
83
96
  }
@@ -1,8 +1,9 @@
1
- import { IGroup, IEventListenerId, IUI, IObject, IPointData, IEditorConfig } from '@leafer-ui/interface'
2
- import { IInnerEditor, IEditor, IEditBox, IInnerEditorMode } from '@leafer-in/interface'
1
+ import { IGroup, IEventListenerId, IUI, IObject, IPointData, IEditorConfig, OptionalKeys } from '@leafer-ui/interface'
2
+ import { IInnerEditor, IEditor, IEditBox, IInnerEditorMode, IInnerEditorConfig } from '@leafer-in/interface'
3
3
 
4
4
  import { Group, PointHelper } from '@leafer-ui/draw'
5
5
  import { EditToolCreator } from './EditToolCreator'
6
+ import { editToolMergeConfigAttr } from '../decorator/data'
6
7
 
7
8
 
8
9
  const { abs } = Math, { scale } = PointHelper
@@ -21,9 +22,15 @@ export class InnerEditor implements IInnerEditor {
21
22
  public editTarget: IUI
22
23
  public editConfig?: IEditorConfig
23
24
 
24
- public config: IObject
25
+ public config: IInnerEditorConfig
25
26
  public get userConfig(): IObject { return (this.editBox.mergeConfig[this.tag] || {}) }
26
27
 
28
+ @editToolMergeConfigAttr()
29
+ public readonly mergeConfig: IInnerEditorConfig
30
+ public readonly mergedConfig: IInnerEditorConfig
31
+
32
+ public configKeepKeys: OptionalKeys<IInnerEditorConfig>[] = ['editBox']
33
+
27
34
  public editor: IEditor
28
35
 
29
36
  protected _editBox: IEditBox
@@ -61,6 +68,15 @@ export class InnerEditor implements IInnerEditor {
61
68
  }
62
69
 
63
70
 
71
+ public showView(): void {
72
+ this.view.opacity = 1
73
+ }
74
+
75
+ public hideView(): void {
76
+ this.view.opacity = 0
77
+ }
78
+
79
+
64
80
  // 状态
65
81
 
66
82
  public onLoad(): void { }
@@ -73,17 +89,32 @@ export class InnerEditor implements IInnerEditor {
73
89
  }
74
90
 
75
91
  public onUpdate(): void { }
76
- public update(): void { this.onUpdate() }
92
+ public update(): void {
93
+ if (this.editor) {
94
+ this.updateEditBoxConfig()
95
+ this.onUpdate()
96
+ }
97
+ }
77
98
 
78
99
  public onUnload(): void { }
79
100
  public unload(): void {
80
101
  const { editor } = this
81
102
  if (editor) {
103
+ this.unloadEditBoxConfig()
82
104
  if (editor.app && this.mode === 'focus') editor.selector.hittable = editor.app.tree.hitChildren = true
83
105
  this.onUnload()
84
106
  }
85
107
  }
86
108
 
109
+ public updateEditBoxConfig(): void {
110
+ const { mergeConfig } = this
111
+ if (mergeConfig) this.editBox.config = mergeConfig.editBox
112
+ }
113
+
114
+ public unloadEditBoxConfig(): void {
115
+ this.editBox.config = undefined
116
+ }
117
+
87
118
  public onDestroy(): void { }
88
119
  public destroy(): void {
89
120
  this.onDestroy()
package/types/index.d.ts CHANGED
@@ -1,8 +1,8 @@
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, IEditorDragStartData, IBoundsData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IUIInputData, 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, IBoundsData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IUIInputData, IMatrixData, IDragEvent, IAround, OptionalKeys, 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
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditPointType, IEditBoxWidget, 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';
5
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditPointType, IEditBoxWidget, IEditPointInputData, IEditorEvent, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IInnerEditorMode, IInnerEditorConfig, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
6
6
 
7
7
  declare class EditSelect extends Group implements IEditSelect {
8
8
  editor: IEditor;
@@ -180,6 +180,8 @@ declare class EditBox extends Group implements IEditBox {
180
180
  protected __eventIds: IEventListenerId[];
181
181
  constructor(editor: IEditor);
182
182
  create(): void;
183
+ showView(): void;
184
+ hideView(): void;
183
185
  load(): void;
184
186
  update(): void;
185
187
  unload(): void;
@@ -191,6 +193,8 @@ declare class EditBox extends Group implements IEditBox {
191
193
  getPointsStyle(): IBoxInputData[];
192
194
  getMiddlePointsStyle(): IBoxInputData[];
193
195
  getResizeLinesStyle(): IBoxInputData[];
196
+ updateMoveCursor(): void;
197
+ updatePointCursor(e: IUIEvent): void;
194
198
  onDragStart(e: DragEvent): void;
195
199
  onDrag(e: DragEvent): void;
196
200
  onDragEnd(e: DragEvent): void;
@@ -337,8 +341,11 @@ declare class InnerEditor implements IInnerEditor {
337
341
  get mode(): IInnerEditorMode;
338
342
  editTarget: IUI;
339
343
  editConfig?: IEditorConfig$1;
340
- config: IObject;
344
+ config: IInnerEditorConfig;
341
345
  get userConfig(): IObject;
346
+ readonly mergeConfig: IInnerEditorConfig;
347
+ readonly mergedConfig: IInnerEditorConfig;
348
+ configKeepKeys: OptionalKeys<IInnerEditorConfig>[];
342
349
  editor: IEditor;
343
350
  protected _editBox: IEditBox;
344
351
  get editBox(): IEditBox;
@@ -350,12 +357,16 @@ declare class InnerEditor implements IInnerEditor {
350
357
  getEditTargetPoint(editBoxPoint: IPointData, change?: boolean): IPointData;
351
358
  onCreate(): void;
352
359
  create(): void;
360
+ showView(): void;
361
+ hideView(): void;
353
362
  onLoad(): void;
354
363
  load(): void;
355
364
  onUpdate(): void;
356
365
  update(): void;
357
366
  onUnload(): void;
358
367
  unload(): void;
368
+ updateEditBoxConfig(): void;
369
+ unloadEditBoxConfig(): void;
359
370
  onDestroy(): void;
360
371
  destroy(): void;
361
372
  }
@@ -371,6 +382,12 @@ declare class EditTool extends InnerEditor implements IEditTool {
371
382
  update(): void;
372
383
  unload(): void;
373
384
  }
385
+ interface EditTool {
386
+ readonly isMotionElement?: boolean;
387
+ readonly isFlowElement?: boolean;
388
+ onMoveMotion(e: IEditorMoveEvent): void;
389
+ onMoveFlow(e: IEditorMoveEvent): void;
390
+ }
374
391
 
375
392
  declare class LineEditTool extends EditTool {
376
393
  get tag(): string;