@cocreate/elements 1.31.0 → 1.32.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/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/src/index.js +24 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.32.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.31.1...v1.32.0) (2023-12-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* sort data by filter operator $in ([7fdb3e0](https://github.com/CoCreate-app/CoCreate-elements/commit/7fdb3e0b0e78077fa0a3e4d69c09aa73e9733f41))
|
|
7
|
+
|
|
8
|
+
## [1.31.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.31.0...v1.31.1) (2023-12-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* if no elements retiurned do not fire fetchedData event ([44386d3](https://github.com/CoCreate-app/CoCreate-elements/commit/44386d34a1029f27e0af3caa7ec10813c5085062))
|
|
14
|
+
* improved data.$filter handling ([3ffaa6b](https://github.com/CoCreate-app/CoCreate-elements/commit/3ffaa6b9cc9a5e36b0fe5a9adcf58d99d7184920))
|
|
15
|
+
|
|
1
16
|
# [1.31.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.30.0...v1.31.0) (2023-12-18)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"description": "Fetch content into any html element by using html5 attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags as changes are broadcasted in realtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elements",
|
package/src/index.js
CHANGED
|
@@ -300,6 +300,23 @@ async function setData(element, data) {
|
|
|
300
300
|
} else if (type == 'key')
|
|
301
301
|
type = 'object'
|
|
302
302
|
|
|
303
|
+
if (data.$filter && data.$filter.query) {
|
|
304
|
+
let mergedValues = [];
|
|
305
|
+
|
|
306
|
+
data.$filter.query.forEach(obj => {
|
|
307
|
+
if (obj.operator === '$in') {
|
|
308
|
+
mergedValues = [...mergedValues, ...obj.value];
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
if (mergedValues.length) {
|
|
313
|
+
const sortedType = mergedValues
|
|
314
|
+
.map(name => data[type].find(career => career.name === name))
|
|
315
|
+
.filter(career => career !== undefined);
|
|
316
|
+
data[type] = sortedType
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
303
320
|
for (let el of element) {
|
|
304
321
|
// if rendered in server side skip
|
|
305
322
|
if (el.hasAttribute('rendered'))
|
|
@@ -363,9 +380,14 @@ async function filterData(element, data, type, key) {
|
|
|
363
380
|
} else if (data)
|
|
364
381
|
element.setValue(data)
|
|
365
382
|
|
|
366
|
-
if (data.$filter)
|
|
367
|
-
filter.filters.get(element)
|
|
383
|
+
if (data.$filter) {
|
|
384
|
+
let filterElement = filter.filters.get(element)
|
|
385
|
+
if (filterElement)
|
|
386
|
+
filterElement.index = data.$filter.index
|
|
387
|
+
}
|
|
368
388
|
|
|
389
|
+
if (!data[type] || !Array.isArray(data[type]) || !data[type].length)
|
|
390
|
+
return
|
|
369
391
|
const evt = new CustomEvent('fetchedData', { bubbles: true });
|
|
370
392
|
element.dispatchEvent(evt);
|
|
371
393
|
}
|