@leafer-in/find 1.3.3 → 1.4.0

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
@@ -149,3 +149,4 @@ draw.Creator.finder = function (target) {
149
149
  };
150
150
 
151
151
  exports.Finder = Finder;
152
+ //# sourceMappingURL=find.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.cjs","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Answer","DataHelper","LeafH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AAG3B;;AChJD,MAAM,EAAE,GAAGC,OAAE,CAAC,SAAS;AAEvB,SAAS,WAAW,CAAC,EAAO,EAAA;AACxB,IAAA,OAAO,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAIC,aAAQ,CAAC,QAAQ,KAAKA,aAAQ,CAAC,QAAQ,GAAGC,YAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC3G;AAEA,EAAE,CAAC,IAAI,GAAG,UAAU,SAA0C,EAAE,OAAa,EAAA;AACzE,IAAA,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,SAAwB,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAU;AAC3F,CAAC;AAED,EAAE,CAAC,OAAO,GAAG,UAAU,SAA0C,EAAE,OAAa,EAAA;AAC5E,IAAA,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,SAAwB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAQ;AACxF,CAAC;;ACVDC,WAAM,CAAC,GAAG,CAAC,MAAM,CAAC;AAGlBD,YAAO,CAAC,MAAM,GAAG,UAAU,MAAM,EAAA;AAC7B,IAAA,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;AAC7B,CAAC;;;;"}
package/dist/find.esm.js CHANGED
@@ -147,3 +147,4 @@ Creator.finder = function (target) {
147
147
  };
148
148
 
149
149
  export { Finder };
