@cocreate/element-prototype 1.4.11 → 1.6.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,17 @@
1
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.5.0...v1.6.0) (2023-03-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * replaced get-value and set-value with a super charged version of CoCreate-events ([05f9c1e](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/05f9c1e72f1e685aee7ff42675f320b04c4c0c6c))
7
+
8
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.11...v1.5.0) (2023-03-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * ability to use one checkbox as a boolean ([9dc3e5a](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/9dc3e5a0fa78a9a01a8e95759b48f63de69d111c))
14
+
1
15
  ## [1.4.11](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.10...v1.4.11) (2023-02-01)
2
16
 
3
17
 
package/docs/index.html CHANGED
@@ -72,7 +72,7 @@
72
72
  </div>
73
73
 
74
74
  <div id="demo-preview" class="position:relative overflow:auto background-color:white">
75
- <div get-value="#demo" class="padding:20px"></div>
75
+ <div class="demopreview" class="padding:20px"></div>
76
76
  </div>
77
77
 
78
78
  <div class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.4.11",
3
+ "version": "1.6.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
@@ -21,18 +21,24 @@ const getValue = (element) => {
21
21
  let suffix = element.getAttribute('value-suffix') || "";
22
22
 
23
23
  if (element.type === "checkbox") {
24
- let el_name = element.getAttribute('name');
25
- let checkboxs = document.querySelectorAll(`input[type='checkbox'][name='${el_name}']`);
26
- if (checkboxs.length > 1) {
24
+ let inputs = [element]
25
+ let name = element.getAttribute('name');
26
+ if (name)
27
+ inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
28
+
29
+
30
+ if (inputs.length > 1) {
27
31
  value = [];
28
- checkboxs.forEach(el => {
32
+ inputs.forEach(el => {
29
33
  if (el.checked)
30
34
  value.push(el.value);
31
35
  });
32
- }
33
- else {
34
- if (el.checked)
35
- value = el.value
36
+ } else {
37
+ if (element.checked)
38
+ value = element.value || 'true'
39
+ else if (!element.value)
40
+ value = 'false'
41
+
36
42
  }
37
43
  } else if (element.type === 'radio') {
38
44
  let name = element.getAttribute('name');
package/src/setValue.js CHANGED
@@ -26,13 +26,24 @@ const setValue = (el, value) => {
26
26
  if (isCrdt == "true" || el.type === 'file') return;
27
27
 
28
28
  if (el.type == 'checkbox') {
29
+ let inputs = [el]
29
30
  let name = el.getAttribute('name');
30
- let inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
31
+ if (name)
32
+ inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
33
+
31
34
  for (let i = 0; i < inputs.length; i++) {
32
- if (value.includes(inputs[i].value))
33
- inputs[i].checked = true;
34
- else
35
- inputs[i].checked = false;
35
+ if (inputs[i].value) {
36
+ if (value.includes(inputs[i].value))
37
+ inputs[i].checked = true;
38
+ else
39
+ inputs[i].checked = false;
40
+ } else {
41
+ if (value === 'true' || value === true || value === 'checked')
42
+ inputs[i].checked = true;
43
+ else
44
+ inputs[i].checked = false;
45
+
46
+ }
36
47
  }
37
48
  }
38
49
  else if (el.type === 'radio') {
@@ -66,10 +77,10 @@ const setValue = (el, value) => {
66
77
 
67
78
  else {
68
79
  if (el.hasAttribute('contenteditable') && el == document.activeElement) return;
69
- if (el.tagName === 'DIV') {
70
- if (!el.classList.contains('domEditor') && !el.hasAttribute('get-value') && !el.hasAttribute('get-value-closest'))
71
- return
72
- }
80
+ // if (el.tagName === 'DIV') {
81
+ // if (!el.classList.contains('domEditor') && !el.hasAttribute('get-value') && !el.hasAttribute('get-value-closest'))
82
+ // return
83
+ // }
73
84
 
74
85
  if (valueType == 'string' || valueType == 'text')
75
86
  el.textContent = value;