@cocreate/elements 1.8.3 → 1.10.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 +22 -0
- package/package.json +6 -5
- package/src/index.js +12 -3
- package/src/setValue.js +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [1.10.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.9.0...v1.10.0) (2022-07-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* value-type support and if element name attribute = _id do not save ([164d12f](https://github.com/CoCreate-app/CoCreate-elements/commit/164d12f40a84d85d4114df3b8efe51b9cf6a4e11))
|
|
7
|
+
|
|
8
|
+
# [1.9.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.4...v1.9.0) (2022-07-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* setValue can target element in iframe or parent of iframe using @cocreate/utils queryDocumentSelectorAll ([1447236](https://github.com/CoCreate-app/CoCreate-elements/commit/1447236b86507336a9c3db6452f0760790cabd59))
|
|
14
|
+
* value-type attribute to define if value is an object ([9649b6a](https://github.com/CoCreate-app/CoCreate-elements/commit/9649b6acdbe5e97f5418df5244025a359433891c))
|
|
15
|
+
|
|
16
|
+
## [1.8.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.3...v1.8.4) (2022-06-18)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* bump dependencies ([cbbf0b8](https://github.com/CoCreate-app/CoCreate-elements/commit/cbbf0b8d14e2c8c5c79733ecf5dae4f8e20ad72d))
|
|
22
|
+
|
|
1
23
|
## [1.8.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.2...v1.8.3) (2022-06-16)
|
|
2
24
|
|
|
3
25
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.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",
|
|
@@ -61,9 +61,10 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.4.
|
|
65
|
-
"@cocreate/crud-client": "^1.7.
|
|
66
|
-
"@cocreate/docs": "^1.3.
|
|
67
|
-
"@cocreate/observer": "^1.5.
|
|
64
|
+
"@cocreate/actions": "^1.4.3",
|
|
65
|
+
"@cocreate/crud-client": "^1.7.1",
|
|
66
|
+
"@cocreate/docs": "^1.3.3",
|
|
67
|
+
"@cocreate/observer": "^1.5.3",
|
|
68
|
+
"@cocreate/utils": "^1.8.1"
|
|
68
69
|
}
|
|
69
70
|
}
|
package/src/index.js
CHANGED
|
@@ -89,7 +89,16 @@ function setData(elements, data) {
|
|
|
89
89
|
|
|
90
90
|
// if (data['collection'] == collection && data['document_id'] == document_id && !isEditable) {
|
|
91
91
|
if (data['collection'] == collection && data['document_id'] == document_id) {
|
|
92
|
-
|
|
92
|
+
let value;
|
|
93
|
+
let valueType = el.getAttribute('value-type');
|
|
94
|
+
if(valueType == 'object' || valueType == 'json'){
|
|
95
|
+
// if (name == 'data')
|
|
96
|
+
// value = JSON.stringify(data[name])
|
|
97
|
+
// else
|
|
98
|
+
value = JSON.stringify(data.data[name])
|
|
99
|
+
value = decodeURIComponent(value)
|
|
100
|
+
} else
|
|
101
|
+
value = encodeData[name];
|
|
93
102
|
setValue(el, value);
|
|
94
103
|
|
|
95
104
|
isRendered = true;
|
|
@@ -130,8 +139,8 @@ function __initEvents(el) {
|
|
|
130
139
|
if (!elementEvents.has(el)) {
|
|
131
140
|
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' || el.hasAttribute('contenteditable')) {
|
|
132
141
|
el.addEventListener('input', function(e) {
|
|
133
|
-
const {document_id, isRealtime, isCrdt} = crud.getAttr(el);
|
|
134
|
-
if (isCrdt == "true" && document_id || isRealtime == "false") return;
|
|
142
|
+
const {document_id, name, isRealtime, isCrdt} = crud.getAttr(el);
|
|
143
|
+
if (isCrdt == "true" && document_id || isRealtime == "false" || name == "_id") return;
|
|
135
144
|
if (document_id && e.detail && e.detail.skip == true) return;
|
|
136
145
|
save(el);
|
|
137
146
|
});
|
package/src/setValue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import observer from '@cocreate/observer';
|
|
2
2
|
import crud from '@cocreate/crud-client';
|
|
3
|
-
import {
|
|
3
|
+
import { queryDocumentSelectorAll } from '@cocreate/utils';
|
|
4
4
|
|
|
5
5
|
function initSetValues() {
|
|
6
6
|
var elements = document.querySelectorAll('[set-value]');
|
|
@@ -35,7 +35,7 @@ function setValueByFind(element){
|
|
|
35
35
|
if (!value) return;
|
|
36
36
|
let selector = element.getAttribute('set-value');
|
|
37
37
|
if(!selector) return;
|
|
38
|
-
let elements =
|
|
38
|
+
let elements = queryDocumentSelectorAll(selector);
|
|
39
39
|
|
|
40
40
|
for(let element of elements){
|
|
41
41
|
if (key){
|
|
@@ -73,7 +73,8 @@ function setValueByFind(element){
|
|
|
73
73
|
|
|
74
74
|
var setValue = (el, value) => {
|
|
75
75
|
if (value === null || value === undefined) return;
|
|
76
|
-
|
|
76
|
+
let valueType = el.getAttribute('value-type');
|
|
77
|
+
|
|
77
78
|
if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT') {
|
|
78
79
|
const {isCrdt} = crud.getAttr(el);
|
|
79
80
|
if (isCrdt == "true" || el.type === 'file') return;
|
|
@@ -130,7 +131,10 @@ var setValue = (el, value) => {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
else {
|
|
133
|
-
|
|
134
|
+
if (valueType == 'string' || valueType == 'text')
|
|
135
|
+
el.textContent = value;
|
|
136
|
+
else
|
|
137
|
+
el.innerHTML = value;
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
}
|
|
@@ -140,8 +144,10 @@ var setValue = (el, value) => {
|
|
|
140
144
|
}
|
|
141
145
|
else {
|
|
142
146
|
if (el.hasAttribute('contenteditable') && el == document.activeElement) return;
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
if (valueType == 'string' || valueType == 'text')
|
|
148
|
+
el.textContent = value;
|
|
149
|
+
else
|
|
150
|
+
el.innerHTML = value;
|
|
145
151
|
if (el.hasAttribute("value")) {
|
|
146
152
|
el.setAttribute("value", value);
|
|
147
153
|
}
|