@eox/itemfilter 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4985,7 +4985,7 @@ let Ye = class extends ea {
4985
4985
  geometry: l.geometry,
4986
4986
  mode: l.mode
4987
4987
  }, o), {});
4988
- if (Object.keys(s).length > 0) {
4988
+ if (Object.values(s).map((o) => o.geometry).filter((o) => !!o).length > 0) {
4989
4989
  const o = [];
4990
4990
  for (let u = 0; u < i.length; u++) {
4991
4991
  const l = {};
@@ -327,7 +327,7 @@ section.inline details.details-filter summary {
327
327
  overflow-x: hidden;
328
328
  overflow-y: auto;
329
329
  }
330
- `;var ca=Object.defineProperty,ha=Object.getOwnPropertyDescriptor,We=(r,e,t,i)=>{for(var n=i>1?void 0:i?ha(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&ca(e,t,n),n};class an{constructor(){this.aggregateResults=void 0,this.enableHighlighting=!1,this.enableSearch=!1,this.exclusiveFilters=!1,this.filterProperties=[],this.fuseConfig={keys:["title"]},this.inlineMode=!1,this.matchAllWhenEmpty=!0,this.onSearch=()=>{},this.onSelect=()=>{},this.showResults=!0,this.titleProperty="title"}}we.EOxItemFilter=class extends Qs{constructor(){super(...arguments),this._resultAggregation=[],this._items=[],this._filters={},this._config=new an,this.apply=e=>{this._items=e.map((t,i)=>({id:`item-${i}`,...t})),this._fuse=new at(this._items,{threshold:.4,distance:50,includeMatches:!0,useExtendedSearch:!0,...this._config.fuseConfig}),this._config.filterProperties.length&&this._config.filterProperties.forEach(t=>{const i={},n=s=>t.format==="date"?Rt(s).unix():parseInt(s);this._items.forEach(s=>{if(t.type==="range"){if(Array.isArray(s[t.key])){const o=[n(s[t.key][0]),n(s[t.key][1])];i.min=i.min!==void 0?Math.min(i.min,o[0]):o[0],i.max=i.max!==void 0?Math.max(i.max,o[1]):o[1]}else{const o=n(s[t.key]);i.min=i.min!==void 0?Math.min(i.min,o):o,i.max=i.max!==void 0?Math.max(i.max,o):o}return}Array.isArray(s[t.key])?s[t.key].forEach(o=>{i[o]=void 0}):i[s[t.key]]=void 0}),this._filters[t.key]={type:t.type||"string",keys:i,...t.type==="range"&&{min:i.min,max:i.max,format:t.format},...t.type==="spatial"&&{mode:t.mode}}}),this._config.matchAllWhenEmpty!==!1&&(this._results=this.sortResults(this._items),this.requestUpdate()),this._config.aggregateResults&&(this._resultAggregation=[...new Set(this._items.reduce((t,i)=>t.concat(i[this._config.aggregateResults]),[]))].sort((t,i)=>t.localeCompare(i)))},this.inputHandler=()=>{this.search(this.renderRoot.querySelector("input[type='text']").value)},this.debouncedInputHandler=Js(this.inputHandler,500,{leading:!0})}set config(e){const t=this._config;this._config={...new an,...e},this.requestUpdate("config",t)}get config(){return this._config}async search(e="",t=this._filters){const i=Object.entries(t).filter(([u,a])=>a.type==="string").reduce((u,[a,h])=>{const g="$or",v=[],_=M=>{const L={};L[a]=`="${M}"`,v.push(L)};return Object.entries(h.keys).filter(([M,L])=>L).forEach(([M,L])=>_(M)),v.length>0&&u.push({[g]:v}),u},[]);let n;if(!(e.length>0)&&!i.length&&this._config.matchAllWhenEmpty!==!1)n=this._items;else if(this.config.externalSearch)n=(await(await fetch(`${this.config.externalSearch(e,t)}`)).json()).features;else{const u={$and:[...e.length>0?[{$or:[...this._config.fuseConfig.keys.map(h=>({[h]:e}))]}]:[],...i]},a=this._fuse.search(u);n=this._config.enableHighlighting?eo(a,"highlight",this._config.titleProperty):a.map(h=>h.item)}const s=Object.entries(this._filters).filter(([u,a])=>a.type==="range").reduce((u,[a,h])=>(u[a]={min:h.keys.min,max:h.keys.max,format:h.format},u),{});if(Object.keys(s).length>0){const u=[];for(let a=0;a<n.length;a++){const h={};for(let[g,v]of Object.entries(s)){const _=M=>v.format==="date"?Rt(M).unix():M;n[a].hasOwnProperty(g)?Array.isArray(n[a][g])?h[g]=s[g].min<=_(n[a][g][1])&&_(n[a][g][0])<=s[g].max:_(n[a][g])>=s[g].min&&_(n[a][g])<=s[g].max?h[g]=!0:h[g]=!1:h[g]=!0}Object.values(h).every(g=>!!g)&&u.push(n[a])}n=[...u]}const o=Object.entries(this._filters).filter(([u,a])=>a.type==="spatial").reduce((u,[a,h])=>(u[a]={geometry:h.geometry,mode:h.mode},u),{});if(Object.keys(o).length>0){const u=[];for(let a=0;a<n.length;a++){const h={};for(let g of Object.keys(o)){const v=o[g].mode||"within";n[a].hasOwnProperty(g)&&(v==="within"?aa(n[a][g],o[g].geometry):oa(n[a][g],o[g].geometry))?h[g]=!0:h[g]=!1}Object.values(h).every(g=>!!g)&&u.push(n[a])}n=[...u]}this._results=this.sortResults(n),this._config.onSearch(n),this.requestUpdate()}aggregateResults(e,t){return e.filter(i=>{const n=i[this._config.aggregateResults];let s;return this._filters[this._config.aggregateResults]&&(s=Object.keys(this._filters[this._config.aggregateResults]).filter(u=>this._filters[this._config.aggregateResults].keys[u])),(s!=null&&s.length?s.includes(t):!0)&&Array.isArray(n)?n.includes(t):n===t})}sortResults(e){return[...e].sort((t,i)=>t[this._config.titleProperty].localeCompare(i[this._config.titleProperty]))}toggleFilter(e,t,i){i&&Object.keys(this._filters).filter(o=>this._filters[o].type==="string").forEach(o=>{this._config.filterProperties.find(u=>u.key===o).exclusive&&Object.keys(this._filters[o].keys).forEach(u=>{this._filters[o].keys[u]=!1})}),this._filters[e].keys[t]=!this._filters[e].keys[t];const n=this.renderRoot.querySelector('input[type="text"]');n?this.search(n.value):this.search();const s=this.renderRoot.querySelectorAll("ul#results input[type='radio']");for(let o=0;o<s.length;o++)s[o].checked=!1;this._selectedResult&&setTimeout(()=>{const o=this.renderRoot.querySelector(`#${this._selectedResult.id}`);o&&(o.checked=!0,this.requestUpdate())})}resetFilters(){this.renderRoot.querySelectorAll(".details-filter input").forEach(t=>{t.checked=!1});const e=this.renderRoot.querySelector('input[type="text"]');e&&(e.value=""),Object.keys(this._filters).forEach(t=>{if(this._filters[t].type==="range"){this._filters[t].keys.min=this._filters[t].min,this._filters[t].keys.max=this._filters[t].max;return}if(this._filters[t].type==="spatial"){this._filters[t].geometry=void 0,this.renderRoot.querySelector("eox-itemfilter-spatial-filter").reset();return}Object.keys(this._filters[t].keys).forEach(i=>{this._filters[t].keys[i]=!1})}),this.search(),this.requestUpdate()}render(){return ge`
330
+ `;var ca=Object.defineProperty,ha=Object.getOwnPropertyDescriptor,We=(r,e,t,i)=>{for(var n=i>1?void 0:i?ha(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&ca(e,t,n),n};class an{constructor(){this.aggregateResults=void 0,this.enableHighlighting=!1,this.enableSearch=!1,this.exclusiveFilters=!1,this.filterProperties=[],this.fuseConfig={keys:["title"]},this.inlineMode=!1,this.matchAllWhenEmpty=!0,this.onSearch=()=>{},this.onSelect=()=>{},this.showResults=!0,this.titleProperty="title"}}we.EOxItemFilter=class extends Qs{constructor(){super(...arguments),this._resultAggregation=[],this._items=[],this._filters={},this._config=new an,this.apply=e=>{this._items=e.map((t,i)=>({id:`item-${i}`,...t})),this._fuse=new at(this._items,{threshold:.4,distance:50,includeMatches:!0,useExtendedSearch:!0,...this._config.fuseConfig}),this._config.filterProperties.length&&this._config.filterProperties.forEach(t=>{const i={},n=s=>t.format==="date"?Rt(s).unix():parseInt(s);this._items.forEach(s=>{if(t.type==="range"){if(Array.isArray(s[t.key])){const o=[n(s[t.key][0]),n(s[t.key][1])];i.min=i.min!==void 0?Math.min(i.min,o[0]):o[0],i.max=i.max!==void 0?Math.max(i.max,o[1]):o[1]}else{const o=n(s[t.key]);i.min=i.min!==void 0?Math.min(i.min,o):o,i.max=i.max!==void 0?Math.max(i.max,o):o}return}Array.isArray(s[t.key])?s[t.key].forEach(o=>{i[o]=void 0}):i[s[t.key]]=void 0}),this._filters[t.key]={type:t.type||"string",keys:i,...t.type==="range"&&{min:i.min,max:i.max,format:t.format},...t.type==="spatial"&&{mode:t.mode}}}),this._config.matchAllWhenEmpty!==!1&&(this._results=this.sortResults(this._items),this.requestUpdate()),this._config.aggregateResults&&(this._resultAggregation=[...new Set(this._items.reduce((t,i)=>t.concat(i[this._config.aggregateResults]),[]))].sort((t,i)=>t.localeCompare(i)))},this.inputHandler=()=>{this.search(this.renderRoot.querySelector("input[type='text']").value)},this.debouncedInputHandler=Js(this.inputHandler,500,{leading:!0})}set config(e){const t=this._config;this._config={...new an,...e},this.requestUpdate("config",t)}get config(){return this._config}async search(e="",t=this._filters){const i=Object.entries(t).filter(([u,a])=>a.type==="string").reduce((u,[a,h])=>{const g="$or",v=[],_=M=>{const L={};L[a]=`="${M}"`,v.push(L)};return Object.entries(h.keys).filter(([M,L])=>L).forEach(([M,L])=>_(M)),v.length>0&&u.push({[g]:v}),u},[]);let n;if(!(e.length>0)&&!i.length&&this._config.matchAllWhenEmpty!==!1)n=this._items;else if(this.config.externalSearch)n=(await(await fetch(`${this.config.externalSearch(e,t)}`)).json()).features;else{const u={$and:[...e.length>0?[{$or:[...this._config.fuseConfig.keys.map(h=>({[h]:e}))]}]:[],...i]},a=this._fuse.search(u);n=this._config.enableHighlighting?eo(a,"highlight",this._config.titleProperty):a.map(h=>h.item)}const s=Object.entries(this._filters).filter(([u,a])=>a.type==="range").reduce((u,[a,h])=>(u[a]={min:h.keys.min,max:h.keys.max,format:h.format},u),{});if(Object.keys(s).length>0){const u=[];for(let a=0;a<n.length;a++){const h={};for(let[g,v]of Object.entries(s)){const _=M=>v.format==="date"?Rt(M).unix():M;n[a].hasOwnProperty(g)?Array.isArray(n[a][g])?h[g]=s[g].min<=_(n[a][g][1])&&_(n[a][g][0])<=s[g].max:_(n[a][g])>=s[g].min&&_(n[a][g])<=s[g].max?h[g]=!0:h[g]=!1:h[g]=!0}Object.values(h).every(g=>!!g)&&u.push(n[a])}n=[...u]}const o=Object.entries(this._filters).filter(([u,a])=>a.type==="spatial").reduce((u,[a,h])=>(u[a]={geometry:h.geometry,mode:h.mode},u),{});if(Object.values(o).map(u=>u.geometry).filter(u=>!!u).length>0){const u=[];for(let a=0;a<n.length;a++){const h={};for(let g of Object.keys(o)){const v=o[g].mode||"within";n[a].hasOwnProperty(g)&&(v==="within"?aa(n[a][g],o[g].geometry):oa(n[a][g],o[g].geometry))?h[g]=!0:h[g]=!1}Object.values(h).every(g=>!!g)&&u.push(n[a])}n=[...u]}this._results=this.sortResults(n),this._config.onSearch(n),this.requestUpdate()}aggregateResults(e,t){return e.filter(i=>{const n=i[this._config.aggregateResults];let s;return this._filters[this._config.aggregateResults]&&(s=Object.keys(this._filters[this._config.aggregateResults]).filter(u=>this._filters[this._config.aggregateResults].keys[u])),(s!=null&&s.length?s.includes(t):!0)&&Array.isArray(n)?n.includes(t):n===t})}sortResults(e){return[...e].sort((t,i)=>t[this._config.titleProperty].localeCompare(i[this._config.titleProperty]))}toggleFilter(e,t,i){i&&Object.keys(this._filters).filter(o=>this._filters[o].type==="string").forEach(o=>{this._config.filterProperties.find(u=>u.key===o).exclusive&&Object.keys(this._filters[o].keys).forEach(u=>{this._filters[o].keys[u]=!1})}),this._filters[e].keys[t]=!this._filters[e].keys[t];const n=this.renderRoot.querySelector('input[type="text"]');n?this.search(n.value):this.search();const s=this.renderRoot.querySelectorAll("ul#results input[type='radio']");for(let o=0;o<s.length;o++)s[o].checked=!1;this._selectedResult&&setTimeout(()=>{const o=this.renderRoot.querySelector(`#${this._selectedResult.id}`);o&&(o.checked=!0,this.requestUpdate())})}resetFilters(){this.renderRoot.querySelectorAll(".details-filter input").forEach(t=>{t.checked=!1});const e=this.renderRoot.querySelector('input[type="text"]');e&&(e.value=""),Object.keys(this._filters).forEach(t=>{if(this._filters[t].type==="range"){this._filters[t].keys.min=this._filters[t].min,this._filters[t].keys.max=this._filters[t].max;return}if(this._filters[t].type==="spatial"){this._filters[t].geometry=void 0,this.renderRoot.querySelector("eox-itemfilter-spatial-filter").reset();return}Object.keys(this._filters[t].keys).forEach(i=>{this._filters[t].keys[i]=!1})}),this.search(),this.requestUpdate()}render(){return ge`
331
331
  <style>
332
332
  ${la}
333
333
  ${!this.unstyled&&ua}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/itemfilter",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",