@cocreate/element-prototype 1.19.0 → 1.20.1
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 +21 -0
- package/docs/index.html +0 -4
- package/package.json +1 -1
- package/src/getValue.js +35 -5
- package/src/setValue.js +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.20.1](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.20.0...v1.20.1) (2024-02-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* insert select options from src file ([7b644e1](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/7b644e10368ca21f4e478c2b333759430b466ef2))
|
|
7
|
+
* Removed https://cdn.cocreate.app/latest/CoCreate.min.css ([144d3e0](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/144d3e0c0996f52022f89d404d785d08a1762cfc))
|
|
8
|
+
|
|
9
|
+
# [1.20.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.19.0...v1.20.0) (2024-02-03)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* distpatchEvents if innerHtml ([9d55c26](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/9d55c26492014af2750a38ea7ea7e939b3df6577))
|
|
15
|
+
* remove api typo ([2d7728b](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/2d7728b8e52d1d0d290ebfac1c35308cfb9c200a))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* value-types to handle date and time ([3a72fbc](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/3a72fbc23d9b8008a0bc488ac8230f5dfc2f86ea))
|
|
21
|
+
|
|
1
22
|
# [1.19.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.18.0...v1.19.0) (2024-01-30)
|
|
2
23
|
|
|
3
24
|
|
package/docs/index.html
CHANGED
|
@@ -19,10 +19,6 @@
|
|
|
19
19
|
<meta name="robots" content="index,follow" />
|
|
20
20
|
|
|
21
21
|
<!-- CoCreate CSS CDN -->
|
|
22
|
-
<link
|
|
23
|
-
rel="stylesheet"
|
|
24
|
-
href="https://cdn.cocreate.app/latest/CoCreate.min.css"
|
|
25
|
-
type="text/css" />
|
|
26
22
|
|
|
27
23
|
<link rel="manifest" href="/manifest.webmanifest" />
|
|
28
24
|
</head>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
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
|
@@ -33,7 +33,8 @@ const setValue = (el, value, dispatch) => {
|
|
|
33
33
|
if (suffix)
|
|
34
34
|
value = value.toString().replace(suffix, "");
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// TODO: el.options vs rendenring options from src
|
|
37
|
+
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' && el.options.length) {
|
|
37
38
|
let { isCrdt } = getAttributes(el)
|
|
38
39
|
if (isCrdt == null || isCrdt == undefined)
|
|
39
40
|
isCrdt = el.getAttribute('crdt')
|
|
@@ -132,6 +133,10 @@ const setValue = (el, value, dispatch) => {
|
|
|
132
133
|
if (el.hasAttribute("value")) {
|
|
133
134
|
el.setAttribute("value", value);
|
|
134
135
|
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
dispatchEvents(el, dispatch);
|
|
139
|
+
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
if (el.getAttribute('contenteditable'))
|