@cocreate/elements 1.15.10 → 1.16.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/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -6
- package/demo/get-value.html +0 -26
- package/demo/set-value.html +0 -41
- package/src/getValue.js +0 -109
- package/src/setValue.js +0 -94
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.16.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.15.10...v1.16.0) (2023-03-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* replaced get-value and set-value with a super charged version of CoCreate-events ([7a12d60](https://github.com/CoCreate-app/CoCreate-elements/commit/7a12d603f4881aa9b16710513155243d8f7cea70))
|
|
7
|
+
|
|
1
8
|
## [1.15.10](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.15.9...v1.15.10) (2023-02-19)
|
|
2
9
|
|
|
3
10
|
|
package/docs/index.html
CHANGED
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
</div>
|
|
107
107
|
|
|
108
108
|
<div id="demo-preview" class="position:relative overflow:auto background-color:white">
|
|
109
|
-
<div
|
|
109
|
+
<div class="demopreview" class="padding:20px"></div>
|
|
110
110
|
</div>
|
|
111
111
|
|
|
112
112
|
<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/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.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/index.js
CHANGED
|
@@ -3,8 +3,6 @@ import action from '@cocreate/actions';
|
|
|
3
3
|
import crud from '@cocreate/crud-client';
|
|
4
4
|
import ccfilter from '@cocreate/filter';
|
|
5
5
|
import '@cocreate/element-prototype';
|
|
6
|
-
import { initSetValues} from './setValue';
|
|
7
|
-
import { initGetValues} from './getValue';
|
|
8
6
|
import './fetchSrc';
|
|
9
7
|
|
|
10
8
|
|
|
@@ -120,7 +118,7 @@ function setData(elements, data) {
|
|
|
120
118
|
for (let el of elements) {
|
|
121
119
|
const { collection, document_id, name, isRead, isUpdate, isCrdt } = crud.getAttributes(el);
|
|
122
120
|
|
|
123
|
-
if (el.hasAttribute('actions')) continue;
|
|
121
|
+
if (el.hasAttribute('actions') || el.tagName === 'DIV' && !el.classList.contains('domEditor')) continue;
|
|
124
122
|
if (!name || isRead == "false" || isUpdate == "false" || isCrdt == "true") continue;
|
|
125
123
|
|
|
126
124
|
if (data.document[0]['collection'] == collection && data.document[0]['_id'] == document_id) {
|
|
@@ -204,8 +202,5 @@ action.init({
|
|
|
204
202
|
});
|
|
205
203
|
|
|
206
204
|
init();
|
|
207
|
-
initGetValues();
|
|
208
|
-
initSetValues();
|
|
209
|
-
|
|
210
205
|
|
|
211
206
|
export default {initElements, initElement, save};
|
package/demo/get-value.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>Value | CoCreateJS</title>
|
|
5
|
-
|
|
6
|
-
<!-- CoCreate Favicon -->
|
|
7
|
-
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
8
|
-
<!-- CoCreate CSS CDN -->
|
|
9
|
-
<link rel="stylesheet" href="https://cdn.cocreate.app/logic/latest/CoCreate-logic.min.css" type="text/css"/>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
|
|
13
|
-
<input id="testing" value="new">
|
|
14
|
-
<h1 get-value="#testing" get-value-key="ty" class="{{ty}}" test="{{ty}}">{{ty}}</h1>
|
|
15
|
-
|
|
16
|
-
<hr/>
|
|
17
|
-
|
|
18
|
-
<input id="testing1" value="new1" />
|
|
19
|
-
<input get-value="#testing1" />
|
|
20
|
-
<input get-value="#testing1" />
|
|
21
|
-
|
|
22
|
-
<script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>
|
|
23
|
-
<!--<script src="../dist/CoCreate-form.js"></script>-->
|
|
24
|
-
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
package/demo/set-value.html
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>Value | CoCreateJS</title>
|
|
5
|
-
|
|
6
|
-
<!-- CoCreate Favicon -->
|
|
7
|
-
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
8
|
-
<!-- CoCreate CSS CDN -->
|
|
9
|
-
<link rel="stylesheet" href="https://cdn.cocreate.app/logic/latest/CoCreate-logic.min.css" type="text/css"/>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<!-- windows -->
|
|
13
|
-
<!--<ul get-value="##a123"> </ul>-->
|
|
14
|
-
<!--<ul id="a123"> hello </ul>-->
|
|
15
|
-
|
|
16
|
-
<cocreate-select class="floating-label" id="collection" placeholder="collection:" set-value="#document_id" set-value-key="setcollection" active>
|
|
17
|
-
<ul fetch-collection template_id="collection" class="options z-index:7 margin-top:5px">
|
|
18
|
-
<cc-option class="option template" template_id="collection" value="{{collection.name}}">
|
|
19
|
-
<span>{{collection.name}}</span>
|
|
20
|
-
</cc-option>
|
|
21
|
-
</ul>
|
|
22
|
-
</cocreate-select>
|
|
23
|
-
|
|
24
|
-
<cocreate-select class="floating-label" id="document_id" placeholder="document_id:" active>
|
|
25
|
-
<ul fetch-collection="{{setcollection}}" template_id="document_id" class="options z-index:7 margin-top:5px">
|
|
26
|
-
<cc-option class="option template" template_id="document_id" value="{{document._id}}">
|
|
27
|
-
<span>{{document._id}}</span>
|
|
28
|
-
</cc-option>
|
|
29
|
-
</ul>
|
|
30
|
-
</cocreate-select>
|
|
31
|
-
|
|
32
|
-
<input value="new" set-value="#testing" set-value-key="ty">
|
|
33
|
-
<h1 id="testing" class="{{ty}}" test="{{ty}}">{{ty}}</h1>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<!--<script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>-->
|
|
38
|
-
<script src="https://cdn.cocreate.app/latest/CoCreate.min.js" ></script>
|
|
39
|
-
|
|
40
|
-
</body>
|
|
41
|
-
</html>
|
package/src/getValue.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import observer from '@cocreate/observer';
|
|
2
|
-
import '@cocreate/element-prototype';
|
|
3
|
-
|
|
4
|
-
// ToDo: actions="getValue", get-value-target, attribute get-value= selector or value compare to event components like toggle
|
|
5
|
-
|
|
6
|
-
const valueEls = new Map();
|
|
7
|
-
|
|
8
|
-
function initGetValues() {
|
|
9
|
-
var elements = document.querySelectorAll('[get-value], [get-value-closest]');
|
|
10
|
-
initElements(elements);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function initElements(elements) {
|
|
14
|
-
for (let element of elements)
|
|
15
|
-
initElement(element);
|
|
16
|
-
for(let valueEl of valueEls.keys())
|
|
17
|
-
setValueByFind(valueEl);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function initElement(element, mutation) {
|
|
21
|
-
let selector = element.getAttribute('get-value') || element.getAttribute('get-value-closest');
|
|
22
|
-
if (!selector) return;
|
|
23
|
-
if (/{{\s*([\w\W]+)\s*}}/g.test(selector)) return;
|
|
24
|
-
|
|
25
|
-
let valueEl
|
|
26
|
-
if (element.hasAttribute('get-value-closest'))
|
|
27
|
-
valueEl = element.closest(selector);
|
|
28
|
-
else
|
|
29
|
-
valueEl = document.querySelector(selector);
|
|
30
|
-
if (!valueEl) return;
|
|
31
|
-
|
|
32
|
-
initEvents(valueEl, element, mutation);
|
|
33
|
-
|
|
34
|
-
element.dispatchEvent(new Event("input", {
|
|
35
|
-
"bubbles": true
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function initEvents(valueEl, element, mutation){
|
|
41
|
-
if (!valueEls.has(valueEl)) {
|
|
42
|
-
valueEls.set(valueEl, [element]);
|
|
43
|
-
|
|
44
|
-
valueEl.addEventListener('input', (e) => {
|
|
45
|
-
setValueByFind(e.target);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
49
|
-
setValueByFind(e.target);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else
|
|
53
|
-
valueEls.get(valueEl).push(element);
|
|
54
|
-
|
|
55
|
-
// ToDo: check to see if creates any loops or un wanted save by input event
|
|
56
|
-
if (mutation)
|
|
57
|
-
mutation = [element]
|
|
58
|
-
setValueByFind(valueEl, mutation)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function setValueByFind(valueEl, mutation) {
|
|
62
|
-
let value = valueEl.getValue();
|
|
63
|
-
if (!value) return;
|
|
64
|
-
|
|
65
|
-
let elements = mutation || valueEls.get(valueEl);
|
|
66
|
-
if (elements) {
|
|
67
|
-
for(let element of elements){
|
|
68
|
-
let key = element.getAttribute('get-value-key');
|
|
69
|
-
if (key){
|
|
70
|
-
key = `{{${key}}}`;
|
|
71
|
-
const regex = new RegExp(key, "g");
|
|
72
|
-
for (let attribute of element.attributes){
|
|
73
|
-
let attrName = attribute.name;
|
|
74
|
-
let attrValue = attribute.value;
|
|
75
|
-
let setAttr = false;
|
|
76
|
-
if (attrValue.includes(key)){
|
|
77
|
-
attrValue = attrValue.replace(regex, value);
|
|
78
|
-
setAttr = true;
|
|
79
|
-
}
|
|
80
|
-
if (attrName.includes(key)){
|
|
81
|
-
element.removeAttribute(key);
|
|
82
|
-
attrName = attrName.replace(regex, value);
|
|
83
|
-
setAttr = true;
|
|
84
|
-
}
|
|
85
|
-
if (setAttr)
|
|
86
|
-
element.setAttribute(attrName, attrValue);
|
|
87
|
-
}
|
|
88
|
-
let html = element.innerHTML;
|
|
89
|
-
if (html.indexOf(key) !== -1){
|
|
90
|
-
html = html.replace(regex, value);
|
|
91
|
-
element.innerHTML = html;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else
|
|
95
|
-
element.setValue(value);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
observer.init({
|
|
101
|
-
name: 'get-value',
|
|
102
|
-
observe: ['addedNodes'],
|
|
103
|
-
target: '[get-value], [get-value-closest]',
|
|
104
|
-
callback: function(mutation) {
|
|
105
|
-
initElement(mutation.target, true);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
export { initGetValues };
|
package/src/setValue.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import observer from '@cocreate/observer';
|
|
2
|
-
import crud from '@cocreate/crud-client';
|
|
3
|
-
import { queryDocumentSelectorAll } from '@cocreate/utils';
|
|
4
|
-
import '@cocreate/element-prototype';
|
|
5
|
-
|
|
6
|
-
// ToDo: actions="setValue", set-value-target, attribute set-value= selector or value compare to event components like toggle
|
|
7
|
-
|
|
8
|
-
function initSetValues() {
|
|
9
|
-
var elements = document.querySelectorAll('[set-value], [set-value-closest]');
|
|
10
|
-
initElements(elements);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function initElements(elements) {
|
|
14
|
-
for (let element of elements)
|
|
15
|
-
initElement(element);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function initElement(element) {
|
|
19
|
-
initEvents(element);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function initEvents(element){
|
|
23
|
-
element.addEventListener('input', (e) => {
|
|
24
|
-
setValueByFind(e.target);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
element.addEventListener('updated_by_fetch', (e) => {
|
|
28
|
-
setValueByFind(e.target);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
setValueByFind(element);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const setValueMap = new Map();
|
|
35
|
-
function setValueByFind(element){
|
|
36
|
-
let key = element.getAttribute('set-value-key');
|
|
37
|
-
if (key)
|
|
38
|
-
key = `{{${key}}}`;
|
|
39
|
-
|
|
40
|
-
let value = element.getValue();
|
|
41
|
-
if (!value) return;
|
|
42
|
-
|
|
43
|
-
let selector = element.getAttribute('set-value');
|
|
44
|
-
if (!selector) return;
|
|
45
|
-
let elements;
|
|
46
|
-
if (element.hasAttribute('set-value-closest'))
|
|
47
|
-
elements = [element.closest(selector)];
|
|
48
|
-
else
|
|
49
|
-
elements = queryDocumentSelectorAll(selector);
|
|
50
|
-
|
|
51
|
-
for(let element of elements){
|
|
52
|
-
if (key){
|
|
53
|
-
if (setValueMap.has(element))
|
|
54
|
-
key = setValueMap.get(element);
|
|
55
|
-
const regex = new RegExp(key, "g");
|
|
56
|
-
for (let attribute of element.attributes){
|
|
57
|
-
let attrName = attribute.name;
|
|
58
|
-
let attrValue = attribute.value;
|
|
59
|
-
let setAttr = false;
|
|
60
|
-
if (attrValue.includes(key)){
|
|
61
|
-
attrValue = attrValue.replace(regex, value);
|
|
62
|
-
setAttr = true;
|
|
63
|
-
}
|
|
64
|
-
if (attrName.includes(key)){
|
|
65
|
-
element.removeAttribute(key);
|
|
66
|
-
attrName = attrName.replace(regex, value);
|
|
67
|
-
setAttr = true;
|
|
68
|
-
}
|
|
69
|
-
if (setAttr)
|
|
70
|
-
element.setAttribute(attrName, attrValue);
|
|
71
|
-
}
|
|
72
|
-
let html = element.innerHTML;
|
|
73
|
-
if (html.indexOf(key) !== -1){
|
|
74
|
-
html = html.replace(regex, value);
|
|
75
|
-
element.innerHTML = html;
|
|
76
|
-
}
|
|
77
|
-
setValueMap.set(element, value)
|
|
78
|
-
}
|
|
79
|
-
else
|
|
80
|
-
element.setValue(value);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
observer.init({
|
|
86
|
-
name: 'set-value',
|
|
87
|
-
observe: ['addedNodes'],
|
|
88
|
-
target: '[set-value], [set-value-closest]',
|
|
89
|
-
callback: function(mutation) {
|
|
90
|
-
initElement(mutation.target);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
export { initSetValues };
|