@eox/itemfilter 1.11.0 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/itemfilter",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@types/geojson": "^7946.0.14",
@@ -94,7 +94,9 @@ export class EOxItemFilterRange extends LitElement {
94
94
  return when(
95
95
  this.filterObject,
96
96
  () => html`
97
- <div style="margin-left: var(--list-padding)">
97
+ <div
98
+ style="margin-left: var(--list-padding); display: flex; gap: .5rem; align-items: center;"
99
+ >
98
100
  ${this.#label("min", "before")}
99
101
  <tc-range-slider
100
102
  min="${this.filterObject.min}"
@@ -1,3 +1,4 @@
1
+ import { getValue } from "./";
1
2
  /**
2
3
  * Fetches and filters items based on the provided filters and configuration using an external API.
3
4
  *
@@ -7,12 +8,20 @@
7
8
  * @returns {Promise<Array<Object>>} The filtered items from the external API.
8
9
  */
9
10
  async function filterExternal(items, filters, config) {
11
+ const functionResult = config.externalFilter(items, filters);
12
+ // Check if the function returns a string or an object
13
+ // If string, assume this is the url to be fetched;
14
+ // If object, assume structure { url: "<API endpoint>", key?: "<nested.property.key for items>"}
15
+ const url =
16
+ typeof functionResult === "string" || functionResult instanceof String
17
+ ? functionResult
18
+ : functionResult.url;
10
19
  // Generate the URL for the external API based on the provided items and filters
11
- const response = await fetch(`${config.externalFilter(items, filters)}`);
20
+ const response = await fetch(url);
12
21
  const jsonData = await response.json();
13
22
 
14
23
  // Return the array from the parsed JSON data
15
- return jsonData;
24
+ return functionResult.key ? getValue(functionResult.key, jsonData) : jsonData;
16
25
  }
17
26
 
18
27
  export default filterExternal;
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * Get value based on nested key or individual key
3
3
  *
4
- * @param {string} key - Key to identify the value
4
+ * @param {string|Function} key - Key to identify the value
5
5
  * @param {Object} items - Items contain list of key & it's value
6
6
  * @returns {any}
7
7
  */
8
8
  export default function getValue(key, items) {
9
+ if (typeof key === "function") {
10
+ return key(items);
11
+ }
9
12
  return key?.includes(".")
10
13
  ? key.split(".").reduce((acc, key) => acc && acc[key], items)
11
14
  : items[key];
package/src/main.js CHANGED
@@ -190,22 +190,25 @@ export class EOxItemFilter extends LitElement {
190
190
 
191
191
  /**
192
192
  * The property of the result items used for display
193
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
193
194
  *
194
- * @type String
195
+ * @type String|Function
195
196
  */
196
197
  this.titleProperty = "title";
197
198
 
198
199
  /**
199
200
  * The property of the result items used for a subtitle
201
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
200
202
  *
201
- * @type String
203
+ * @type String|Function
202
204
  */
203
205
  this.subTitleProperty = undefined;
204
206
 
205
207
  /**
206
208
  * The property of the result items used for an image
209
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
207
210
  *
208
- * @type String
211
+ * @type String|Function
209
212
  */
210
213
  this.imageProperty = undefined;
211
214
 
@@ -405,6 +408,42 @@ export class EOxItemFilter extends LitElement {
405
408
  this.requestUpdate();
406
409
  }
407
410
 
411
+ /**
412
+ * Dispatches an event when result component triggers the "mouseenter:result" event.
413
+ *
414
+ * @param {{detail: Object}} evt - "mouseenter:result" event triggered by result component
415
+ */
416
+ mouseEnterResult(evt) {
417
+ /**
418
+ * Fires when a result is hovered; event detail is `result`
419
+ */
420
+ this.dispatchEvent(
421
+ new CustomEvent("mouseenter:result", {
422
+ detail: evt.detail,
423
+ bubbles: true,
424
+ composed: true,
425
+ }),
426
+ );
427
+ }
428
+
429
+ /**
430
+ * Dispatches an event when result component triggers the "mouseleave:result" event.
431
+ *
432
+ * @param {{detail: Object}} evt - "mouseleave:result" event triggered by result component
433
+ */
434
+ mouseLeaveResult(evt) {
435
+ /**
436
+ * Fires when a result is hovered; event detail is `result`
437
+ */
438
+ this.dispatchEvent(
439
+ new CustomEvent("mouseleave:result", {
440
+ detail: evt.detail,
441
+ bubbles: true,
442
+ composed: true,
443
+ }),
444
+ );
445
+ }
446
+
408
447
  /**
409
448
  * Emits "click:result-action" event.
410
449
  *
@@ -542,6 +581,8 @@ export class EOxItemFilter extends LitElement {
542
581
  .enableResultAction=${this.enableResultAction}
543
582
  .resultActionIcon=${this.resultActionIcon}
544
583
  @result=${this.updateResult}
584
+ @mouseenter:result=${this.mouseEnterResult}
585
+ @mouseleave:result=${this.mouseLeaveResult}
545
586
  @click:result-action=${this.emitResultAction}
546
587
  >
547
588
  <nav class="title-nav">
@@ -1,3 +1,5 @@
1
+ import { getValue } from "../../helpers";
2
+
1
3
  /**
2
4
  * Sorts the provided items based on the title property specified in the configuration.
3
5
  *
@@ -7,7 +9,10 @@
7
9
  */
8
10
  function sortResultsMethod(items, config) {
9
11
  return [...items].sort((a, b) =>
10
- a[config.titleProperty].localeCompare(b[config.titleProperty]),
12
+ getValue(config.titleProperty, a)
13
+ .toString()
14
+ .localeCompare(getValue(config.titleProperty, b))
15
+ .toString(),
11
16
  );
12
17
  }
13
18
 
@@ -95,6 +95,20 @@ export function createItemListMethod(
95
95
  }),
96
96
  );
97
97
  }}
98
+ @mouseenter=${() => {
99
+ EOxItemFilterResults.dispatchEvent(
100
+ new CustomEvent("mouseenter:result", {
101
+ detail: item,
102
+ }),
103
+ );
104
+ }}
105
+ @mouseleave=${() => {
106
+ EOxItemFilterResults.dispatchEvent(
107
+ new CustomEvent("mouseleave:result", {
108
+ detail: item,
109
+ }),
110
+ );
111
+ }}
98
112
  >
99
113
  <nav id="${item.id}" class="responsive tiny-space">
100
114
  ${when(
@@ -156,15 +170,16 @@ export function createItemListMethod(
156
170
  ? "highlight-enabled"
157
171
  : ""}"
158
172
  >${unsafeHTML(
159
- item.highlightedText || item[config.titleProperty],
173
+ item.highlightedText ||
174
+ getValue(config.titleProperty, item).toString(),
160
175
  )}</span
161
176
  >
162
177
  ${when(
163
- !!item[config.subTitleProperty],
178
+ !!getValue(config.subTitleProperty, item),
164
179
  () => html`
165
180
  <small class="subtitle no-line truncate"
166
181
  >${unsafeHTML(
167
- item[config.subTitleProperty].toString(),
182
+ getValue(config.subTitleProperty, item).toString(),
168
183
  )}</small
169
184
  >
170
185
  `,
package/src/style.eox.js CHANGED
@@ -391,7 +391,6 @@ details summary:hover {
391
391
  background: var(--item-hover-color);
392
392
  }
393
393
  eox-itemfilter-results li.highlighted {
394
- color: white;
395
394
  background: var(--item-select-color);
396
395
  }
397
396
  mark.highlight {
@@ -1 +1 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/components/filters/range.js"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH;IAEE;;;;;;;;;MAGE;IAKA;;OAEG;IACH,kBAAsB;IAOtB;;OAEG;IACH,cAFU,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CAEQ;IAEjD;;OAEG;IACH,gCAEE;IAuBJ;;OAEG;IACH,cAEC;IAED;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,oBAkBC;;CACF;2BA/GgC,KAAK"}
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/components/filters/range.js"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH;IAEE;;;;;;;;;MAGE;IAKA;;OAEG;IACH,kBAAsB;IAOtB;;OAEG;IACH,cAFU,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CAEQ;IAEjD;;OAEG;IACH,gCAEE;IAuBJ;;OAEG;IACH,cAEC;IAED;;;;OAIG;IACH,oBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,oBAoBC;;CACF;2BAjHgC,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"filter-external.d.ts","sourceRoot":"","sources":["../../src/helpers/filter-external.js"],"names":[],"mappings":";AAAA;;;;;;;GAOG;AACH,uCALW,KAAK,KAAQ,8BAGX,OAAO,CAAC,KAAK,KAAQ,CAAC,CASlC"}
1
+ {"version":3,"file":"filter-external.d.ts","sourceRoot":"","sources":["../../src/helpers/filter-external.js"],"names":[],"mappings":";AACA;;;;;;;GAOG;AACH,uCALW,KAAK,KAAQ,8BAGX,OAAO,CAAC,KAAK,KAAQ,CAAC,CAiBlC"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Get value based on nested key or individual key
3
3
  *
4
- * @param {string} key - Key to identify the value
4
+ * @param {string|Function} key - Key to identify the value
5
5
  * @param {Object} items - Items contain list of key & it's value
6
6
  * @returns {any}
7
7
  */
8
- export default function getValue(key: string, items: any): any;
8
+ export default function getValue(key: string | Function, items: any): any;
9
9
  //# sourceMappingURL=get-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-value.d.ts","sourceRoot":"","sources":["../../src/helpers/get-value.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,sCAJW,MAAM,eAEJ,GAAG,CAMf"}
1
+ {"version":3,"file":"get-value.d.ts","sourceRoot":"","sources":["../../src/helpers/get-value.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,sCAJW,MAAM,WAAS,eAEb,GAAG,CASf"}
package/types/main.d.ts CHANGED
@@ -199,22 +199,25 @@ export class EOxItemFilter extends LitElement {
199
199
  showResults: boolean;
200
200
  /**
201
201
  * The property of the result items used for display
202
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
202
203
  *
203
- * @type String
204
+ * @type String|Function
204
205
  */
205
- titleProperty: string;
206
+ titleProperty: string | Function;
206
207
  /**
207
208
  * The property of the result items used for a subtitle
209
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
208
210
  *
209
- * @type String
211
+ * @type String|Function
210
212
  */
211
- subTitleProperty: string;
213
+ subTitleProperty: string | Function;
212
214
  /**
213
215
  * The property of the result items used for an image
216
+ * Supports passing a function which recieves the current item as parameter and is expected to return a string
214
217
  *
215
- * @type String
218
+ * @type String|Function
216
219
  */
217
- imageProperty: string;
220
+ imageProperty: string | Function;
218
221
  /**
219
222
  * Unique id property of items
220
223
  *
@@ -308,6 +311,22 @@ export class EOxItemFilter extends LitElement {
308
311
  updateResult(evt: {
309
312
  detail: any;
310
313
  }): void;
314
+ /**
315
+ * Dispatches an event when result component triggers the "mouseenter:result" event.
316
+ *
317
+ * @param {{detail: Object}} evt - "mouseenter:result" event triggered by result component
318
+ */
319
+ mouseEnterResult(evt: {
320
+ detail: any;
321
+ }): void;
322
+ /**
323
+ * Dispatches an event when result component triggers the "mouseleave:result" event.
324
+ *
325
+ * @param {{detail: Object}} evt - "mouseleave:result" event triggered by result component
326
+ */
327
+ mouseLeaveResult(evt: {
328
+ detail: any;
329
+ }): void;
311
330
  /**
312
331
  * Emits "click:result-action" event.
313
332
  *
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.js"],"names":[],"mappings":"AA8BA;;;;;;;GAOG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkCC;IAoBC;;OAEG;IACH,OAFS,KAAK,KAAQ,CAEL;IAEjB;;;OAGG;IACH,aAAiB;IAEjB;;;OAGG;IACH,SAFS,KAAK,KAAQ,CAEL;IAEjB;;;OAGG;IACH,oBAA0B;IAE1B;;;OAGG;IACH,eAEE;IAEF;;;;OAIG;IACH,yBAAiC;IAEjC;;;;;OAKG;IACH,0BAA6B;IAE7B;;;;OAIG;IACH,4BAA+B;IAE/B;;;;;OAKG;IACH,yBAA0B;IAE1B;;;OAGG;IACH,kBAFS,KAAK,CAAC;QAAC,GAAG,CAAC,SAAS;QAAC,IAAI,CAAC,EAAE,KAAK,QAAQ,CAAC;QAAC,KAAK,SAAS;QAAC,IAAI,SAAS;QAAC,WAAW,CAAC,SAAS;QAAC,MAAM,CAAC,SAAS;QAAC,KAAK,CAAC,MAAQ;KAAC,CAAC,CAE9G;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Aa1B;IAED;;;;OAIG;IACH,sBAFW;QAAC,MAAM,MAAQ;KAAC,QAa1B;IAED;;;;OAIG;IACH,sBAFW;QAAC,MAAM,MAAQ;KAAC,QAa1B;IAED;;OAEG;IACH,+CAkIC;;CACF;2BAtlByC,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"sort-results.d.ts","sourceRoot":"","sources":["../../../src/methods/itemfilter/sort-results.js"],"names":[],"mappings":";AAAA;;;;;;GAMG;AACH,0CAJW,KAAK,KAAQ,gBAEX,KAAK,KAAQ,CAMzB"}
1
+ {"version":3,"file":"sort-results.d.ts","sourceRoot":"","sources":["../../../src/methods/itemfilter/sort-results.js"],"names":[],"mappings":";AAEA;;;;;;GAMG;AACH,0CAJW,KAAK,KAAQ,gBAEX,KAAK,KAAQ,CASzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/methods/results/create.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,6DAJW,MAAM,8BAEJ,OAAO,KAAK,EAAE,kBAAkB,CAuC5C;AAED;;;;;;GAMG;AACH,sFAHW,MAAM,GACJ,OAAO,KAAK,EAAE,cAAc,CA4JxC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/methods/results/create.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,6DAJW,MAAM,8BAEJ,OAAO,KAAK,EAAE,kBAAkB,CAuC5C;AAED;;;;;;GAMG;AACH,sFAHW,MAAM,GACJ,OAAO,KAAK,EAAE,cAAc,CA2KxC"}
@@ -1 +1 @@
1
- {"version":3,"file":"style.eox.d.ts","sourceRoot":"","sources":["../src/style.eox.js"],"names":[],"mappings":"AAKA,8BAidE"}
1
+ {"version":3,"file":"style.eox.d.ts","sourceRoot":"","sources":["../src/style.eox.js"],"names":[],"mappings":"AAKA,8BAgdE"}