@cocreate/elements 1.4.9 → 1.5.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 +28 -0
- package/demo/input-and-fetch.html +2 -2
- package/package.json +1 -1
- package/src/getValue.js +27 -9
- package/src/setValue.js +85 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.5.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.12...v1.5.0) (2021-12-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* set-value and set-value-key attribute to add placeholders that can be replaced by value onChange ([266cf5f](https://github.com/CoCreate-app/CoCreate-elements/commit/266cf5f7f72869a9a390889d24ddab2fed038c26))
|
|
7
|
+
|
|
8
|
+
## [1.4.12](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.11...v1.4.12) (2021-12-24)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* get-value observer typo ([1ab5e84](https://github.com/CoCreate-app/CoCreate-elements/commit/1ab5e84428a680bd0e4a1c62091fd55edf22f69d))
|
|
14
|
+
|
|
15
|
+
## [1.4.11](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.10...v1.4.11) (2021-12-23)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* renamed filter-value_type to filter-value-type ([5ec9280](https://github.com/CoCreate-app/CoCreate-elements/commit/5ec928076ba52fe83f526208091778eb00a81a03))
|
|
21
|
+
|
|
22
|
+
## [1.4.10](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.9...v1.4.10) (2021-12-20)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* firefox setValue content is removed if iframe.srcDoc is removed ([68da8ec](https://github.com/CoCreate-app/CoCreate-elements/commit/68da8ec1736997af6e814e50c737b8761013a5b7))
|
|
28
|
+
|
|
1
29
|
## [1.4.9](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.8...v1.4.9) (2021-12-15)
|
|
2
30
|
|
|
3
31
|
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
<!--<table class="width:100% border-collapse:collapse">-->
|
|
51
51
|
<!-- <tr class="border-bottom:1px_solid_darkgray">-->
|
|
52
52
|
<!-- <td class="position:sticky top:0 background:white padding-top:0 padding:10px ">-->
|
|
53
|
-
<!-- <input type="text" class="floating-label" filter-name="name"
|
|
53
|
+
<!-- <input type="text" class="floating-label" filter-name="name" template_id="datatable" placeholder="Name">-->
|
|
54
54
|
<!-- <span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6">-->
|
|
55
55
|
<!-- <a order-by="name" toggle-order="asc" template_id="datatable"></a>-->
|
|
56
56
|
<!-- </span>-->
|
|
57
57
|
<!-- </td>-->
|
|
58
58
|
<!-- <td class="position:sticky top:0 background:white padding:10px padding-top:0">-->
|
|
59
|
-
<!-- <input type="text" class="floating-label" filter-name="Document Id"
|
|
59
|
+
<!-- <input type="text" class="floating-label" filter-name="Document Id" template_id="datatable" placeholder="Type" />-->
|
|
60
60
|
<!-- <span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6">-->
|
|
61
61
|
<!-- <a order-by="_id" toggle-order="asc" template_id="datatable"></a>-->
|
|
62
62
|
<!-- </span>-->
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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
|
@@ -16,17 +16,20 @@ function initElement(element) {
|
|
|
16
16
|
let valueEl = document.getElementById(id);
|
|
17
17
|
if(!valueEl) return;
|
|
18
18
|
let value = getValue(valueEl)
|
|
19
|
+
if (value)
|
|
19
20
|
setValue(element, value)
|
|
20
21
|
|
|
21
|
-
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
|
|
22
|
+
// if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
|
|
22
23
|
|
|
23
|
-
valueEl.addEventListener('input', (e) => {
|
|
24
|
-
|
|
25
|
-
})
|
|
24
|
+
// valueEl.addEventListener('input', (e) => {
|
|
25
|
+
// setValueByFind(e.target)
|
|
26
|
+
// })
|
|
26
27
|
|
|
27
|
-
valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
28
|
-
|
|
29
|
-
})
|
|
28
|
+
// valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
29
|
+
// setValueByFind(e.target)
|
|
30
|
+
// })
|
|
31
|
+
|
|
32
|
+
initEvents(valueEl);
|
|
30
33
|
|
|
31
34
|
element.dispatchEvent(new Event("input", {
|
|
32
35
|
"bubbles": true
|
|
@@ -34,6 +37,21 @@ function initElement(element) {
|
|
|
34
37
|
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
const valueEls = new Map();
|
|
41
|
+
function initEvents(valueEl){
|
|
42
|
+
if (!valueEls.has(valueEl)) {
|
|
43
|
+
valueEls.set(valueEl);
|
|
44
|
+
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
|
|
45
|
+
valueEl.addEventListener('input', (e) => {
|
|
46
|
+
setValueByFind(e.target)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
50
|
+
setValueByFind(e.target)
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
function setValueByFind(valueEl){
|
|
38
56
|
let value = getValue(valueEl)
|
|
39
57
|
let id = valueEl.getAttribute('id')
|
|
@@ -95,11 +113,11 @@ function __encryptPassword(str) {
|
|
|
95
113
|
}
|
|
96
114
|
|
|
97
115
|
observer.init({
|
|
98
|
-
name: '
|
|
116
|
+
name: 'get-value',
|
|
99
117
|
observe: ['addedNodes'],
|
|
100
118
|
target: '[get-value]',
|
|
101
119
|
callback: function(mutation) {
|
|
102
|
-
|
|
120
|
+
initElement(mutation.target);
|
|
103
121
|
}
|
|
104
122
|
});
|
|
105
123
|
|
package/src/setValue.js
CHANGED
|
@@ -1,4 +1,72 @@
|
|
|
1
|
+
import observer from '@cocreate/observer';
|
|
1
2
|
import crud from '@cocreate/crud-client';
|
|
3
|
+
import {getValue} from './getValue';
|
|
4
|
+
|
|
5
|
+
function initSetValues() {
|
|
6
|
+
var elements = document.querySelectorAll('[set-value]');
|
|
7
|
+
initElements(elements);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function initElements(elements) {
|
|
11
|
+
for (let element of elements)
|
|
12
|
+
initElement(element);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function initElement(element) {
|
|
16
|
+
initEvents(element);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function initEvents(element){
|
|
20
|
+
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(element.tagName) || element.contentEditable)
|
|
21
|
+
element.addEventListener('input', (e) => {
|
|
22
|
+
setValueByFind(e.target);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
element.addEventListener('updated_by_fetch', (e) => {
|
|
26
|
+
setValueByFind(e.target);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function setValueByFind(element){
|
|
31
|
+
let key = element.getAttribute('set-value-key');
|
|
32
|
+
if (key)
|
|
33
|
+
key = `{{${key}}}`;
|
|
34
|
+
let value = getValue(element);
|
|
35
|
+
if (!value) return;
|
|
36
|
+
let selector = element.getAttribute('set-value');
|
|
37
|
+
if(!selector) return;
|
|
38
|
+
let elements = document.querySelectorAll(selector);
|
|
39
|
+
|
|
40
|
+
for(let element of elements){
|
|
41
|
+
if (key){
|
|
42
|
+
const regex = new RegExp(key, "g");
|
|
43
|
+
for (let attribute of element.attributes){
|
|
44
|
+
let attrName = attribute.name;
|
|
45
|
+
let attrValue = attribute.value;
|
|
46
|
+
let setAttr = false;
|
|
47
|
+
if (attrValue.includes(key)){
|
|
48
|
+
attrValue = attrValue.replace(regex, value);
|
|
49
|
+
setAttr = true;
|
|
50
|
+
}
|
|
51
|
+
if (attrName.includes(key)){
|
|
52
|
+
element.removeAttribute(key);
|
|
53
|
+
attrName = attrName.replace(regex, value);
|
|
54
|
+
setAttr = true;
|
|
55
|
+
}
|
|
56
|
+
if(setAttr)
|
|
57
|
+
element.setAttribute(attrName, attrValue);
|
|
58
|
+
}
|
|
59
|
+
let html = element.innerHTML;
|
|
60
|
+
if (html.indexOf(key) !== -1){
|
|
61
|
+
html.replace(regex, value);
|
|
62
|
+
element.innerHTML = html;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
setValue(element, value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
2
70
|
|
|
3
71
|
var setValue = (el, value) => {
|
|
4
72
|
if (value === null || value === undefined) return;
|
|
@@ -38,6 +106,11 @@ var setValue = (el, value) => {
|
|
|
38
106
|
|
|
39
107
|
else if (el.tagName === 'IFRAME') {
|
|
40
108
|
el.srcdoc = value;
|
|
109
|
+
// el.contentDocument.documentElement.innerHTML = value;
|
|
110
|
+
if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
|
|
111
|
+
// Do Firefox-related activities
|
|
112
|
+
}
|
|
113
|
+
else
|
|
41
114
|
el.onload = function(e) {
|
|
42
115
|
el.removeAttribute('srcdoc');
|
|
43
116
|
};
|
|
@@ -139,4 +212,16 @@ function dispatchEvents(el) {
|
|
|
139
212
|
el.dispatchEvent(changeEvent);
|
|
140
213
|
}
|
|
141
214
|
|
|
215
|
+
observer.init({
|
|
216
|
+
name: 'set-value',
|
|
217
|
+
observe: ['addedNodes'],
|
|
218
|
+
target: '[set-value]',
|
|
219
|
+
callback: function(mutation) {
|
|
220
|
+
initElement(mutation.target);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
initSetValues();
|
|
226
|
+
|
|
142
227
|
export {setValue};
|