@eox/itemfilter 0.11.1 → 0.12.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.
@@ -3789,9 +3789,10 @@ let rr = class extends _e {
3789
3789
  return this;
3790
3790
  }
3791
3791
  _getItems() {
3792
- return Object.keys(this.filterObject.state).sort((t, e) => t.localeCompare(e)).map((t) => ({
3793
- id: t,
3794
- title: t.replace(/^./, t[0].toUpperCase())
3792
+ const t = "sort" in this.filterObject ? this.filterObject.sort : (e, r) => e.localeCompare(r);
3793
+ return Object.keys(this.filterObject.state).sort(t).map((e) => ({
3794
+ id: e,
3795
+ title: e.replace(/^./, e[0].toUpperCase())
3795
3796
  }));
3796
3797
  }
3797
3798
  _getSelectedItems() {
@@ -3993,9 +3994,10 @@ let ir = class extends _e {
3993
3994
  return this;
3994
3995
  }
3995
3996
  _getItems() {
3996
- return Object.keys(this.filterObject.state).sort((t, e) => t.localeCompare(e)).map((t) => ({
3997
- id: t,
3998
- title: t.replace(/^./, t[0].toUpperCase())
3997
+ const t = "sort" in this.filterObject ? this.filterObject.sort : (e, r) => e.localeCompare(r);
3998
+ return Object.keys(this.filterObject.state).sort(t).map((e) => ({
3999
+ id: e,
4000
+ title: e.replace(/^./, e[0].toUpperCase())
3999
4001
  }));
4000
4002
  }
4001
4003
  _getSelectedItems() {
@@ -4017,7 +4019,7 @@ let ir = class extends _e {
4017
4019
  this.filterObject,
4018
4020
  () => X`
4019
4021
  ${de(
4020
- this.inline || Object.keys(this.filterObject.state).length > 1,
4022
+ this.inline || Object.keys(this.filterObject.state).length > 10,
4021
4023
  () => X`
4022
4024
  <eox-autocomplete
4023
4025
  .items=${this._getItems()}
@@ -5623,7 +5625,7 @@ let Lr = class extends _e {
5623
5625
  }
5624
5626
  ];
5625
5627
  this.eoxMap = this.renderRoot.querySelector("eox-map"), setTimeout(() => {
5626
- this.eoxMap.setLayers(t);
5628
+ this.eoxMap.layers = t;
5627
5629
  const e = (r) => {
5628
5630
  const i = new CustomEvent("filter", {
5629
5631
  detail: {
@@ -654,7 +654,7 @@ eox-itemfilter-expandcontainer button.reset-icon:before {
654
654
  </li>
655
655
  `)}
656
656
  </ul>
657
- `}};et([J()],We.prototype,"filter",2),et([J()],We.prototype,"idProperty",2),et([J()],We.prototype,"items",2),et([J()],We.prototype,"titleProperty",2),et([J({type:Boolean})],We.prototype,"multiple",2),et([J()],We.prototype,"selectedItems",2),et([J({type:Boolean})],We.prototype,"unstyled",2),et([Ue()],We.prototype,"_currentHighlight",2),We=et([ke("eox-selectionlist")],We);var al=Object.defineProperty,cl=Object.getOwnPropertyDescriptor,vr=(t,e,r,i)=>{for(var n=i>1?void 0:i?cl(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&al(e,r,n),n};let rr=class extends _e{constructor(){super(...arguments),this.inline=!1,this.unstyled=!1}reset(){this.renderRoot.querySelectorAll("input[type='checkbox']").forEach(t=>{t instanceof HTMLInputElement&&(t.checked=!1)}),Ct(this.filterObject),this.requestUpdate()}createRenderRoot(){return this}_getItems(){return Object.keys(this.filterObject.state).sort((t,e)=>t.localeCompare(e)).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_getSelectedItems(){return Object.keys(this.filterObject.state).filter(t=>this.filterObject.state[t]).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_handleSelected(t){var e;Object.keys(this.filterObject.state).forEach(r=>{this.filterObject.state[r]=t.map(i=>i.id).includes(r)}),this.filterObject.stringifiedState=Object.keys(this.filterObject.state).filter(r=>this.filterObject.state[r]).join(", "),((e=this.filterObject.stringifiedState)==null?void 0:e.length)>0&&(this.filterObject.dirty=!0),this.dispatchEvent(new CustomEvent("filter"))}render(){return de(this.filterObject,()=>Y`
657
+ `}};et([J()],We.prototype,"filter",2),et([J()],We.prototype,"idProperty",2),et([J()],We.prototype,"items",2),et([J()],We.prototype,"titleProperty",2),et([J({type:Boolean})],We.prototype,"multiple",2),et([J()],We.prototype,"selectedItems",2),et([J({type:Boolean})],We.prototype,"unstyled",2),et([Ue()],We.prototype,"_currentHighlight",2),We=et([ke("eox-selectionlist")],We);var al=Object.defineProperty,cl=Object.getOwnPropertyDescriptor,vr=(t,e,r,i)=>{for(var n=i>1?void 0:i?cl(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&al(e,r,n),n};let rr=class extends _e{constructor(){super(...arguments),this.inline=!1,this.unstyled=!1}reset(){this.renderRoot.querySelectorAll("input[type='checkbox']").forEach(t=>{t instanceof HTMLInputElement&&(t.checked=!1)}),Ct(this.filterObject),this.requestUpdate()}createRenderRoot(){return this}_getItems(){const t="sort"in this.filterObject?this.filterObject.sort:(e,r)=>e.localeCompare(r);return Object.keys(this.filterObject.state).sort(t).map(e=>({id:e,title:e.replace(/^./,e[0].toUpperCase())}))}_getSelectedItems(){return Object.keys(this.filterObject.state).filter(t=>this.filterObject.state[t]).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_handleSelected(t){var e;Object.keys(this.filterObject.state).forEach(r=>{this.filterObject.state[r]=t.map(i=>i.id).includes(r)}),this.filterObject.stringifiedState=Object.keys(this.filterObject.state).filter(r=>this.filterObject.state[r]).join(", "),((e=this.filterObject.stringifiedState)==null?void 0:e.length)>0&&(this.filterObject.dirty=!0),this.dispatchEvent(new CustomEvent("filter"))}render(){return de(this.filterObject,()=>Y`
658
658
  ${de(this.inline||Object.keys(this.filterObject.state).length>10,()=>Y`
659
659
  <eox-autocomplete
660
660
  multiple
@@ -688,8 +688,8 @@ eox-itemfilter-expandcontainer button.reset-icon:before {
688
688
  <div class="range-after">
689
689
  ${this.filterObject.format==="date"?Lt.unix(this.filterObject.state.max):this.filterObject.state.max}
690
690
  </div>
691
- `)}};Vn([J()],oi.prototype,"filterObject",2),oi=Vn([ke("eox-itemfilter-range")],oi);var Ll=Object.defineProperty,Cl=Object.getOwnPropertyDescriptor,br=(t,e,r,i)=>{for(var n=i>1?void 0:i?Cl(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&Ll(e,r,n),n};let ir=class extends _e{constructor(){super(...arguments),this.inline=!1,this.unstyled=!1}reset(){this.renderRoot.querySelectorAll("input[type='radio']").forEach(t=>{t instanceof HTMLInputElement&&(t.checked=!1)}),Ct(this.filterObject),this.requestUpdate()}createRenderRoot(){return this}_getItems(){return Object.keys(this.filterObject.state).sort((t,e)=>t.localeCompare(e)).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_getSelectedItems(){return Object.keys(this.filterObject.state).filter(t=>this.filterObject.state[t]).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_handleSelected(t){var e;Object.keys(this.filterObject.state).forEach(r=>{this.filterObject.state[r]=t.detail.map(i=>i.id).includes(r)}),this.filterObject.stringifiedState=Object.keys(this.filterObject.state).filter(r=>this.filterObject.state[r])[0],((e=this.filterObject.stringifiedState)==null?void 0:e.length)>0&&(this.filterObject.dirty=!0),this.dispatchEvent(new CustomEvent("filter"))}render(){return de(this.filterObject,()=>Y`
692
- ${de(this.inline||Object.keys(this.filterObject.state).length>1,()=>Y`
691
+ `)}};Vn([J()],oi.prototype,"filterObject",2),oi=Vn([ke("eox-itemfilter-range")],oi);var Ll=Object.defineProperty,Cl=Object.getOwnPropertyDescriptor,br=(t,e,r,i)=>{for(var n=i>1?void 0:i?Cl(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&Ll(e,r,n),n};let ir=class extends _e{constructor(){super(...arguments),this.inline=!1,this.unstyled=!1}reset(){this.renderRoot.querySelectorAll("input[type='radio']").forEach(t=>{t instanceof HTMLInputElement&&(t.checked=!1)}),Ct(this.filterObject),this.requestUpdate()}createRenderRoot(){return this}_getItems(){const t="sort"in this.filterObject?this.filterObject.sort:(e,r)=>e.localeCompare(r);return Object.keys(this.filterObject.state).sort(t).map(e=>({id:e,title:e.replace(/^./,e[0].toUpperCase())}))}_getSelectedItems(){return Object.keys(this.filterObject.state).filter(t=>this.filterObject.state[t]).map(t=>({id:t,title:t.replace(/^./,t[0].toUpperCase())}))}_handleSelected(t){var e;Object.keys(this.filterObject.state).forEach(r=>{this.filterObject.state[r]=t.detail.map(i=>i.id).includes(r)}),this.filterObject.stringifiedState=Object.keys(this.filterObject.state).filter(r=>this.filterObject.state[r])[0],((e=this.filterObject.stringifiedState)==null?void 0:e.length)>0&&(this.filterObject.dirty=!0),this.dispatchEvent(new CustomEvent("filter"))}render(){return de(this.filterObject,()=>Y`
692
+ ${de(this.inline||Object.keys(this.filterObject.state).length>10,()=>Y`
693
693
  <eox-autocomplete
694
694
  .items=${this._getItems()}
695
695
  .selectedItems=${this._getSelectedItems()}
@@ -726,7 +726,7 @@ eox-itemfilter-expandcontainer button.reset-icon:before {
726
726
  .geometry=${(t=this.filterObject.state)==null?void 0:t.geometry}
727
727
  @filter="${e=>{this.filterObject.state.geometry=e.detail.geometry,this.filterObject.dirty=!0,this.filterObject.stringifiedState="Polygon",this.dispatchEvent(new CustomEvent("filter"))}}"
728
728
  ></eox-itemfilter-spatial>
729
- `})}};nr([J()],yi.prototype,"filterObject",2),yi=nr([ke("eox-itemfilter-spatial")],yi);let _r=class extends _e{render(){return Y`<eox-map part="map" style="height: 400px"></eox-map>`}firstUpdated(){this.setup()}setup(){const t=[{type:"Vector",properties:{id:"draw"},source:{type:"Vector",...this.geometry&&{format:"GeoJSON"},...this.geometry&&{url:this.createFeatureUrl(this.geometry)}},zIndex:1,interactions:[{type:"draw",options:{id:"drawInteraction",type:"Box",modify:!0}}]},{type:"Tile",source:{type:"XYZ",url:"https://s2maps-tiles.eu/wmts/1.0.0/osm_3857/default/g/{z}/{y}/{x}.jpg",attribution:"{ OSM: Data &copy; OpenStreetMap contributors and others, Rendering &copy; EOX }"}}];this.eoxMap=this.renderRoot.querySelector("eox-map"),setTimeout(()=>{this.eoxMap.setLayers(t);const e=r=>{const i=new CustomEvent("filter",{detail:{geometry:{type:"Polygon",coordinates:r.getGeometry().clone().transform("EPSG:3857","EPSG:4326").getCoordinates()}}});this.dispatchEvent(i)};this.eoxMap.interactions.drawInteraction.on("drawend",r=>{e(r.feature),this.eoxMap.removeInteraction("drawInteraction")}),this.eoxMap.interactions.drawInteraction_modify.on("modifyend",r=>{e(r.features.getArray()[0])})},1e3)}createFeatureUrl(t){return`data:text/json,${encodeURIComponent(JSON.stringify({type:"FeatureCollection",features:[{type:"Feature",properties:null,geometry:t}]}))}`}reset(){var e;const t=this.eoxMap.getLayerById("draw").getSource();((e=t.getFeatures())==null?void 0:e.length)>0&&(t.clear(),this.eoxMap.removeInteraction("drawInteraction_modify"),this.setup())}};nr([J()],_r.prototype,"geometry",2),nr([Ue()],_r.prototype,"eoxMap",2),_r=nr([ke("eox-itemfilter-spatial-filter")],_r);var Na=Object.defineProperty,Ba=Object.getOwnPropertyDescriptor,ms=(t,e,r,i)=>{for(var n=i>1?void 0:i?Ba(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&Na(e,r,n),n};let vi=class extends _e{constructor(){super(...arguments),this.inputHandler=()=>{const t=this.renderRoot.querySelector("input[type='text']");this.filterObject.keys.forEach(e=>{this.filterObject.state[e]=t.value}),this.filterObject.dirty=!0,this.filterObject.stringifiedState=t.value,this.dispatchEvent(new CustomEvent("filter"))},this.debouncedInputHandler=Xn(this.inputHandler,500,{leading:!0})}reset(){const t=this.renderRoot.querySelector("input[type='text']");t.value="",Ct(this.filterObject),this.filterObject.dirty=!1,this.requestUpdate()}createRenderRoot(){return this}render(){return de(this.filterObject,()=>Y`
729
+ `})}};nr([J()],yi.prototype,"filterObject",2),yi=nr([ke("eox-itemfilter-spatial")],yi);let _r=class extends _e{render(){return Y`<eox-map part="map" style="height: 400px"></eox-map>`}firstUpdated(){this.setup()}setup(){const t=[{type:"Vector",properties:{id:"draw"},source:{type:"Vector",...this.geometry&&{format:"GeoJSON"},...this.geometry&&{url:this.createFeatureUrl(this.geometry)}},zIndex:1,interactions:[{type:"draw",options:{id:"drawInteraction",type:"Box",modify:!0}}]},{type:"Tile",source:{type:"XYZ",url:"https://s2maps-tiles.eu/wmts/1.0.0/osm_3857/default/g/{z}/{y}/{x}.jpg",attribution:"{ OSM: Data &copy; OpenStreetMap contributors and others, Rendering &copy; EOX }"}}];this.eoxMap=this.renderRoot.querySelector("eox-map"),setTimeout(()=>{this.eoxMap.layers=t;const e=r=>{const i=new CustomEvent("filter",{detail:{geometry:{type:"Polygon",coordinates:r.getGeometry().clone().transform("EPSG:3857","EPSG:4326").getCoordinates()}}});this.dispatchEvent(i)};this.eoxMap.interactions.drawInteraction.on("drawend",r=>{e(r.feature),this.eoxMap.removeInteraction("drawInteraction")}),this.eoxMap.interactions.drawInteraction_modify.on("modifyend",r=>{e(r.features.getArray()[0])})},1e3)}createFeatureUrl(t){return`data:text/json,${encodeURIComponent(JSON.stringify({type:"FeatureCollection",features:[{type:"Feature",properties:null,geometry:t}]}))}`}reset(){var e;const t=this.eoxMap.getLayerById("draw").getSource();((e=t.getFeatures())==null?void 0:e.length)>0&&(t.clear(),this.eoxMap.removeInteraction("drawInteraction_modify"),this.setup())}};nr([J()],_r.prototype,"geometry",2),nr([Ue()],_r.prototype,"eoxMap",2),_r=nr([ke("eox-itemfilter-spatial-filter")],_r);var Na=Object.defineProperty,Ba=Object.getOwnPropertyDescriptor,ms=(t,e,r,i)=>{for(var n=i>1?void 0:i?Ba(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(n=(i?o(e,r,n):o(n))||n);return i&&n&&Na(e,r,n),n};let vi=class extends _e{constructor(){super(...arguments),this.inputHandler=()=>{const t=this.renderRoot.querySelector("input[type='text']");this.filterObject.keys.forEach(e=>{this.filterObject.state[e]=t.value}),this.filterObject.dirty=!0,this.filterObject.stringifiedState=t.value,this.dispatchEvent(new CustomEvent("filter"))},this.debouncedInputHandler=Xn(this.inputHandler,500,{leading:!0})}reset(){const t=this.renderRoot.querySelector("input[type='text']");t.value="",Ct(this.filterObject),this.filterObject.dirty=!1,this.requestUpdate()}createRenderRoot(){return this}render(){return de(this.filterObject,()=>Y`
730
730
  <style>
731
731
  input {
732
732
  max-height: 100%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/itemfilter",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",
package/test/state.cy.ts CHANGED
@@ -6,6 +6,13 @@ describe("Item Filter Config", () => {
6
6
  agriculture: true,
7
7
  health: true,
8
8
  };
9
+ const customOrder = {
10
+ health: 0,
11
+ water: 1,
12
+ air: 2,
13
+ economy: 3,
14
+ agriculture: 4,
15
+ } as { [key: string]: number };
9
16
  const selectedResultIndex = 1;
10
17
  beforeEach(() => {
11
18
  cy.mount(`<eox-itemfilter></eox-itemfilter>`)
@@ -19,6 +26,7 @@ describe("Item Filter Config", () => {
19
26
  key: "themes",
20
27
  type: "multiselect",
21
28
  expanded: true,
29
+ sort: (a, b) => customOrder[a] - customOrder[b],
22
30
  // @ts-ignore
23
31
  state,
24
32
  },
@@ -73,4 +81,21 @@ describe("Item Filter Config", () => {
73
81
  cy.get("input[data-cy=result-radio][checked]").should("have.length", 1);
74
82
  });
75
83
  });
84
+
85
+ it("should have a custom order", () => {
86
+ cy.get("eox-itemfilter")
87
+ .shadow()
88
+ .within(() => {
89
+ cy.get("eox-itemfilter-multiselect > eox-selectionlist")
90
+ .shadow()
91
+ .within(() => {
92
+ Object.keys(customOrder).forEach((state) => {
93
+ cy.get("ul [data-identifier]")
94
+ .eq(customOrder[state])
95
+ .invoke("attr", "data-identifier")
96
+ .should("eq", state);
97
+ });
98
+ });
99
+ });
100
+ });
76
101
  });