@cocreate/utils 1.15.3 → 1.16.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 +7 -0
- package/package.json +1 -1
- package/src/utils.js +56 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.16.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.15.3...v1.16.0) (2022-12-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* getAttributes, getAttributeNames and setAttributeNames ([de2d962](https://github.com/CoCreate-app/CoCreate-utils/commit/de2d96223017f457a1bf13e07ee1a8c49a0596ed))
|
|
7
|
+
|
|
1
8
|
## [1.15.3](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.15.2...v1.15.3) (2022-12-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -480,7 +480,58 @@
|
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
482
|
return data;
|
|
483
|
-
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function getAttributes(el) {
|
|
486
|
+
if (!el) return;
|
|
487
|
+
|
|
488
|
+
let attributes = window.CoCreateConfig.attributes;
|
|
489
|
+
let object = {};
|
|
490
|
+
|
|
491
|
+
for (let attribute of el.attributes) {
|
|
492
|
+
let variable = attributes[attribute.name]
|
|
493
|
+
if (variable) {
|
|
494
|
+
object[variable] = attribute.value
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return object
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function getAttributeNames(variables) {
|
|
502
|
+
let reversedObject = {}
|
|
503
|
+
for (const key of Object.keys(CoCreateConfig.attributes)) {
|
|
504
|
+
reversedObject[CoCreateConfig.attributes[key]] = key
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
let attributes = [];
|
|
508
|
+
for (const variable of variables) {
|
|
509
|
+
let attribute = reversedObject[variable]
|
|
510
|
+
if (attribute)
|
|
511
|
+
attributes.push(attribute)
|
|
512
|
+
}
|
|
513
|
+
return attributes
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function setAttributeNames(attributes, overWrite) {
|
|
517
|
+
let reversedObject = {}
|
|
518
|
+
for (const key of Object.keys(CoCreateConfig.attributes)) {
|
|
519
|
+
reversedObject[CoCreateConfig.attributes[key]] = key
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
for (const attribute of Object.keys(attributes)) {
|
|
523
|
+
const variable = attributes[attribute]
|
|
524
|
+
if (!reversedObject[variable] || overWrite != false)
|
|
525
|
+
reversedObject[variable] = attribute
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
let revertObject = {}
|
|
529
|
+
for (const key of Object.keys(reversedObject)) {
|
|
530
|
+
revertObject[reversedObject[key]] = key
|
|
531
|
+
}
|
|
532
|
+
CoCreateConfig.attributes = revertObject
|
|
533
|
+
}
|
|
534
|
+
|
|
484
535
|
|
|
485
536
|
// function computeStyles(el, properties) {
|
|
486
537
|
// let computed = window.getComputedStyle(el);
|
|
@@ -518,7 +569,10 @@
|
|
|
518
569
|
queryDocumentSelectorAll,
|
|
519
570
|
queryData,
|
|
520
571
|
searchData,
|
|
521
|
-
sortData
|
|
572
|
+
sortData,
|
|
573
|
+
getAttributes,
|
|
574
|
+
setAttributeNames,
|
|
575
|
+
getAttributeNames
|
|
522
576
|
}
|
|
523
577
|
|
|
524
578
|
}));
|