@leafer-in/find 1.8.0 → 1.9.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/dist/find.cjs CHANGED
@@ -1,66 +1,70 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var draw = require('@leafer-ui/draw');
3
+ var draw = require("@leafer-ui/draw");
4
+
5
+ const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = draw.Answer;
4
6
 
5
- const { Yes, NoAndSkip, YesAndSkip } = draw.Answer;
6
7
  const idCondition = {}, classNameCondition = {}, tagCondition = {};
8
+
7
9
  class Finder {
8
10
  constructor(target) {
9
11
  this.innerIdMap = {};
10
12
  this.idMap = {};
11
13
  this.methods = {
12
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
13
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
14
+ id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
15
+ 1) : 0,
16
+ innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf),
17
+ 1) : 0,
14
18
  className: (leaf, name) => leaf.className === name ? 1 : 0,
15
19
  tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
16
20
  tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
17
21
  };
18
- if (this.target = target)
19
- this.__listenEvents();
22
+ if (this.target = target) this.__listenEvents();
20
23
  }
21
24
  getBy(condition, branch, one, options) {
22
25
  switch (typeof condition) {
23
- case 'number':
24
- const leaf = this.getByInnerId(condition, branch);
25
- return one ? leaf : (leaf ? [leaf] : []);
26
- case 'string':
27
- switch (condition[0]) {
28
- case '#':
29
- idCondition.id = condition.substring(1), condition = idCondition;
30
- break;
31
- case '.':
32
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
33
- break;
34
- default:
35
- tagCondition.tag = condition, condition = tagCondition;
36
- }
37
- case 'object':
38
- if (condition.id !== undefined) {
39
- const leaf = this.getById(condition.id, branch);
40
- return one ? leaf : (leaf ? [leaf] : []);
41
- }
42
- else if (condition.tag) {
43
- const { tag } = condition, isArray = tag instanceof Array;
44
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? draw.DataHelper.toMap(tag) : tag);
45
- }
46
- else {
47
- return this.getByMethod(this.methods.className, branch, one, condition.className);
48
- }
49
- case 'function':
50
- return this.getByMethod(condition, branch, one, options);
26
+ case "number":
27
+ const leaf = this.getByInnerId(condition, branch);
28
+ return one ? leaf : leaf ? [ leaf ] : [];
29
+
30
+ case "string":
31
+ switch (condition[0]) {
32
+ case "#":
33
+ idCondition.id = condition.substring(1), condition = idCondition;
34
+ break;
35
+
36
+ case ".":
37
+ classNameCondition.className = condition.substring(1), condition = classNameCondition;
38
+ break;
39
+
40
+ default:
41
+ tagCondition.tag = condition, condition = tagCondition;
42
+ }
43
+
44
+ case "object":
45
+ if (!draw.isUndefined(condition.id)) {
46
+ const leaf = this.getById(condition.id, branch);
47
+ return one ? leaf : leaf ? [ leaf ] : [];
48
+ } else if (condition.tag) {
49
+ const {tag: tag} = condition, isArr = draw.isArray(tag);
50
+ return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? draw.DataHelper.toMap(tag) : tag);
51
+ } else {
52
+ return this.getByMethod(this.methods.className, branch, one, condition.className);
53
+ }
54
+
55
+ case "function":
56
+ return this.getByMethod(condition, branch, one, options);
51
57
  }
52
58
  }
53
59
  getByInnerId(innerId, branch) {
54
60
  const cache = this.innerIdMap[innerId];
55
- if (cache)
56
- return cache;
61
+ if (cache) return cache;
57
62
  this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
58
63
  return this.findLeaf;
59
64
  }
60
65
  getById(id, branch) {
61
66
  const cache = this.idMap[id];
62
- if (cache && draw.LeafHelper.hasParent(cache, branch || this.target))
63
- return cache;
67
+ if (cache && draw.LeafHelper.hasParent(cache, branch || this.target)) return cache;
64
68
  this.eachFind(this.toChildren(branch), this.methods.id, null, id);
65
69
  return this.findLeaf;
66
70
  }
@@ -83,46 +87,38 @@ class Finder {
83
87
  if (result === Yes || result === YesAndSkip) {
84
88
  if (list) {
85
89
  list.push(child);
86
- }
87
- else {
90
+ } else {
88
91
  this.findLeaf = child;
89
92
  return;
90
93
  }
91
94
  }
92
- if (child.isBranch && result < NoAndSkip)
93
- this.eachFind(child.children, method, list, options);
95
+ if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options);
94
96
  }
95
97
  }
96
98
  toChildren(branch) {
97
99
  this.findLeaf = null;
98
- return [branch || this.target];
100
+ return [ branch || this.target ];
99
101
  }
100
102
  __onRemoveChild(event) {
101
- const { id, innerId } = event.child;
102
- if (this.idMap[id])
103
- delete this.idMap[id];
104
- if (this.innerIdMap[innerId])
105
- delete this.innerIdMap[innerId];
103
+ const {id: id, innerId: innerId} = event.child;
104
+ if (this.idMap[id]) delete this.idMap[id];
105
+ if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId];
106
106
  }
