@cocreate/local-storage 1.6.9 → 1.7.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/index.js +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.6.10...v1.7.0) (2023-05-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* applied getValue and setValue ([d196bc2](https://github.com/CoCreate-app/CoCreate-local-storage/commit/d196bc2880e62c8822745e66a3dde6dce7f86a49))
|
|
7
|
+
|
|
8
|
+
## [1.6.10](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.6.9...v1.6.10) (2023-05-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* storage eventlistener typo ([6b638e6](https://github.com/CoCreate-app/CoCreate-local-storage/commit/6b638e6953a740d0a340625af73c800aff11dac6))
|
|
14
|
+
|
|
1
15
|
## [1.6.9](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.6.8...v1.6.9) (2023-05-06)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/local-storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A Simple component similar to CoCreate-input & CoCreate-fetch which Save and fetch data for inputs, textarea, selects from localstorage. Easily configured using HTML5 attributes and/or JavaScript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"local-storage",
|
package/src/index.js
CHANGED
|
@@ -6,14 +6,15 @@ const CoCreateLocalStorage = {
|
|
|
6
6
|
storage: new Map(),
|
|
7
7
|
|
|
8
8
|
init: function() {
|
|
9
|
+
const self = this
|
|
9
10
|
var elements = document.querySelectorAll('[localstorage-set], [localstorage-get]');
|
|
10
11
|
this.initElements(elements)
|
|
11
12
|
window.addEventListener('storage', function(e) {
|
|
12
13
|
elements = document.querySelectorAll(`[localstorage-get="${e.key}"]`)
|
|
13
14
|
for (let element of elements) {
|
|
14
|
-
let value =
|
|
15
|
+
let value = self.getItem(e.key)
|
|
15
16
|
if (value != null){
|
|
16
|
-
element.value
|
|
17
|
+
element.setValue(value)
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
});
|
|
@@ -31,14 +32,15 @@ const CoCreateLocalStorage = {
|
|
|
31
32
|
if (isRealtime == "false") return;
|
|
32
33
|
|
|
33
34
|
let key = e.target.getAttribute('localstorage-set');
|
|
34
|
-
|
|
35
|
+
if (key)
|
|
36
|
+
this.setItem(key, e.target.value);
|
|
35
37
|
|
|
36
38
|
let elements = document.querySelectorAll(`[localstorage-get="${key}"]`)
|
|
37
39
|
for (let el of elements) {
|
|
38
40
|
if (el != element) {
|
|
39
41
|
let value = this.getItem(key)
|
|
40
42
|
if (value != null){
|
|
41
|
-
el.value
|
|
43
|
+
el.setValue(value)
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -74,8 +76,9 @@ const CoCreateLocalStorage = {
|
|
|
74
76
|
let set_els = form.querySelectorAll('[localstorage-set]')
|
|
75
77
|
for (let el of set_els) {
|
|
76
78
|
let key = el.getAttribute('localstorage-set');
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
let value = el.getValue()
|
|
80
|
+
if (value && key){
|
|
81
|
+
this.setItem(key, value);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
let get_els = form.querySelectorAll('[localstorage-get]')
|
|
@@ -84,12 +87,12 @@ const CoCreateLocalStorage = {
|
|
|
84
87
|
if (!key) return;
|
|
85
88
|
let value = this.getItem(key)
|
|
86
89
|
if (value != null){
|
|
87
|
-
el.value
|
|
90
|
+
el.setValue(value)
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
let remove_els = form.querySelectorAll('[localstorage-remove]')
|
|
91
94
|
for (let el of remove_els) {
|
|
92
|
-
el.
|
|
95
|
+
el.setValue('')
|
|
93
96
|
let key = el.getAttribute('localstorage-remove');
|
|
94
97
|
if (key) {
|
|
95
98
|
this.removeItem(key)
|