@cocreate/element-prototype 1.6.6 → 1.8.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/demo/index.html +1 -0
- package/docs/index.html +2 -1
- package/package.json +1 -1
- package/src/getValue.js +20 -6
- package/src/setValue.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.8.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.7.0...v1.8.0) (2023-04-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added pwa manifest ([56f9312](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/56f9312293b1d6816c5c7482956851c5aba08273))
|
|
7
|
+
|
|
8
|
+
# [1.7.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.6.6...v1.7.0) (2023-04-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* setValue checks for prefix and suffix and removes them from value prior to setting value ([41cd87d](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/41cd87d28d9f77524917516bb4de76dc13ec78d5))
|
|
14
|
+
* support value-type array ([05715a3](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/05715a38a6601fe0dc8fdde7e027d29a26aaf49d))
|
|
15
|
+
|
|
1
16
|
## [1.6.6](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.6.5...v1.6.6) (2023-04-11)
|
|
2
17
|
|
|
3
18
|
|
package/demo/index.html
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
8
|
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
9
9
|
<title>element-prototype | CoCreateJS</title>
|
|
10
|
+
<link rel="manifest" href="/manifest.json">
|
|
10
11
|
</head>
|
|
11
12
|
|
|
12
13
|
<body>
|
package/docs/index.html
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
<!-- CoCreate CSS CDN -->
|
|
14
14
|
<link rel="stylesheet" href="https://cdn.cocreate.app/latest/CoCreate.min.css" type="text/css" />
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
<link rel="manifest" href="/manifest.json" />
|
|
17
|
+
</head>
|
|
17
18
|
|
|
18
19
|
<body>
|
|
19
20
|
<div collection="" document_id="" name="" id="cocreate-element-prototype">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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
|
@@ -24,14 +24,19 @@ const getValue = (element) => {
|
|
|
24
24
|
let inputs = [element]
|
|
25
25
|
let name = element.getAttribute('name');
|
|
26
26
|
if (name)
|
|
27
|
-
inputs = document.querySelectorAll(`input[type="${
|
|
27
|
+
inputs = document.querySelectorAll(`input[type="${element.type}"][name="${name}"]`);
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
if (inputs.length > 1) {
|
|
31
31
|
value = [];
|
|
32
32
|
inputs.forEach(el => {
|
|
33
|
-
if (el.checked)
|
|
34
|
-
|
|
33
|
+
if (el.checked) {
|
|
34
|
+
let checkedValue = el.value
|
|
35
|
+
if (prefix || suffix)
|
|
36
|
+
checkedValue = prefix + checkedValue + suffix;
|
|
37
|
+
|
|
38
|
+
value.push(checkedValue);
|
|
39
|
+
}
|
|
35
40
|
});
|
|
36
41
|
} else {
|
|
37
42
|
if (element.checked)
|
|
@@ -57,7 +62,10 @@ const getValue = (element) => {
|
|
|
57
62
|
let options = element.selectedOptions;
|
|
58
63
|
value = [];
|
|
59
64
|
for (let i = 0; i < options.length; i++) {
|
|
60
|
-
|
|
65
|
+
let optionValue = options[i].value
|
|
66
|
+
if (prefix || suffix)
|
|
67
|
+
optionValue = prefix + optionValue + suffix;
|
|
68
|
+
value.push(optionValue);
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
else if (element.tagName == 'INPUT' || element.tagName == 'SELECT') {
|
|
@@ -78,8 +86,14 @@ const getValue = (element) => {
|
|
|
78
86
|
else {
|
|
79
87
|
value = element.innerHTML;
|
|
80
88
|
}
|
|
81
|
-
if (
|
|
82
|
-
|
|
89
|
+
if (!Array.isArray(value)) {
|
|
90
|
+
if (prefix || suffix)
|
|
91
|
+
value = prefix + value + suffix;
|
|
92
|
+
|
|
93
|
+
if (element.getAttribute('value-type') == 'array')
|
|
94
|
+
value = [value];
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
|
|
84
98
|
return value;
|
|
85
99
|
};
|
package/src/setValue.js
CHANGED
|
@@ -18,6 +18,12 @@ HTMLHeadingElement.prototype.setValue = function(value) {
|
|
|
18
18
|
const setValue = (el, value) => {
|
|
19
19
|
if (value === null || value === undefined) return;
|
|
20
20
|
let valueType = el.getAttribute('value-type');
|
|
21
|
+
let prefix = el.getAttribute('value-prefix') || "";
|
|
22
|
+
let suffix = el.getAttribute('value-suffix') || "";
|
|
23
|
+
if (prefix)
|
|
24
|
+
value = text.replace(prefix, "");
|
|
25
|
+
if (suffix)
|
|
26
|
+
value = text.replace(suffix, "");
|
|
21
27
|
|
|
22
28
|
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT') {
|
|
23
29
|
let {isCrdt} = getAttributes(el)
|