@cocreate/element-prototype 1.18.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 +14 -0
- package/package.json +1 -1
- package/src/getValue.js +72 -4
- package/src/setValue.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
1
15
|
# [1.18.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.17.0...v1.18.0) (2024-01-17)
|
|
2
16
|
|
|
3
17
|
|
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)
|
|
@@ -64,6 +64,11 @@ const getValue = (element) => {
|
|
|
64
64
|
value = [Number(element.min), Number(element.value)];
|
|
65
65
|
} else if (element.type === "password") {
|
|
66
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
|
|
67
72
|
} else if (element.tagName == "SELECT" && element.hasAttribute('multiple')) {
|
|
68
73
|
let options = element.selectedOptions;
|
|
69
74
|
value = [];
|
|
@@ -109,13 +114,76 @@ const getValue = (element) => {
|
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
|
|
112
|
-
if (value === '$
|
|
113
|
-
value = localStorage.getItem('user_id')
|
|
114
|
-
else if (value === '$organization_id')
|
|
117
|
+
if (value === '$organization_id')
|
|
115
118
|
value = localStorage.getItem('organization_id')
|
|
119
|
+
else if (value === '$user_id')
|
|
120
|
+
value = localStorage.getItem('user_id')
|
|
116
121
|
else if (value === '$clientId')
|
|
117
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
|
+
|
|
118
185
|
return value;
|
|
186
|
+
|
|
119
187
|
};
|
|
120
188
|
|
|
121
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 === true || 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;
|