@leafer/selector 1.0.5 → 1.0.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/selector",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "@leafer/selector",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.5"
25
+ "@leafer/core": "1.0.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.5"
28
+ "@leafer/interface": "1.0.7"
29
29
  }
30
30
  }
package/src/Picker.ts CHANGED
@@ -6,7 +6,7 @@ const { hitRadiusPoint } = BoundsHelper
6
6
 
7
7
  export class Picker {
8
8
 
9
- protected target: ILeaf
9
+ protected target?: ILeaf
10
10
  protected selector: ISelector
11
11
 
12
12
  protected findList: ILeafList
@@ -74,7 +74,7 @@ export class Picker {
74
74
  path.add(leaf)
75
75
  leaf = leaf.parent
76
76
  }
77
- path.add(this.target)
77
+ if (this.target) path.add(this.target)
78
78
  return path
79
79
  }
80
80
 
package/src/Selector.ts CHANGED
@@ -8,7 +8,7 @@ const { Yes, NoAndSkip, YesAndSkip } = Answer
8
8
  const idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition
9
9
  export class Selector implements ISelector {
10
10
 
11
- public target: ILeaf
11
+ public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)
12
12
 
13
13
  public proxy?: ISelectorProxy // editor
14
14
 
@@ -22,8 +22,8 @@ export class Selector implements ISelector {
22
22
  protected findLeaf: ILeaf
23
23
 
24
24
  protected methods = {
25
- id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
26
- innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
25
+ id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
26
+ innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
27
27
  className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,
28
28
  tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,
29
29
  tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0
@@ -36,7 +36,7 @@ export class Selector implements ISelector {
36
36
  this.target = target
37
37
  if (userConfig) this.config = DataHelper.default(userConfig, this.config)
38
38
  this.picker = new Picker(target, this)
39
- this.__listenEvents()
39
+ if (target) this.__listenEvents()
40
40
  }
41
41
 
42
42
  public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {
@@ -69,7 +69,7 @@ export class Selector implements ISelector {
69
69
  }
70
70
 
71
71
  public getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult {
72
- if (Platform.name === 'node') this.target.emit(LayoutEvent.CHECK_UPDATE)
72
+ if (Platform.name === 'node' && this.target) this.target.emit(LayoutEvent.CHECK_UPDATE)
73
73
  return this.picker.getByPoint(hitPoint, hitRadius, options)
74
74
  }
75
75
 
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions
2
2
  import { LeafList, ChildEvent, PropertyEvent } from '@leafer/core';
3
3
 
4
4
  declare class Picker {
5
- protected target: ILeaf;
5
+ protected target?: ILeaf;
6
6
  protected selector: ISelector;
7
7
  protected findList: ILeafList;
8
8
  protected exclude: ILeafList;
@@ -21,7 +21,7 @@ declare class Picker {
21
21
  }
22
22
 
23
23
  declare class Selector implements ISelector {
24
- target: ILeaf;
24
+ target?: ILeaf;
25
25
  proxy?: ISelectorProxy;
26
26
  config: ISelectorConfig;
27
27
  protected picker: Picker;