@cocreate/elements 1.3.18 → 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 +7 -0
- package/package.json +1 -1
- package/src/getValue.js +55 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.18...v1.4.0) (2021-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added attribute get-value to get a value from a target element ([d24b60c](https://github.com/CoCreate-app/CoCreate-elements/commit/d24b60cc7a00d3899311be4bf7ea2fc2c798c4a7))
|
|
7
|
+
|
|
1
8
|
## [1.3.18](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.17...v1.3.18) (2021-11-20)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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",
|
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};
|