@cocreate/element-prototype 1.19.0 → 1.20.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 +13 -0
- package/package.json +1 -1
- package/src/getValue.js +35 -5
- package/src/setValue.js +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [1.20.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.19.0...v1.20.0) (2024-02-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* distpatchEvents if innerHtml ([9d55c26](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/9d55c26492014af2750a38ea7ea7e939b3df6577))
|
|
7
|
+
* remove api typo ([2d7728b](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/2d7728b8e52d1d0d290ebfac1c35308cfb9c200a))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* value-types to handle date and time ([3a72fbc](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/3a72fbc23d9b8008a0bc488ac8230f5dfc2f86ea))
|
|
13
|
+
|
|
1
14
|
# [1.19.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.18.0...v1.19.0) (2024-01-30)
|
|
2
15
|
|
|
3
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"element-prototype",
|
package/src/getValue.js
CHANGED
|
@@ -26,6 +26,7 @@ const getValue = (element) => {
|
|
|
26
26
|
|
|
27
27
|
let prefix = element.getAttribute('value-prefix') || "";
|
|
28
28
|
let suffix = element.getAttribute('value-suffix') || "";
|
|
29
|
+
let valueType = element.getAttribute('value-type');
|
|
29
30
|
|
|
30
31
|
if (element.type === "checkbox") {
|
|
31
32
|
let inputs = [element]
|
|
@@ -78,10 +79,40 @@ const getValue = (element) => {
|
|
|
78
79
|
optionValue = prefix + optionValue + suffix;
|
|
79
80
|
value.push(optionValue);
|
|
80
81
|
}
|
|
81
|
-
} else if (["time", "datetime", "datetime-local"].includes(element.type)) {
|
|
82
|
-
value
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
} else if (["time", "date", "datetime", "datetime-local"].includes(element.type)) {
|
|
83
|
+
if (value === '$now')
|
|
84
|
+
value = new Date()
|
|
85
|
+
else if (value)
|
|
86
|
+
value = new Date(value)
|
|
87
|
+
|
|
88
|
+
if (value) {
|
|
89
|
+
if (!valueType)
|
|
90
|
+
value = value.toISOString()
|
|
91
|
+
|
|
92
|
+
if (element.type === 'time')
|
|
93
|
+
// value = value.substring(11, 8) + 'Z';
|
|
94
|
+
value = value.substring(11, 19) + 'Z';
|
|
95
|
+
|
|
96
|
+
switch (valueType) {
|
|
97
|
+
case 'getDayName':
|
|
98
|
+
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
99
|
+
value = days[value.getDay()];
|
|
100
|
+
break;
|
|
101
|
+
case 'getMonthName':
|
|
102
|
+
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
103
|
+
value = months[value.getMonth()];
|
|
104
|
+
break;
|
|
105
|
+
case 'toUnixTimestamp':
|
|
106
|
+
value = Math.floor(value.getTime() / 1000);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
if (typeof value[valueType] === 'function') {
|
|
110
|
+
value = value[valueType]();
|
|
111
|
+
} else {
|
|
112
|
+
console.warn(`The method ${valueType} is not a function of Date object.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
85
116
|
} else if (element.tagName == 'INPUT' || element.tagName == 'SELECT') {
|
|
86
117
|
value = element.value;
|
|
87
118
|
} else if (element.tagName == 'TEXTAREA') {
|
|
@@ -97,7 +128,6 @@ const getValue = (element) => {
|
|
|
97
128
|
value = element.innerHTML;
|
|
98
129
|
}
|
|
99
130
|
|
|
100
|
-
let valueType = element.getAttribute('value-type');
|
|
101
131
|
if (!Array.isArray(value)) {
|
|
102
132
|
if (prefix || suffix)
|
|
103
133
|
value = prefix + value + suffix;
|
package/src/setValue.js
CHANGED