107
107
  __checkIdChange(event) {
108
- if (event.attrName === 'id') {
108
+ if (event.attrName === "id") {
109
109
  const id = event.oldValue;
110
- if (this.idMap[id])
111
- delete this.idMap[id];
110
+ if (this.idMap[id]) delete this.idMap[id];
112
111
  }
113
112
  }
114
113
  __listenEvents() {
115
- this.__eventIds = [
116
- this.target.on_(draw.ChildEvent.REMOVE, this.__onRemoveChild, this),
117
- this.target.on_(draw.PropertyEvent.CHANGE, this.__checkIdChange, this)
118
- ];
114
+ this.__eventIds = [ this.target.on_(draw.ChildEvent.REMOVE, this.__onRemoveChild, this), this.target.on_(draw.PropertyEvent.CHANGE, this.__checkIdChange, this) ];
119
115
  }
120
116
  __removeListenEvents() {
121
117
  this.target.off_(this.__eventIds);
122
118
  this.__eventIds.length = 0;
123
119
  }
124
120
  destroy() {
125
- const { __eventIds } = this;
121
+ const {__eventIds: __eventIds} = this;
126
122
  if (__eventIds && __eventIds.length) {
127
123
  this.__removeListenEvents();
128
124
  this.innerIdMap = {};
@@ -133,18 +129,22 @@ class Finder {
133
129
  }
134
130
 
135
131
  const ui = draw.UI.prototype;
132
+
136
133
  function getSelector(ui) {
137
- return ui.leafer ? ui.leafer.selector : (draw.Platform.selector || (draw.Platform.selector = draw.Creator.selector()));
134
+ return ui.leafer ? ui.leafer.selector : draw.Platform.selector || (draw.Platform.selector = draw.Creator.selector());
138
135
  }
139
- ui.find = function (condition, options) {
136
+
137
+ ui.find = function(condition, options) {
140
138
  return getSelector(this).getBy(condition, this, false, options);
141
139
  };
142
- ui.findOne = function (condition, options) {
140
+
141
+ ui.findOne = function(condition, options) {
143
142
  return getSelector(this).getBy(condition, this, true, options);
144
143
  };
145
144
 
146
- draw.Plugin.add('find');
147
- draw.Creator.finder = function (target) {
145
+ draw.Plugin.add("find");
146
+
147
+ draw.Creator.finder = function(target) {
148
148
  return new Finder(target);
149
149
  };
150
150
 
package/dist/find.esm.js CHANGED
@@ -1,64 +1,68 @@
1
- import { Answer, DataHelper, LeafHelper, ChildEvent, PropertyEvent, UI, Platform, Creator, Plugin } from '@leafer-ui/draw';
1
+ import { Answer, isUndefined, isArray, DataHelper, LeafHelper, ChildEvent, PropertyEvent, UI, Platform, Creator, Plugin } from "@leafer-ui/draw";
2
+
3
+ const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = Answer;
2
4
 
3
- const { Yes, NoAndSkip, YesAndSkip } = Answer;
4
5
  const idCondition = {}, classNameCondition = {}, tagCondition = {};
6
+
5
7
  class Finder {
6
8
  constructor(target) {
7
9
  this.innerIdMap = {};
8
10
  this.idMap = {};
9
11
  this.methods = {
10
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
11
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
12
+ id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
13
+ 1) : 0,
14
+ innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf),
15
+ 1) : 0,
12
16
  className: (leaf, name) => leaf.className === name ? 1 : 0,
13
17
  tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
14
18
  tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
15
19
  };
16
- if (this.target = target)
17
- this.__listenEvents();
20
+ if (this.target = target) this.__listenEvents();
18
21
  }
19
22
  getBy(condition, branch, one, options) {
20
23
  switch (typeof condition) {
21
- case 'number':
22
- const leaf = this.getByInnerId(condition, branch);
23
- return one ? leaf : (leaf ? [leaf] : []);
24
- case 'string':
25
- switch (condition[0]) {
26
- case '#':
27
- idCondition.id = condition.substring(1), condition = idCondition;
28
- break;
29
- case '.':
30
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
31
- break;
32
- default:
33
- tagCondition.tag = condition, condition = tagCondition;
34
- }
35
- case 'object':
36
- if (condition.id !== undefined) {
37
- const leaf = this.getById(condition.id, branch);
38
- return one ? leaf : (leaf ? [leaf] : []);
39
- }
40
- else if (condition.tag) {
41
- const { tag } = condition, isArray = tag instanceof Array;
42
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
43
- }
44
- else {
45
- return this.getByMethod(this.methods.className, branch, one, condition.className);
46
- }
47
- case 'function':
48
- return this.getByMethod(condition, branch, one, options);
24
+ case "number":
25
+ const leaf = this.getByInnerId(condition, branch);
26
+ return one ? leaf : leaf ? [ leaf ] : [];
27
+
28
+ case "string":
29
+ switch (condition[0]) {
30
+ case "#":
31
+ idCondition.id = condition.substring(1), condition = idCondition;
32
+ break;
33
+
34
+ case ".":
35
+ classNameCondition.className = condition.substring(1), condition = classNameCondition;
36
+ break;
37
+
38
+ default:
39
+ tagCondition.tag = condition, condition = tagCondition;
40
+ }
41
+
42
+ case "object":
43
+ if (!isUndefined(condition.id)) {
44
+ const leaf = this.getById(condition.id, branch);
45
+ return one ? leaf : leaf ? [ leaf ] : [];
46
+ } else if (condition.tag) {
47
+ const {tag: tag} = condition, isArr = isArray(tag);
48
+ return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? DataHelper.toMap(tag) : tag);
49
+ } else {
50
+ return this.getByMethod(this.methods.className, branch, one, condition.className);
51
+ }
52
+
53
+ case "function":
54
+ return this.getByMethod(condition, branch, one, options);
49
55
  }
50
56
  }
51
57
  getByInnerId(innerId, branch) {
52
58
  const cache = this.innerIdMap[innerId];
53
- if (cache)
54
- return cache;
59
+ if (cache) return cache;
55
60
  this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
56
61
  return this.findLeaf;
57
62
  }
58
63
  getById(id, branch) {
59
64
  const cache = this.idMap[id];
60
- if (cache && LeafHelper.hasParent(cache, branch || this.target))
61
- return cache;
65
+ if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache;
62
66
  this.eachFind(this.toChildren(branch), this.methods.id, null, id);
63
67
  return this.findLeaf;
64
68
  }
@@ -81,46 +85,38 @@ class Finder {
81
85
  if (result === Yes || result === YesAndSkip) {
82
86
  if (list) {
83
87
  list.push(child);
84
- }
85
- else {
88
+ } else {
86
89
  this.findLeaf = child;
87
90
  return;
88
91
  }
89
92
  }
90
- if (child.isBranch && result < NoAndSkip)
91
- this.eachFind(child.children, method, list, options);
93
+ if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options);
92
94
  }
93
95
  }
94
96
  toChildren(branch) {
95
97
  this.findLeaf = null;
96
- return [branch || this.target];
98
+ return [ branch || this.target ];
97
99
  }
98
100
  __onRemoveChild(event) {
99
- const { id, innerId } = event.child;
100
- if (this.idMap[id])
101
- delete this.idMap[id];
102
- if (this.innerIdMap[innerId])
103
- delete this.innerIdMap[innerId];
101
+ const {id: id, innerId: innerId} = event.child;
102
+ if (this.idMap[id]) delete this.idMap[id];
103
+ if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId];
104
104
  }
