@cocreate/element-prototype 1.27.0 → 1.28.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,21 @@
1
+ # [1.28.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.27.0...v1.28.0) (2024-12-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * comment test regex ([bde8534](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/bde8534e9306b43cc48fc93b0fee88dd06370d8c))
7
+ * dat yype inputs set to empty string if value does not exist ([14069f9](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/14069f973b9b112674ad6d4d6ed2f0da8110e3ca))
8
+ * dynamically generate regex ([afb8c89](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/afb8c89df4882f1b5a1c4994c208693c69c3e1f8))
9
+ * handling type="checkbox" ([e567ff5](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/e567ff5fcffed1b77a58630248d0c886f3371edf))
10
+ * if dispatchEvent dispatch if value empty or oldValue = newValue ([66cc576](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/66cc576ca6aa0754b16d3e7024f42af2f0076da7))
11
+ * removed redundant prtotype, HTMLElement can handle all elements ([876d2c0](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/876d2c08850b0b4ef8f33fa6ab8da893f5786e82))
12
+
13
+
14
+ ### Features
15
+
16
+ * attribute value-bubbles to define whether input event bubbles on element value is set on ([93a9d0e](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/93a9d0eff64f213d2f59a31d8db227cc13ed9548))
17
+ * utility to handle operators accross all prototypes ([7eb7a5e](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/7eb7a5e69fcacfc1f385fb4262252d97a89194f8))
18
+
1
19
  # [1.27.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.26.0...v1.27.0) (2024-11-04)
2
20
 
3
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.27.0",
3
+ "version": "1.28.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",
@@ -1,79 +1,55 @@
1
+ import utility from "./utility";
2
+
1
3
  // Store a reference to the original getAttribute function
2
4
  const originalGetAttribute = Element.prototype.getAttribute;
3
- const attributes = new Map()
5
+ const attributes = new Map();
4
6
 
5
- window.addEventListener('storage', updateAttributes);
6
- window.addEventListener('updateAttributes', function (e) {
7
- updateAttributes(e.detail);
7
+ window.addEventListener("storage", updateAttributes);
8
+ window.addEventListener("updateAttributes", function (e) {
9
+ updateAttributes(e.detail);
8
10
  });
9
11
 
10
12
  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
- }
13
+ const keys = ["organization_id", "user_id", "clientId", "session_id"];
14
+ if (keys.includes(e.key)) {
15
+ let attr = attributes.get(e.key) || [];
16
+ for (let attribute of attr) {
17
+ attribute.element.setAttribute(attribute.name, e.newValue);
18
+ }
19
+ }
18
20
  }
19
21
 
20
22
  // Override the getAttribute function
21
23
  Element.prototype.getAttribute = function (name) {
22
- let value = originalGetAttribute.call(this, name);
23
-
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.hasOwnProperty(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') {
45
- value = window.innerWidth
46
- } else if (value === '$innerHeight') {
47
- value = window.innerHeight
48
- } else if (typeof value === 'string') {
49
- if (value.startsWith('$search')) {
50
- const searchParams = new URLSearchParams(window.location.search);
51
- if (value.includes('.')) {
52
- value = searchParams.get(value.split('.')[1]);
53
- } else {
54
- const paramsObject = {};
55
-
56
- // Iterate over all key-value pairs and add them to the object
57
- for (const [key, value] of searchParams) {
58
- paramsObject[key] = value;
59
- }
60
- value = paramsObject
61
- }
62
-
63
- } else if ([
64
- '$href',
65
- '$origin',
66
- '$protocol',
67
- '$host',
68
- '$hostname',
69
- '$port',
70
- '$pathname',
71
- '$hash'
72
- ].includes(value)) {
73
- value = window.location[value.substring(1)]
74
- }
75
- }
76
-
77
- return value;
24
+ let value = originalGetAttribute.call(this, name);
25
+
26
+ const localKeys = {
27
+ $organization_id: "organization_id",
28
+ $user_id: "user_id",
29
+ $clientId: "clientId",
30
+ $session_id: "session_id"
31
+ };
32
+
33
+ if (localKeys.hasOwnProperty(value)) {
34
+ let newValue = localStorage.getItem(localKeys[value]);
35
+
36
+ if (!attributes.has(localKeys[value])) {
37
+ attributes.set(localKeys[value], []);
38
+ }
39
+
40
+ attributes.get(localKeys[value]).push({
41
+ element: this,
42
+ name,
43
+ value: newValue
44
+ });
45
+ value = newValue;
46
+ } else if (value === "$innerWidth") {
47
+ value = window.innerWidth;
48
+ } else if (value === "$innerHeight") {
49
+ value = window.innerHeight;
50
+ } else if (typeof value === "string" && value.includes("$")) {
51
+ value = utility.urlOperators(value);
52
+ }
53
+
54
+ return value;
78
55
  };
79
-