@cocreate/element-prototype 1.17.0 → 1.19.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 +27 -0
- package/package.json +1 -1
- package/src/getValue.js +82 -5
- package/src/setValue.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
# [1.19.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.18.0...v1.19.0) (2024-01-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* improved input true and false value ([b788abb](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/b788abba4ea09c774af693f89bf6da96a5721665))
|
|
7
|
+
* value must be a string to test for url operators ([de1ed9d](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/de1ed9d64164b08098c34c0ceb5b51918d201f0e))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* handle url search params ([2bc548e](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/2bc548ed1adf74dfa795161e8d7959f79d75482d))
|
|
13
|
+
* special values and regex support ([083d56a](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/083d56a4ab63aa6a8d347770dcfda5ddafedc866))
|
|
14
|
+
|
|
15
|
+
# [1.18.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.17.0...v1.18.0) (2024-01-17)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* handle checkbox value true ([ec73ce0](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/ec73ce0ecfff3a21c2f3b333514ca166ca28a69a))
|
|
21
|
+
* handling checkbox defualt values ([635f262](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/635f2626e7be3117dea6a4603bea45a7d80ba82a))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* if value matches operators $user_id, $organization_id, $clientId will return from localStorage ([e4bb41a](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/e4bb41a47350d97c64677f68f0d28b356e981122))
|
|
27
|
+
|
|
1
28
|
# [1.17.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.16.0...v1.17.0) (2023-12-18)
|
|
2
29
|
|
|
3
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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/getValue.js
CHANGED
|
@@ -17,7 +17,7 @@ HTMLHeadingElement.prototype.getValue = function () {
|
|
|
17
17
|
|
|
18
18
|
// TODO: check if using a a switch case will provide better performance
|
|
19
19
|
const getValue = (element) => {
|
|
20
|
-
let value = element.value || element.getAttribute('value')
|
|
20
|
+
let value = element.value || element.getAttribute('value') || "";
|
|
21
21
|
if (element.hasAttribute('component') || element.hasAttribute('plugin')) {
|
|
22
22
|
value = storage.get(element)
|
|
23
23
|
storage.delete(element)
|
|
@@ -46,10 +46,13 @@ const getValue = (element) => {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
} else {
|
|
49
|
-
if (element.checked)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (element.checked) {
|
|
50
|
+
if (element.hasAttribute('value'))
|
|
51
|
+
value = element.value || true
|
|
52
|
+
else
|
|
53
|
+
value = true
|
|
54
|
+
} else
|
|
55
|
+
value = false
|
|
53
56
|
|
|
54
57
|
}
|
|
55
58
|
} else if (element.type === 'radio') {
|
|
@@ -61,6 +64,11 @@ const getValue = (element) => {
|
|
|
61
64
|
value = [Number(element.min), Number(element.value)];
|
|
62
65
|
} else if (element.type === "password") {
|
|
63
66
|
value = btoa(value || '');
|
|
67
|
+
} else if (element.type === "email") {
|
|
68
|
+
value = value.toLowerCase();
|
|
69
|
+
} else if (element.type === "url") {
|
|
70
|
+
// TODO: define attributes to return url parts
|
|
71
|
+
// return as a string or an object of url parts
|
|
64
72
|
} else if (element.tagName == "SELECT" && element.hasAttribute('multiple')) {
|
|
65
73
|
let options = element.selectedOptions;
|
|
66
74
|
value = [];
|
|
@@ -106,7 +114,76 @@ const getValue = (element) => {
|
|
|
106
114
|
}
|
|
107
115
|
}
|
|
108
116
|
|
|
117
|
+
if (value === '$organization_id')
|
|
118
|
+
value = localStorage.getItem('organization_id')
|
|
119
|
+
else if (value === '$user_id')
|
|
120
|
+
value = localStorage.getItem('user_id')
|
|
121
|
+
else if (value === '$clientId')
|
|
122
|
+
value = localStorage.getItem('clientId')
|
|
123
|
+
else if (value === '$session_id')
|
|
124
|
+
value = localStorage.getItem('session_id')
|
|
125
|
+
else if (typeof value === 'string') {
|
|
126
|
+
if (value.startsWith('$search')) {
|
|
127
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
128
|
+
if (value.includes('.')) {
|
|
129
|
+
value = searchParams.get(value.split('.')[1]);
|
|
130
|
+
} else {
|
|
131
|
+
const paramsObject = {};
|
|
132
|
+
|
|
133
|
+
// Iterate over all key-value pairs and add them to the object
|
|
134
|
+
for (const [key, value] of searchParams) {
|
|
135
|
+
paramsObject[key] = value;
|
|
136
|
+
}
|
|
137
|
+
value = paramsObject
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} else if ([
|
|
141
|
+
'$href',
|
|
142
|
+
'$origin',
|
|
143
|
+
'$protocol',
|
|
144
|
+
'$host',
|
|
145
|
+
'$hostname',
|
|
146
|
+
'$port',
|
|
147
|
+
'$pathname',
|
|
148
|
+
'$hash'
|
|
149
|
+
].includes(value)) {
|
|
150
|
+
value = window.location[value.substring(1)]
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let replace = element.getAttribute('value-replace');
|
|
155
|
+
let replaceAll = element.getAttribute('value-replaceall');
|
|
156
|
+
|
|
157
|
+
if (replace || replaceAll) {
|
|
158
|
+
let replaceWith = element.getAttribute('value-replace-with') || "";
|
|
159
|
+
let replaceRegex = element.getAttribute('value-replace-regex');
|
|
160
|
+
|
|
161
|
+
if (replaceRegex) {
|
|
162
|
+
try {
|
|
163
|
+
if (replace)
|
|
164
|
+
value = value.replace(replaceRegex, replaceWith);
|
|
165
|
+
else
|
|
166
|
+
value = value.replaceAll(replaceRegex, replaceWith);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error('getValue() Regex error:', error, element);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (replace)
|
|
172
|
+
value = value.replace(replace, replaceWith);
|
|
173
|
+
else
|
|
174
|
+
value = value.replaceAll(replaceAll, replaceWith);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let lowercase = element.getAttribute('value-lowercase')
|
|
179
|
+
if (lowercase || lowercase === '')
|
|
180
|
+
value = value.toLowerCase()
|
|
181
|
+
let uppercase = element.getAttribute('value-uppercase');
|
|
182
|
+
if (uppercase || uppercase === '')
|
|
183
|
+
value = value.toUpperCase()
|
|
184
|
+
|
|
109
185
|
return value;
|
|
186
|
+
|
|
110
187
|
};
|
|
111
188
|
|
|
112
189
|
export { getValue, storage };
|
package/src/setValue.js
CHANGED
|
@@ -47,7 +47,9 @@ const setValue = (el, value, dispatch) => {
|
|
|
47
47
|
|
|
48
48
|
for (let i = 0; i < inputs.length; i++) {
|
|
49
49
|
if (inputs[i].value) {
|
|
50
|
-
if (value
|
|
50
|
+
if (value === true || value === false)
|
|
51
|
+
inputs[i].checked = value;
|
|
52
|
+
else if (value.includes(inputs[i].value))
|
|
51
53
|
inputs[i].checked = true;
|
|
52
54
|
else
|
|
53
55
|
inputs[i].checked = false;
|