105
105
  __checkIdChange(event) {
106
- if (event.attrName === 'id') {
106
+ if (event.attrName === "id") {
107
107
  const id = event.oldValue;
108
- if (this.idMap[id])
109
- delete this.idMap[id];
108
+ if (this.idMap[id]) delete this.idMap[id];
110
109
  }
111
110
  }
112
111
  __listenEvents() {
113
- this.__eventIds = [
114
- this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
115
- this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
116
- ];
112
+ this.__eventIds = [ this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this), this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this) ];
117
113
  }
118
114
  __removeListenEvents() {
119
115
  this.target.off_(this.__eventIds);
120
116
  this.__eventIds.length = 0;
121
117
  }
122
118
  destroy() {
123
- const { __eventIds } = this;
119
+ const {__eventIds: __eventIds} = this;
124
120
  if (__eventIds && __eventIds.length) {
125
121
  this.__removeListenEvents();
126
122
  this.innerIdMap = {};
@@ -131,18 +127,22 @@ class Finder {
131
127
  }
132
128
 
133
129
  const ui = UI.prototype;
130
+
134
131
  function getSelector(ui) {
135
- return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
132
+ return ui.leafer ? ui.leafer.selector : Platform.selector || (Platform.selector = Creator.selector());
136
133
  }
137
- ui.find = function (condition, options) {
134
+
135
+ ui.find = function(condition, options) {
138
136
  return getSelector(this).getBy(condition, this, false, options);
139
137
  };
140
- ui.findOne = function (condition, options) {
138
+
139
+ ui.findOne = function(condition, options) {
141
140
  return getSelector(this).getBy(condition, this, true, options);
142
141
  };
143
142
 
144
- Plugin.add('find');
145
- Creator.finder = function (target) {
143
+ Plugin.add("find");
144
+
145
+ Creator.finder = function(target) {
146
146
  return new Finder(target);
147
147
  };
148
148
 
@@ -1,2 +1,2 @@
1
- import{Answer as t,DataHelper as e,LeafHelper as i,ChildEvent as s,PropertyEvent as n,UI as h,Platform as r,Creator as d,Plugin as a}from"@leafer-ui/draw";const{Yes:o,NoAndSkip:c,YesAndSkip:l}=t,g={},f={},u={};class _{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(t,i,s,n){switch(typeof t){case"number":const h=this.getByInnerId(t,i);return s?h:h?[h]:[];case"string":switch(t[0]){case"#":g.id=t.substring(1),t=g;break;case".":f.className=t.substring(1),t=f;break;default:u.tag=t,t=u}case"object":if(void 0!==t.id){const e=this.getById(t.id,i);return s?e:e?[e]:[]}if(t.tag){const{tag:n}=t,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?e.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,t.className);case"function":return this.getByMethod(t,i,s,n)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const s=this.idMap[t];return s&&i.hasParent(s,e||this.target)?s:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,h;for(let r=0,d=t.length;r<d;r++){if(n=t[r],h=e(n,s),h===o||h===l){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&h<c&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(s.REMOVE,this.__onRemoveChild,this),this.target.on_(n.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const m=h.prototype;function p(t){return t.leafer?t.leafer.selector:r.selector||(r.selector=d.selector())}m.find=function(t,e){return p(this).getBy(t,this,!1,e)},m.findOne=function(t,e){return p(this).getBy(t,this,!0,e)},a.add("find"),d.finder=function(t){return new _(t)};export{_ as Finder};
1
+ import{Answer as t,isUndefined as e,isArray as i,DataHelper as s,LeafHelper as n,ChildEvent as h,PropertyEvent as d,UI as r,Platform as a,Creator as o,Plugin as c}from"@leafer-ui/draw";const{Yes:l,NoAndSkip:g,YesAndSkip:f}=t,u={},_={},m={};class p{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(t,n,h,d){switch(typeof t){case"number":const r=this.getByInnerId(t,n);return h?r:r?[r]:[];case"string":switch(t[0]){case"#":u.id=t.substring(1),t=u;break;case".":_.className=t.substring(1),t=_;break;default:m.tag=t,t=m}case"object":if(e(t.id)){if(t.tag){const{tag:e}=t,d=i(e);return this.getByMethod(d?this.methods.tags:this.methods.tag,n,h,d?s.toMap(e):e)}return this.getByMethod(this.methods.className,n,h,t.className)}{const e=this.getById(t.id,n);return h?e:e?[e]:[]}case"function":return this.getByMethod(t,n,h,d)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&n.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,h;for(let d=0,r=t.length;d<r;d++){if(n=t[d],h=e(n,s),h===l||h===f){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&h<g&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(h.REMOVE,this.__onRemoveChild,this),this.target.on_(d.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const I=r.prototype;function M(t){return t.leafer?t.leafer.selector:a.selector||(a.selector=o.selector())}I.find=function(t,e){return M(this).getBy(t,this,!1,e)},I.findOne=function(t,e){return M(this).getBy(t,this,!0,e)},c.add("find"),o.finder=function(t){return new p(t)};export{p as Finder};
2
2
  //# sourceMappingURL=find.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.esm.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"2JAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAA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QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAOC,IAAI,QAGXJ,EAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
1
+ {"version":3,"file":"find.esm.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper, isArray, isUndefined } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (!isUndefined(condition.id)) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArr = isArray(tag)\n return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","isUndefined","isArr","isArray","getByMethod","DataHelper","toMap","getById","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"yLAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAAC,WAAuB,CAAA,EACvBD,KAAAE,MAAkB,CAAA,EAIlBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SAAWC,KAAKE,MAAMI,GAAQD,GAAO,GAAK,EACtGE,QAAS,CAACF,EAAaE,IAAoBF,EAAKE,UAAYA,GAAWP,KAAKD,SAAWC,KAAKC,WAAWM,GAAWF,GAAO,GAAK,EAC9HG,UAAW,CAACH,EAAaC,IAAiBD,EAAKG,YAAcF,EAAO,EAAI,EACxEG,IAAK,CAACJ,EAAaC,IAAiBD,EAAKK,QAAUJ,EAAO,EAAI,EAC9DK,KAAM,CAACN,EAAaO,IAAyBA,EAAQP,EAAKK,OAAS,EAAI,IAOnEV,KAAKD,OAASA,IAAQC,KAAKa,gBACnC,CAEO,KAAAC,CAAMC,EAA2DC,EAAgBC,EAAeC,GACnG,cAAeH,GACX,IAAK,SACD,MAAMV,EAAOL,KAAKmB,aAAaJ,EAAWC,GAC1C,OAAOC,EAAMZ,EAAQA,EAAO,CAACA,GAAQ,GACzC,IAAK,SACD,OAAQU,EAAU,IACd,IAAK,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pE,CAEU,oBAAAyD,GACNzD,KAAKD,OAAO2D,KAAK1D,KAAKmD,YACtBnD,KAAKmD,WAAWR,OAAS,CAC7B,CAEO,OAAAgB,GACH,MAAMR,WAAEA,GAAenD,KACnBmD,GAAcA,EAAWR,SACzB3C,KAAKyD,uBACLzD,KAAKC,WAAa,CAAA,EAClBD,KAAKE,MAAQ,CAAA,GAEjBF,KAAK+B,SAAW,IACpB,EC9IJ,MAAM6B,EAAKC,EAAGC,UAEd,SAASC,EAAYH,GACjB,OAAOA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAASD,WAAaC,EAASD,SAAWE,EAAQF,WAC/F,CAEAL,EAAGQ,KAAO,SAAUrD,EAA4CG,GAC5D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAOkB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAOC,IAAI,QAGXJ,EAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
package/dist/find.js CHANGED
@@ -1,66 +1,68 @@
1
1
  this.LeaferIN = this.LeaferIN || {};
2
- this.LeaferIN.find = (function (exports, draw) {
3
- 'use strict';
4
2
 
5
- const { Yes, NoAndSkip, YesAndSkip } = draw.Answer;
3
+ this.LeaferIN.find = function(exports, draw) {
4
+ "use strict";
5
+ const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = draw.Answer;
6
6
  const idCondition = {}, classNameCondition = {}, tagCondition = {};
7
7
  class Finder {
8
8
  constructor(target) {
9
9
  this.innerIdMap = {};
10
10
  this.idMap = {};
11
11
  this.methods = {
12
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
13
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
12
+ id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
13
+ 1) : 0,
14
+ innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf),
15
+ 1) : 0,
14
16
  className: (leaf, name) => leaf.className === name ? 1 : 0,
15
17
  tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
16
18
  tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
17
19
  };
18
- if (this.target = target)
19
- this.__listenEvents();
20
+ if (this.target = target) this.__listenEvents();
20
21
  }
21
22
  getBy(condition, branch, one, options) {
22
23
  switch (typeof condition) {
23
- case 'number':
24
- const leaf = this.getByInnerId(condition, branch);
25
- return one ? leaf : (leaf ? [leaf] : []);
26
- case 'string':
27
- switch (condition[0]) {
28
- case '#':
29
- idCondition.id = condition.substring(1), condition = idCondition;
30
- break;
31
- case '.':
32
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
33
- break;
34
- default:
35
- tagCondition.tag = condition, condition = tagCondition;
36
- }
37
- case 'object':
38
- if (condition.id !== undefined) {
39
- const leaf = this.getById(condition.id, branch);
40
- return one ? leaf : (leaf ? [leaf] : []);
41
- }
42
- else if (condition.tag) {
43
- const { tag } = condition, isArray = tag instanceof Array;
44
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? draw.DataHelper.toMap(tag) : tag);
45
- }
46
- else {
47
- return this.getByMethod(this.methods.className, branch, one, condition.className);
48
- }
49
- case 'function':
50
- return this.getByMethod(condition, branch, one, options);
24
+ case "number":
25
+ const leaf = this.getByInnerId(condition, branch);
26
+ return one ? leaf : leaf ? [ leaf ] : [];
27
+
28
+ case "string":
29
+ switch (condition[0]) {
30
+ case "#":
31
+ idCondition.id = condition.substring(1), condition = idCondition;
32
+ break;
33
+
34
+ case ".":
35
+ classNameCondition.className = condition.substring(1), condition = classNameCondition;
36
+ break;
37
+
38
+ default:
39
+ tagCondition.tag = condition, condition = tagCondition;
40
+ }
41
+
42
+ case "object":
43
+ if (!draw.isUndefined(condition.id)) {
44
+ const leaf = this.getById(condition.id, branch);
45
+ return one ? leaf : leaf ? [ leaf ] : [];
46
+ } else if (condition.tag) {
47
+ const {tag: tag} = condition, isArr = draw.isArray(tag);
48
+ return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? draw.DataHelper.toMap(tag) : tag);
49
+ } else {
50
+ return this.getByMethod(this.methods.className, branch, one, condition.className);
51
+ }
52
+
53
+ case "function":
54
+ return this.getByMethod(condition, branch, one, options);
51
55
  }
52
56
  }
53
57
  getByInnerId(innerId, branch) {
54
58
  const cache = this.innerIdMap[innerId];
55
- if (cache)
56
- return cache;
59
+ if (cache) return cache;
57
60
  this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
58
61
  return this.findLeaf;
59
62
  }
60
63
  getById(id, branch) {
61
64
  const cache = this.idMap[id];
62
- if (cache && draw.LeafHelper.hasParent(cache, branch || this.target))
63
- return cache;
65
+ if (cache && draw.LeafHelper.hasParent(cache, branch || this.target)) return cache;
64
66
  this.eachFind(this.toChildren(branch), this.methods.id, null, id);
65
67
  return this.findLeaf;
66
68
  }
@@ -83,46 +85,38 @@ this.LeaferIN.find = (function (exports, draw) {
83
85
  if (result === Yes || result === YesAndSkip) {
84
86
  if (list) {
85
87
  list.push(child);
86
- }
87
- else {
88
+ } else {
88
89
  this.findLeaf = child;
89
90
  return;
90
91
  }
91
92
  }
92
- if (child.isBranch && result < NoAndSkip)
93
- this.eachFind(child.children, method, list, options);
93
+ if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options);
94
94
  }
95
95
  }
96
96
  toChildren(branch) {
97
97
  this.findLeaf = null;
98
- return [branch || this.target];
98
+ return [ branch || this.target ];
99
99
  }
100
100
  __onRemoveChild(event) {
101
- const { id, innerId } = event.child;
102
- if (this.idMap[id])
103
- delete this.idMap[id];
104
- if (this.innerIdMap[innerId])
105
- delete this.innerIdMap[innerId];
101
+ const {id: id, innerId: innerId} = event.child;
102
+ if (this.idMap[id]) delete this.idMap[id];
103
+ if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId];
106
104
  }
107
105
  __checkIdChange(event) {
108
- if (event.attrName === 'id') {
106
+ if (event.attrName === "id") {
109
107
  const id = event.oldValue;
110
- if (this.idMap[id])
111
- delete this.idMap[id];
108
+ if (this.idMap[id]) delete this.idMap[id];
112
109
  }
113
110
  }
114
111
  __listenEvents() {
115
- this.__eventIds = [
116
- this.target.on_(draw.ChildEvent.REMOVE, this.__onRemoveChild, this),
117
- this.target.on_(draw.PropertyEvent.CHANGE, this.__checkIdChange, this)
118
- ];
112
+ this.__eventIds = [ this.target.on_(draw.ChildEvent.REMOVE, this.__onRemoveChild, this), this.target.on_(draw.PropertyEvent.CHANGE, this.__checkIdChange, this) ];
119
113
  }
120
114
  __removeListenEvents() {
121
115
  this.target.off_(this.__eventIds);
122
116
  this.__eventIds.length = 0;
123
117
  }
124
118
  destroy() {
125
- const { __eventIds } = this;
119
+ const {__eventIds: __eventIds} = this;
126
120
  if (__eventIds && __eventIds.length) {
127
121
  this.__removeListenEvents();
128
122
  this.innerIdMap = {};
@@ -131,25 +125,20 @@ this.LeaferIN.find = (function (exports, draw) {
131
125
  this.findLeaf = null;
132
126
  }
133
127
  }
134
-
135
128
  const ui = draw.UI.prototype;
136
129
  function getSelector(ui) {
137
- return ui.leafer ? ui.leafer.selector : (draw.Platform.selector || (draw.Platform.selector = draw.Creator.selector()));
130
+ return ui.leafer ? ui.leafer.selector : draw.Platform.selector || (draw.Platform.selector = draw.Creator.selector());
138
131
  }
139
- ui.find = function (condition, options) {
132
+ ui.find = function(condition, options) {
140
133
  return getSelector(this).getBy(condition, this, false, options);
141
134
  };
142
- ui.findOne = function (condition, options) {
135
+ ui.findOne = function(condition, options) {
143
136
  return getSelector(this).getBy(condition, this, true, options);
144
137
  };
145
-
146
- draw.Plugin.add('find');
147
- draw.Creator.finder = function (target) {
138
+ draw.Plugin.add("find");
139
+ draw.Creator.finder = function(target) {
148
140
  return new Finder(target);
149
141
  };
150
-
151
142
  exports.Finder = Finder;
152
-
153
143
  return exports;
154
-
155
- })({}, LeaferUI);
144
+ }({}, LeaferUI);
package/dist/find.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@leafer-ui/draw");const{Yes:e,NoAndSkip:i,YesAndSkip:s}=t.Answer,n={},h={},r={};class a{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(e,i,s,a){switch(typeof e){case"number":const d=this.getByInnerId(e,i);return s?d:d?[d]:[];case"string":switch(e[0]){case"#":n.id=e.substring(1),e=n;break;case".":h.className=e.substring(1),e=h;break;default:r.tag=e,e=r}case"object":if(void 0!==e.id){const t=this.getById(e.id,i);return s?t:t?[t]:[]}if(e.tag){const{tag:n}=e,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?t.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,e.className);case"function":return this.getByMethod(e,i,s,a)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(e,i){const s=this.idMap[e];return s&&t.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,e),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,n,h,r){let a,d;for(let o=0,c=t.length;o<c;o++){if(a=t[o],d=n(a,r),d===e||d===s){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<i&&this.eachFind(a.children,n,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(t.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(t.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const d=t.UI.prototype;function o(e){return e.leafer?e.leafer.selector:t.Platform.selector||(t.Platform.selector=t.Creator.selector())}d.find=function(t,e){return o(this).getBy(t,this,!1,e)},d.findOne=function(t,e){return o(this).getBy(t,this,!0,e)},t.Plugin.add("find"),t.Creator.finder=function(t){return new a(t)},exports.Finder=a;
1
+ "use strict";var t=require("@leafer-ui/draw");const{Yes:e,NoAndSkip:i,YesAndSkip:s}=t.Answer,n={},h={},r={};class a{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(e,i,s,a){switch(typeof e){case"number":const d=this.getByInnerId(e,i);return s?d:d?[d]:[];case"string":switch(e[0]){case"#":n.id=e.substring(1),e=n;break;case".":h.className=e.substring(1),e=h;break;default:r.tag=e,e=r}case"object":if(t.isUndefined(e.id)){if(e.tag){const{tag:n}=e,h=t.isArray(n);return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?t.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,e.className)}{const t=this.getById(e.id,i);return s?t:t?[t]:[]}case"function":return this.getByMethod(e,i,s,a)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(e,i){const s=this.idMap[e];return s&&t.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,e),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,n,h,r){let a,d;for(let o=0,l=t.length;o<l;o++){if(a=t[o],d=n(a,r),d===e||d===s){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<i&&this.eachFind(a.children,n,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(t.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(t.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const d=t.UI.prototype;function o(e){return e.leafer?e.leafer.selector:t.Platform.selector||(t.Platform.selector=t.Creator.selector())}d.find=function(t,e){return o(this).getBy(t,this,!1,e)},d.findOne=function(t,e){return o(this).getBy(t,this,!0,e)},t.Plugin.add("find"),t.Creator.finder=function(t){return new a(t)},exports.Finder=a;
2
2
  //# sourceMappingURL=find.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.min.cjs","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"8CAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAMA,OACvCC,EAAc,CAAA,EAAsBC,EAAqB,CAAoB,EAAEC,EAAe,CAAoB,QAE3GC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAUC,WAAa,CAAE,EACzBD,KAAKE,MAAa,CAAE,EAIpBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SAAWC,KAAKE,MAAMI,GAAQD,GAAO,GAAK,EACtGE,QAAS,CAACF,EAAaE,IAAoBF,EAAKE,UAAYA,GAAWP,KAAKD,SAAWC,KAAKC,WAAWM,GAAWF,GAAO,GAAK,EAC9HG,UAAW,CAACH,EAAaC,IAAiBD,EAAKG,YAAcF,EAAO,EAAI,EACxEG,IAAK,CAACJ,EAAaC,IAAiBD,EAAKK,QAAUJ,EAAO,EAAI,EAC9DK,KAAM,CAACN,EAAaO,IAAyBA,EAAQP,EAAKK,OAAS,EAAI,IAOnEV,KAAKD,OAASA,IAAQC,KAAKa,iBAG5B,KAAAC,CAAMC,EAA2DC,EAAgBC,EAAeC,GACnG,cAAeH,GACX,IAAK,SACD,MAAMV,EAAOL,KAAKmB,aAAaJ,EAAWC,GAC1C,OAAOC,EAAMZ,EAAQA,EAAO,CAACA,GAAQ,GACzC,IAAK,SACD,OAAQU,EAAU,IACd,IAAK,IACDrB,EAAYU,GAAKW,EAAUK,UAAU,GAAIL,EAAYrB,EAAa,MACtE,IAAK,IACDC,EAAmBa,UAAYO,EAAUK,UAAU,GAAIL,EAAYpB,EAAoB,MAC3F,QACIC,EAAaa,IAAMM,EAAWA,EAAYnB,EAEtD,IAAK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xB,MAAM6B,EAAKC,EAAEA,GAACC,UAEd,SAASC,EAAYH,GACjB,OAAOA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAAAA,SAASD,WAAaC,EAAQA,SAACD,SAAWE,UAAQF,WAC/F,CAEAL,EAAGQ,KAAO,SAAUrD,EAA4CG,GAC5D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAOkB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAAA,OAAOC,IAAI,QAGXJ,EAAAA,QAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
1
+ {"version":3,"file":"find.min.cjs","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper, isArray, isUndefined } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (!isUndefined(condition.id)) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArr = isArray(tag)\n return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","isUndefined","isArr","isArray","getByMethod","DataHelper","toMap","getById","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"8CAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAAA,OACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAAC,WAAuB,CAAA,EACvBD,KAAAE,MAAkB,CAAA,EAIlBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SAAWC,KAAKE,MAAMI,GAAQD,GAAO,GAAK,EACtGE,QAAS,CAACF,EAAaE,IAAoBF,EAAKE,UAAYA,GAAWP,KAAKD,SAAWC,KAAKC,WAAWM,GAAWF,GAAO,GAAK,EAC9HG,UAAW,CAACH,EAAaC,IAAiBD,EAAKG,YAAcF,EAAO,EAAI,EACxEG,IAAK,CAACJ,EAAaC,IAAiBD,EAAKK,QAAUJ,EAAO,EAAI,EAC9DK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{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(t,i,s,n){switch(typeof t){case"number":const d=this.getByInnerId(t,i);return s?d:d?[d]:[];case"string":switch(t[0]){case"#":h.id=t.substring(1),t=h;break;case".":r.className=t.substring(1),t=r;break;default:a.tag=t,t=a}case"object":if(void 0!==t.id){const e=this.getById(t.id,i);return s?e:e?[e]:[]}if(t.tag){const{tag:n}=t,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?e.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,t.className);case"function":return this.getByMethod(t,i,s,n)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,i){const s=this.idMap[t];return s&&e.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,h,r){let a,d;for(let o=0,c=t.length;o<c;o++){if(a=t[o],d=e(a,r),d===i||d===n){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<s&&this.eachFind(a.children,e,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(e.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(e.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const o=e.UI.prototype;function c(t){return t.leafer?t.leafer.selector:e.Platform.selector||(e.Platform.selector=e.Creator.selector())}return o.find=function(t,e){return c(this).getBy(t,this,!1,e)},o.findOne=function(t,e){return c(this).getBy(t,this,!0,e)},e.Plugin.add("find"),e.Creator.finder=function(t){return new d(t)},t.Finder=d,t}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.find=function(t,e){"use strict";const{Yes:i,NoAndSkip:s,YesAndSkip:n}=e.Answer,h={},r={},a={};class d{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(t,i,s,n){switch(typeof t){case"number":const d=this.getByInnerId(t,i);return s?d:d?[d]:[];case"string":switch(t[0]){case"#":h.id=t.substring(1),t=h;break;case".":r.className=t.substring(1),t=r;break;default:a.tag=t,t=a}case"object":if(e.isUndefined(t.id)){if(t.tag){const{tag:n}=t,h=e.isArray(n);return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?e.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,t.className)}{const e=this.getById(t.id,i);return s?e:e?[e]:[]}case"function":return this.getByMethod(t,i,s,n)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,i){const s=this.idMap[t];return s&&e.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,h,r){let a,d;for(let o=0,c=t.length;o<c;o++){if(a=t[o],d=e(a,r),d===i||d===n){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<s&&this.eachFind(a.children,e,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(e.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(e.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const o=e.UI.prototype;function c(t){return t.leafer?t.leafer.selector:e.Platform.selector||(e.Platform.selector=e.Creator.selector())}return o.find=function(t,e){return c(this).getBy(t,this,!1,e)},o.findOne=function(t,e){return c(this).getBy(t,this,!0,e)},e.Plugin.add("find"),e.Creator.finder=function(t){return new d(t)},t.Finder=d,t}({},LeaferUI);
2
2
  //# sourceMappingURL=find.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"8EAIA,MAAMA,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,GAC5D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAOkB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAAA,OAAOC,IAAI,QAGXJ,EAAAA,QAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
1
+ {"version":3,"file":"find.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper, isArray, isUndefined } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (!isUndefined(condition.id)) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArr = isArray(tag)\n return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","isUndefined","isArr","isArray","getByMethod","DataHelper","toMap","getById","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"8EAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAAA,OACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAAC,WAAuB,CAAA,EACvBD,KAAAE,MAAkB,CAAA,EAIlBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SAAWC,KAAKE,MAAMI,GAAQD,GAAO,GAAK,EACtGE,QAAS,CAACF,EAAaE,IAAoBF,EAAKE,UAAYA,GAAWP,KAAKD,SAAWC,KAAKC,WAAWM,GAAWF,GAAO,GAAK,EAC9HG,UAAW,CAACH,EAAaC,IAAiBD,EAAKG,YAAcF,EAAO,EAAI,EACxEG,IAAK,CAACJ,EAAaC,IAAiBD,EAAKK,QAAUJ,EAAO,EAAI,EAC9DK,KAAM,CAACN,EAAaO,IAAyBA,EAAQP,EAAKK,OAAS,EAAI,IAOnEV,KAAKD,OAASA,IAAQC,KAAKa,gBACnC,CAEO,KAAAC,CAAMC,EAA2DC,EAAgBC,EAAeC,GACnG,cAAeH,GACX,IAAK,SACD,MAAMV,EAAOL,KAAKmB,a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CACdnD,KAAKD,OAAOqD,IAAIC,EAAAA,WAAWC,OAAQtD,KAAK8C,gBAAiB9C,MACzDA,KAAKD,OAAOqD,IAAIG,EAAAA,cAAcC,OAAQxD,KAAKgD,gBAAiBhD,MAEpE,CAEU,oBAAAyD,GACNzD,KAAKD,OAAO2D,KAAK1D,KAAKmD,YACtBnD,KAAKmD,WAAWR,OAAS,CAC7B,CAEO,OAAAgB,GACH,MAAMR,WAAEA,GAAenD,KACnBmD,GAAcA,EAAWR,SACzB3C,KAAKyD,uBACLzD,KAAKC,WAAa,CAAA,EAClBD,KAAKE,MAAQ,CAAA,GAEjBF,KAAK+B,SAAW,IACpB,EC9IJ,MAAM6B,EAAKC,EAAAA,GAAGC,UAEd,SAASC,EAAYH,GACjB,OAAOA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAAAA,SAASD,WAAaC,EAAAA,SAASD,SAAWE,UAAQF,WAC/F,QAEAL,EAAGQ,KAAO,SAAUrD,EAA4CG,GAC5D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAOkB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAAA,OAAOC,IAAI,QAGXJ,EAAAA,QAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/find",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "@leafer-in/find",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.8.0",
38
- "@leafer-ui/interface": "^1.8.0",
39
- "@leafer-in/interface": "^1.8.0"
37
+ "@leafer-ui/draw": "^1.9.1",
38
+ "@leafer-ui/interface": "^1.9.1",
39
+ "@leafer-in/interface": "^1.9.1"
40
40
  }
41
41
  }
package/src/Finder.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'
2
- import { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'
2
+ import { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper, isArray, isUndefined } from '@leafer-ui/draw'
3
3
 
4
4
 
5
5
  const { Yes, NoAndSkip, YesAndSkip } = Answer
@@ -44,12 +44,12 @@ export class Finder implements IFinder {
44
44
  tagCondition.tag = condition, condition = tagCondition
45
45
  }
46
46
  case 'object':
47
- if (condition.id !== undefined) {
47
+ if (!isUndefined(condition.id)) {
48
48
  const leaf = this.getById(condition.id as string, branch)
49
49
  return one ? leaf : (leaf ? [leaf] : [])
50
50
  } else if (condition.tag) {
51
- const { tag } = condition, isArray = tag instanceof Array
52
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)
51
+ const { tag } = condition, isArr = isArray(tag)
52
+ return this.getByMethod(isArr ? this.methods.tags : this.methods.tag, branch, one, isArr ? DataHelper.toMap(tag) : tag)
53
53
  } else {
54
54
  return this.getByMethod(this.methods.className, branch, one, condition.className)
55
55
  }