@leafer-in/editor 2.2.0 → 2.2.2

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.0",
3
+ "version": "2.2.2",
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.0",
38
- "@leafer-ui/core": "^2.2.0",
39
- "@leafer-in/resize": "^2.2.0",
40
- "@leafer-ui/interface": "^2.2.0",
41
- "@leafer-in/interface": "^2.2.0"
37
+ "@leafer-ui/draw": "^2.2.2",
38
+ "@leafer-ui/core": "^2.2.2",
39
+ "@leafer-in/resize": "^2.2.2",
40
+ "@leafer-ui/interface": "^2.2.2",
41
+ "@leafer-in/interface": "^2.2.2"
42
42
  }
43
43
  }
@@ -1,9 +1,10 @@
1
1
  import { IFunction, ILeaf, IObject, IUI, } from '@leafer-ui/interface'
2
- import { defineKey, isNull, isArray, isObject, isUndefined } from '@leafer-ui/draw'
2
+ import { defineKey, isNull, isArray, isObject, isUndefined, DataHelper } from '@leafer-ui/draw'
3
3
 
4
- import { IEditor } from '@leafer-in/interface'
4
+ import { IEditor, IInnerEditor } from '@leafer-in/interface'
5
5
 
6
6
  import { EditorEvent } from '../event/EditorEvent'
7
+ import { EditorHelper } from '../helper/EditorHelper'
7
8
 
8
9
 
