@cocreate/elements 1.11.1 → 1.12.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.12.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.11.1...v1.12.0) (2022-08-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * add getValue() and setValue() to HTMLElement.prototype ([1fde509](https://github.com/CoCreate-app/CoCreate-elements/commit/1fde50918b279bb49103bf7bea1f24861615a0a9))
7
+
1
8
  ## [1.11.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.11.0...v1.11.1) (2022-08-01)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.11.1",
3
+ "version": "1.12.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",
@@ -1,51 +1,30 @@
1
- let v = el.getValue()
1
+ import { setValue } from './setValue';
2
+ import { getValue } from './getValue';
2
3
 
3
- HTMLElement.prototype.getValue = function() {
4
- this.style.display = 'none';
5
- };
6
-
7
- HTMLInputElement.prototype.getValue = function() {
8
- let value = this.value;
4
+ HTMLElement.prototype.getValue = function() {
5
+ let value = getValue(this)
6
+ return value;
7
+ };
9
8
 
10
- let prefix = this.getAttribute('value-prefix') || "";
11
- let suffix = this.getAttribute('value-suffix') || "";
9
+ HTMLElement.prototype.setValue = function(value) {
10
+ setValue(this, value)
11
+ };
12
12
 
13
- if (this.type === "checkbox") {
14
- let el_name = this.getAttribute('name');
15
- let checkboxs = document.querySelectorAll(`input[type=checkbox][name='${el_name}']`);
16
- if (checkboxs.length > 1) {
17
- value = [];
18
- checkboxs.forEach(el => {
19
- if (el.checked) value.push(el.value);
20
- });
21
- }
22
- else {
23
- value = this.checked;
24
- }
25
- }
26
- else if (this.type === "number") {
27
- value = Number(value);
28
- }
29
- else if (this.type === "password") {
30
- value = this.__encryptPassword(value);
31
- }
13
+ HTMLInputElement.prototype.getValue = function() {
14
+ let value = getValue(this)
15
+ return value;
16
+ };
32
17
 
33
- if (typeof value == "string") {
34
- value = prefix + value + suffix;
35
- }
18
+ HTMLInputElement.prototype.setValue = function(value) {
19
+ setValue(this, value)
20
+ };
36
21
 
37
- if (this.tagName == "SELECT" && this.hasAttribute('multiple')) {
38
- let options = this.selectedOptions;
39
- value = [];
40
- for (let i = 0; i < options.length; i++) {
41
- value.push(options[i].value);
42
- }
43
- }
22
+ HTMLHeadingElement.prototype.getValue = function() {
23
+ let value = getValue(this)
24
+ return value;
25
+ };
26
+
27
+ HTMLHeadingElement.prototype.setValue = function(value) {
28
+ setValue(this, value)
29
+ };
44
30
 
45
- return value;
46
- };
47
-
48
- HTMLHeadingElement.prototype.getValue = function() {
49
- this.style.display = 'none';
50
- };
51
-
package/src/getValue.js CHANGED
@@ -62,7 +62,7 @@ function setValueByFind(valueEl, mutation) {
62
62
  if (valueEl.hasAttribute('value'))
63
63
  value = valueEl.getAttribute('value');
64
64
  else if(valueEl.getValue)
65
- value = valueEl.getValue(valueEl);
65
+ value = valueEl.getValue();
66
66
  else
67
67
  value = getValue(valueEl);
68
68
  if (!value) return;
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ import crud from '@cocreate/crud-client';
4
4
  import { initSetValues, setValue } from './setValue';
5
5
  import { initGetValues, getValue } from './getValue';
6
6
  import './fetchSrc';
7
+ import './HTMLElement';
7
8
 
8
9
  const selector = "[collection][document_id][name]:not(cocreate-select, link), input, textarea, select, [contenteditable]";
9
10
  const initializing = new Map();
@@ -33,11 +34,6 @@ function initElements(elements) {
33
34
  }
34
35
 
35
36
  function initElement(el) {
36
- if (el.tagName != 'DIV' || el.classList.contains('domEditor') || el.hasAttribute('contenteditable')){
37
- el.getValue = getValue;
38
- el.setValue = setValue;
39
- }
40
-
41
37
  __initEvents(el);
42
38
 
43
39
  if (el.closest('.template')) return;
@@ -97,7 +93,7 @@ function setData(elements, data) {
97
93
  } else
98
94
  value = crud.getObjectValueByPath(data.data, name);
99
95
 
100
- setValue(el, value);
96
+ el.setValue(value);
101
97
 
102
98
  isRendered = true;
103
99
  }
package/src/setValue.js CHANGED
@@ -36,7 +36,7 @@ function setValueByFind(element){
36
36
 
37
37
  let value
38
38
  if(element.getValue)
39
- value = element.getValue(element);
39
+ value = element.getValue();
40
40
  if (!value) return;
41
41
 
42
42
  let selector = element.getAttribute('set-value');