@cocreate/elements 1.3.17 → 1.4.2

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 CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.4.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.1...v1.4.2) (2021-11-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update dependencies ([e097490](https://github.com/CoCreate-app/CoCreate-elements/commit/e0974902933a9bb56903e2ba4ba906072d59f2b6))
7
+
8
+ ## [1.4.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.0...v1.4.1) (2021-11-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * impoved the way checkbox and multiple select is handled. Commented change eventListener ([99b7160](https://github.com/CoCreate-app/CoCreate-elements/commit/99b71600a644eed41461b910e96bb6b053069dfe))
14
+
15
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.18...v1.4.0) (2021-11-21)
16
+
17
+
18
+ ### Features
19
+
20
+ * added attribute get-value to get a value from a target element ([d24b60c](https://github.com/CoCreate-app/CoCreate-elements/commit/d24b60cc7a00d3899311be4bf7ea2fc2c798c4a7))
21
+
22
+ ## [1.3.18](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.17...v1.3.18) (2021-11-20)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * remove cdn.CoCreate.min.css ([ace6aef](https://github.com/CoCreate-app/CoCreate-elements/commit/ace6aef4cf1c6e6cf07ed5ca3b8a8e8ea64780f9))
28
+
1
29
  ## [1.3.17](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.3.16...v1.3.17) (2021-11-20)
2
30
 
3
31
 
package/docs/index.html CHANGED
@@ -14,9 +14,7 @@
14
14
 
15
15
  <!-- CoCreate Favicon -->
16
16
  <link rel="icon" type="image/png" sizes="32x32" href="https://cocreate.app/images/favicon.ico">
17
- <!-- CoCreate CSS CDN -->
18
- <link rel="stylesheet" href="https://cdn.cocreate.app/latest/CoCreate.min.css" type="text/css" />
19
- <link rel="stylesheet" href="https://ws.cocreate.app/docs.css" collection="apples" document_id="6069ff5042ef8ff5175a5c8d" name="css" type="text/css" />
17
+ <link rel="stylesheet" href="/docs/index.css" collection="files" document_id="60888216117c640e7596303f" name="src" type="text/css" save="true" />
20
18
  </head>
21
19
 
22
20
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.3.17",
3
+ "version": "1.4.2",
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,9 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/action": "^1.3.15",
65
- "@cocreate/crud-client": "^1.4.29",
66
- "@cocreate/docs": "^1.2.53",
67
- "@cocreate/observer": "^1.3.45"
64
+ "@cocreate/action": "^1.3.17",
65
+ "@cocreate/crud-client": "^1.4.33",
66
+ "@cocreate/docs": "^1.2.55",
67
+ "@cocreate/observer": "^1.3.47"
68
68
  }
69
69
  }
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};
package/src/index.js CHANGED
@@ -102,8 +102,8 @@ function setData(elements, data) {
102
102
  async function save(element) {
103
103
  let value = getValue(element);
104
104
  let isFlat = false;
105
- if (element.tagName == "INPUT" && element.type === "checkbox" || element.tagName == "SELECT" && element.hasAttribute('multiple'))
106
- isFlat = true;
105
+ // if (element.tagName == "INPUT" && element.type === "checkbox" || element.tagName == "SELECT" && element.hasAttribute('multiple'))
106
+ // isFlat = true;
107
107
  await crud.save(element, value, isFlat);
108
108
  }
109
109
 
@@ -115,7 +115,6 @@ function __initSocket() {
115
115
 
116
116
  function __initEvents(el) {
117
117
  if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' || el.hasAttribute('contenteditable')) {
118
-
119
118
  el.addEventListener('input', function(e) {
120
119
  const {document_id, isRealtime, isCrdt} = crud.getAttr(el);
121
120
  if (isCrdt == "true" && document_id || isRealtime == "false") return;
@@ -123,14 +122,14 @@ function __initEvents(el) {
123
122
  save(el);
124
123
  });
125
124
 
126
- el.addEventListener('change', function(e) {
127
- if (el.tagName == 'SELECT') {
128
- const {isRealtime, isSave, isUpdate} = crud.getAttr(el);
129
- if (isRealtime == "false" || isSave == "false" || isUpdate == "false") return;
130
- if (e.detail && e.detail.skip == true) return;
131
- save(el);
132
- }
133
- });
125
+ // el.addEventListener('change', function(e) {
126
+ // if (el.tagName == 'SELECT') {
127
+ // const {isRealtime, isSave, isUpdate} = crud.getAttr(el);
128
+ // if (isRealtime == "false" || isSave == "false" || isUpdate == "false") return;
129
+ // if (e.detail && e.detail.skip == true) return;
130
+ // save(el);
131
+ // }
132
+ // });
134
133
  }
135
134
  }
136
135