@leafer-in/editor 2.2.11 → 2.3.1

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.11",
3
+ "version": "2.3.1",
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.11",
38
- "@leafer-ui/core": "^2.2.11",
39
- "@leafer-in/resize": "^2.2.11",
40
- "@leafer-ui/interface": "^2.2.11",
41
- "@leafer-in/interface": "^2.2.11"
37
+ "@leafer-ui/draw": "^2.3.1",
38
+ "@leafer-ui/core": "^2.3.1",
39
+ "@leafer-in/resize": "^2.3.1",
40
+ "@leafer-ui/interface": "^2.3.1",
41
+ "@leafer-in/interface": "^2.3.1"
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() 忽略对齐像素设置
@@ -586,6 +586,10 @@ export class EditBox extends Group implements IEditBox {
586
586
  Object.values(EditBox.WidgetList).forEach(item => { this.widgets.push(new item(this)) })
587
587
  }
588
588
 
589
+ public getWidget(name: string): IEditBoxWidget {
590
+ return this.widgets.find(item => item.tag === name)
591
+ }
592
+
589
593
  protected loadWidgets(): void {
590
594
  this.widgets.forEach(item => item.onLoad())
591
595
  }
package/types/index.d.ts CHANGED
@@ -218,6 +218,7 @@ 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;