@cocreate/elements 1.4.10 → 1.6.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 +34 -0
- package/demo/get-value.html +30 -0
- package/demo/input-and-fetch.html +2 -2
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/getValue.js +63 -36
- package/src/index.js +5 -2
- package/src/setValue.js +78 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.5.0...v1.6.0) (2022-01-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* ability to use key as innerHTML ([ca76c3c](https://github.com/CoCreate-app/CoCreate-elements/commit/ca76c3ce1f4f28fc86ec47f808a1f21546159bb3))
|
|
7
|
+
* get-value attribute value now supports a selector added # to all values currently in get-value attributes ([dd4c9e3](https://github.com/CoCreate-app/CoCreate-elements/commit/dd4c9e327029d5bd7774695541c8c46cb05e88fe))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* getValue now has support for get-value-key ([951e027](https://github.com/CoCreate-app/CoCreate-elements/commit/951e02725b5a50852e9e3838a2f16e4cf230ebec))
|
|
13
|
+
|
|
14
|
+
# [1.5.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.12...v1.5.0) (2021-12-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* 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))
|
|
20
|
+
|
|
21
|
+
## [1.4.12](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.11...v1.4.12) (2021-12-24)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* get-value observer typo ([1ab5e84](https://github.com/CoCreate-app/CoCreate-elements/commit/1ab5e84428a680bd0e4a1c62091fd55edf22f69d))
|
|
27
|
+
|
|
28
|
+
## [1.4.11](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.10...v1.4.11) (2021-12-23)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* renamed filter-value_type to filter-value-type ([5ec9280](https://github.com/CoCreate-app/CoCreate-elements/commit/5ec928076ba52fe83f526208091778eb00a81a03))
|
|
34
|
+
|
|
1
35
|
## [1.4.10](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.9...v1.4.10) (2021-12-20)
|
|
2
36
|
|
|
3
37
|
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
<input id="testing" value="new">
|
|
17
|
+
<h1 get-value="#testing" get-value-key="ty" class="{{ty}}" test="{{ty}}">{{ty}}</h1>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<hr/>
|
|
22
|
+
|
|
23
|
+
<input id="testing1" value="new1" />
|
|
24
|
+
<input get-value="#testing1" />
|
|
25
|
+
<input get-value="#testing1" />
|
|
26
|
+
|
|
27
|
+
<!--<script src="../dist/CoCreate-form.js"></script>-->
|
|
28
|
+
<script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -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/docs/index.html
CHANGED
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
<div class="svSplitter svHorizontal"> </div>
|
|
115
115
|
|
|
116
116
|
<div class="svPanel">
|
|
117
|
-
<iframe get-value="demo" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
|
|
117
|
+
<iframe get-value="#demo" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
|
|
118
118
|
</div>
|
|
119
119
|
|
|
120
120
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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,34 +1,32 @@
|
|
|
1
1
|
import observer from '@cocreate/observer';
|
|
2
|
-
import {setValue} from './setValue';
|
|
2
|
+
import { setValue } from './setValue';
|
|
3
|
+
|
|
4
|
+
const valueEls = new Map();
|
|
3
5
|
|
|
4
6
|
function initGetValues() {
|
|
5
7
|
var elements = document.querySelectorAll('[get-value]');
|
|
6
|
-
initElements(elements)
|
|
8
|
+
initElements(elements);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
function initElements(elements) {
|
|
10
12
|
for (let element of elements)
|
|
11
|
-
initElement(element)
|
|
13
|
+
initElement(element);
|
|
14
|
+
for(let valueEl of valueEls.keys())
|
|
15
|
+
setValueByFind(valueEl);
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
function initElement(element) {
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
if(!valueEl) return;
|
|
18
|
-
let value = getValue(valueEl)
|
|
19
|
-
setValue(element, value)
|
|
19
|
+
let selector = element.getAttribute('get-value');
|
|
20
|
+
if(!selector) return;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// valueEl.addEventListener('input', (e) => {
|
|
24
|
-
// setValueByFind(e.target)
|
|
25
|
-
// })
|
|
22
|
+
let valueEl = document.querySelector(selector);
|
|
23
|
+
if(!valueEl) return;
|
|
26
24
|
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
25
|
+
// let value = getValue(valueEl);
|
|
26
|
+
// if (value)
|
|
27
|
+
// setValue(element, value);
|
|
30
28
|
|
|
31
|
-
initEvents(valueEl);
|
|
29
|
+
initEvents(valueEl, element);
|
|
32
30
|
|
|
33
31
|
element.dispatchEvent(new Event("input", {
|
|
34
32
|
"bubbles": true
|
|
@@ -36,28 +34,57 @@ function initElement(element) {
|
|
|
36
34
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
function initEvents(valueEl, element){
|
|
38
|
+
if (!valueEls.has(valueEl))
|
|
39
|
+
valueEls.set(valueEl, [element]);
|
|
40
|
+
else {
|
|
41
|
+
valueEls.get(valueEl).push(element);
|
|
43
42
|
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
|
|
44
43
|
valueEl.addEventListener('input', (e) => {
|
|
45
|
-
setValueByFind(e.target)
|
|
46
|
-
})
|
|
44
|
+
setValueByFind(e.target);
|
|
45
|
+
});
|
|
47
46
|
|
|
48
47
|
valueEl.addEventListener('updated_by_fetch', (e) => {
|
|
49
|
-
setValueByFind(e.target)
|
|
50
|
-
})
|
|
48
|
+
setValueByFind(e.target);
|
|
49
|
+
});
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
function setValueByFind(valueEl){
|
|
55
|
-
let value = getValue(valueEl)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for(let element of elements)
|
|
60
|
-
|
|
53
|
+
function setValueByFind(valueEl) {
|
|
54
|
+
let value = getValue(valueEl);
|
|
55
|
+
if (!value) return;
|
|
56
|
+
let elements = valueEls.get(valueEl);
|
|
57
|
+
|
|
58
|
+
for(let element of elements){
|
|
59
|
+
let key = element.getAttribute('get-value-key');
|
|
60
|
+
if (key){
|
|
61
|
+
key = `{{${key}}}`;
|
|
62
|
+
const regex = new RegExp(key, "g");
|
|
63
|
+
for (let attribute of element.attributes){
|
|
64
|
+
let attrName = attribute.name;
|
|
65
|
+
let attrValue = attribute.value;
|
|
66
|
+
let setAttr = false;
|
|
67
|
+
if (attrValue.includes(key)){
|
|
68
|
+
attrValue = attrValue.replace(regex, value);
|
|
69
|
+
setAttr = true;
|
|
70
|
+
}
|
|
71
|
+
if (attrName.includes(key)){
|
|
72
|
+
element.removeAttribute(key);
|
|
73
|
+
attrName = attrName.replace(regex, value);
|
|
74
|
+
setAttr = true;
|
|
75
|
+
}
|
|
76
|
+
if(setAttr)
|
|
77
|
+
element.setAttribute(attrName, attrValue);
|
|
78
|
+
}
|
|
79
|
+
let html = element.innerHTML;
|
|
80
|
+
if (html.indexOf(key) !== -1){
|
|
81
|
+
html = html.replace(regex, value);
|
|
82
|
+
element.innerHTML = html;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
setValue(element, value);
|
|
87
|
+
}
|
|
61
88
|
}
|
|
62
89
|
|
|
63
90
|
var getValue = (element) => {
|
|
@@ -112,13 +139,13 @@ function __encryptPassword(str) {
|
|
|
112
139
|
}
|
|
113
140
|
|
|
114
141
|
observer.init({
|
|
115
|
-
name: '
|
|
142
|
+
name: 'get-value',
|
|
116
143
|
observe: ['addedNodes'],
|
|
117
144
|
target: '[get-value]',
|
|
118
145
|
callback: function(mutation) {
|
|
119
|
-
|
|
146
|
+
initElement(mutation.target);
|
|
120
147
|
}
|
|
121
148
|
});
|
|
122
149
|
|
|
123
|
-
initGetValues();
|
|
124
|
-
export {getValue};
|
|
150
|
+
// initGetValues();
|
|
151
|
+
export { initGetValues, getValue };
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import observer from '@cocreate/observer';
|
|
2
2
|
import action from '@cocreate/actions';
|
|
3
3
|
import crud from '@cocreate/crud-client';
|
|
4
|
-
import {setValue} from './setValue';
|
|
5
|
-
import {getValue} from './getValue';
|
|
4
|
+
import { initSetValues, setValue } from './setValue';
|
|
5
|
+
import { initGetValues, getValue } from './getValue';
|
|
6
6
|
|
|
7
7
|
const selector = "[collection][document_id][name]:not(cocreate-select, link), input, textarea, select, [contenteditable]";
|
|
8
8
|
|
|
@@ -164,5 +164,8 @@ action.init({
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
init();
|
|
167
|
+
initGetValues();
|
|
168
|
+
initSetValues();
|
|
169
|
+
|
|
167
170
|
|
|
168
171
|
export default {initElements, initElement, save, getValue, setValue};
|
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 = 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;
|
|
@@ -144,4 +212,13 @@ function dispatchEvents(el) {
|
|
|
144
212
|
el.dispatchEvent(changeEvent);
|
|
145
213
|
}
|
|
146
214
|
|
|
147
|
-
|
|
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
|
+
export { initSetValues, setValue };
|