@cocreate/local-storage 1.15.1 → 1.16.1
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 +22 -0
- package/docs/index.html +335 -327
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/index.js +242 -229
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.16.1](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.16.0...v1.16.1) (2025-04-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* dispatch end event on action element rather than document ([65da81f](https://github.com/CoCreate-app/CoCreate-local-storage/commit/65da81fa402e24b8233e3a7619022aedbe78e376))
|
|
7
|
+
* update observer observe param to type and and attributeName to attributeFilter ([954a73e](https://github.com/CoCreate-app/CoCreate-local-storage/commit/954a73ea1cf4b3535cf077f8c7262de37a44dbf9))
|
|
8
|
+
|
|
9
|
+
# [1.16.0](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.15.1...v1.16.0) (2024-11-04)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* observer taget has been renamed to selector ([3137770](https://github.com/CoCreate-app/CoCreate-local-storage/commit/3137770eca8bbd8d5c823785379c3064f940fa58))
|
|
15
|
+
* pretier.config.js and file formating ([ce99cca](https://github.com/CoCreate-app/CoCreate-local-storage/commit/ce99ccae6a9a47b508b11383fb6f4d171493edc7))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* add prettier.config.js and format files ([fa22606](https://github.com/CoCreate-app/CoCreate-local-storage/commit/fa22606e069635d78a96564c8f40920738085d79))
|
|
21
|
+
* add prettier.config.js and format files ([45ecc79](https://github.com/CoCreate-app/CoCreate-local-storage/commit/45ecc7928de87acf1c1133418d609c1ca6b1e272))
|
|
22
|
+
|
|
1
23
|
## [1.15.1](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.15.0...v1.15.1) (2024-06-12)
|
|
2
24
|
|
|
3
25
|
|
package/docs/index.html
CHANGED
|
@@ -1,341 +1,349 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<title>CoCreate-local-storage Documentation | CoCreateJS</title>
|
|
8
|
+
<link
|
|
9
|
+
rel="icon"
|
|
10
|
+
type="image/png"
|
|
11
|
+
sizes="32x32"
|
|
12
|
+
href="https://cocreate.app/images/favicon.ico"
|
|
13
|
+
/>
|
|
14
|
+
<meta
|
|
15
|
+
name="description"
|
|
16
|
+
content="Simple component to save and fetch data for inputs, textarea, selects from localstorage. easilly configuable with attributes and/or JavaScript API."
|
|
17
|
+
/>
|
|
18
|
+
<meta
|
|
19
|
+
name="keywords"
|
|
20
|
+
content="helper classes, utility classes, css framework, css library, inline style classes"
|
|
21
|
+
/>
|
|
22
|
+
<meta name="robots" content="index,follow" />
|
|
23
|
+
<meta
|
|
24
|
+
property="og:image"
|
|
25
|
+
content="https://cdn.cocreate.app/docs/local-storage.png"
|
|
26
|
+
/>
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
<!-- CoCreate CSS CDN-->
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
<link
|
|
31
|
+
rel="stylesheet"
|
|
32
|
+
href="https://ws.cocreate.app/docs.css"
|
|
33
|
+
array="apples"
|
|
34
|
+
object="6069ff5042ef8ff5175a5c8d"
|
|
35
|
+
key="css"
|
|
36
|
+
type="text/css"
|
|
37
|
+
/>
|
|
38
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
39
|
+
</head>
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
share-network="share"
|
|
103
|
-
title="Share on share"
|
|
104
|
-
><i src="/assets/svg/share-alt.svg"></i
|
|
105
|
-
></a>
|
|
106
|
-
</div>
|
|
107
|
-
<a
|
|
108
|
-
href="https://github.com/CoCreate-app/CoCreate-local-storage"
|
|
109
|
-
target="_blank"
|
|
110
|
-
class="margin-right:15px"
|
|
111
|
-
><i src="/assets/svg/github.svg"></i
|
|
112
|
-
></a>
|
|
113
|
-
</div>
|
|
41
|
+
<body>
|
|
42
|
+
<!-- Navbar -->
|
|
43
|
+
<nav
|
|
44
|
+
class="width:100% display:flex align-items:center background:transparent padding-top:10px padding-bottom:10px"
|
|
45
|
+
content_id="content"
|
|
46
|
+
scroll="sticky-nav,"
|
|
47
|
+
scroll-up="5"
|
|
48
|
+
scroll-down="5"
|
|
49
|
+
path="../"
|
|
50
|
+
src="../components/navbar.html"
|
|
51
|
+
></nav>
|
|
52
|
+
<sidenav
|
|
53
|
+
id="menuL"
|
|
54
|
+
class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl"
|
|
55
|
+
resizable
|
|
56
|
+
resize-selector="[content_id='content']"
|
|
57
|
+
resize-property="margin-left"
|
|
58
|
+
resize-value="width"
|
|
59
|
+
>
|
|
60
|
+
<menu array="files" object="603717b07de7fb350ae9fec8" key="src"></menu>
|
|
61
|
+
<div resize="right"></div>
|
|
62
|
+
</sidenav>
|
|
63
|
+
<main
|
|
64
|
+
class="padding-top:15px padding:15px@lg@xl"
|
|
65
|
+
content_id="content"
|
|
66
|
+
id="cocreate-local-storage"
|
|
67
|
+
>
|
|
68
|
+
<div
|
|
69
|
+
class="display:flex flex-wrap:wrap justify-content:space-between position:relative margin:10px"
|
|
70
|
+
>
|
|
71
|
+
<div class="display:flex align-items:center">
|
|
72
|
+
<h2>CoCreate-local-storage</h2>
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
class="display:flex align-items:center font-size:20px position:absolute right:0 padding:5px background:white"
|
|
76
|
+
>
|
|
77
|
+
<div
|
|
78
|
+
class="display:flex align-items:center transition:0.3s padding-left:10px"
|
|
79
|
+
share-network="true"
|
|
80
|
+
share-text="Simple component to save and fetch data for inputs, textarea, selects from localstorage. easilly configuable with attributes and/or JavaScript API."
|
|
81
|
+
share-title="CoCreate-local-storage"
|
|
82
|
+
share-height="600"
|
|
83
|
+
share-width="700"
|
|
84
|
+
share-media="https://cdn.cocreate.app/docs/local-storage.png"
|
|
85
|
+
hover="display:block!important"
|
|
86
|
+
hover-selector=".social-networks"
|
|
87
|
+
>
|
|
88
|
+
<div class="display:none social-networks">
|
|
89
|
+
<a
|
|
90
|
+
class="margin-right:15px"
|
|
91
|
+
share-network="twitter"
|
|
92
|
+
title="Share on twitter"
|
|
93
|
+
><i src="/assets/svg/twitter.svg"></i
|
|
94
|
+
></a>
|
|
95
|
+
<a
|
|
96
|
+
class="margin-right:15px"
|
|
97
|
+
share-network="facebook"
|
|
98
|
+
title="Share on Facebook"
|
|
99
|
+
><i src="/assets/svg/facebook.svg"></i
|
|
100
|
+
></a>
|
|
101
|
+
<a
|
|
102
|
+
class="margin-right:15px"
|
|
103
|
+
share-network="instagram"
|
|
104
|
+
title="Share on instagram"
|
|
105
|
+
><i src="/assets/svg/instagram.svg"></i
|
|
106
|
+
></a>
|
|
114
107
|
</div>
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
108
|
+
<a
|
|
109
|
+
class="margin-right:15px"
|
|
110
|
+
share-network="share"
|
|
111
|
+
title="Share on share"
|
|
112
|
+
><i src="/assets/svg/share-alt.svg"></i
|
|
113
|
+
></a>
|
|
114
|
+
</div>
|
|
115
|
+
<a
|
|
116
|
+
href="https://github.com/CoCreate-app/CoCreate-local-storage"
|
|
117
|
+
target="_blank"
|
|
118
|
+
class="margin-right:15px"
|
|
119
|
+
><i src="/assets/svg/github.svg"></i
|
|
120
|
+
></a>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
<h1
|
|
124
|
+
class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100"
|
|
125
|
+
>
|
|
126
|
+
A Simple component similar to CoCreate-input & CoCreate-fetch which
|
|
127
|
+
Save and fetch data for inputs, textarea, selects from localstorage.
|
|
128
|
+
Easily configured using HTML5 attributes and/or JavaScript API
|
|
129
|
+
</h1>
|
|
130
|
+
<div id="local-storage-section" class="display:flex flex-wrap:wrap">
|
|
131
|
+
<div
|
|
132
|
+
class="flex-grow:1 width:400px width:300px@xs padding:0px_10px margin-top:60px"
|
|
133
|
+
>
|
|
134
|
+
<div
|
|
135
|
+
id="local-storage-install"
|
|
136
|
+
class="border-bottom:1px_solid_lightgrey"
|
|
137
|
+
scroll
|
|
138
|
+
scroll-intersect="color:dodgerblue"
|
|
139
|
+
scroll-selector="#local-storage-install-section"
|
|
140
|
+
>
|
|
141
|
+
<span
|
|
142
|
+
class="display:flex align-items:center width:fit-content"
|
|
143
|
+
hover="display:block!important"
|
|
144
|
+
hover-selector="[href='#local-storage-install']"
|
|
145
|
+
>
|
|
146
|
+
<h2 class="padding:5px_0px">Install</h2>
|
|
147
|
+
<a
|
|
148
|
+
class="margin-left:10px display:none"
|
|
149
|
+
href="#local-storage-install"
|
|
150
|
+
><i src="/assets/svg/link.svg"></i
|
|
151
|
+
></a>
|
|
152
|
+
</span>
|
|
153
|
+
</div>
|
|
154
|
+
<pre><code class="language-bash">npm i @cocreate/local-storage</code></pre>
|
|
155
|
+
<p class="padding:10px_0px line-height:1.5">
|
|
156
|
+
Or you can use cdn link:
|
|
157
|
+
</p>
|
|
158
|
+
<pre><code class="language-html"><script>https://cdn.cocreate.app/local-storage/latest/CoCreate-local-storage.min.js</script></code></pre>
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
<div
|
|
161
|
+
id="local-storage-usage"
|
|
162
|
+
class="margin-top:80px border-bottom:1px_solid_lightgrey"
|
|
163
|
+
scroll
|
|
164
|
+
scroll-intersect="color:dodgerblue"
|
|
165
|
+
scroll-selector="#local-storage-usage-section"
|
|
166
|
+
>
|
|
167
|
+
<span
|
|
168
|
+
class="display:flex align-items:center width:fit-content"
|
|
169
|
+
hover="display:block!important"
|
|
170
|
+
hover-selector="[href='#local-storage-usage']"
|
|
171
|
+
>
|
|
172
|
+
<h2 class="padding:5px_0px">Usage</h2>
|
|
173
|
+
<a
|
|
174
|
+
class="margin-left:10px display:none"
|
|
175
|
+
href="#local-storage-usage"
|
|
176
|
+
><i src="/assets/svg/link.svg"></i
|
|
177
|
+
></a>
|
|
178
|
+
</span>
|
|
179
|
+
</div>
|
|
180
|
+
<div class="">
|
|
181
|
+
<p class="padding:10px_0px line-height:1.5">
|
|
182
|
+
This is local-storage usage
|
|
183
|
+
</p>
|
|
171
184
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
<span class="cocreate-badge warning"
|
|
222
|
-
>optional</span
|
|
223
|
-
>
|
|
224
|
-
</h4>
|
|
225
|
-
<p>local-storage-attribute</p>
|
|
226
|
-
</li>
|
|
227
|
-
</ul>
|
|
228
|
-
</div>
|
|
185
|
+
<div class="flex-grow:1 min-width:300px width:100%">
|
|
186
|
+
<pre><code class="language-html"><div></div></code></pre>
|
|
187
|
+
</div>
|
|
188
|
+
<p class="padding:10px_0px line-height:1.5">
|
|
189
|
+
This is local-storage usage
|
|
190
|
+
</p>
|
|
191
|
+
<p class="padding:10px_0px line-height:1.5">
|
|
192
|
+
This is local-storage usage
|
|
193
|
+
</p>
|
|
194
|
+
</div>
|
|
195
|
+
<div
|
|
196
|
+
id="local-storage-attributes"
|
|
197
|
+
class="margin-top:80px border-bottom:1px_solid_lightgrey"
|
|
198
|
+
scroll
|
|
199
|
+
scroll-intersect="color:dodgerblue"
|
|
200
|
+
scroll-selector="#local-storage-attributes-section"
|
|
201
|
+
>
|
|
202
|
+
<span
|
|
203
|
+
class="display:flex align-items:center width:fit-content"
|
|
204
|
+
hover="display:block!important"
|
|
205
|
+
hover-selector="[href='#local-storage-attributes']"
|
|
206
|
+
>
|
|
207
|
+
<h2 class="padding:5px_0px">Attributes</h2>
|
|
208
|
+
<a
|
|
209
|
+
class="margin-left:10px display:none"
|
|
210
|
+
href="#local-storage-attributes"
|
|
211
|
+
><i src="/assets/svg/link.svg"></i
|
|
212
|
+
></a>
|
|
213
|
+
</span>
|
|
214
|
+
</div>
|
|
215
|
+
<ul class="list-style-type:none">
|
|
216
|
+
<li class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
|
217
|
+
<h4>
|
|
218
|
+
<span>local-storage</span>
|
|
219
|
+
<span class="cocreate-badge success">string</span>
|
|
220
|
+
<span class="cocreate-badge warning">optional</span>
|
|
221
|
+
</h4>
|
|
222
|
+
<p>local-storage-attribute</p>
|
|
223
|
+
</li>
|
|
224
|
+
<li class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
|
225
|
+
<h4>
|
|
226
|
+
<span>local-storage</span>
|
|
227
|
+
<span class="cocreate-badge success">string</span>
|
|
228
|
+
<span class="cocreate-badge warning">optional</span>
|
|
229
|
+
</h4>
|
|
230
|
+
<p>local-storage-attribute</p>
|
|
231
|
+
</li>
|
|
232
|
+
</ul>
|
|
233
|
+
</div>
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
235
|
+
<div
|
|
236
|
+
class="flex-grow:1 width:300px padding:0px_10px margin-top:60px border-bottom:1px_solid_lightgrey"
|
|
237
|
+
>
|
|
238
|
+
<!-- SandBox -->
|
|
239
|
+
<div
|
|
240
|
+
id="local-storage-demo"
|
|
241
|
+
class="border-bottom:1px_solid_lightgrey"
|
|
242
|
+
scroll
|
|
243
|
+
scroll-intersect="color:dodgerblue"
|
|
244
|
+
scroll-selector="#local-storage-demo-section"
|
|
245
|
+
>
|
|
246
|
+
<span
|
|
247
|
+
class="display:flex align-items:center width:fit-content"
|
|
248
|
+
hover="display:block!important"
|
|
249
|
+
hover-selector="[href='#local-storage-demo']"
|
|
250
|
+
>
|
|
251
|
+
<h2 class="padding:5px_0px">Demo</h2>
|
|
252
|
+
<a
|
|
253
|
+
class="margin-left:10px display:none"
|
|
254
|
+
href="#local-storage-demo"
|
|
255
|
+
><i src="/assets/svg/link.svg"></i
|
|
256
|
+
></a>
|
|
257
|
+
</span>
|
|
258
|
+
</div>
|
|
259
|
+
<div class="position:sticky top:0 padding:15px_0px height:100vh">
|
|
260
|
+
<!-- SandBox -->
|
|
261
|
+
<div
|
|
262
|
+
class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
|
|
263
|
+
id="playground"
|
|
264
|
+
>
|
|
265
|
+
<div
|
|
266
|
+
id="demo-code"
|
|
267
|
+
resizable
|
|
268
|
+
class="position:relative height:50%"
|
|
269
|
+
>
|
|
270
|
+
<textarea
|
|
271
|
+
type="code"
|
|
272
|
+
lang="html"
|
|
273
|
+
array="demos"
|
|
274
|
+
object=""
|
|
275
|
+
key="demo"
|
|
276
|
+
save="false"
|
|
277
|
+
id="demo"
|
|
278
|
+
class="height:100% width:100% outline:none border:none resize:none padding:5px"
|
|
279
|
+
></textarea>
|
|
280
|
+
<div resize="bottom" class="background:lightgrey"></div>
|
|
281
|
+
</div>
|
|
274
282
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
<div
|
|
284
|
+
id="demo-preview"
|
|
285
|
+
class="position:relative overflow:auto background-color:white"
|
|
286
|
+
>
|
|
287
|
+
<div class="demopreview padding:20px"></div>
|
|
288
|
+
</div>
|
|
280
289
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
fullscreen-selector="#playground"></a>
|
|
325
|
-
</div>
|
|
326
|
-
</div>
|
|
327
|
-
<!-- End SandBox -->
|
|
328
|
-
</div>
|
|
329
|
-
</div>
|
|
290
|
+
<div
|
|
291
|
+
class="font-size:20px position:absolute top:10px right:10px opacity:0.6"
|
|
292
|
+
>
|
|
293
|
+
<a
|
|
294
|
+
class="margin-right:10px"
|
|
295
|
+
id="eye"
|
|
296
|
+
show="#eye-slash"
|
|
297
|
+
hide="#eye, #demo-preview"
|
|
298
|
+
toggle="code-height"
|
|
299
|
+
toggle-selector="#demo-code"
|
|
300
|
+
><i class="height:18px" src="/assets/svg/eye.svg"></i
|
|
301
|
+
></a>
|
|
302
|
+
<a
|
|
303
|
+
class="margin-right:10px"
|
|
304
|
+
hidden
|
|
305
|
+
id="eye-slash"
|
|
306
|
+
show="#eye, #demo-preview"
|
|
307
|
+
hide="#eye-slash"
|
|
308
|
+
toggle="code-height"
|
|
309
|
+
toggle-selector="#demo-code"
|
|
310
|
+
><i src="/assets/svg/eye-slash.svg"></i
|
|
311
|
+
></a>
|
|
312
|
+
<a
|
|
313
|
+
class="margin-right:10px"
|
|
314
|
+
id="code"
|
|
315
|
+
show="#code-slash"
|
|
316
|
+
hide="#code, #demo-code"
|
|
317
|
+
><i src="/assets/svg/code.svg"></i
|
|
318
|
+
></a>
|
|
319
|
+
<a
|
|
320
|
+
class="margin-right:10px"
|
|
321
|
+
hidden
|
|
322
|
+
id="code-slash"
|
|
323
|
+
show="#code, #demo-code"
|
|
324
|
+
hide="#code-slash"
|
|
325
|
+
><i class="height:18px" src="/assets/svg/code.svg"></i
|
|
326
|
+
></a>
|
|
327
|
+
<a
|
|
328
|
+
class="margin-right:5px"
|
|
329
|
+
fullscreen
|
|
330
|
+
fullscreen-selector="#playground"
|
|
331
|
+
></a>
|
|
332
|
+
</div>
|
|
330
333
|
</div>
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
334
|
+
<!-- End SandBox -->
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
<button
|
|
339
|
+
href="https://github.com/CoCreate-app/CoCreate-local-storage/tree/master/docs/index.html?message=docs%3A%20describe%20your%20change..."
|
|
340
|
+
target="_blank"
|
|
341
|
+
class="display:flex justify-content:center align-items:center position:fixed bottom:15px right:15px height:50px width:50px border-radius:50% box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4)"
|
|
342
|
+
>
|
|
343
|
+
<i src="../assets/svg/pencil-alt.svg"></i>
|
|
344
|
+
</button>
|
|
345
|
+
</main>
|
|
338
346
|
|
|
339
|
-
|
|
340
|
-
|
|
347
|
+
<script src="https://CoCreate.app/dist/CoCreate.js"></script>
|
|
348
|
+
</body>
|
|
341
349
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/local-storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
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
|
@@ -1,234 +1,247 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import Observer from "@cocreate/observer";
|
|
2
|
+
import Actions from "@cocreate/actions";
|
|
3
3
|
|
|
4
4
|
const CoCreateLocalStorage = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
5
|
+
support: true,
|
|
6
|
+
storage: new Map(),
|
|
7
|
+
|
|
8
|
+
init: function () {
|
|
9
|
+
const self = this;
|
|
10
|
+
var elements = document.querySelectorAll(
|
|
11
|
+
"[localstorage-set], [localstorage-get]"
|
|
12
|
+
);
|
|
13
|
+
this.initElements(elements);
|
|
14
|
+
|
|
15
|
+
window.addEventListener("storage", function (e) {
|
|
16
|
+
elements = document.querySelectorAll(
|
|
17
|
+
`[localstorage-get="${e.key}"]`
|
|
18
|
+
);
|
|
19
|
+
for (let element of elements) {
|
|
20
|
+
// TODO: return if localstorage-selector, etc...
|
|
21
|
+
// - Decide how best to handle, considering localstorage is also handled by event.
|
|
22
|
+
if (
|
|
23
|
+
element.hasAttribute("localstorage-attribute") ||
|
|
24
|
+
element.hasAttribute("localstorage-value") ||
|
|
25
|
+
element.hasAttribute("localstorage-key")
|
|
26
|
+
)
|
|
27
|
+
return;
|
|
28
|
+
let value = self.getItem(e.key);
|
|
29
|
+
if (value != null) {
|
|
30
|
+
element.setValue(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a collection of elements.
|
|
38
|
+
* @param {Array<Element>} elements - An array of elements to be initialized.
|
|
39
|
+
*/
|
|
40
|
+
initElements: function (elements) {
|
|
41
|
+
for (let element of elements) this.initElement(element);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Initializes a single element.
|
|
46
|
+
* @param {Element} element - The element to initialize. This function expects an 'Element' type.
|
|
47
|
+
*/
|
|
48
|
+
initElement: function (element) {
|
|
49
|
+
let value = this.getItem(element);
|
|
50
|
+
if (value) element.setValue(value);
|
|
51
|
+
else {
|
|
52
|
+
let inputEvent = new CustomEvent("input", {
|
|
53
|
+
bubbles: true
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
Object.defineProperty(inputEvent, "target", {
|
|
57
|
+
writable: false,
|
|
58
|
+
value: element
|
|
59
|
+
});
|
|
60
|
+
element.dispatchEvent(inputEvent);
|
|
61
|
+
}
|
|
62
|
+
element.addEventListener("input", (e) => {
|
|
63
|
+
let isRealtime = element.getAttribute("realtime");
|
|
64
|
+
// Returns if realtime false.
|
|
65
|
+
if (!isRealtime && isRealtime === "false") return;
|
|
66
|
+
|
|
67
|
+
let key = e.target.getAttribute("localstorage-set");
|
|
68
|
+
// Set the key and value in the localstorage.
|
|
69
|
+
if (key) this.setItem(key, e.target.value);
|
|
70
|
+
|
|
71
|
+
let elements = document.querySelectorAll(
|
|
72
|
+
`[localstorage-get="${key}"]`
|
|
73
|
+
);
|
|
74
|
+
for (let el of elements) {
|
|
75
|
+
if (el != element) {
|
|
76
|
+
let value = this.getItem(key);
|
|
77
|
+
// Set the value of the element.
|
|
78
|
+
if (value != null) {
|
|
79
|
+
el.setValue(value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param key
|
|
88
|
+
*
|
|
89
|
+
* @return { Mixed } The value associated with the key or undefined if not found. Note that this will be returned as a string if the key is an array
|
|
90
|
+
*/
|
|
91
|
+
getItem: function (key) {
|
|
92
|
+
// Returns the value of the key in the storage.
|
|
93
|
+
if (this.support) return window.localStorage.getItem(key);
|
|
94
|
+
else return this.storage.get(key);
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param key - key name to store the value under
|
|
99
|
+
* @param value - value to store
|
|
100
|
+
*/
|
|
101
|
+
setItem: function (key, value) {
|
|
102
|
+
try {
|
|
103
|
+
if (this.support) {
|
|
104
|
+
const oldValue = localStorage.getItem(key);
|
|
105
|
+
|
|
106
|
+
window.localStorage.setItem(key, value);
|
|
107
|
+
|
|
108
|
+
const keys = [
|
|
109
|
+
"organization_id",
|
|
110
|
+
"user_id",
|
|
111
|
+
"clientId",
|
|
112
|
+
"session_id"
|
|
113
|
+
];
|
|
114
|
+
if (keys.includes(key)) {
|
|
115
|
+
const updateEvent = new CustomEvent("updateAttributes", {
|
|
116
|
+
detail: { key, newValue: value, oldValue }
|
|
117
|
+
});
|
|
118
|
+
window.dispatchEvent(updateEvent);
|
|
119
|
+
}
|
|
120
|
+
} else this.storage.set(key, value);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (
|
|
123
|
+
error instanceof DOMException &&
|
|
124
|
+
(error.code === 22 ||
|
|
125
|
+
error.code === 1014 ||
|
|
126
|
+
error.name === "QuotaExceededError" ||
|
|
127
|
+
error.name === "NS_ERROR_DOM_QUOTA_REACHED")
|
|
128
|
+
) {
|
|
129
|
+
// TODO: create a fallback method, perhaps setting in indexeddb if above a specific size
|
|
130
|
+
console.log(
|
|
131
|
+
"Local storage limit exceeded. Falling back to IndexedDB."
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
console.error("Error setting item:", error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param key - The key name to delete from the storage
|
|
141
|
+
*/
|
|
142
|
+
removeItem: function (key) {
|
|
143
|
+
// Removes an item from the storage.
|
|
144
|
+
if (this.support) window.localStorage.removeItem(key);
|
|
145
|
+
else this.storage.delete(key);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param action
|
|
150
|
+
*
|
|
151
|
+
* @return { undefined } No return
|
|
152
|
+
*/
|
|
153
|
+
runStorage: async function (action) {
|
|
154
|
+
const form = action.form;
|
|
155
|
+
// If the form is not a form return false.
|
|
156
|
+
if (!form) return;
|
|
157
|
+
|
|
158
|
+
let set_els = form.querySelectorAll("[localstorage-set]");
|
|
159
|
+
for (let el of set_els) {
|
|
160
|
+
let key = el.getAttribute("localstorage-set");
|
|
161
|
+
let value = await el.getValue();
|
|
162
|
+
// Sets the value of an item.
|
|
163
|
+
if (value && key) {
|
|
164
|
+
this.setItem(key, value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let get_els = form.querySelectorAll("[localstorage-get]");
|
|
168
|
+
for (let el of get_els) {
|
|
169
|
+
let key = el.getAttribute("localstorage-get");
|
|
170
|
+
// If key is not set return false.
|
|
171
|
+
if (!key) return;
|
|
172
|
+
let value = this.getItem(key);
|
|
173
|
+
// Set the value of the element.
|
|
174
|
+
if (value != null) {
|
|
175
|
+
el.setValue(value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
let remove_els = form.querySelectorAll("[localstorage-remove]");
|
|
179
|
+
for (let el of remove_els) {
|
|
180
|
+
el.setValue("");
|
|
181
|
+
let key = el.getAttribute("localstorage-remove");
|
|
182
|
+
// Removes an item from the list.
|
|
183
|
+
if (key) {
|
|
184
|
+
this.removeItem(key);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
action.element.dispatchEvent(
|
|
189
|
+
new CustomEvent("localStorage", {
|
|
190
|
+
detail: {}
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
checkSupport: function () {
|
|
196
|
+
// Check if the browser supports localStorage.
|
|
197
|
+
if (!("localStorage" in window)) {
|
|
198
|
+
console.log("This browser doesn't support localStorage.");
|
|
199
|
+
this.support = false;
|
|
200
|
+
} else {
|
|
201
|
+
try {
|
|
202
|
+
let test = window.localStorage.getItem("test");
|
|
203
|
+
// If the CoCreateConfig. localStorage is false this method will set support to false.
|
|
204
|
+
if (window.CoCreateConfig)
|
|
205
|
+
if (window.CoCreateConfig.localStorage === false)
|
|
206
|
+
// If the server supports local storage
|
|
207
|
+
this.support = false;
|
|
208
|
+
} catch (e) {
|
|
209
|
+
this.support = false;
|
|
210
|
+
} finally {
|
|
211
|
+
// Initialize the component. If support is enabled the method init is called.
|
|
212
|
+
if (this.support) this.init();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
Actions.init(
|
|
219
|
+
{
|
|
220
|
+
name: "localStorage",
|
|
221
|
+
endEvent: "localStorage",
|
|
222
|
+
callback: (data) => {
|
|
223
|
+
CoCreateLocalStorage.runStorage(data);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "localStorageRemove",
|
|
228
|
+
endEvent: "localStorageRemoved",
|
|
229
|
+
callback: (data) => {
|
|
230
|
+
CoCreateLocalStorage.runStorage(data);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
Observer.init({
|
|
236
|
+
types: ["addedNodes"],
|
|
237
|
+
selector: "[localstorage-set]",
|
|
238
|
+
callback: async function (mutation) {
|
|
239
|
+
let key = mutation.target.getAttribute("localstorage-set");
|
|
240
|
+
let value = await mutation.target.getValue();
|
|
241
|
+
if (key && value) localStorage.setItem(key, value);
|
|
242
|
+
}
|
|
230
243
|
});
|
|
231
244
|
|
|
232
|
-
CoCreateLocalStorage.checkSupport()
|
|
245
|
+
CoCreateLocalStorage.checkSupport();
|
|
233
246
|
|
|
234
|
-
export default CoCreateLocalStorage;
|
|
247
|
+
export default CoCreateLocalStorage;
|