@cocreate/element-prototype 1.26.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 +33 -0
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/getAttribute.js +44 -68
- package/src/getValue.js +396 -378
- package/src/setValue.js +222 -221
- package/src/utility.js +80 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
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
|
+
|
|
19
|
+
# [1.27.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.26.0...v1.27.0) (2024-11-04)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* pretier.config.js and file formating ([1428fd9](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/1428fd96719f9411d97af5f067a4f95e99a94eed))
|
|
25
|
+
* removed exec returning null ([240543b](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/240543b19eafe8cd2714ee7f81f9edf0c20774bf))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* add prettier.config.js and format files ([0acda3c](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/0acda3c61bd6f832a3544d202a7e59a87ee464d3))
|
|
31
|
+
* loop through regex improved value handling ([3ac5f8d](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/3ac5f8dfc978cfc25322b5ef927b8df995c0ab50))
|
|
32
|
+
* value-dispatch attribute to dispatch event even if value is null or undefined ([7f2ca4b](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/7f2ca4b18ec668f77895b3d369b379d4420aa046))
|
|
33
|
+
|
|
1
34
|
# [1.26.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.25.0...v1.26.0) (2024-09-21)
|
|
2
35
|
|
|
3
36
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
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",
|
package/src/getAttribute.js
CHANGED
|
@@ -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(
|
|
6
|
-
window.addEventListener(
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|