@leafer-in/find 2.0.1 → 2.0.3
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 +16 -5
- package/dist/find.esm.js +16 -5
- package/dist/find.esm.min.js +1 -1
- package/dist/find.esm.min.js.map +1 -1
- package/dist/find.js +15 -5
- package/dist/find.min.cjs +1 -1
- package/dist/find.min.cjs.map +1 -1
- package/dist/find.min.js +1 -1
- package/dist/find.min.js.map +1 -1
- package/package.json +4 -4
- package/src/Finder.ts +13 -4
- package/src/index.ts +11 -3
- package/types/index.d.ts +2 -2
package/dist/find.cjs
CHANGED
|
@@ -7,9 +7,7 @@ const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = draw.Answer;
|
|
|
7
7
|
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
8
8
|
|
|
9
9
|
class Finder {
|
|
10
|
-
constructor(target) {
|
|
11
|
-
this.innerIdMap = {};
|
|
12
|
-
this.idMap = {};
|
|
10
|
+
constructor(target, _config) {
|
|
13
11
|
this.methods = {
|
|
14
12
|
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
|
|
15
13
|
1) : 0,
|
|
@@ -19,6 +17,13 @@ class Finder {
|
|
|
19
17
|
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
20
18
|
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
21
19
|
};
|
|
20
|
+
this.idMap = {};
|
|
21
|
+
this.innerIdMap = {};
|
|
22
|
+
const app = target && target.app;
|
|
23
|
+
if (app) {
|
|
24
|
+
app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap;
|
|
25
|
+
app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap;
|
|
26
|
+
}
|
|
22
27
|
if (this.target = target) this.__listenEvents();
|
|
23
28
|
}
|
|
24
29
|
getBy(condition, branch, one, options) {
|
|
@@ -145,8 +150,14 @@ ui.findOne = function(condition, options) {
|
|
|
145
150
|
|
|
146
151
|
draw.Plugin.add("find");
|
|
147
152
|
|
|
148
|
-
draw.Creator.finder = function(target) {
|
|
149
|
-
return new Finder(target);
|
|
153
|
+
draw.Creator.finder = function(target, config) {
|
|
154
|
+
return new Finder(target, config);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
draw.LeafHelper.cacheId = function(t) {
|
|
158
|
+
const {leafer: leafer, id: id} = t;
|
|
159
|
+
if (id) leafer.app.idMap[id] = t;
|
|
160
|
+
if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t;
|
|
150
161
|
};
|
|
151
162
|
|
|
152
163
|
exports.Finder = Finder;
|
package/dist/find.esm.js
CHANGED
|
@@ -5,9 +5,7 @@ const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = Answer;
|
|
|
5
5
|
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
6
6
|
|
|
7
7
|
class Finder {
|
|
8
|
-
constructor(target) {
|
|
9
|
-
this.innerIdMap = {};
|
|
10
|
-
this.idMap = {};
|
|
8
|
+
constructor(target, _config) {
|
|
11
9
|
this.methods = {
|
|
12
10
|
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
|
|
13
11
|
1) : 0,
|
|
@@ -17,6 +15,13 @@ class Finder {
|
|
|
17
15
|
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
18
16
|
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
19
17
|
};
|
|
18
|
+
this.idMap = {};
|
|
19
|
+
this.innerIdMap = {};
|
|
20
|
+
const app = target && target.app;
|
|
21
|
+
if (app) {
|
|
22
|
+
app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap;
|
|
23
|
+
app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap;
|
|
24
|
+
}
|
|
20
25
|
if (this.target = target) this.__listenEvents();
|
|
21
26
|
}
|
|
22
27
|
getBy(condition, branch, one, options) {
|
|
@@ -143,8 +148,14 @@ ui.findOne = function(condition, options) {
|
|
|
143
148
|
|
|
144
149
|
Plugin.add("find");
|
|
145
150
|
|
|
146
|
-
Creator.finder = function(target) {
|
|
147
|
-
return new Finder(target);
|
|
151
|
+
Creator.finder = function(target, config) {
|
|
152
|
+
return new Finder(target, config);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
LeafHelper.cacheId = function(t) {
|
|
156
|
+
const {leafer: leafer, id: id} = t;
|
|
157
|
+
if (id) leafer.app.idMap[id] = t;
|
|
158
|
+
if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t;
|
|
148
159
|
};
|
|
149
160
|
|
|
150
161
|
export { Finder };
|
package/dist/find.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Answer as t,isUndefined as e,isArray as i,DataHelper as s,LeafHelper as n,ChildEvent as h,PropertyEvent as
|
|
1
|
+
import{Answer as t,isUndefined as e,isArray as i,DataHelper as s,LeafHelper as n,ChildEvent as h,PropertyEvent as a,UI as d,Platform as r,Creator as o,Plugin as c}from"@leafer-ui/draw";const{Yes:l,NoAndSkip:g,YesAndSkip:p}=t,f={},u={},M={};class I{constructor(t,e){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.idMap={},this.innerIdMap={};const i=t&&t.app;i&&(i.idMap?this.idMap=i.idMap:i.idMap=this.idMap,i.innerIdMap?this.innerIdMap=i.innerIdMap:i.innerIdMap=this.innerIdMap),(this.target=t)&&this.__listenEvents()}getBy(t,n,h,a){switch(typeof t){case"number":const d=this.getByInnerId(t,n);return h?d:d?[d]:[];case"string":switch(t[0]){case"#":f.id=t.substring(1),t=f;break;case".":u.className=t.substring(1),t=u;break;default:M.tag=t,t=M}case"object":if(e(t.id)){if(t.tag){const{tag:e}=t,a=i(e);return this.getByMethod(a?this.methods.tags:this.methods.tag,n,h,a?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,a)}}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 a=0,d=t.length;a<d;a++){if(n=t[a],h=e(n,s),"boolean"==typeof h&&(h=h?1:0),h===l||h===p){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_(a.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.prototype;function m(t){return t.leafer?t.leafer.selector:r.selector||(r.selector=o.selector())}_.find=function(t,e){return m(this).getBy(t,this,!1,e)},_.findOne=function(t,e){return m(this).getBy(t,this,!0,e)},c.add("find"),o.finder=function(t,e){return new I(t,e)},n.cacheId=function(t){const{leafer:e,id:i}=t;i&&(e.app.idMap[i]=t),e.cacheInnerId&&(e.app.innerIdMap[t.innerId]=t)};export{I as Finder};
|
|
2
2
|
//# sourceMappingURL=find.esm.min.js.map
|
package/dist/find.esm.min.js.map
CHANGED
|
@@ -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, 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 (typeof result === 'boolean') result = result ? 1 : 0\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,aAAa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,WAAa,CACdnD,KAAKD,OAAOqD,IAAIC,EAAWC,OAAQtD,KAAK8C,gBAAiB9C,MACzDA,KAAKD,OAAOqD,IAAIG,EAAcC,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,EC/IJ,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"}
|
|
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, ISelectorConfig, ILeafer } 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, _config: ISelectorConfig) {\n this.idMap = {}\n this.innerIdMap = {}\n\n const app = (target && target.app) as ILeafer\n if (app) {\n app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap\n app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap\n }\n\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 (typeof result === 'boolean') result = result ? 1 : 0\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 { ILeaf } from '@leafer-ui/interface'\nimport { Creator, LeafHelper, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target, config) {\n return new Finder(target, config)\n}\n\nLeafHelper.cacheId = function (t: ILeaf): void { // 创建时缓存id元素\n const { leafer, id } = t\n if (id) leafer.app.idMap[id] = t\n if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t\n\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","_config","this","methods","id","leaf","name","idMap","innerId","innerIdMap","className","tag","__tag","tags","nameMap","app","__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","config","cacheId","t","cacheInnerId"],"mappings":"yLAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,EAAeC,GAXjBC,KAAAC,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQJ,KAAKF,SAAWE,KAAKK,MAAMD,GAAQD,GAAO,GAAK,EACtGG,QAAS,CAACH,EAAaG,IAAoBH,EAAKG,UAAYA,GAAWN,KAAKF,SAAWE,KAAKO,WAAWD,GAAWH,GAAO,GAAK,EAC9HK,UAAW,CAACL,EAAaC,IAAiBD,EAAKK,YAAcJ,EAAO,EAAI,EACxEK,IAAK,CAACN,EAAaC,IAAiBD,EAAKO,QAAUN,EAAO,EAAI,EAC9DO,KAAM,CAACR,EAAaS,IAAyBA,EAAQT,EAAKO,OAAS,EAAI,GAOvEV,KAAKK,MAAQ,CAAA,EACbL,KAAKO,WAAa,CAAA,EAElB,MAAMM,EAAOf,GAAUA,EAAOe,IAC1BA,IACAA,EAAIR,MAAQL,KAAKK,MAAQQ,EAAIR,MAAQQ,EAAIR,MAAQL,KAAKK,MACtDQ,EAAIN,WAAaP,KAAKO,WAAaM,EAAIN,WAAaM,EAAIN,WAAaP,KAAKO,aAG1EP,KAAKF,OAASA,IAAQE,KAAKc,gBACnC,CAEO,KAAAC,CAAMC,EAA2DC,EAAgBC,EAAeC,GACnG,cAAeH,GACX,IAAK,SACD,MAAMb,EAAOH,KAAKoB,aAAaJ,EAAWC,GAC1C,OAAOC,EAAMf,EAAQA,EA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C,OAAQvD,KAAK+C,gBAAiB/C,MACzDA,KAAKF,OAAOuD,IAAIG,EAAcC,OAAQzD,KAAKiD,gBAAiBjD,MAEpE,CAEU,oBAAA0D,GACN1D,KAAKF,OAAO6D,KAAK3D,KAAKoD,YACtBpD,KAAKoD,WAAWR,OAAS,CAC7B,CAEO,OAAAgB,GACH,MAAMR,WAAEA,GAAepD,KACnBoD,GAAcA,EAAWR,SACzB5C,KAAK0D,uBACL1D,KAAKO,WAAa,CAAA,EAClBP,KAAKK,MAAQ,CAAA,GAEjBL,KAAKgC,SAAW,IACpB,ECxJJ,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,EAAYhE,MAAMe,MAAMC,EAA0BhB,MAAM,EAAOmB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAYhE,MAAMe,MAAMC,EAA0BhB,MAAM,EAAMmB,EACzE,ECTAoD,EAAOC,IAAI,QAGXJ,EAAQK,OAAS,SAAU3E,EAAQ4E,GAC/B,OAAO,IAAI9E,EAAOE,EAAQ4E,EAC9B,EAEAzC,EAAW0C,QAAU,SAAUC,GAC3B,MAAMX,OAAEA,EAAM/D,GAAEA,GAAO0E,EACnB1E,IAAI+D,EAAOpD,IAAIR,MAAMH,GAAM0E,GAC3BX,EAAOY,eAAcZ,EAAOpD,IAAIN,WAAWqE,EAAEtE,SAAWsE,EAEhE"}
|
package/dist/find.js
CHANGED
|
@@ -5,9 +5,7 @@ this.LeaferIN.find = function(exports, draw) {
|
|
|
5
5
|
const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = draw.Answer;
|
|
6
6
|
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
7
7
|
class Finder {
|
|
8
|
-
constructor(target) {
|
|
9
|
-
this.innerIdMap = {};
|
|
10
|
-
this.idMap = {};
|
|
8
|
+
constructor(target, _config) {
|
|
11
9
|
this.methods = {
|
|
12
10
|
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf),
|
|
13
11
|
1) : 0,
|
|
@@ -17,6 +15,13 @@ this.LeaferIN.find = function(exports, draw) {
|
|
|
17
15
|
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
18
16
|
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
19
17
|
};
|
|
18
|
+
this.idMap = {};
|
|
19
|
+
this.innerIdMap = {};
|
|
20
|
+
const app = target && target.app;
|
|
21
|
+
if (app) {
|
|
22
|
+
app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap;
|
|
23
|
+
app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap;
|
|
24
|
+
}
|
|
20
25
|
if (this.target = target) this.__listenEvents();
|
|
21
26
|
}
|
|
22
27
|
getBy(condition, branch, one, options) {
|
|
@@ -137,8 +142,13 @@ this.LeaferIN.find = function(exports, draw) {
|
|
|
137
142
|
return getSelector(this).getBy(condition, this, true, options);
|
|
138
143
|
};
|
|
139
144
|
draw.Plugin.add("find");
|
|
140
|
-
draw.Creator.finder = function(target) {
|
|
141
|
-
return new Finder(target);
|
|
145
|
+
draw.Creator.finder = function(target, config) {
|
|
146
|
+
return new Finder(target, config);
|
|
147
|
+
};
|
|
148
|
+
draw.LeafHelper.cacheId = function(t) {
|
|
149
|
+
const {leafer: leafer, id: id} = t;
|
|
150
|
+
if (id) leafer.app.idMap[id] = t;
|
|
151
|
+
if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t;
|
|
142
152
|
};
|
|
143
153
|
exports.Finder = Finder;
|
|
144
154
|
return exports;
|
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={},
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw");const{Yes:e,NoAndSkip:i,YesAndSkip:s}=t.Answer,n={},a={},r={};class h{constructor(t,e){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.idMap={},this.innerIdMap={};const i=t&&t.app;i&&(i.idMap?this.idMap=i.idMap:i.idMap=this.idMap,i.innerIdMap?this.innerIdMap=i.innerIdMap:i.innerIdMap=this.innerIdMap),(this.target=t)&&this.__listenEvents()}getBy(e,i,s,h){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".":a.className=e.substring(1),e=a;break;default:r.tag=e,e=r}case"object":if(t.isUndefined(e.id)){if(e.tag){const{tag:n}=e,a=t.isArray(n);return this.getByMethod(a?this.methods.tags:this.methods.tag,i,s,a?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,h)}}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,a,r){let h,d;for(let o=0,c=t.length;o<c;o++){if(h=t[o],d=n(h,r),"boolean"==typeof d&&(d=d?1:0),d===e||d===s){if(!a)return void(this.findLeaf=h);a.push(h)}h.isBranch&&d<i&&this.eachFind(h.children,n,a,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,e){return new h(t,e)},t.LeafHelper.cacheId=function(t){const{leafer:e,id:i}=t;i&&(e.app.idMap[i]=t),e.cacheInnerId&&(e.app.innerIdMap[t.innerId]=t)},exports.Finder=h;
|
|
2
2
|
//# sourceMappingURL=find.min.cjs.map
|
package/dist/find.min.cjs.map
CHANGED
|
@@ -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, 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 (typeof result === 'boolean') result = result ? 1 : 0\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,C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AA,SAASD,WAAaC,EAAAA,SAASD,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, ISelectorConfig, ILeafer } 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, _config: ISelectorConfig) {\n this.idMap = {}\n this.innerIdMap = {}\n\n const app = (target && target.app) as ILeafer\n if (app) {\n app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap\n app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap\n }\n\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 (typeof result === 'boolean') result = result ? 1 : 0\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 { ILeaf } from '@leafer-ui/interface'\nimport { Creator, LeafHelper, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target, config) {\n return new Finder(target, config)\n}\n\nLeafHelper.cacheId = function (t: ILeaf): void { // 创建时缓存id元素\n const { leafer, id } = t\n if (id) leafer.app.idMap[id] = t\n if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t\n\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","_config","this","methods","id","leaf","name","idMap","innerId","innerIdMap","className","tag","__tag","tags","nameMap","app","__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","config","cacheId","t","cacheInnerId"],"mappings":"8CAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAAA,OACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,EAAeC,GAXjBC,KAAAC,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQJ,KAAKF,SA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OA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAAAA,SAASD,WAAaC,EAAAA,SAASD,SAAWE,UAAQF,WAC/F,CAEAL,EAAGQ,KAAO,SAAUrD,EAA4CG,GAC5D,OAAO6C,EAAYhE,MAAMe,MAAMC,EAA0BhB,MAAM,EAAOmB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAYhE,MAAMe,MAAMC,EAA0BhB,MAAM,EAAMmB,EACzE,ECTAoD,EAAAA,OAAOC,IAAI,QAGXJ,EAAAA,QAAQK,OAAS,SAAU3E,EAAQ4E,GAC/B,OAAO,IAAI9E,EAAOE,EAAQ4E,EAC9B,EAEAzC,EAAAA,WAAW0C,QAAU,SAAUC,GAC3B,MAAMX,OAAEA,EAAM/D,GAAEA,GAAO0E,EACnB1E,IAAI+D,EAAOpD,IAAIR,MAAMH,GAAM0E,GAC3BX,EAAOY,eAAcZ,EAAOpD,IAAIN,WAAWqE,EAAEtE,SAAWsE,EAEhE"}
|
package/dist/find.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.find=function(t,e){"use strict";const{Yes:i,NoAndSkip:s,YesAndSkip:n}=e.Answer,h={},
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.find=function(t,e){"use strict";const{Yes:i,NoAndSkip:s,YesAndSkip:n}=e.Answer,h={},a={},r={};class d{constructor(t,e){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.idMap={},this.innerIdMap={};const i=t&&t.app;i&&(i.idMap?this.idMap=i.idMap:i.idMap=this.idMap,i.innerIdMap?this.innerIdMap=i.innerIdMap:i.innerIdMap=this.innerIdMap),(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".":a.className=t.substring(1),t=a;break;default:r.tag=t,t=r}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,a){let r,d;for(let o=0,c=t.length;o<c;o++){if(r=t[o],d=e(r,a),"boolean"==typeof d&&(d=d?1:0),d===i||d===n){if(!h)return void(this.findLeaf=r);h.push(r)}r.isBranch&&d<s&&this.eachFind(r.children,e,h,a)}}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,e){return new d(t,e)},e.LeafHelper.cacheId=function(t){const{leafer:e,id:i}=t;i&&(e.app.idMap[i]=t),e.cacheInnerId&&(e.app.innerIdMap[t.innerId]=t)},t.Finder=d,t}({},LeaferUI);
|
|
2
2
|
//# sourceMappingURL=find.min.js.map
|
package/dist/find.min.js.map
CHANGED
|
@@ -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, 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 (typeof result === 'boolean') result = result ? 1 : 0\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,EA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AME,WAAYJ,KAAKE,MAAME,GAClCJ,KAAKC,WAAWM,WAAiBP,KAAKC,WAAWM,EACzD,CAEU,eAAAyC,CAAgBD,GACtB,GAAuB,OAAnBA,EAAME,SAAmB,CACzB,MAAM7C,EAAK2C,EAAMG,SACblD,KAAKE,MAAME,WAAYJ,KAAKE,MAAME,EAC1C,CACJ,CAGU,cAAAS,GACNb,KAAKmD,WAAa,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,EC/IJ,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"}
|
|
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, ISelectorConfig, ILeafer } 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, _config: ISelectorConfig) {\n this.idMap = {}\n this.innerIdMap = {}\n\n const app = (target && target.app) as ILeafer\n if (app) {\n app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap\n app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap\n }\n\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 (typeof result === 'boolean') result = result ? 1 : 0\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 { ILeaf } from '@leafer-ui/interface'\nimport { Creator, LeafHelper, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target, config) {\n return new Finder(target, config)\n}\n\nLeafHelper.cacheId = function (t: ILeaf): void { // 创建时缓存id元素\n const { leafer, id } = t\n if (id) leafer.app.idMap[id] = t\n if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t\n\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","_config","this","methods","id","leaf","name","idMap","innerId","innerIdMap","className","tag","__tag","tags","nameMap","app","__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","config","cacheId","t","cacheInnerId"],"mappings":"8EAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAAA,OACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAA,EAAsBC,EAAe,CAAA,QAEvFC,EAoBT,WAAAC,CAAYC,EAAeC,GAXjBC,KAAAC,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQJ,KAAKF,SAAWE,KAAKK,MAAMD,GAAQD,GAAO,GAAK,EACtGG,QAAS,CAACH,EAAaG,IAAoBH,EAAKG,UAAYA,GAAWN,KAAKF,SAAWE,KAAKO,WAAWD,GAAWH,GAAO,GAAK,EAC9HK,UAAW,CAACL,EAAaC,IAAiBD,EAAKK,YAAcJ,EAAO,EAAI,EACxEK,IAAK,CAACN,EAAaC,IAAiBD,EAAKO,QAAUN,EAAO,EAAI,EAC9DO,KAAM,CAACR,EAAaS,IAAyBA,EAAQT,EAAKO,OAAS,EAAI,GAOvEV,KAAKK,MAAQ,CAAA,EACbL,KAAKO,WAAa,CAAA,EAElB,MAAMM,EAAOf,GAAUA,EAAOe,IAC1BA,IACAA,EAAIR,MAAQL,KAAKK,MAAQQ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SAAUC,GAC3B,MAAMX,OAAEA,EAAM/D,GAAEA,GAAO0E,EACnB1E,IAAI+D,EAAOpD,IAAIR,MAAMH,GAAM0E,GAC3BX,EAAOY,eAAcZ,EAAOpD,IAAIN,WAAWqE,EAAEtE,SAAWsE,EAEhE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/find",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
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": "^2.0.
|
|
38
|
-
"@leafer-ui/interface": "^2.0.
|
|
39
|
-
"@leafer-in/interface": "^2.0.
|
|
37
|
+
"@leafer-ui/draw": "^2.0.3",
|
|
38
|
+
"@leafer-ui/interface": "^2.0.3",
|
|
39
|
+
"@leafer-in/interface": "^2.0.3"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/Finder.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'
|
|
1
|
+
import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder, ISelectorConfig, ILeafer } from '@leafer-ui/interface'
|
|
2
2
|
import { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper, isArray, isUndefined } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -9,8 +9,8 @@ export class Finder implements IFinder {
|
|
|
9
9
|
|
|
10
10
|
public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)
|
|
11
11
|
|
|
12
|
-
protected innerIdMap: ILeafMap
|
|
13
|
-
protected idMap: ILeafMap
|
|
12
|
+
protected innerIdMap: ILeafMap
|
|
13
|
+
protected idMap: ILeafMap
|
|
14
14
|
|
|
15
15
|
protected findLeaf: ILeaf
|
|
16
16
|
|
|
@@ -25,7 +25,16 @@ export class Finder implements IFinder {
|
|
|
25
25
|
protected __eventIds: IEventListenerId[]
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
constructor(target: ILeaf) {
|
|
28
|
+
constructor(target: ILeaf, _config: ISelectorConfig) {
|
|
29
|
+
this.idMap = {}
|
|
30
|
+
this.innerIdMap = {}
|
|
31
|
+
|
|
32
|
+
const app = (target && target.app) as ILeafer
|
|
33
|
+
if (app) {
|
|
34
|
+
app.idMap ? this.idMap = app.idMap : app.idMap = this.idMap
|
|
35
|
+
app.innerIdMap ? this.innerIdMap = app.innerIdMap : app.innerIdMap = this.innerIdMap
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
if (this.target = target) this.__listenEvents()
|
|
30
39
|
}
|
|
31
40
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Finder } from './Finder'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ILeaf } from '@leafer-ui/interface'
|
|
4
|
+
import { Creator, LeafHelper, Plugin } from '@leafer-ui/draw'
|
|
4
5
|
import { Finder } from './Finder'
|
|
5
6
|
import './find'
|
|
6
7
|
|
|
@@ -8,6 +9,13 @@ import './find'
|
|
|
8
9
|
Plugin.add('find')
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
Creator.finder = function (target) {
|
|
12
|
-
return new Finder(target)
|
|
12
|
+
Creator.finder = function (target, config) {
|
|
13
|
+
return new Finder(target, config)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
LeafHelper.cacheId = function (t: ILeaf): void { // 创建时缓存id元素
|
|
17
|
+
const { leafer, id } = t
|
|
18
|
+
if (id) leafer.app.idMap[id] = t
|
|
19
|
+
if (leafer.cacheInnerId) leafer.app.innerIdMap[t.innerId] = t
|
|
20
|
+
|
|
13
21
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IFinder, ILeaf, ILeafMap, IBooleanMap, IEventListenerId, IFindCondition, IFindMethod } from '@leafer-ui/interface';
|
|
1
|
+
import { IFinder, ILeaf, ILeafMap, IBooleanMap, IEventListenerId, ISelectorConfig, IFindCondition, IFindMethod } from '@leafer-ui/interface';
|
|
2
2
|
import { ChildEvent, PropertyEvent } from '@leafer-ui/draw';
|
|
3
3
|
|
|
4
4
|
declare class Finder implements IFinder {
|
|
@@ -14,7 +14,7 @@ declare class Finder implements IFinder {
|
|
|
14
14
|
tags: (leaf: ILeaf, nameMap: IBooleanMap) => 1 | 0;
|
|
15
15
|
};
|
|
16
16
|
protected __eventIds: IEventListenerId[];
|
|
17
|
-
constructor(target: ILeaf);
|
|
17
|
+
constructor(target: ILeaf, _config: ISelectorConfig);
|
|
18
18
|
getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[];
|
|
19
19
|
getByInnerId(innerId: number, branch?: ILeaf): ILeaf;
|
|
20
20
|
getById(id: string, branch?: ILeaf): ILeaf;
|