@cocreate/elements 1.3.18 → 1.4.3
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 +28 -0
- package/package.json +5 -5
- package/src/getValue.js +55 -0
- package/src/index.js +10 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.4.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.2...v1.4.3) (2021-11-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update dependencies ([f733f85](https://github.com/CoCreate-app/CoCreate-elements/commit/f733f85b60f867fd68a1f50974308f2117974c93))
|
|
7
|
+
|
|
8
|
+
## [1.4.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.1...v1.4.2) (2021-11-23)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update dependencies ([e097490](https://github.com/CoCreate-app/CoCreate-elements/commit/e0974902933a9bb56903e2ba4ba906072d59f2b6))
|
|
14
|
+
|
|
15
|
+
## [1.4.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.0...v1.4.1) (2021-11-23)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* impoved the way checkbox and multiple select is handled. Commented change eventListener ([99b7160](https://github.com/CoCreate-app/CoCreate-elements/commit/99b71600a644eed41461b910e96bb6b053069dfe))
|
|
21
|
+
|
|
22
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.18...v1.4.0) (2021-11-21)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* added attribute get-value to get a value from a target element ([d24b60c](https://github.com/CoCreate-app/CoCreate-elements/commit/d24b60cc7a00d3899311be4bf7ea2fc2c798c4a7))
|
|
28
|
+
|
|
1
29
|
## [1.3.18](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.17...v1.3.18) (2021-11-20)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.3
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Fetch content into any html element by using html5 attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags as changes are broadcasted in realtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elements",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/action": "^1.3.
|
|
65
|
-
"@cocreate/crud-client": "^1.4.
|
|
66
|
-
"@cocreate/docs": "^1.2.
|
|
67
|
-
"@cocreate/observer": "^1.3.
|
|
64
|
+
"@cocreate/action": "^1.3.18",
|
|
65
|
+
"@cocreate/crud-client": "^1.4.34",
|
|
66
|
+
"@cocreate/docs": "^1.2.56",
|
|
67
|
+
"@cocreate/observer": "^1.3.48"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/getValue.js
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
import observer from '@cocreate/observer';
|
|
2
|
+
import {setValue} from './setValue';
|
|
3
|
+
|
|
4
|
+
function initGetValues() {
|
|
5
|
+
var elements = document.querySelectorAll('[get-value]');
|
|
6
|
+
initElements(elements)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function initElements(elements) {
|
|
10
|
+
for (let element of elements)
|
|
11
|
+
initElement(element)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function initElement(element) {
|
|
15
|
+
let id = element.getAttribute('get-value')
|
|
16
|
+
let valueEl = document.getElementById(id);
|
|
17
|
+
if(!valueEl) return;
|
|
18
|
+
let value = getValue(valueEl)
|
|
19
|
+
setValue(element, value)
|
|
20
|
+
|
|
21
|
+
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
|
|
22
|
+
|
|
23
|
+
valueEl.addEventListener('input', (e) => {
|
|
24
|
+
setValueByFind(e.target)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
28
|
+
setValueByFind(e.target)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
element.dispatchEvent(new Event("input", {
|
|
32
|
+
"bubbles": true
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function setValueByFind(valueEl){
|
|
38
|
+
let value = getValue(valueEl)
|
|
39
|
+
let id = valueEl.getAttribute('id')
|
|
40
|
+
if(!id) return;
|
|
41
|
+
var elements = document.querySelectorAll('[get-value="' + id + '"]');
|
|
42
|
+
for(let element of elements)
|
|
43
|
+
setValue(element, value)
|
|
44
|
+
}
|
|
45
|
+
|
|
1
46
|
var getValue = (element) => {
|
|
2
47
|
let value = element.value;
|
|
3
48
|
let prefix = element.getAttribute('value-prefix') || "";
|
|
@@ -49,4 +94,14 @@ function __encryptPassword(str) {
|
|
|
49
94
|
return encodedString;
|
|
50
95
|
}
|
|
51
96
|
|
|
97
|
+
observer.init({
|
|
98
|
+
name: 'CoCreateLogic',
|
|
99
|
+
observe: ['addedNodes'],
|
|
100
|
+
target: '[get-value]',
|
|
101
|
+
callback: function(mutation) {
|
|
102
|
+
CoCreateLogic.getValues.initElement(mutation.target);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
initGetValues();
|
|
52
107
|
export {getValue};
|
package/src/index.js
CHANGED
|
@@ -102,8 +102,8 @@ function setData(elements, data) {
|
|
|
102
102
|
async function save(element) {
|
|
103
103
|
let value = getValue(element);
|
|
104
104
|
let isFlat = false;
|
|
105
|
-
if (element.tagName == "INPUT" && element.type === "checkbox" || element.tagName == "SELECT" && element.hasAttribute('multiple'))
|
|
106
|
-
isFlat = true;
|
|
105
|
+
// if (element.tagName == "INPUT" && element.type === "checkbox" || element.tagName == "SELECT" && element.hasAttribute('multiple'))
|
|
106
|
+
// isFlat = true;
|
|
107
107
|
await crud.save(element, value, isFlat);
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -115,7 +115,6 @@ function __initSocket() {
|
|
|
115
115
|
|
|
116
116
|
function __initEvents(el) {
|
|
117
117
|
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' || el.hasAttribute('contenteditable')) {
|
|
118
|
-
|
|
119
118
|
el.addEventListener('input', function(e) {
|
|
120
119
|
const {document_id, isRealtime, isCrdt} = crud.getAttr(el);
|
|
121
120
|
if (isCrdt == "true" && document_id || isRealtime == "false") return;
|
|
@@ -123,14 +122,14 @@ function __initEvents(el) {
|
|
|
123
122
|
save(el);
|
|
124
123
|
});
|
|
125
124
|
|
|
126
|
-
el.addEventListener('change', function(e) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
125
|
+
// el.addEventListener('change', function(e) {
|
|
126
|
+
// if (el.tagName == 'SELECT') {
|
|
127
|
+
// const {isRealtime, isSave, isUpdate} = crud.getAttr(el);
|
|
128
|
+
// if (isRealtime == "false" || isSave == "false" || isUpdate == "false") return;
|
|
129
|
+
// if (e.detail && e.detail.skip == true) return;
|
|
130
|
+
// save(el);
|
|
131
|
+
// }
|
|
132
|
+
// });
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
|