@cocreate/element-prototype 1.6.5 → 1.7.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 CHANGED
@@ -1,3 +1,18 @@
1
+ # [1.7.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.6.6...v1.7.0) (2023-04-13)
2
+
3
+
4
+ ### Features
5
+
6
+ * 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))
7
+ * support value-type array ([05715a3](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/05715a38a6601fe0dc8fdde7e027d29a26aaf49d))
8
+
9
+ ## [1.6.6](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.6.5...v1.6.6) (2023-04-11)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * bump dependencies ([01ccfc5](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/01ccfc5ab21c851593391f410e0c850331aec1a7))
15
+
1
16
  ## [1.6.5](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.6.4...v1.6.5) (2023-04-11)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.6.5",
3
+ "version": "1.7.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",
@@ -60,8 +60,8 @@
60
60
  "webpack-log": "^3.0.1"
61
61
  },
62
62
  "dependencies": {
63
- "@cocreate/docs": "^1.6.4",
64
- "@cocreate/hosting": "^1.8.4",
65
- "@cocreate/utils": "^1.19.4"
63
+ "@cocreate/docs": "^1.6.5",
64
+ "@cocreate/hosting": "^1.8.5",
65
+ "@cocreate/utils": "^1.19.5"
66
66
  }
67
67
  }
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="${el.type}"][name="${name}"]`);
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
- value.push(el.value);
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
- value.push(options[i].value);
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 (prefix || suffix)
82
- value = prefix + value + suffix;
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)