@leafer/selector 1.0.0-rc.22 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/selector",
3
- "version": "1.0.0-rc.22",
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.22"
25
+ "@leafer/core": "1.0.0-rc.23"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.22"
28
+ "@leafer/interface": "1.0.0-rc.23"
29
29
  }
30
30
  }
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
- const leaf = this.getById(condition.substring(1), branch)
52
- return one ? leaf : (leaf ? [leaf] : [])
50
+ idCondition.id = condition.substring(1), condition = idCondition; break
53
51
  case '.':
54
- return this.getByMethod(this.methods.className, branch, one, condition.substring(1)) // className
52
+ classNameCondition.className = condition.substring(1), condition = classNameCondition; break
55
53
  default:
56
- return this.getByMethod(this.methods.tag, branch, one, condition) // tagName
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,4 +1,4 @@
1
- import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions, IPickResult, IPickBottom, 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 {
@@ -33,10 +33,11 @@ declare class Selector implements ISelector {
33
33
  innerId: (leaf: ILeaf, innerId: number) => 1 | 0;
34
34
  className: (leaf: ILeaf, name: string) => 1 | 0;
35
35
  tag: (leaf: ILeaf, name: string) => 1 | 0;
36
+ tags: (leaf: ILeaf, nameMap: IBooleanMap) => 1 | 0;
36
37
  };
37
38
  protected __eventIds: IEventListenerId[];
38
39
  constructor(target: ILeaf, userConfig?: ISelectorConfig);
39
- 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[];
40
41
  getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
41
42
  getByInnerId(innerId: number, branch?: ILeaf): ILeaf;
42
43
  getById(id: string, branch?: ILeaf): ILeaf;