@cocreate/local-storage 1.14.4 → 1.15.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 CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.15.1](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.15.0...v1.15.1) (2024-06-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump cocreate dependencies ([e656b78](https://github.com/CoCreate-app/CoCreate-local-storage/commit/e656b78a8fd21f1828332fb9d12aae947447fbde))
7
+ * svg icon class ([0efceb9](https://github.com/CoCreate-app/CoCreate-local-storage/commit/0efceb9b90551d1de1f8acc840eb4e3ad5a1975a))
8
+
9
+ # [1.15.0](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.14.4...v1.15.0) (2024-05-08)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * action property typo ([f17a85f](https://github.com/CoCreate-app/CoCreate-local-storage/commit/f17a85f7c4221044af7c0f7c92004beae7269f10))
15
+ * dispatch event if value null ([9975383](https://github.com/CoCreate-app/CoCreate-local-storage/commit/99753839b55a54497e91e5d29ad17585b1cb83e3))
16
+
17
+
18
+ ### Features
19
+
20
+ * dispatch updateAttributes event for operators ([ee86894](https://github.com/CoCreate-app/CoCreate-local-storage/commit/ee86894c119e5d375abe681ab03df5a9999860b9))
21
+
1
22
  ## [1.14.4](https://github.com/CoCreate-app/CoCreate-local-storage/compare/v1.14.3...v1.14.4) (2024-04-29)
2
23
 
3
24
 
package/docs/index.html CHANGED
@@ -82,43 +82,33 @@
82
82
  class="margin-right:15px"
83
83
  share-network="twitter"
84
84
  title="Share on twitter"
85
- ><i
86
- class="height:20px fill:#505050"
87
- src="/assets/svg/twitter.svg"></i
85
+ ><i src="/assets/svg/twitter.svg"></i
88
86
  ></a>
89
87
  <a
90
88
  class="margin-right:15px"
91
89
  share-network="facebook"
92
90
  title="Share on Facebook"
93
- ><i
94
- class="height:20px fill:#505050"
95
- src="/assets/svg/facebook.svg"></i
91
+ ><i src="/assets/svg/facebook.svg"></i
96
92
  ></a>
97
93
  <a
98
94
  class="margin-right:15px"
99
95
  share-network="instagram"
100
96
  title="Share on instagram"
101
- ><i
102
- class="height:20px fill:#505050"
103
- src="/assets/svg/instagram.svg"></i
97
+ ><i src="/assets/svg/instagram.svg"></i
104
98
  ></a>
105
99
  </div>
106
100
  <a
107
101
  class="margin-right:15px"
108
102
  share-network="share"
109
103
  title="Share on share"
110
- ><i
111
- class="height:20px fill:#505050"
112
- src="/assets/svg/share-alt.svg"></i
104
+ ><i src="/assets/svg/share-alt.svg"></i
113
105
  ></a>
114
106
  </div>
115
107
  <a
116
108
  href="https://github.com/CoCreate-app/CoCreate-local-storage"
117
109
  target="_blank"
118
110
  class="margin-right:15px"
119
- ><i
120
- class="height:20px fill:#505050"
121
- src="/assets/svg/github.svg"></i
111
+ ><i src="/assets/svg/github.svg"></i
122
112
  ></a>
123
113
  </div>
124
114
  </div>
@@ -146,9 +136,7 @@
146
136
  <a
147
137
  class="margin-left:10px display:none"
148
138
  href="#local-storage-install"
149
- ><i
150
- class="height:20px fill:#505050"
151
- src="/assets/svg/link.svg"></i
139
+ ><i src="/assets/svg/link.svg"></i
152
140
  ></a>
153
141
  </span>
154
142
  </div>
@@ -172,9 +160,7 @@
172
160
  <a
173
161
  class="margin-left:10px display:none"
174
162
  href="#local-storage-usage"
175
- ><i
176
- class="height:20px fill:#505050"
177
- src="/assets/svg/link.svg"></i
163
+ ><i src="/assets/svg/link.svg"></i
178
164
  ></a>
179
165
  </span>
180
166
  </div>
@@ -207,9 +193,7 @@
207
193
  <a
208
194
  class="margin-left:10px display:none"
209
195
  href="#local-storage-attributes"
210
- ><i
211
- class="height:20px fill:#505050"
212
- src="/assets/svg/link.svg"></i
196
+ ><i src="/assets/svg/link.svg"></i
213
197
  ></a>
214
198
  </span>
215
199
  </div>
@@ -260,9 +244,7 @@
260
244
  <a
261
245
  class="margin-left:10px display:none"
262
246
  href="#local-storage-demo"
263
- ><i
264
- class="height:20px fill:#505050"
265
- src="/assets/svg/link.svg"></i
247
+ ><i src="/assets/svg/link.svg"></i
266
248
  ></a>
267
249
  </span>
268
250
  </div>
@@ -306,7 +288,7 @@
306
288
  toggle="code-height"
307
289
  toggle-selector="#demo-code"
308
290
  ><i
309
- class="height:18px fill:#505050"
291
+ class="height:18px"
310
292
  src="/assets/svg/eye.svg"></i
311
293
  ></a>
312
294
  <a
@@ -317,18 +299,14 @@
317
299
  hide="#eye-slash"
318
300
  toggle="code-height"
319
301
  toggle-selector="#demo-code"
320
- ><i
321
- class="height:20px fill:#505050"
322
- src="/assets/svg/eye-slash.svg"></i
302
+ ><i src="/assets/svg/eye-slash.svg"></i
323
303
  ></a>
324
304
  <a
325
305
  class="margin-right:10px"
326
306
  id="code"
327
307
  show="#code-slash"
328
308
  hide="#code, #demo-code"
329
- ><i
330
- class="height:20px fill:#505050"
331
- src="/assets/svg/code.svg"></i
309
+ ><i src="/assets/svg/code.svg"></i
332
310
  ></a>
333
311
  <a
334
312
  class="margin-right:10px"
@@ -337,7 +315,7 @@
337
315
  show="#code, #demo-code"
338
316
  hide="#code-slash"
339
317
  ><i
340
- class="display:flex height:18px fill:#505050"
318
+ class="height:18px"
341
319
  src="/assets/svg/code.svg"></i
342
320
  ></a>
343
321
  <a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/local-storage",
3
- "version": "1.14.4",
3
+ "version": "1.15.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",
@@ -58,7 +58,7 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/actions": "^1.18.1",
62
- "@cocreate/observer": "^1.16.0"
61
+ "@cocreate/actions": "^1.18.2",
62
+ "@cocreate/observer": "^1.16.1"
63
63
  }
64
64
  }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import observer from '@cocreate/observer';
2
- import action from '@cocreate/actions'
2
+ import actions from '@cocreate/actions'
3
3
 
4
4
  const CoCreateLocalStorage = {
5
5
  support: true,
@@ -39,7 +39,20 @@ const CoCreateLocalStorage = {
39
39
  * @param {Element} element - The element to initialize. This function expects an 'Element' type.
40
40
  */
41
41
  initElement: function (element) {
42
- this.getItem(element)
42
+ let value = this.getItem(element)
43
+ if (value)
44
+ element.setValue(value)
45
+ else {
46
+ let inputEvent = new CustomEvent('input', {
47
+ bubbles: true
48
+ });
49
+
50
+ Object.defineProperty(inputEvent, 'target', {
51
+ writable: false,
52
+ value: element
53
+ });
54
+ element.dispatchEvent(inputEvent);
55
+ }
43
56
  element.addEventListener('input', (e) => {
44
57
  let isRealtime = element.getAttribute('realtime')
45
58
  // Returns if realtime false.
@@ -83,9 +96,19 @@ const CoCreateLocalStorage = {
83
96
  */
84
97
  setItem: function (key, value) {
85
98
  try {
86
- if (this.support)
99
+ if (this.support) {
100
+ const oldValue = localStorage.getItem(key);
101
+
87
102
  window.localStorage.setItem(key, value);
88
- else
103
+
104
+ const keys = ['organization_id', 'user_id', 'clientId', 'session_id'];
105
+ if (keys.includes(key)) {
106
+ const updateEvent = new CustomEvent('updateAttributes', {
107
+ detail: { key, newValue: value, oldValue }
108
+ });
109
+ window.dispatchEvent(updateEvent);
110
+ }
111
+ } else
89
112
  this.storage.set(key, value);
90
113
  } catch (error) {
91
114
  if (error instanceof DOMException && (error.code === 22 || error.code === 1014 || error.name === 'QuotaExceededError' || error.name === 'NS_ERROR_DOM_QUOTA_REACHED')) {
@@ -109,12 +132,12 @@ const CoCreateLocalStorage = {
109
132
  },
110
133
 
111
134
  /**
112
- * @param btn
135
+ * @param action
113
136
  *
114
137
  * @return { undefined } No return
115
138
  */
116
- runStorage: async function (btn) {
117
- const form = btn.form;
139
+ runStorage: async function (action) {
140
+ const form = action.form;
118
141
  // If the form is not a form return false.
119
142
  if (!form) return;
120
143
 
@@ -178,21 +201,22 @@ const CoCreateLocalStorage = {
178
201
  }
179
202
  }
180
203
 
181
- action.init({
182
- name: "localStorage",
183
- endEvent: "localStorage",
184
- callback: (data) => {
185
- CoCreateLocalStorage.runStorage(data.element)
204
+ actions.init(
205
+ {
206
+ name: "localStorage",
207
+ endEvent: "localStorage",
208
+ callback: (data) => {
209
+ CoCreateLocalStorage.runStorage(data)
210
+ },
186
211
  },
187
- })
188
-
189
- action.init({
190
- name: "localStorageRemove",
191
- endEvent: "localStorageRemoved",
192
- callback: (data) => {
193
- CoCreateLocalStorage.runStorage(data.element)
194
- },
195
- })
212
+ {
213
+ name: "localStorageRemove",
214
+ endEvent: "localStorageRemoved",
215
+ callback: (data) => {
216
+ CoCreateLocalStorage.runStorage(data)
217
+ }
218
+ }
219
+ )
196
220
 
197
221
  observer.init({
198
222
  observe: ['addedNodes'],