@cocreate/element-prototype 1.22.3 → 1.23.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,16 @@
1
+ # [1.23.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.22.3...v1.23.0) (2024-05-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed utils ([71a5003](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/71a5003bf7ca85b704140e10b132d8728600f518))
7
+
8
+
9
+ ### Features
10
+
11
+ * update attibutes using keyObperators on storage change or event updateAttributes ([5a33bbd](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/5a33bbd90ba6564a8ee9583935e5e0c1663d5d39))
12
+ * valueType boolean ([7f6777f](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/7f6777fb8ab6417d8b920cfbd2135c402423b6d6))
13
+
1
14
  ## [1.22.3](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.22.2...v1.22.3) (2024-04-29)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.22.3",
3
+ "version": "1.23.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",
@@ -57,7 +57,5 @@
57
57
  "webpack-cli": "^4.5.0",
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
- "dependencies": {
61
- "@cocreate/utils": "^1.33.6"
62
- }
60
+ "dependencies": {}
63
61
  }
@@ -1,23 +1,51 @@
1
1
  // Store a reference to the original getAttribute function
2
2
  const originalGetAttribute = Element.prototype.getAttribute;
3
+ const attributes = new Map()
4
+
5
+ window.addEventListener('storage', updateAttributes);
6
+ window.addEventListener('updateAttributes', function (e) {
7
+ updateAttributes(e.detail);
8
+ });
9
+
10
+ function updateAttributes(e) {
11
+ const keys = ['organization_id', 'user_id', 'clientId', 'session_id'];
12
+ if (keys.includes(e.key)) {
13
+ let attr = attributes.get(e.key) || []
14
+ for (let attribute of attr) {
15
+ attribute.element.setAttribute(attribute.name, e.newValue)
16
+ }
17
+ }
18
+ }
3
19
 
4
20
  // Override the getAttribute function
5
21
  Element.prototype.getAttribute = function (name) {
6
22
  let value = originalGetAttribute.call(this, name);
7
23
 
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')
24
+ const localKeys = {
25
+ '$organization_id': 'organization_id',
26
+ '$user_id': 'user_id',
27
+ '$clientId': 'clientId',
28
+ '$session_id': 'session_id'
29
+ };
30
+
31
+ if (localKeys[value]) {
32
+ let newValue = localStorage.getItem(localKeys[value]);
33
+
34
+ if (!attributes.has(localKeys[value])) {
35
+ attributes.set(localKeys[value], []);
36
+ }
37
+
38
+ attributes.get(localKeys[value]).push({
39
+ element: this,
40
+ name,
41
+ value: newValue
42
+ });
43
+ value = newValue
44
+ } else if (value === '$innerWidth') {
17
45
  value = window.innerWidth
18
- else if (value === '$innerHeight')
46
+ } else if (value === '$innerHeight') {
19
47
  value = window.innerHeight
20
- else if (typeof value === 'string') {
48
+ } else if (typeof value === 'string') {
21
49
  if (value.startsWith('$search')) {
22
50
  const searchParams = new URLSearchParams(window.location.search);
23
51
  if (value.includes('.')) {
package/src/getValue.js CHANGED
@@ -146,6 +146,13 @@ const getValue = (element) => {
146
146
  }
147
147
  }
148
148
 
149
+ if (valueType === 'boolean') {
150
+ if (!value || value === 'fasle')
151
+ return false
152
+ else
153
+ return true
154
+ }
155
+
149
156
  if (value === '$organization_id')
150
157
  value = localStorage.getItem('organization_id')
151
158
  else if (value === '$user_id')
package/src/setValue.js CHANGED
@@ -1,4 +1,3 @@
1
- import { getAttributes } from '@cocreate/utils';
2
1
  import { storage } from './getValue';
3
2
 
4
3
  HTMLElement.prototype.setValue = function (value, dispatch) {
@@ -15,6 +14,10 @@ HTMLHeadingElement.prototype.setValue = function (value, dispatch) {
15
14
 
16
15
  // TODO: check if using a a switch case will provide better performance
17
16
  const setValue = (el, value, dispatch) => {
17
+ if (value === '$false') {
18
+ return dispatchEvents(el, dispatch)
19
+ };
20
+
18
21
  if (value === null || value === undefined) return;
19
22
  if (el.hasAttribute('component') || el.hasAttribute('plugin'))
20
23
  return storage.set(el, value)
@@ -36,10 +39,9 @@ const setValue = (el, value, dispatch) => {
36
39
  // TODO: el.options vs rendenring options from src
37
40
  if (el.tagName == 'INPUT' || el.tagName == 'TEXTAREA' || el.tagName == 'SELECT' && el.options.length) {
38
41
  // 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')
42
- if (isCrdt == "true" || el.type === 'file') return;
42
+ let isCrdt = el.getAttribute('crdt')
43
+ if (isCrdt == "true" || el.type === 'file')
44
+ return;
43
45
 
44
46
  if (el.type == 'checkbox') {
45
47
  let inputs = [el]