@cocreate/elements 1.7.5 → 1.8.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,25 @@
1
+ ## [1.8.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.1...v1.8.2) (2022-06-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * if element has attribute render initEvents before returning ([3730429](https://github.com/CoCreate-app/CoCreate-elements/commit/3730429037c71796936fd6affcda3031f71c65e5))
7
+
8
+ ## [1.8.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.8.0...v1.8.1) (2022-06-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update dependencies ([0424726](https://github.com/CoCreate-app/CoCreate-elements/commit/04247260f353cabc2e2e8b2049bd5194a7730397))
14
+ * update docs css document_id ([7565dff](https://github.com/CoCreate-app/CoCreate-elements/commit/7565dffe43ea3b78714f5ebcec1fbd4aa33d1a81))
15
+
16
+ # [1.8.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.7.5...v1.8.0) (2022-06-04)
17
+
18
+
19
+ ### Features
20
+
21
+ * 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))
22
+
1
23
  ## [1.7.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.7.4...v1.7.5) (2022-06-02)
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.5",
3
+ "version": "1.8.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/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,6 +3,7 @@ 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]";
8
9
  const initializing = new Map();
@@ -36,6 +37,9 @@ function initElement(el) {
36
37
  el.getValue = getValue;
37
38
  el.setValue = setValue;
38
39
  }
40
+
41
+ __initEvents(el);
42
+
39
43
  // if rendered in server side skip
40
44
  if (el.hasAttribute('rendered')) {
41
45
  el.removeAttribute('rendered');
@@ -45,7 +49,6 @@ function initElement(el) {
45
49
  if (el.closest('.template')) return;
46
50
 
47
51
  const { collection, document_id, name, isRead } = crud.getAttr(el);
48
- __initEvents(el);
49
52
  if (!collection || !document_id || !name) return;
50
53
  if (!document_id.match(/^[0-9a-fA-F]{24}$/)) return;
51
54
  if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(name)) return;