@cocreate/elements 1.7.4 → 1.8.1

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,25 @@
1
+ ## [1.8.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.0...v1.8.1) (2022-06-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update dependencies ([0424726](https://github.com/CoCreate-app/CoCreate-elements/commit/04247260f353cabc2e2e8b2049bd5194a7730397))
7
+ * update docs css document_id ([7565dff](https://github.com/CoCreate-app/CoCreate-elements/commit/7565dffe43ea3b78714f5ebcec1fbd4aa33d1a81))
8
+
9
+ # [1.8.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.7.5...v1.8.0) (2022-06-04)
10
+
11
+
12
+ ### Features
13
+
14
+ * supports adding src attribute to any element to fetch the file and render the results in the element ([0507159](https://github.com/CoCreate-app/CoCreate-elements/commit/0507159aa0a9311a2bbc7fd89e17b20d39d7622c))
15
+
16
+ ## [1.7.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.7.4...v1.7.5) (2022-06-02)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * add element to map to reduce repetitive reads. ([8d4e2e9](https://github.com/CoCreate-app/CoCreate-elements/commit/8d4e2e9d1c2a544e2eef8b72fbfe97a62bd7452f))
22
+
1
23
  ## [1.7.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.7.3...v1.7.4) (2022-05-23)
2
24
 
3
25
 
package/docs/index.html CHANGED
@@ -14,7 +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
- <link rel="stylesheet" href="/docs/index.css" collection="files" document_id="62827d7e8082ce05b081430b" name="src" type="text/css" save="true" />
17
+ <link rel="stylesheet" href="/docs/index.css" collection="files" document_id="60888216117c640e7596303f" name="src" type="text/css" save="true" />
18
18
  </head>
19
19
 
20
20
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.7.4",
3
+ "version": "1.8.1",
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/actions": "^1.4.1",
65
- "@cocreate/crud-client": "^1.6.2",
66
- "@cocreate/docs": "^1.3.1",
67
- "@cocreate/observer": "^1.5.1"
64
+ "@cocreate/actions": "^1.4.2",
65
+ "@cocreate/crud-client": "^1.7.0",
66
+ "@cocreate/docs": "^1.3.2",
67
+ "@cocreate/observer": "^1.5.2"
68
68
  }
69
69
  }
@@ -0,0 +1,56 @@
1
+ import observer from '@cocreate/observer';
2
+
3
+ const selector = '[src]:not(img, video, script, input, iframe, frame)'
4
+ const initializing = new Map();
5
+
6
+
7
+ function init() {
8
+ var elements = document.querySelectorAll(selector);
9
+ initElements(elements);
10
+ };
11
+
12
+ function initElements(elements) {
13
+ for (let element of elements)
14
+ initElement(element);
15
+ };
16
+
17
+ async function initElement(element) {
18
+ let src = element.getAttribute('src');
19
+ let initialize = initializing.get(element)
20
+ if (!initialize || initialize.src != src){
21
+ initializing.set(element, {src});
22
+ if (src)
23
+ try {
24
+ let response = await fetch(src); // Gets a promise
25
+ let text = await response.text(); // Replaces body with response
26
+ if (text){
27
+ element.innerHTML = text; // Replaces body with response
28
+ initializing.delete(el)
29
+ }
30
+ } catch (err) {
31
+ console.log('Fetch error:' + err); // Error handling
32
+ }
33
+ }
34
+ };
35
+
36
+ observer.init({
37
+ name: 'CoCreateSrc',
38
+ observe: ['addedNodes'],
39
+ target: selector,
40
+ callback: function(mutation) {
41
+ initElement(mutation.target);
42
+ }
43
+ });
44
+
45
+ observer.init({
46
+ name: 'CoCreateSrcAttributes',
47
+ observe: ['attributes'],
48
+ attributeName: ['src'],
49
+ target: selector,
50
+ callback: function(mutation) {
51
+ initElement(mutation.target);
52
+ }
53
+ });
54
+
55
+ init()
56
+
package/src/index.js CHANGED
@@ -3,8 +3,10 @@ import action from '@cocreate/actions';
3
3
  import crud from '@cocreate/crud-client';
4
4
  import { initSetValues, setValue } from './setValue';
5
5
  import { initGetValues, getValue } from './getValue';
6
+ import './fetchSrc';
6
7
 
7
8
  const selector = "[collection][document_id][name]:not(cocreate-select, link), input, textarea, select, [contenteditable]";
9
+ const initializing = new Map();
8
10
 
9
11
  function init() {
10
12
  let elements = document.querySelectorAll(selector);
@@ -19,9 +21,14 @@ function initElements(elements) {
19
21
  if (doc) {
20
22
  let collection = doc.collection;
21
23
  let document_id = doc.document_id;
22
- documents.set(`${collection}${document_id}`, {collection, document_id});
24
+ let initialize = initializing.get(element)
25
+ if (!initialize || initialize.collection != collection && initialize.document_id != document_id){
26
+ initializing.set(element, {collection, document_id});
27
+ documents.set(`${collection}${document_id}`, {collection, document_id});
28
+ }
23
29
  }
24
30
  }
31
+
25
32
  read(documents, elements);
26
33
  }
27
34
 
@@ -85,6 +92,8 @@ function setData(elements, data) {
85
92
 
86
93
  isRendered = true;
87
94
  }
95
+ initializing.delete(el)
96
+
88
97
  });
89
98
 
90
99
  if (isRendered) {