@cocreate/element-prototype 1.2.28 → 1.4.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 +14 -0
- package/package.json +1 -1
- package/src/getValue.js +5 -2
- package/src/setValue.js +46 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.3.0...v1.4.0) (2023-01-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* run CoCReate,pass on elementsprior t inserting. merge domEditor and alements together ([d39f8ff](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/d39f8ffd287ed82754314a401b7c33e7bf902450))
|
|
7
|
+
|
|
8
|
+
# [1.3.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.2.28...v1.3.0) (2023-01-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* improved handling of checkbox and radio ([b7444f2](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/b7444f275a6cad77d6d1678e823ca654b3e4df63))
|
|
14
|
+
|
|
1
15
|
## [1.2.28](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.2.27...v1.2.28) (2023-01-09)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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
|
@@ -22,7 +22,7 @@ const getValue = (element) => {
|
|
|
22
22
|
|
|
23
23
|
if (element.type === "checkbox") {
|
|
24
24
|
let el_name = element.getAttribute('name');
|
|
25
|
-
let checkboxs = document.querySelectorAll(`input[type=checkbox][name='${el_name}']`);
|
|
25
|
+
let checkboxs = document.querySelectorAll(`input[type='checkbox'][name='${el_name}']`);
|
|
26
26
|
if (checkboxs.length > 1) {
|
|
27
27
|
value = [];
|
|
28
28
|
checkboxs.forEach(el => {
|
|
@@ -34,7 +34,10 @@ const getValue = (element) => {
|
|
|
34
34
|
if (el.checked)
|
|
35
35
|
value = el.value
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
} else if (element.type === 'radio') {
|
|
38
|
+
let name = element.getAttribute('name');
|
|
39
|
+
value = document.querySelector(`input[name="${name}"]:checked`).value
|
|
40
|
+
}
|
|
38
41
|
else if (element.type === "number") {
|
|
39
42
|
value = Number(value);
|
|
40
43
|
}
|
package/src/setValue.js
CHANGED
|
@@ -26,11 +26,13 @@ const setValue = (el, value) => {
|
|
|
26
26
|
if (isCrdt == "true" || el.type === 'file') return;
|
|
27
27
|
|
|
28
28
|
if (el.type == 'checkbox') {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
let name = el.getAttribute('name');
|
|
30
|
+
let inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
|
|
31
|
+
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;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
else if (el.type === 'radio') {
|
|
@@ -59,15 +61,36 @@ const setValue = (el, value) => {
|
|
|
59
61
|
else if (el.tagName === 'IFRAME')
|
|
60
62
|
el.srcdoc = value;
|
|
61
63
|
|
|
62
|
-
else if (el.tagName === '
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
else if (el.tagName === 'SCRIPT')
|
|
65
|
+
setScript(el, value);
|
|
66
|
+
|
|
67
|
+
else {
|
|
68
|
+
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
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
if (valueType == 'string' || valueType == 'text')
|
|
75
|
+
el.textContent = value;
|
|
76
|
+
else {
|
|
77
|
+
let newElement = document.createElement("div");
|
|
78
|
+
newElement.innerHTML = value;
|
|
79
|
+
setPass(newElement)
|
|
80
|
+
|
|
81
|
+
let CoCreateJS = newElement.querySelector('script[src*="CoCreate.js"], script[src*="CoCreate.min.js"]')
|
|
82
|
+
if (CoCreateJS)
|
|
83
|
+
CoCreateJS.remove()
|
|
84
|
+
|
|
85
|
+
let CoCreateCSS = newElement.querySelector('link[href*="CoCreate.css"], link[href*="CoCreate.min.css"]')
|
|
86
|
+
if (CoCreateCSS)
|
|
87
|
+
CoCreateCSS.remove()
|
|
88
|
+
|
|
89
|
+
let css = newElement.querySelector('link[collection], link[document]')
|
|
90
|
+
if (css)
|
|
91
|
+
css.remove()
|
|
92
|
+
|
|
93
|
+
if (el.getAttribute('domEditor') == "replace") {
|
|
71
94
|
let parentNode = el.parentNode;
|
|
72
95
|
if (parentNode) {
|
|
73
96
|
if (newElement.children[0]) {
|
|
@@ -77,29 +100,16 @@ const setValue = (el, value) => {
|
|
|
77
100
|
parentNode.replaceChild(newElement, el);
|
|
78
101
|
}
|
|
79
102
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (valueType == 'string' || valueType == 'text')
|
|
83
|
-
el.textContent = value;
|
|
84
|
-
else
|
|
85
|
-
el.innerHTML = value;
|
|
103
|
+
} else {
|
|
104
|
+
el.innerHTML = newElement.innerHTML;
|
|
86
105
|
}
|
|
87
106
|
}
|
|
88
|
-
}
|
|
89
107
|
|
|
90
|
-
else if (el.tagName === 'SCRIPT'){
|
|
91
|
-
setScript(el, value);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
if (el.hasAttribute('contenteditable') && el == document.activeElement) return;
|
|
95
|
-
if (valueType == 'string' || valueType == 'text')
|
|
96
|
-
el.textContent = value;
|
|
97
|
-
else
|
|
98
|
-
el.innerHTML = value;
|
|
99
108
|
if (el.hasAttribute("value")) {
|
|
100
109
|
el.setAttribute("value", value);
|
|
101
110
|
}
|
|
102
111
|
}
|
|
112
|
+
|
|
103
113
|
if (el.getAttribute('contenteditable'))
|
|
104
114
|
dispatchEvents(el);
|
|
105
115
|
|
|
@@ -115,6 +125,14 @@ const setValue = (el, value) => {
|
|
|
115
125
|
}
|
|
116
126
|
};
|
|
117
127
|
|
|
128
|
+
function setPass(el) {
|
|
129
|
+
if (CoCreate.pass) {
|
|
130
|
+
let passElements = el.querySelectorAll('[pass_id]');
|
|
131
|
+
if (passElements)
|
|
132
|
+
CoCreate.pass.initElements(passElements)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
function setScript(script, value) {
|
|
119
137
|
let newScript = document.createElement('script');
|
|
120
138
|
newScript.attributes = script.attributes;
|