@cocreate/elements 1.5.0 → 1.6.3

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,38 @@
1
+ ## [1.6.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.6.2...v1.6.3) (2022-01-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update class overflow:overlay to overflow:auto ([111577e](https://github.com/CoCreate-app/CoCreate-elements/commit/111577e6c6642a85af1e33b67f0267e6471da4fb))
7
+
8
+ ## [1.6.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.6.1...v1.6.2) (2022-01-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * if crdt = true but document_id is empty save ([cd69a43](https://github.com/CoCreate-app/CoCreate-elements/commit/cd69a434ec33ac7f32ded29f715154f22a1bd4e8))
14
+
15
+ ## [1.6.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.6.0...v1.6.1) (2022-01-02)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add input event listener to valueEl ([ea77493](https://github.com/CoCreate-app/CoCreate-elements/commit/ea77493fed7401b2ccd3d825b73198daf03f836c))
21
+ * check if document_id is a valid id if not return ([220151f](https://github.com/CoCreate-app/CoCreate-elements/commit/220151f9ee0b2c9ff8e4afc06cc24ad5b891b161))
22
+
23
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.5.0...v1.6.0) (2022-01-01)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * ability to use key as innerHTML ([ca76c3c](https://github.com/CoCreate-app/CoCreate-elements/commit/ca76c3ce1f4f28fc86ec47f808a1f21546159bb3))
29
+ * 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))
30
+
31
+
32
+ ### Features
33
+
34
+ * getValue now has support for get-value-key ([951e027](https://github.com/CoCreate-app/CoCreate-elements/commit/951e02725b5a50852e9e3838a2f16e4cf230ebec))
35
+
1
36
  # [1.5.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.4.12...v1.5.0) (2021-12-27)
2
37
 
3
38
 
@@ -0,0 +1,32 @@
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="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>
28
+ <!--<script src="../dist/CoCreate-form.js"></script>-->
29
+ <!--<script src="../../../CoCreateJS/dist/CoCreate.js" ></script>-->
30
+
31
+ </body>
32
+ </html>
@@ -20,7 +20,7 @@
20
20
  <!--<textarea type="text" placeholder="description" name="description"></textarea>-->
21
21
  <!-- <cocreate-select class="floating-label" collection="apples3" name="industry" placeholder="Industry">-->
22
22
  <!-- <input placeholder="Search" template_id="industries">-->
23
- <!--<cc-options fetch-collection="apples3" template_id="industries" class="options overflow:overlay">-->
23
+ <!--<cc-options fetch-collection="apples3" template_id="industries" class="options overflow:auto">-->
24
24
  <!-- <cc-option class="template" template_id="industries" value="{{data._id}}">-->
25
25
  <!-- <h4 collection="apples3" document_id="{{data._id}}" name="name">industry name</h4>-->
26
26
  <!-- </cc-option>-->
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.5.0",
3
+ "version": "1.6.3",
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,35 +1,29 @@
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 id = element.getAttribute('get-value')
16
- let valueEl = document.getElementById(id);
17
- if(!valueEl) return;
18
- let value = getValue(valueEl)
19
- if (value)
20
- setValue(element, value)
21
-
22
- // if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
19
+ let selector = element.getAttribute('get-value');
20
+ if(!selector) return;
21
+ if(/{{\s*([\w\W]+)\s*}}/g.test(selector)) return;
23
22
 
24
- // valueEl.addEventListener('input', (e) => {
25
- // setValueByFind(e.target)
26
- // })
27
-
28
- // valueEl.addEventListener('updated_by_fetch', (e) => {
29
- // setValueByFind(e.target)
30
- // })
31
-
32
- initEvents(valueEl);
23
+ let valueEl = document.querySelector(selector);
24
+ if(!valueEl) return;
25
+
26
+ initEvents(valueEl, element);
33
27
 
34
28
  element.dispatchEvent(new Event("input", {
35
29
  "bubbles": true
@@ -37,28 +31,57 @@ function initElement(element) {
37
31
 
38
32
  }
39
33
 
40
- const valueEls = new Map();
41
- function initEvents(valueEl){
34
+ function initEvents(valueEl, element){
42
35
  if (!valueEls.has(valueEl)) {
43
- valueEls.set(valueEl);
36
+ valueEls.set(valueEl, [element]);
44
37
  if (['INPUT', 'TEXTAREA', 'SELECT'].includes(valueEl.tagName) || valueEl.contentEditable)
45
38
  valueEl.addEventListener('input', (e) => {
46
- setValueByFind(e.target)
47
- })
39
+ setValueByFind(e.target);
40
+ });
48
41
 
49
42
  valueEl.addEventListener('updated_by_fetch', (e) => {
50
- setValueByFind(e.target)
51
- })
43
+ setValueByFind(e.target);
44
+ });
52
45
  }
46
+ else
47
+ valueEls.get(valueEl).push(element);
53
48
  }
54
49
 
55
- function setValueByFind(valueEl){
56
- let value = getValue(valueEl)
57
- let id = valueEl.getAttribute('id')
58
- if(!id) return;
59
- var elements = document.querySelectorAll('[get-value="' + id + '"]');
60
- for(let element of elements)
61
- setValue(element, value)
50
+ function setValueByFind(valueEl) {
51
+ let value = getValue(valueEl);
52
+ if (!value) return;
53
+ let elements = valueEls.get(valueEl);
54
+
55
+ for(let element of elements){
56
+ let key = element.getAttribute('get-value-key');
57
+ if (key){
58
+ key = `{{${key}}}`;
59
+ const regex = new RegExp(key, "g");
60
+ for (let attribute of element.attributes){
61
+ let attrName = attribute.name;
62
+ let attrValue = attribute.value;
63
+ let setAttr = false;
64
+ if (attrValue.includes(key)){
65
+ attrValue = attrValue.replace(regex, value);
66
+ setAttr = true;
67
+ }
68
+ if (attrName.includes(key)){
69
+ element.removeAttribute(key);
70
+ attrName = attrName.replace(regex, value);
71
+ setAttr = true;
72
+ }
73
+ if(setAttr)
74
+ element.setAttribute(attrName, attrValue);
75
+ }
76
+ let html = element.innerHTML;
77
+ if (html.indexOf(key) !== -1){
78
+ html = html.replace(regex, value);
79
+ element.innerHTML = html;
80
+ }
81
+ }
82
+ else
83
+ setValue(element, value);
84
+ }
62
85
  }
63
86
 
64
87
  var getValue = (element) => {
@@ -121,5 +144,4 @@ observer.init({
121
144
  }
122
145
  });
123
146
 
124
- initGetValues();
125
- export {getValue};
147
+ 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
 
@@ -39,10 +39,11 @@ function initElement(el) {
39
39
  if (el.closest('.template')) return;
40
40
 
41
41
  const { collection, document_id, name, isRead } = crud.getAttr(el);
42
+ __initEvents(el);
42
43
  if (!collection || !name) return;
44
+ if (!document_id.match(/^[0-9a-fA-F]{24}$/)) return;
43
45
  if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(name)) return;
44
46
 
45
- __initEvents(el);
46
47
  if (isRead == 'false') return;
47
48
  return {collection, document_id};
48
49
  }
@@ -118,7 +119,7 @@ function __initEvents(el) {
118
119
  el.addEventListener('input', function(e) {
119
120
  const {document_id, isRealtime, isCrdt} = crud.getAttr(el);
120
121
  if (isCrdt == "true" && document_id || isRealtime == "false") return;
121
- if (e.detail && e.detail.skip == true) return;
122
+ if (document_id && e.detail && e.detail.skip == true) return;
122
123
  save(el);
123
124
  });
124
125
 
@@ -164,5 +165,8 @@ action.init({
164
165
  });
165
166
 
166
167
  init();
168
+ initGetValues();
169
+ initSetValues();
170
+
167
171
 
168
172
  export default {initElements, initElement, save, getValue, setValue};
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 {getValue} from './getValue';
3
+ import { getValue } from './getValue';
4
4
 
5
5
  function initSetValues() {
6
6
  var elements = document.querySelectorAll('[set-value]');
@@ -58,7 +58,7 @@ function setValueByFind(element){
58
58
  }
59
59
  let html = element.innerHTML;
60
60
  if (html.indexOf(key) !== -1){
61
- html.replace(regex, value);
61
+ html = html.replace(regex, value);
62
62
  element.innerHTML = html;
63
63
  }
64
64
  }
@@ -221,7 +221,4 @@ observer.init({
221
221
  }
222
222
  });
223
223
 
224
-
225
- initSetValues();
226
-
227
- export {setValue};
224
+ export { initSetValues, setValue };