@leafer-in/find 1.12.1 → 1.12.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 CHANGED
@@ -84,6 +84,7 @@ class Finder {
84
84
  for (let i = 0, len = children.length; i < len; i++) {
85
85
  child = children[i];
86
86
  result = method(child, options);
87
+ if (typeof result === "boolean") result = result ? 1 : 0;
87
88
  if (result === Yes || result === YesAndSkip) {
88
89
  if (list) {
89
90
  list.push(child);
package/dist/find.esm.js CHANGED
@@ -82,6 +82,7 @@ class Finder {
82
82
  for (let i = 0, len = children.length; i < len; i++) {
83
83
  child = children[i];
84
84
  result = method(child, options);
85
+ if (typeof result === "boolean") result = result ? 1 : 0;
85
86
  if (result === Yes || result === YesAndSkip) {
86
87
  if (list) {
87
88
  list.push(child);
@@ -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 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};
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={},_={},p={};class m{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:p.tag=t,t=p}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),"boolean"==typeof h&&(h=h?1:0),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 m(t)};export{m 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, 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,EAA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BA,EAAME,SAAmB,CACzB,MAAM7C,EAAK2C,EAAMG,SACblD,KAAKE,MAAME,WAAYJ,KAAKE,MAAME,EAC1C,CACJ,CAGU,cAAAS,GACNb,KAAKmD,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,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"}
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,WA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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
@@ -82,6 +82,7 @@ this.LeaferIN.find = function(exports, draw) {
82
82
  for (let i = 0, len = children.length; i < len; i++) {
83
83
  child = children[i];
84
84
  result = method(child, options);
85
+ if (typeof result === "boolean") result = result ? 1 : 0;
85
86
  if (result === Yes || result === YesAndSkip) {
86
87
  if (list) {
87
88
  list.push(child);
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(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;
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),"boolean"==typeof d&&(d=d?1:0),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, 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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AAWM,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,EC9IJ,MAAM6B,EAAKC,EAAAA,GAAGC,UAEd,SAASC,EAAYH,GACjB,OAAOA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAAAA,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 } 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,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,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,SACD,GAAKyB,EAAAA,YAAYN,EAAUX,IAGpB,IAAIW,EAAUN,IAAK,CACtB,MAAMA,IAAEA,GAAQM,E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,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,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"}
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={},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);
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),"boolean"==typeof d&&(d=d?1:0),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, 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,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ages/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,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,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,SACD,GAAKyB,EAAAA,YAAYN,EAA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AAenD,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/find",
3
- "version": "1.12.1",
3
+ "version": "1.12.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": "^1.12.1",
38
- "@leafer-ui/interface": "^1.12.1",
39
- "@leafer-in/interface": "^1.12.1"
37
+ "@leafer-ui/draw": "^1.12.3",
38
+ "@leafer-ui/interface": "^1.12.3",
39
+ "@leafer-in/interface": "^1.12.3"
40
40
  }
41
41
  }
package/src/Finder.ts CHANGED
@@ -93,6 +93,7 @@ export class Finder implements IFinder {
93
93
  for (let i = 0, len = children.length; i < len; i++) {
94
94
  child = children[i]
95
95
  result = method(child, options)
96
+ if (typeof result === 'boolean') result = result ? 1 : 0
96
97
  if (result === Yes || result === YesAndSkip) {
97
98
  if (list) {
98
99
  list.push(child)