@cocreate/element-prototype 1.20.1 → 1.22.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,22 @@
1
+ # [1.22.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.21.0...v1.22.0) (2024-02-20)
2
+
3
+
4
+ ### Features
5
+
6
+ * $innerWidth and $innerHeight operators ([c731aab](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/c731aab6aa26f8b3abe1b67624a5b98a6eae5aa9))
7
+
8
+ # [1.21.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.20.1...v1.21.0) (2024-02-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * getAttribute crdt ([bea2bfb](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/bea2bfb611e23fbb90249f982502e5208fab57d3))
14
+
15
+
16
+ ### Features
17
+
18
+ * getAttribute prototype to handle operator values ([fa3c83f](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/fa3c83f67ad96961e3e77dabd8d717b1dd57854a))
19
+
1
20
  ## [1.20.1](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.20.0...v1.20.1) (2024-02-05)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.20.1",
3
+ "version": "1.22.0",
4
4
  "description": "A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "element-prototype",
@@ -0,0 +1,51 @@
1
+ // Store a reference to the original getAttribute function
2
+ const originalGetAttribute = Element.prototype.getAttribute;
3
+
4
+ // Override the getAttribute function
5
+ Element.prototype.getAttribute = function (name) {
6
+ let value = originalGetAttribute.call(this, name);
7
+
8
+ if (value === '$organization_id')
9
+ value = localStorage.getItem('organization_id')
10
+ else if (value === '$user_id')
11
+ value = localStorage.getItem('user_id')
12
+ else if (value === '$clientId')
13
+ value = localStorage.getItem('clientId')
14
+ else if (value === '$session_id')
15
+ value = localStorage.getItem('session_id')
16
+ else if (value === '$innerWidth')
17
+ value = window.innerWidth
18
+ else if (value === '$innerHeight')
19
+ value = window.innerHeight
20
+ else if (typeof value === 'string') {
21
+ if (value.startsWith('$search')) {
22
+ const searchParams = new URLSearchParams(window.location.search);
23
+ if (value.includes('.')) {
24
+ value = searchParams.get(value.split('.')[1]);
25
+ } else {
26
+ const paramsObject = {};
27
+
28
+ // Iterate over all key-value pairs and add them to the object
29
+ for (const [key, value] of searchParams) {
30
+ paramsObject[key] = value;
31
+ }
32
+ value = paramsObject
33
+ }
34
+
35
+ } else if ([
36
+ '$href',
37
+ '$origin',
38
+ '$protocol',
39
+ '$host',
40
+ '$hostname',
41
+ '$port',
42
+ '$pathname',
43
+ '$hash'
44
+ ].includes(value)) {
45
+ value = window.location[value.substring(1)]
46
+ }
47
+ }
48
+
49
+ return value;
50
+ };
51
+
package/src/index.js CHANGED
@@ -22,6 +22,6 @@
22
22
 
23
23
  import { setValue } from './setValue';
24
24
  import { getValue } from './getValue';
25
+ import { getAttribute } from './getAttribute';
25
26
 
26
-
27
- export default { getValue, setValue }
27
+ export default { getValue, setValue, getAttribute }
package/src/setValue.js CHANGED
@@ -35,9 +35,10 @@ const setValue = (el, value, dispatch) => {
35
35
 
36
36
  // TODO: el.options vs rendenring options from src
37
37
  if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' && el.options.length) {
38
- let { isCrdt } = getAttributes(el)
39
- if (isCrdt == null || isCrdt == undefined)
40
- isCrdt = el.getAttribute('crdt')
38
+ // TODO: attribute config undefined when used with onload-value
39
+ let isCrdt = el.getAttribute('crdt') // getAttributes(el)
40
+ // if (isCrdt == null || isCrdt == undefined)
41
+ // isCrdt = el.getAttribute('crdt')
41
42
  if (isCrdt == "true" || el.type === 'file') return;
42
43
 
43
44
  if (el.type == 'checkbox') {