@leafer/selector 1.0.0-rc.6 → 1.0.0-rc.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.0-rc.6",
3
+ "version": "1.0.0-rc.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.0-rc.6"
25
+ "@leafer/core": "1.0.0-rc.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.6"
28
+ "@leafer/interface": "1.0.0-rc.7"
29
29
  }
30
30
  }
package/src/Pather.ts CHANGED
@@ -63,10 +63,10 @@ export class Pather {
63
63
  public getPath(leaf: ILeaf): LeafList {
64
64
  const path = new LeafList()
65
65
  while (leaf) {
66
- path.push(leaf)
66
+ path.add(leaf)
67
67
  leaf = leaf.parent
68
68
  }
69
- path.push(this.target)
69
+ path.add(this.target)
70
70
  return path
71
71
  }
72
72
 
@@ -76,7 +76,7 @@ export class Pather {
76
76
  for (let i = path.list.length - 1; i > -1; i--) {
77
77
  item = path.list[i]
78
78
  if (!item.__.hittable) break
79
- hittablePath.unshift(item)
79
+ hittablePath.addAt(item, 0)
80
80
  if (!item.__.hitChildren) break
81
81
  }
82
82
  return hittablePath
@@ -96,7 +96,7 @@ export class Pather {
96
96
  for (let j = 0, jLen = path.length; j < jLen; j++) {
97
97
  leaf = path.list[j]
98
98
  if (nextPath && nextPath.has(leaf)) break
99
- throughPath.push(leaf)
99
+ throughPath.add(leaf)
100
100
  }
101
101
  }
102
102
 
package/src/Selector.ts CHANGED
@@ -1,28 +1,29 @@
1
- import { ILeaf, ILeafMap, ILeafList, ISelector, ISelectPathResult, ISelectPathOptions, IPointData, IEventListenerId, ISelectorConfig, IFindMethod } from '@leafer/interface'
1
+ import { ILeaf, ILeafMap, ISelector, ISelectorProxy, ISelectPathResult, ISelectPathOptions, IPointData, IEventListenerId, ISelectorConfig, IFindMethod, AnswerType } from '@leafer/interface'
2
2
  import { ChildEvent, LayoutEvent, DataHelper, Platform, PropertyEvent, LeafHelper } from '@leafer/core'
3
3
 
4
4
  import { Pather } from './Pather'
5
5
 
6
6
 
7
+ const { Yes, NoAndSkip, YesAndSkip } = AnswerType
8
+
7
9
  export class Selector implements ISelector {
8
10
 
9
11
  public target: ILeaf
10
12
 
11
- public list: ILeafList
13
+ public proxy?: ISelectorProxy // editor
12
14
 
13
15
  public config: ISelectorConfig = {}
14
16
 
15
17
  protected pather: Pather
16
18
 
17
-
18
19
  protected innerIdMap: ILeafMap = {}
19
20
  protected idMap: ILeafMap = {}
20
21
 
21
22
  protected findLeaf: ILeaf
22
23
 
23
24
  protected methods = {
24
- id: (leaf: ILeaf, name: string) => leaf.id === name ? this.idMap[name] = leaf : 0,
25
- innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? this.innerIdMap[innerId] = leaf : 0,
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,
26
27
  className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,
27
28
  tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0
28
29
  }
@@ -37,11 +38,6 @@ export class Selector implements ISelector {
37
38
  this.__listenEvents()
38
39
  }
39
40
 
40
- public getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult {
41
- if (Platform.name === 'node') this.target.emit(LayoutEvent.CHECK_UPDATE)
42
- return this.pather.getByPoint(hitPoint, hitRadius, options)
43
- }
44
-
45
41
  public getBy(condition: number | string | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {
46
42
  switch (typeof condition) {
47
43
  case 'number':
@@ -62,6 +58,11 @@ export class Selector implements ISelector {
62
58
  }
63
59
  }
64
60
 
61
+ public getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult {
62
+ if (Platform.name === 'node') this.target.emit(LayoutEvent.CHECK_UPDATE)
63
+ return this.pather.getByPoint(hitPoint, hitRadius, options)
64
+ }
65
+
65
66
  public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {
66
67
  const cache = this.innerIdMap[innerId]
67
68
  if (cache) return cache
@@ -91,11 +92,12 @@ export class Selector implements ISelector {
91
92
  }
92
93
 
93
94
 
94
- protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any,): void {
95
- let child: ILeaf
95
+ protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {
96
+ let child: ILeaf, result: AnswerType
96
97
  for (let i = 0, len = children.length; i < len; i++) {
97
98
  child = children[i]
98
- if (method(child, options)) {
99
+ result = method(child, options)
100
+ if (result === Yes || result === YesAndSkip) {
99
101
  if (list) {
100
102
  list.push(child)
101
103
  } else {
@@ -103,7 +105,7 @@ export class Selector implements ISelector {
103
105
  return
104
106
  }
105
107
  }
106
- if (child.isBranch) this.eachFind(child.children, method, list, options)
108
+ if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)
107
109
  }
108
110
  }
109
111
 
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, ISelectPathOptions, ISelectPathResult, ISelectorConfig, ILeafMap, IEventListenerId, IFindMethod } from '@leafer/interface';
1
+ import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, ISelectPathOptions, ISelectPathResult, ISelectorProxy, ISelectorConfig, ILeafMap, IEventListenerId, IFindMethod } from '@leafer/interface';
2
2
  import { LeafList, ChildEvent, PropertyEvent } from '@leafer/core';
3
3
 
4
4
  declare class Pather {
@@ -21,22 +21,22 @@ declare class Pather {
21
21
 
22
22
  declare class Selector implements ISelector {
23
23
  target: ILeaf;
24
- list: ILeafList;
24
+ proxy?: ISelectorProxy;
25
25
  config: ISelectorConfig;
26
26
  protected pather: Pather;
27
27
  protected innerIdMap: ILeafMap;
28
28
  protected idMap: ILeafMap;
29
29
  protected findLeaf: ILeaf;
30
30
  protected methods: {
31
- id: (leaf: ILeaf, name: string) => ILeaf | 0;
32
- innerId: (leaf: ILeaf, innerId: number) => ILeaf | 0;
31
+ id: (leaf: ILeaf, name: string) => 1 | 0;
32
+ innerId: (leaf: ILeaf, innerId: number) => 1 | 0;
33
33
  className: (leaf: ILeaf, name: string) => 1 | 0;
34
34
  tag: (leaf: ILeaf, name: string) => 1 | 0;
35
35
  };
36
36
  protected __eventIds: IEventListenerId[];
37
37
  constructor(target: ILeaf, userConfig?: ISelectorConfig);
38
- getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult;
39
38
  getBy(condition: number | string | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[];
39
+ getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult;
40
40
  getByInnerId(innerId: number, branch?: ILeaf): ILeaf;
41
41
  getById(id: string, branch?: ILeaf): ILeaf;
42
42
  getByClassName(className: string, branch?: ILeaf): ILeaf[];