150
+ //# sourceMappingURL=find.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.esm.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":[],"mappings":";;AAIA,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM;AAC7C,MAAM,WAAW,GAAG,EAAoB,EAAE,kBAAkB,GAAG,EAAoB,EAAE,YAAY,GAAG,EAAoB;MAE3G,MAAM,CAAA;AAoBf,IAAA,WAAA,CAAY,MAAa,EAAA;QAhBf,IAAU,CAAA,UAAA,GAAa,EAAE;QACzB,IAAK,CAAA,KAAA,GAAa,EAAE;AAIpB,QAAA,IAAA,CAAA,OAAO,GAAG;AAChB,YAAA,EAAE,EAAE,CAAC,IAAW,EAAE,IAAY,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;AACvG,YAAA,OAAO,EAAE,CAAC,IAAW,EAAE,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O,CAAQ;AACxF,CAAC;;ACVD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;AAGlB,OAAO,CAAC,MAAM,GAAG,UAAU,MAAM,EAAA;AAC7B,IAAA,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;AAC7B,CAAC;;;;"}
@@ -1 +1,2 @@
1
1
  import{DataHelper as t,LeafHelper as e,ChildEvent as i,PropertyEvent as s,Answer as n,UI as h,Platform as r,Creator as d,Plugin as a}from"@leafer-ui/draw";const{Yes:o,NoAndSkip:c,YesAndSkip:l}=n,g={},f={},u={};class _{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(e,i,s,n){switch(typeof e){case"number":const h=this.getByInnerId(e,i);return s?h:h?[h]:[];case"string":switch(e[0]){case"#":g.id=e.substring(1),e=g;break;case".":f.className=e.substring(1),e=f;break;default:u.tag=e,e=u}case"object":if(void 0!==e.id){const t=this.getById(e.id,i);return s?t:t?[t]:[]}if(e.tag){const{tag:n}=e,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?t.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,e.className);case"function":return this.getByMethod(e,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.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,i,s){let n,h;for(let r=0,d=t.length;r<d;r++){if(n=t[r],h=e(n,s),h===o||h===l){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&h<c&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(i.REMOVE,this.__onRemoveChild,this),this.target.on_(s.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const m=h.prototype;function p(t){return t.leafer?t.leafer.selector:r.selector||(r.selector=d.selector())}m.find=function(t,e){return p(this).getBy(t,this,!1,e)},m.findOne=function(t,e){return p(this).getBy(t,this,!0,e)},a.add("find"),d.finder=function(t){return new _(t)};export{_ as Finder};
2
+ //# sourceMappingURL=find.esm.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.esm.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"2JAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EACjCC,EAAc,CAAA,EAAsBC,EAAqB,CAAoB,EAAEC,EAAe,CAAoB,QAE3GC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAUC,WAAa,CAAE,EACzBD,KAAKE,MAAa,CAAE,EAIpBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SA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  return exports;
154
154
 
155
155
  })({}, LeaferUI);
156
+ //# sourceMappingURL=find.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Answer","DataHelper","LeafHelper","ChildEvent","PropertyEvent","UI","Platform","Creator","Plugin"],"mappings":";;;;IAIA,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,GAAGA,WAAM;IAC7C,MAAM,WAAW,GAAG,EAAoB,EAAE,kBAAkB,GAAG,E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C,aAAQ,CAAC,QAAQ,KAAKA,aAAQ,CAAC,QAAQ,GAAGC,YAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3G;IAEA,EAAE,CAAC,IAAI,GAAG,UAAU,SAA0C,EAAE,OAAa,EAAA;IACzE,IAAA,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,SAAwB,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAU;IAC3F,CAAC;IAED,EAAE,CAAC,OAAO,GAAG,UAAU,SAA0C,EAAE,OAAa,EAAA;IAC5E,IAAA,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,SAAwB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAQ;IACxF,CAAC;;ACVDC,eAAM,CAAC,GAAG,CAAC,MAAM,CAAC;AAGlBD,gBAAO,CAAC,MAAM,GAAG,UAAU,MAAM,EAAA;IAC7B,IAAA,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;IAC7B,CAAC;;;;;;;;;;"}
package/dist/find.min.cjs CHANGED
@@ -1 +1,2 @@
1
1
  "use strict";var t=require("@leafer-ui/draw");const{Yes:e,NoAndSkip:i,YesAndSkip:s}=t.Answer,n={},h={},r={};class a{constructor(t){this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},(this.target=t)&&this.__listenEvents()}getBy(e,i,s,a){switch(typeof e){case"number":const d=this.getByInnerId(e,i);return s?d:d?[d]:[];case"string":switch(e[0]){case"#":n.id=e.substring(1),e=n;break;case".":h.className=e.substring(1),e=h;break;default:r.tag=e,e=r}case"object":if(void 0!==e.id){const t=this.getById(e.id,i);return s?t:t?[t]:[]}if(e.tag){const{tag:n}=e,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?t.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,e.className);case"function":return this.getByMethod(e,i,s,a)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(e,i){const s=this.idMap[e];return s&&t.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,e),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,n,h,r){let a,d;for(let o=0,c=t.length;o<c;o++){if(a=t[o],d=n(a,r),d===e||d===s){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<i&&this.eachFind(a.children,n,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(t.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(t.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const d=t.UI.prototype;function o(e){return e.leafer?e.leafer.selector:t.Platform.selector||(t.Platform.selector=t.Creator.selector())}d.find=function(t,e){return o(this).getBy(t,this,!1,e)},d.findOne=function(t,e){return o(this).getBy(t,this,!0,e)},t.Plugin.add("find"),t.Creator.finder=function(t){return new a(t)},exports.Finder=a;
2
+ //# sourceMappingURL=find.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.min.cjs","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector","leafer","selector","Platform","Creator","find","findOne","Plugin","add","finder"],"mappings":"8CAIA,MAAMA,IAAEA,EAAGC,UAAEA,EAASC,WAAEA,GAAeC,EAAMA,OACvCC,EAAc,CAAA,EAAsBC,EAAqB,CAAoB,EAAEC,EAAe,CAAoB,QAE3GC,EAoBT,WAAAC,CAAYC,GAhBFC,KAAUC,WAAa,CAAE,EACzBD,KAAKE,MAAa,CAAE,EAIpBF,KAAAG,QAAU,CAChBC,GAAI,CAACC,EAAaC,IAAiBD,EAAKD,KAAOE,GAAQN,KAAKD,SAAWC,KAAKE,MAAMI,GAAQD,GAAO,GAAK,EACtGE,QAAS,CAACF,EAAaE,IAAoBF,EAAKE,UAAYA,GAAWP,KAAKD,SAAWC,KAAKC,WAAWM,GAAWF,GAAO,GAAK,EAC9HG,UAAW,CAACH,EAAaC,IAAiBD,EAAKG,YAAcF,EAAO,EAAI,EACxEG,IAAK,CAACJ,EAAaC,IAAiBD,EAAKK,QAAUJ,EAAO,EAAI,EAC9DK,KAAM,CAACN,EAAaO,IAAyBA,EAAQP,EAAKK,OAAS,EAAI,IAOnEV,KAAKD,OAASA,IAAQC,KAAKa,iBAG5B,KAAAC,CAAMC,EAA2DC,EAAgBC,EAAeC,GACnG,cAAeH,GACX,IAAK,SACD,MAAMV,EAAOL,KAAKmB,aAAaJ,EAAWC,GAC1C,OAAOC,EAAMZ,EAAQA,EAAO,CAACA,GAAQ,GACzC,IAAK,SACD,OAAQU,EAAU,IACd,IAAK,IACDrB,EAAYU,GAAKW,EAAUK,UAAU,GAAIL,EAAYrB,EAAa,MACtE,IAAK,IACDC,EAAmBa,UAAYO,EAAUK,UAAU,GAAIL,EAAYpB,EAAoB,MAC3F,QACIC,EAAaa,IAAMM,EAAWA,EAAYnB,EAEtD,I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C7IxB,MAAM6B,EAAKC,EAAEA,GAACC,UAEd,SAASC,EAAYH,GACjB,OAAOA,EAAGI,OAASJ,EAAGI,OAAOC,SAAYC,EAAAA,SAASD,WAAaC,EAAQA,SAACD,SAAWE,UAAQF,WAC/F,CAEAL,EAAGQ,KAAO,SAAUrD,EAA4CG,GAC5D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAOkB,EAC1E,EAEA0C,EAAGS,QAAU,SAAUtD,EAA4CG,GAC/D,OAAO6C,EAAY/D,MAAMc,MAAMC,EAA0Bf,MAAM,EAAMkB,EACzE,ECVAoD,EAAAA,OAAOC,IAAI,QAGXJ,EAAAA,QAAQK,OAAS,SAAUzE,GACvB,OAAO,IAAIF,EAAOE,EACtB"}
package/dist/find.min.js CHANGED
@@ -1 +1,2 @@
1
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(void 0!==t.id){const e=this.getById(t.id,i);return s?e:e?[e]:[]}if(t.tag){const{tag:n}=t,h=n instanceof Array;return this.getByMethod(h?this.methods.tags:this.methods.tag,i,s,h?e.DataHelper.toMap(n):n)}return this.getByMethod(this.methods.className,i,s,t.className);case"function":return this.getByMethod(t,i,s,n)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,i){const s=this.idMap[t];return s&&e.LeafHelper.hasParent(s,i||this.target)?s:(this.eachFind(this.toChildren(i),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,h,r){let a,d;for(let o=0,c=t.length;o<c;o++){if(a=t[o],d=e(a,r),d===i||d===n){if(!h)return void(this.findLeaf=a);h.push(a)}a.isBranch&&d<s&&this.eachFind(a.children,e,h,r)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(e.ChildEvent.REMOVE,this.__onRemoveChild,this),this.target.on_(e.PropertyEvent.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){const{__eventIds:t}=this;t&&t.length&&(this.__removeListenEvents(),this.innerIdMap={},this.idMap={}),this.findLeaf=null}}const o=e.UI.prototype;function c(t){return t.leafer?t.leafer.selector:e.Platform.selector||(e.Platform.selector=e.Creator.selector())}return o.find=function(t,e){return c(this).getBy(t,this,!1,e)},o.findOne=function(t,e){return c(this).getBy(t,this,!0,e)},e.Plugin.add("find"),e.Creator.finder=function(t){return new d(t)},t.Finder=d,t}({},LeaferUI);
2
+ //# sourceMappingURL=find.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.min.js","sources":["../../../../../../src/in/packages/find/src/Finder.ts","../../../../../../src/in/packages/find/src/find.ts","../../../../../../src/in/packages/find/src/index.ts"],"sourcesContent":["import { ILeaf, ILeafMap, IEventListenerId, IFindMethod, IAnswer, IFindCondition, IBooleanMap, IFinder } from '@leafer-ui/interface'\nimport { ChildEvent, DataHelper, Answer, PropertyEvent, LeafHelper } from '@leafer-ui/draw'\n\n\nconst { Yes, NoAndSkip, YesAndSkip } = Answer\nconst idCondition = {} as IFindCondition, classNameCondition = {} as IFindCondition, tagCondition = {} as IFindCondition\n\nexport class Finder implements IFinder {\n\n public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据)\n\n protected innerIdMap: ILeafMap = {}\n protected idMap: ILeafMap = {}\n\n protected findLeaf: ILeaf\n\n protected methods = {\n id: (leaf: ILeaf, name: string) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,\n innerId: (leaf: ILeaf, innerId: number) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,\n className: (leaf: ILeaf, name: string) => leaf.className === name ? 1 : 0,\n tag: (leaf: ILeaf, name: string) => leaf.__tag === name ? 1 : 0,\n tags: (leaf: ILeaf, nameMap: IBooleanMap) => nameMap[leaf.__tag] ? 1 : 0\n }\n\n protected __eventIds: IEventListenerId[]\n\n\n constructor(target: ILeaf) {\n if (this.target = target) this.__listenEvents()\n }\n\n public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {\n switch (typeof condition) {\n case 'number':\n const leaf = this.getByInnerId(condition, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n case 'string':\n switch (condition[0]) {\n case '#':\n idCondition.id = condition.substring(1), condition = idCondition; break\n case '.':\n classNameCondition.className = condition.substring(1), condition = classNameCondition; break\n default:\n tagCondition.tag = condition, condition = tagCondition\n }\n case 'object':\n if (condition.id !== undefined) {\n const leaf = this.getById(condition.id as string, branch)\n return one ? leaf : (leaf ? [leaf] : [])\n } else if (condition.tag) {\n const { tag } = condition, isArray = tag instanceof Array\n return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag)\n } else {\n return this.getByMethod(this.methods.className, branch, one, condition.className)\n }\n case 'function':\n return this.getByMethod(condition as IFindMethod, branch, one, options)\n }\n }\n\n\n public getByInnerId(innerId: number, branch?: ILeaf): ILeaf {\n const cache = this.innerIdMap[innerId]\n if (cache) return cache\n this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId)\n return this.findLeaf\n }\n\n public getById(id: string, branch?: ILeaf): ILeaf {\n const cache = this.idMap[id]\n if (cache && LeafHelper.hasParent(cache, branch || this.target)) return cache\n this.eachFind(this.toChildren(branch), this.methods.id, null, id)\n return this.findLeaf\n }\n\n public getByClassName(className: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.className, branch, false, className) as ILeaf[]\n }\n\n public getByTag(tag: string, branch?: ILeaf): ILeaf[] {\n return this.getByMethod(this.methods.tag, branch, false, tag) as ILeaf[]\n }\n\n public getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf[] | ILeaf {\n const list: ILeaf[] = one ? null : []\n this.eachFind(this.toChildren(branch), method, list, options)\n return list || this.findLeaf\n }\n\n\n protected eachFind(children: ILeaf[], method: IFindMethod, list?: ILeaf[], options?: any): void {\n let child: ILeaf, result: IAnswer\n for (let i = 0, len = children.length; i < len; i++) {\n child = children[i]\n result = method(child, options)\n if (result === Yes || result === YesAndSkip) {\n if (list) {\n list.push(child)\n } else {\n this.findLeaf = child\n return\n }\n }\n if (child.isBranch && result < NoAndSkip) this.eachFind(child.children, method, list, options)\n }\n }\n\n protected toChildren(branch: ILeaf): ILeaf[] {\n this.findLeaf = null\n return [branch || this.target]\n }\n\n\n protected __onRemoveChild(event: ChildEvent): void {\n const { id, innerId } = event.child\n if (this.idMap[id]) delete this.idMap[id]\n if (this.innerIdMap[innerId]) delete this.innerIdMap[innerId]\n }\n\n protected __checkIdChange(event: PropertyEvent): void {\n if (event.attrName === 'id') {\n const id = event.oldValue as string\n if (this.idMap[id]) delete this.idMap[id]\n }\n }\n\n\n protected __listenEvents(): void {\n this.__eventIds = [\n this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),\n this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n this.__eventIds.length = 0\n }\n\n public destroy(): void {\n const { __eventIds } = this\n if (__eventIds && __eventIds.length) {\n this.__removeListenEvents()\n this.innerIdMap = {}\n this.idMap = {}\n }\n this.findLeaf = null\n }\n\n}","\nimport { IFindMethod, ISelector, IFindUIMethod, IUI } from '@leafer-ui/interface'\nimport { UI, Creator, Platform } from '@leafer-ui/draw'\n\n\nconst ui = UI.prototype\n\nfunction getSelector(ui: IUI): ISelector {\n return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))\n}\n\nui.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {\n return getSelector(this).getBy(condition as IFindMethod, this, false, options) as IUI[]\n}\n\nui.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI | undefined {\n return getSelector(this).getBy(condition as IFindMethod, this, true, options) as IUI\n}","export { Finder } from './Finder'\n\nimport { Creator, Plugin } from '@leafer-ui/draw'\nimport { Finder } from './Finder'\nimport './find'\n\n\nPlugin.add('find')\n\n\nCreator.finder = function (target) {\n return new Finder(target)\n}"],"names":["Yes","NoAndSkip","YesAndSkip","Answer","idCondition","classNameCondition","tagCondition","Finder","constructor","target","this","innerIdMap","idMap","methods","id","leaf","name","innerId","className","tag","__tag","tags","nameMap","__listenEvents","getBy","condition","branch","one","options","getByInnerId","substring","undefined","getById","isArray","Array","getByMethod","DataHelper","toMap","cache","eachFind","toChildren","findLeaf","LeafHelper","hasParent","getByClassName","getByTag","method","list","children","child","result","i","len","length","push","isBranch","__onRemoveChild","event","__checkIdChange","attrName","oldValue","__eventIds","on_","ChildEvent","REMOVE","PropertyEvent","CHANGE","__removeListenEvents","off_","destroy","ui","UI","prototype","getSelector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D,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,19 +1,19 @@
1
1
  {
2
2
  "name": "@leafer-in/find",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "@leafer-in/find",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "main": "dist/find.esm.js",
8
+ "main": "dist/find.esm.min.js",
9
9
  "exports": {
10
- "import": "./dist/find.esm.js",
11
- "require": "./dist/find.cjs",
10
+ "import": "./dist/find.esm.min.js",
11
+ "require": "./dist/find.min.cjs",
12
12
  "types": "./types/index.d.ts"
13
13
  },
14
14
  "types": "types/index.d.ts",
15
- "unpkg": "dist/find.js",
16
- "jsdelivr": "dist/find.js",
15
+ "unpkg": "dist/find.min.js",
16
+ "jsdelivr": "dist/find.min.js",
17
17
  "files": [
18
18
  "src",
19
19
  "types",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.3.3",
38
- "@leafer-ui/interface": "^1.3.3",
39
- "@leafer-in/interface": "^1.3.3"
37
+ "@leafer-ui/draw": "^1.4.0",
38
+ "@leafer-ui/interface": "^1.4.0",
39
+ "@leafer-in/interface": "^1.4.0"
40
40
  }
41
41
  }