9
10
  export function targetAttr(fn: IFunction) {
@@ -58,6 +59,8 @@ export function mergeConfigAttr() {
58
59
  if (innerEditor) innerEditor.editConfig && Object.assign(mergeConfig, innerEditor.editConfig) // innerEditor 上的配置
59
60
  else if (editTool) editTool.editConfig && Object.assign(mergeConfig, editTool.editConfig) // editTool 上的配置
60
61
 
62
+ if (element && element.mask) EditorHelper.mergeMaskConfig(mergeConfig, this) // 扩展
63
+
61
64
  if (element && element.editConfig) {
62
65
  let { editConfig } = element
63
66
  if (editConfig.hover || editConfig.hoverStyle || editConfig.hoverPathType) { // 元素的hover样式,不能覆盖到总配置里
@@ -85,3 +88,28 @@ export function mergeConfigAttr() {
85
88
  }
86
89
 
87
90
 
91
+
92
+ // 合并编辑工具配置装饰器
93
+ export function editToolMergeConfigAttr() {
94
+ return (target: IInnerEditor, key: string) => {
95
+ defineKey(target, key, {
96
+ get() {
97
+ const t = this as IInnerEditor
98
+ const { config, userConfig, configKeepKeys } = t, mergedConfig: IObject = config ? DataHelper.clone(config) : {}
99
+
100
+ if (configKeepKeys) {
101
+ for (let key in userConfig) {
102
+ if (!configKeepKeys.includes(key)) mergedConfig[key] = userConfig[key] // 不直接覆盖 configKeepKeys
103
+ }
104
+ }
105
+
106
+ if (t.preMergedConfig) t.preMergedConfig(mergedConfig)
107
+
108
+ if (configKeepKeys) configKeepKeys.forEach(key => { userConfig[key] && Object.assign(mergedConfig[key], userConfig[key]) }) // 单独 assign configKeepKeys
109
+
110
+ return t.mergedConfig = mergedConfig
111
+ }
112
+ } as ThisType<any>)
113
+ }
114
+ }
115
+
@@ -1,8 +1,8 @@
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, DataHelper, isArray, isString, isNumber, isNull, getPointData, isUndefined } from '@leafer-ui/draw'
1
+ import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, ITransformTool, IUIEvent, IEditPointInputData, IObject } from '@leafer-ui/interface'
2
+ import { Group, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, DataHelper, isArray, isString, isNumber, isNull, getPointData, isUndefined, Debug } from '@leafer-ui/draw'
3
3
  import { DragEvent, PointerEvent, KeyEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
4
4
 
5
- import { IEditBox, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
5
+ import { IEditBox, IEditBoxWidget, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
6
6
 
7
7
  import { updatePointCursor, updateMoveCursor } from '../editor/cursor'
8
8
  import { EditPoint } from './EditPoint'
@@ -10,6 +10,7 @@ import { EditDataHelper } from '../helper/EditDataHelper'
10
10
 
11
11
 
12
12
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig: IEditorConfig = undefined
13
+ const debug = Debug.get('EditBox')
13
14
 
14
15
  export class EditBox extends Group implements IEditBox {
15
16
 
@@ -32,12 +33,16 @@ export class EditBox extends Group implements IEditBox {
32
33
  public resizePoints: IEditPoint[] = [] // topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left
33
34
  public rotatePoints: IEditPoint[] = [] // topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left
34
35
  public resizeLines: IEditPoint[] = [] // top, right, bottom, left
36
+ public linkPoints: IEditPoint[] // top, right, bottom, left
35
37
 
36
38
  public enterPoint: IEditPoint
37
39
  public dragPoint: IEditPoint // 正在拖拽的控制点
38
40
 
39
41
  public dragStartData = {} as IEditorDragStartData
40
42
 
43
+ public rectBounds: IBoundsData
44
+ public showPoints: boolean
45
+
41
46
  public config: IEditorConfig
42
47
  public mergedConfig: IEditorConfig
43
48
 
@@ -78,6 +83,7 @@ export class EditBox extends Group implements IEditBox {
78
83
  this.visible = false
79
84
  this.create()
80
85
  this.__listenEvents()
86
+ this.createWidgets()
81
87
  }
82
88
 
83
89
  public create() {
@@ -104,11 +110,10 @@ export class EditBox extends Group implements IEditBox {
104
110
  this.listenPointEvents(circle, 'rotate', 2)
105
111
  this.listenPointEvents(rect, 'move', 8) // center
106
112
 
107
- view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints)
113
+ view.add([...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints])
108
114
  this.add(view)
109
115
  }
110
116
 
111
-
112
117
  public load(): void {
113
118
  const { target, mergeConfig, single, rect, circle, resizePoints, resizeLines } = this
114
119
  const { stroke, strokeWidth, ignorePixelSnap } = mergeConfig
@@ -119,10 +124,11 @@ export class EditBox extends Group implements IEditBox {
119
124
 
120
125
  this.visible = !target.locked
121
126
 
122
- let resizeP: IRect
127
+ let resizeP: IBox
123
128
 
124
129
  for (let i = 0; i < 8; i++) {
125
130
  resizeP = resizePoints[i]
131
+ if (resizeP.children.length) resizeP.clear()
126
132
  resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]))
127
133
  resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90
128
134
  if (i % 2) resizeLines[(i - 1) / 2].set({ pointType: 'resize', rotation: (i - 1) / 2 * 90, ...(resizeLinesStyle[((i - 1) / 2) % resizeLinesStyle.length] || {}) } as IEditPointInputData)
@@ -147,6 +153,7 @@ export class EditBox extends Group implements IEditBox {
147
153
  if (single) DataHelper.stintSet(target.__world, 'ignorePixelSnap', ignorePixelSnap)
148
154
 
149
155
  updateMoveCursor(this)
156
+ this.loadWidgets()
150
157
  }
151
158
 
152
159
  // 必须来自 editor.update(),需同步更新编辑工具
@@ -156,9 +163,11 @@ export class EditBox extends Group implements IEditBox {
156
163
  this.visible = !this.target.locked
157
164
  this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
158
165
  this.updateBounds({ x: 0, y: 0, width, height })
166
+ this.updateWidgets()
159
167
  }
160
168
 
161
169
  public unload(): void {
170
+ this.unloadWidgets()
162
171
  this.visible = false
163
172
  if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null
164
173
  }
@@ -175,6 +184,7 @@ export class EditBox extends Group implements IEditBox {
175
184
  }
176
185
 
177
186
  if (spread) BoundsHelper.spread(bounds, spread)
187
+ this.rectBounds = bounds
178
188
 
179
189
  editMask.visible = mask ? true : 0
180
190
 
@@ -189,7 +199,7 @@ export class EditBox extends Group implements IEditBox {
189
199
  if (this.view.worldOpacity) {
190
200
  const { width, height } = bounds
191
201
  const smallSize = isNumber(hideOnSmall) ? hideOnSmall : 10
192
- const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize)
202
+ const showPoints = this.showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize)
193
203
 
194
204
  let point = {} as IPointData, rotateP: IRect, resizeP: IRect, resizeL: IRect
195
205
 
@@ -528,9 +538,42 @@ export class EditBox extends Group implements IEditBox {
528
538
  this.off_(this.__eventIds)
529
539
  }
530
540
 
541
+ // widgets
542
+
543
+ static WidgetList: IObject = {}
544
+
545
+ protected widgets: IEditBoxWidget[] = []
546
+
547
+ static registerWidget(Widget: IObject): void {
548
+ const { tag } = Widget.prototype as IEditBoxWidget
549
+ EditBox.WidgetList[tag] && debug.repeat(tag)
550
+ EditBox.WidgetList[tag] = Widget
551
+ }
552
+
553
+ protected createWidgets(): void {
554
+ Object.values(EditBox.WidgetList).forEach(item => { this.widgets.push(new item(this)) })
555
+ }
556
+
557
+ protected loadWidgets(): void {
558
+ this.widgets.forEach(item => item.onLoad())
559
+ }
560
+
561
+ protected updateWidgets(): void {
562
+ this.widgets.forEach(item => item.onUpdate())
563
+ }
564
+
565
+ protected unloadWidgets(): void {
566
+ this.widgets.forEach(item => item.onUnload())
567
+ }
568
+
569
+ protected destroyWidgets(): void {
570
+ this.widgets.forEach(item => item.onDestroy())
571
+ }
572
+
531
573
  public destroy(): void {
532
574
  this.editor = null
533
575
  this.__removeListenEvents()
576
+ this.destroyWidgets()
534
577
  super.destroy()
535
578
  }
536
579
 
@@ -8,6 +8,7 @@ import { Stroker } from './Stroker'
8
8
  import { SelectArea } from './SelectArea'
9
9
  import { EditSelectHelper } from '../helper/EditSelectHelper'
10
10
  import { EditorEvent } from '../event/EditorEvent'
11
+ import { EditorHelper } from '../helper/EditorHelper'
11
12
 
12
13
 
13
14
  const { findOne, findByBounds } = EditSelectHelper
@@ -56,7 +57,11 @@ export class EditSelect extends Group implements IEditSelect {
56
57
 
57
58
  protected onSelect(): void {
58
59
  if (this.running) {
59
- this.targetStroker.setTarget(this.editor.list)
60
+ const { editor } = this
61
+ let { list } = editor
62
+ const maskList = EditorHelper.getSiblingMaskElements(editor)
63
+ if (maskList) list = maskList.concat(list)
64
+ this.targetStroker.setTarget(list)
60
65
  this.hoverStroker.target = null
61
66
  }
62
67
  }
@@ -1,6 +1,8 @@
1
- import { IGroup, IGroupInputData, ILeaf, IUI } from '@leafer-ui/interface'
1
+ import { IEditorConfig, IGroup, IGroupInputData, ILeaf, IUI } from '@leafer-ui/interface'
2
2
  import { Group, Matrix } from '@leafer-ui/draw'
3
3
 
4
+ import { IEditor } from '@leafer-in/interface'
5
+
4
6
 
5
7
  const order = (a: ILeaf, b: ILeaf) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b)
6
8
  const reverseOrder = (a: ILeaf, b: ILeaf) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a)
@@ -69,6 +71,10 @@ export const EditorHelper = {
69
71
  list.forEach(leaf => {
70
72
  if (leaf.parent) leaf.parent.addAt(leaf, 0)
71
73
  })
72
- }
74
+ },
75
+
76
+ // need rewrite
77
+ mergeMaskConfig(_mergeConfig: IEditorConfig, _editor: IEditor): void { },
78
+ getSiblingMaskElements(_editor: IEditor): IUI[] { return undefined }
73
79
 
74
80
  }
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ export { EditTool } from './tool/EditTool'
21
21
  export { LineEditTool } from './tool/LineEditTool'
22
22
  export { TransformTool } from './tool/TransformTool'
23
23
 
24
+ export { editToolMergeConfigAttr } from './decorator/data'
24
25
 
25
26
  export { EditorHelper } from './helper/EditorHelper'
26
27
  export { EditDataHelper } from './helper/EditDataHelper'
@@ -1,9 +1,12 @@
1
- import { IGroup, IEventListenerId, IUI, IObject, IEditorConfig } from '@leafer-ui/interface'
1
+ import { IGroup, IEventListenerId, IUI, IObject, IPointData, IEditorConfig } from '@leafer-ui/interface'
2
2
  import { IInnerEditor, IEditor, IEditBox, IInnerEditorMode } from '@leafer-in/interface'
3
3
 
4
- import { Group } from '@leafer-ui/draw'
4
+ import { Group, PointHelper } from '@leafer-ui/draw'
5
5
  import { EditToolCreator } from './EditToolCreator'
6
6
 
7
+
8
+ const { abs } = Math, { scale } = PointHelper
9
+
7
10
  export class InnerEditor implements IInnerEditor {
8
11
 
9
12
  static registerInnerEditor() {
@@ -16,10 +19,10 @@ export class InnerEditor implements IInnerEditor {
16
19
  public get mode(): IInnerEditorMode { return 'focus' } // 专注模式
17
20
 
18
21
  public editTarget: IUI
22
+ public editConfig?: IEditorConfig
19
23
 
20
24
  public config: IObject
21
-
22
- public editConfig?: IEditorConfig
25
+ public get userConfig(): IObject { return (this.editBox.mergeConfig[this.tag] || {}) }
23
26
 
24
27
  public editor: IEditor
25
28
 
@@ -38,6 +41,19 @@ export class InnerEditor implements IInnerEditor {
38
41
  }
39
42
 
40
43
 
44
+ public getEditBoxPoint(editTargetPoint: IPointData, change?: boolean): IPointData {
45
+ const point = change ? editTargetPoint : { x: editTargetPoint.x, y: editTargetPoint.y }, { scaleX, scaleY } = this.editTarget.worldTransform
46
+ scale(point, abs(scaleX), abs(scaleY))
47
+ return point
48
+ }
49
+
50
+ public getEditTargetPoint(editBoxPoint: IPointData, change?: boolean): IPointData {
51
+ const point = change ? editBoxPoint : { x: editBoxPoint.x, y: editBoxPoint.y }, { scaleX, scaleY } = this.editTarget.worldTransform
52
+ scale(point, Math.abs(1 / scaleX), abs(1 / scaleY))
53
+ return point
54
+ }
55
+
56
+
41
57
  public onCreate(): void { }
42
58
  public create(): void {
43
59
  this.view = new Group()
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, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, 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, 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, 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, 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;
@@ -154,9 +154,12 @@ declare class EditBox extends Group implements IEditBox {
154
154
  resizePoints: IEditPoint[];
155
155
  rotatePoints: IEditPoint[];
156
156
  resizeLines: IEditPoint[];
157
+ linkPoints: IEditPoint[];
157
158
  enterPoint: IEditPoint;
158
159
  dragPoint: IEditPoint;
159
160
  dragStartData: IEditorDragStartData;
161
+ rectBounds: IBoundsData;
162
+ showPoints: boolean;
160
163
  config: IEditorConfig$1;
161
164
  mergedConfig: IEditorConfig$1;
162
165
  get mergeConfig(): IEditorConfig$1;
@@ -205,6 +208,14 @@ declare class EditBox extends Group implements IEditBox {
205
208
  listenPointEvents(point: IEditPoint, type: IEditPointType, direction: Direction9): void;
206
209
  protected __listenEvents(): void;
207
210
  protected __removeListenEvents(): void;
211
+ static WidgetList: IObject;
212
+ protected widgets: IEditBoxWidget[];
213
+ static registerWidget(Widget: IObject): void;
214
+ protected createWidgets(): void;
215
+ protected loadWidgets(): void;
216
+ protected updateWidgets(): void;
217
+ protected unloadWidgets(): void;
218
+ protected destroyWidgets(): void;
208
219
  destroy(): void;
209
220
  }
210
221
 
@@ -325,8 +336,9 @@ declare class InnerEditor implements IInnerEditor {
325
336
  get tag(): string;
326
337
  get mode(): IInnerEditorMode;
327
338
  editTarget: IUI;
328
- config: IObject;
329
339
  editConfig?: IEditorConfig$1;
340
+ config: IObject;
341
+ get userConfig(): IObject;
330
342
  editor: IEditor;
331
343
  protected _editBox: IEditBox;
332
344
  get editBox(): IEditBox;
@@ -334,6 +346,8 @@ declare class InnerEditor implements IInnerEditor {
334
346
  view: IGroup;
335
347
  eventIds: IEventListenerId[];
336
348
  constructor(editor: IEditor);
349
+ getEditBoxPoint(editTargetPoint: IPointData, change?: boolean): IPointData;
350
+ getEditTargetPoint(editBoxPoint: IPointData, change?: boolean): IPointData;
337
351
  onCreate(): void;
338
352
  create(): void;
339
353
  onLoad(): void;
@@ -393,11 +407,15 @@ declare class TransformTool implements ITransformTool {
393
407
  emitEvent(event?: IEvent, capture?: boolean): void;
394
408
  }
395
409
 
410
+ declare function editToolMergeConfigAttr(): (target: IInnerEditor, key: string) => void;
411
+
396
412
  declare const EditorHelper: {
397
413
  group(list: IUI[], element?: IUI, userGroup?: IGroup | IGroupInputData): IGroup;
398
414
  ungroup(list: IUI[]): IUI[];
399
415
  toTop(list: IUI[]): void;
400
416
  toBottom(list: IUI[]): void;
417
+ mergeMaskConfig(_mergeConfig: IEditorConfig$1, _editor: IEditor): void;
418
+ getSiblingMaskElements(_editor: IEditor): IUI[];
401
419
  };
402
420
 
403
421
  declare const EditDataHelper: {
@@ -414,4 +432,4 @@ declare const EditSelectHelper: {
414
432
  findByBounds(branch: IUI, bounds: IBounds): IUI[];
415
433
  };
416
434
 
417
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, registerEditTool, registerInnerEditor };
435
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, editToolMergeConfigAttr, registerEditTool, registerInnerEditor };