@leafer/selector 1.0.0-rc.21 → 1.0.0-rc.23
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 +3 -3
- package/src/Picker.ts +27 -17
- package/src/Selector.ts +18 -10
- package/types/index.d.ts +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/selector",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.23",
|
|
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.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.23"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.23"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Picker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom } from '@leafer/interface'
|
|
2
2
|
import { BoundsHelper, LeafList, LeafHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ export class Picker {
|
|
|
9
9
|
protected target: ILeaf
|
|
10
10
|
protected selector: ISelector
|
|
11
11
|
|
|
12
|
-
protected findList:
|
|
12
|
+
protected findList: ILeafList
|
|
13
13
|
protected exclude: ILeafList
|
|
14
14
|
|
|
15
15
|
protected point: IRadiusPointData
|
|
@@ -29,13 +29,13 @@ export class Picker {
|
|
|
29
29
|
this.exclude = options.exclude || null
|
|
30
30
|
|
|
31
31
|
this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius }
|
|
32
|
-
this.findList = options.findList
|
|
32
|
+
this.findList = new LeafList(options.findList)
|
|
33
33
|
|
|
34
34
|
// path
|
|
35
|
-
if (!options.findList) this.
|
|
35
|
+
if (!options.findList) this.hitBranch(target) // 包含through元素
|
|
36
36
|
|
|
37
|
-
const list = this.findList
|
|
38
|
-
const leaf = this.getBestMatchLeaf()
|
|
37
|
+
const { list } = this.findList
|
|
38
|
+
const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable)
|
|
39
39
|
const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf)
|
|
40
40
|
|
|
41
41
|
this.clear()
|
|
@@ -43,22 +43,29 @@ export class Picker {
|
|
|
43
43
|
return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf }
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
public getBestMatchLeaf(): ILeaf {
|
|
47
|
-
|
|
48
|
-
if (targets.length > 1) {
|
|
46
|
+
public getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf {
|
|
47
|
+
if (list.length) {
|
|
49
48
|
let find: ILeaf
|
|
50
|
-
this.findList =
|
|
49
|
+
this.findList = new LeafList()
|
|
51
50
|
const { x, y } = this.point
|
|
52
51
|
const point = { x, y, radiusX: 0, radiusY: 0 }
|
|
53
|
-
for (let i = 0, len =
|
|
54
|
-
find =
|
|
55
|
-
if (LeafHelper.worldHittable(find)) {
|
|
52
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
53
|
+
find = list[i]
|
|
54
|
+
if (ignoreHittable || LeafHelper.worldHittable(find)) {
|
|
56
55
|
this.hitChild(find, point)
|
|
57
|
-
if (this.findList.length) return this.findList[0]
|
|
56
|
+
if (this.findList.length) return this.findList.list[0]
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
|
|
61
|
+
if (bottomList) { // 底部虚拟元素
|
|
62
|
+
for (let i = 0, len = bottomList.length; i < len; i++) {
|
|
63
|
+
this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy)
|
|
64
|
+
if (this.findList.length) return this.findList.list[0]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return list[0]
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
public getPath(leaf: ILeaf): LeafList {
|
|
@@ -104,6 +111,9 @@ export class Picker {
|
|
|
104
111
|
return throughPath
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
protected hitBranch(branch: ILeaf): void {
|
|
115
|
+
this.eachFind(branch.children, branch.__onlyHitMask)
|
|
116
|
+
}
|
|
107
117
|
|
|
108
118
|
protected eachFind(children: ILeaf[], hitMask: boolean): void {
|
|
109
119
|
let child: ILeaf, hit: boolean
|
|
@@ -124,9 +134,9 @@ export class Picker {
|
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
protected hitChild(child: ILeaf, point: IRadiusPointData): void {
|
|
137
|
+
protected hitChild(child: ILeaf, point: IRadiusPointData, proxy?: ILeaf): void {
|
|
128
138
|
if (this.exclude && this.exclude.has(child)) return
|
|
129
|
-
if (child.__hitWorld(point)) this.findList.
|
|
139
|
+
if (child.__hitWorld(point)) this.findList.add(proxy || child)
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
protected clear(): void {
|
package/src/Selector.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { ILeaf, ILeafMap, ISelector, ISelectorProxy, IPickResult, IPickOptions, IPointData, IEventListenerId, ISelectorConfig, IFindMethod, IAnswer } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeafMap, ISelector, ISelectorProxy, IPickResult, IPickOptions, IPointData, IEventListenerId, ISelectorConfig, IFindMethod, IAnswer, IFindCondition, IBooleanMap } from '@leafer/interface'
|
|
2
2
|
import { ChildEvent, LayoutEvent, DataHelper, Answer, Platform, PropertyEvent, LeafHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { Picker } from './Picker'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
7
|
const { Yes, NoAndSkip, YesAndSkip } = Answer
|
|
10
|
-
|
|
8
|
+
const idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition
|
|
11
9
|
export class Selector implements ISelector {
|
|
12
10
|
|
|
13
11
|
public target: ILeaf
|
|
@@ -27,7 +25,8 @@ export class Selector implements ISelector {
|
|
|
27
25
|
id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
|
|
28
26
|
innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
|
|
29
27
|
className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,
|
|
30
|
-
tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0
|
|
28
|
+
tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,
|
|
29
|
+
tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
protected __eventIds: IEventListenerId[]
|
|
@@ -40,7 +39,7 @@ export class Selector implements ISelector {
|
|
|
40
39
|
this.__listenEvents()
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
public getBy(condition: number | string | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {
|
|
42
|
+
public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {
|
|
44
43
|
switch (typeof condition) {
|
|
45
44
|
case 'number':
|
|
46
45
|
const leaf = this.getByInnerId(condition, branch)
|
|
@@ -48,12 +47,21 @@ export class Selector implements ISelector {
|
|
|
48
47
|
case 'string':
|
|
49
48
|
switch (condition[0]) {
|
|
50
49
|
case '#':
|
|
51
|
-
|
|
52
|
-
return one ? leaf : (leaf ? [leaf] : [])
|
|
50
|
+
idCondition.id = condition.substring(1), condition = idCondition; break
|
|
53
51
|
case '.':
|
|
54
|
-
|
|
52
|
+
classNameCondition.className = condition.substring(1), condition = classNameCondition; break
|
|
55
53
|
default:
|
|
56
|
-
|
|
54
|
+
tagCondition.tag = condition, condition = tagCondition
|
|
55
|
+
}
|
|
56
|
+
case 'object':
|
|
57
|
+
if (condition.id !== undefined) {
|
|
58
|
+
const leaf = this.getById(condition.id as string, branch)
|
|
59
|
+
return one ? leaf : (leaf ? [leaf] : [])
|
|
60
|
+
} else if (condition.tag) {
|
|
61
|
+
const { tag } = condition, isArray = tag instanceof Array
|
|
62
|
+
return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)
|
|
63
|
+
} else {
|
|
64
|
+
return this.getByMethod(this.methods.className, branch, one, condition.className)
|
|
57
65
|
}
|
|
58
66
|
case 'function':
|
|
59
67
|
return this.getByMethod(condition as IFindMethod, branch, one, options)
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions, IPickResult, ISelectorProxy, ISelectorConfig, ILeafMap, IEventListenerId, IFindMethod } from '@leafer/interface';
|
|
1
|
+
import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions, IPickResult, IPickBottom, ISelectorProxy, ISelectorConfig, ILeafMap, IBooleanMap, IEventListenerId, IFindCondition, IFindMethod } from '@leafer/interface';
|
|
2
2
|
import { LeafList, ChildEvent, PropertyEvent } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class Picker {
|
|
5
5
|
protected target: ILeaf;
|
|
6
6
|
protected selector: ISelector;
|
|
7
|
-
protected findList:
|
|
7
|
+
protected findList: ILeafList;
|
|
8
8
|
protected exclude: ILeafList;
|
|
9
9
|
protected point: IRadiusPointData;
|
|
10
10
|
constructor(target: ILeaf, selector: ISelector);
|
|
11
11
|
getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
|
|
12
|
-
getBestMatchLeaf(): ILeaf;
|
|
12
|
+
getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf;
|
|
13
13
|
getPath(leaf: ILeaf): LeafList;
|
|
14
14
|
getHitablePath(leaf: ILeaf): LeafList;
|
|
15
15
|
getThroughPath(list: ILeaf[]): LeafList;
|
|
16
|
+
protected hitBranch(branch: ILeaf): void;
|
|
16
17
|
protected eachFind(children: ILeaf[], hitMask: boolean): void;
|
|
17
|
-
protected hitChild(child: ILeaf, point: IRadiusPointData): void;
|
|
18
|
+
protected hitChild(child: ILeaf, point: IRadiusPointData, proxy?: ILeaf): void;
|
|
18
19
|
protected clear(): void;
|
|
19
20
|
destroy(): void;
|
|
20
21
|
}
|
|
@@ -32,10 +33,11 @@ declare class Selector implements ISelector {
|
|
|
32
33
|
innerId: (leaf: ILeaf, innerId: number) => 1 | 0;
|
|
33
34
|
className: (leaf: ILeaf, name: string) => 1 | 0;
|
|
34
35
|
tag: (leaf: ILeaf, name: string) => 1 | 0;
|
|
36
|
+
tags: (leaf: ILeaf, nameMap: IBooleanMap) => 1 | 0;
|
|
35
37
|
};
|
|
36
38
|
protected __eventIds: IEventListenerId[];
|
|
37
39
|
constructor(target: ILeaf, userConfig?: ISelectorConfig);
|
|
38
|
-
getBy(condition: number | string | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[];
|
|
40
|
+
getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[];
|
|
39
41
|
getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
|
|
40
42
|
getByInnerId(innerId: number, branch?: ILeaf): ILeaf;
|
|
41
43
|
getById(id: string, branch?: ILeaf): ILeaf;
|