@cocreate/local-storage 1.7.3 → 1.7.5

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/package.json CHANGED
@@ -1,66 +1,66 @@
1
- {
2
- "name": "@cocreate/local-storage",
3
- "version": "1.7.3",
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
- "keywords": [
6
- "local-storage",
7
- "cocreate",
8
- "low-code-framework",
9
- "no-code-framework",
10
- "cocreatejs",
11
- "cocreatejs-component",
12
- "cocreate-framework",
13
- "no-code",
14
- "low-code",
15
- "collaborative-framework",
16
- "realtime",
17
- "realtime-framework",
18
- "collaboration",
19
- "shared-editing",
20
- "html5-framework",
21
- "javascript-framework"
22
- ],
23
- "publishConfig": {
24
- "access": "public"
25
- },
26
- "scripts": {
27
- "start": "npx webpack --config webpack.config.js",
28
- "build": "NODE_ENV=production npx webpack --config webpack.config.js",
29
- "dev": "npx webpack --config webpack.config.js --watch",
30
- "docs": "node ./node_modules/@cocreate/docs/src/index.js",
31
- "hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/CoCreate-app/CoCreate-local-storage.git"
36
- },
37
- "author": "CoCreate LLC",
38
- "license": "MIT",
39
- "bugs": {
40
- "url": "https://github.com/CoCreate-app/CoCreate-local-storage/issues"
41
- },
42
- "homepage": "https://cocreate.app/docs/local-storage",
43
- "funding": {
44
- "type": "GitHub Sponsors ❤",
45
- "url": "https://github.com/sponsors/CoCreate-app"
46
- },
47
- "main": "./src/index.js",
48
- "devDependencies": {
49
- "@babel/core": "^7.9.6",
50
- "@babel/preset-env": "^7.9.6",
51
- "babel-loader": "^8.1.0",
52
- "clean-webpack-plugin": "^3.0.0",
53
- "file-loader": "^6.2.0",
54
- "mini-css-extract-plugin": "^1.5.0",
55
- "style-loader": "^3.3.1",
56
- "terser-webpack-plugin": "^5.1.1",
57
- "webpack": "^5.24.4",
58
- "webpack-cli": "^4.5.0",
59
- "webpack-log": "^3.0.1"
60
- },
61
- "dependencies": {
62
- "@cocreate/actions": "^1.8.11",
63
- "@cocreate/docs": "^1.7.12",
64
- "@cocreate/observer": "^1.7.9"
65
- }
66
- }
1
+ {
2
+ "name": "@cocreate/local-storage",
3
+ "version": "1.7.5",
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
+ "keywords": [
6
+ "local-storage",
7
+ "cocreate",
8
+ "low-code-framework",
9
+ "no-code-framework",
10
+ "cocreatejs",
11
+ "cocreatejs-component",
12
+ "cocreate-framework",
13
+ "no-code",
14
+ "low-code",
15
+ "collaborative-framework",
16
+ "realtime",
17
+ "realtime-framework",
18
+ "collaboration",
19
+ "shared-editing",
20
+ "html5-framework",
21
+ "javascript-framework"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "start": "npx webpack --config webpack.config.js",
28
+ "build": "NODE_ENV=production npx webpack --config webpack.config.js",
29
+ "dev": "npx webpack --config webpack.config.js --watch",
30
+ "docs": "node ./node_modules/@cocreate/docs/src/index.js",
31
+ "hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/CoCreate-app/CoCreate-local-storage.git"
36
+ },
37
+ "author": "CoCreate LLC",
38
+ "license": "MIT",
39
+ "bugs": {
40
+ "url": "https://github.com/CoCreate-app/CoCreate-local-storage/issues"
41
+ },
42
+ "homepage": "https://cocreate.app/docs/local-storage",
43
+ "funding": {
44
+ "type": "GitHub Sponsors ❤",
45
+ "url": "https://github.com/sponsors/CoCreate-app"
46
+ },
47
+ "main": "./src/index.js",
48
+ "devDependencies": {
49
+ "@babel/core": "^7.9.6",
50
+ "@babel/preset-env": "^7.9.6",
51
+ "babel-loader": "^8.1.0",
52
+ "clean-webpack-plugin": "^3.0.0",
53
+ "file-loader": "^6.2.0",
54
+ "mini-css-extract-plugin": "^1.5.0",
55
+ "style-loader": "^3.3.1",
56
+ "terser-webpack-plugin": "^5.1.1",
57
+ "webpack": "^5.24.4",
58
+ "webpack-cli": "^4.5.0",
59
+ "webpack-log": "^3.0.1"
60
+ },
61
+ "dependencies": {
62
+ "@cocreate/actions": "^1.8.12",
63
+ "@cocreate/docs": "^1.7.13",
64
+ "@cocreate/observer": "^1.8.0"
65
+ }
66
+ }
package/release.config.js CHANGED
@@ -1,22 +1,22 @@
1
- module.exports = {
2
- dryRun: false,
3
- branches: ["master"],
4
- plugins: [
5
- "@semantic-release/commit-analyzer",
6
- "@semantic-release/release-notes-generator",
7
- [
8
- "@semantic-release/changelog",
9
- {
10
- changelogFile: "CHANGELOG.md",
11
- },
12
- ],
13
- "@semantic-release/npm",
14
- "@semantic-release/github",
15
- [
16
- "@semantic-release/git",
17
- {
18
- assets: ["CHANGELOG.md", "package.json"],
19
- },
20
- ],
21
- ],
1
+ module.exports = {
2
+ dryRun: false,
3
+ branches: ["master"],
4
+ plugins: [
5
+ "@semantic-release/commit-analyzer",
6
+ "@semantic-release/release-notes-generator",
7
+ [
8
+ "@semantic-release/changelog",
9
+ {
10
+ changelogFile: "CHANGELOG.md",
11
+ },
12
+ ],
13
+ "@semantic-release/npm",
14
+ "@semantic-release/github",
15
+ [
16
+ "@semantic-release/git",
17
+ {
18
+ assets: ["CHANGELOG.md", "package.json"],
19
+ },
20
+ ],
21
+ ],
22
22
  };
package/src/index.js CHANGED
@@ -1,193 +1,193 @@
1
- import observer from '@cocreate/observer';
2
- import action from '@cocreate/actions'
3
-
4
- const CoCreateLocalStorage = {
5
- support: true,
6
- storage: new Map(),
7
-
8
- /**
9
- * Listen for storage events and update elements if needed. This is called on window. storage and when it's time to get / set data
10
- */
11
- init: function () {
12
- const self = this
13
- var elements = document.querySelectorAll('[localstorage-set], [localstorage-get]');
14
- this.initElements(elements)
15
- /**
16
- * @param e
17
- */
18
- window.addEventListener('storage', function (e) {
19
- elements = document.querySelectorAll(`[localstorage-get="${e.key}"]`)
20
- for (let element of elements) {
21
- let value = self.getItem(e.key)
22
- // Set the value of the element.
23
- if (value != null) {
24
- element.setValue(value)
25
- }
26
- }
27
- });
28
- },
29
-
30
- /**
31
- * @param elements
32
- */
33
- initElements: function (elements) {
34
- for (let element of elements)
35
- this.initElement(element)
36
- },
37
-
38
- /**
39
- * @param element
40
- *
41
- * @return { Object } The binding
42
- */
43
- initElement: function (element) {
44
- this.getItem(element)
45
- element.addEventListener('input', (e) => {
46
- let isRealtime = element.getAttribute('realtime')
47
- // Returns if realtime false.
48
- if (isRealtime == "false") return;
49
-
50
- let key = e.target.getAttribute('localstorage-set');
51
- // Set the key and value in the localstorage.
52
- if (key)
53
- this.setItem(key, e.target.value);
54
-
55
- let elements = document.querySelectorAll(`[localstorage-get="${key}"]`)
56
- for (let el of elements) {
57
- if (el != element) {
58
- let value = this.getItem(key)
59
- // Set the value of the element.
60
- if (value != null) {
61
- el.setValue(value)
62
- }
63
- }
64
-
65
- }
66
- })
67
- },
68
-
69
- /**
70
- * @param key
71
- *
72
- * @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
73
- */
74
- getItem: function (key) {
75
- // Returns the value of the key in the storage.
76
- if (this.support)
77
- return window.localStorage.getItem(key)
78
- else
79
- return this.storage.get(key)
80
- },
81
-
82
- /**
83
- * @param key - key name to store the value under
84
- * @param value - value to store
85
- */
86
- setItem: function (key, value) {
87
- // Set the value of the item.
88
- if (this.support)
89
- window.localStorage.setItem(key, value);
90
- else
91
- this.storage.set(key, value)
92
- },
93
-
94
- /**
95
- * @param key - The key name to delete from the storage
96
- */
97
- removeItem: function (key) {
98
- // Removes an item from the storage.
99
- if (this.support)
100
- window.localStorage.removeItem(key)
101
- else
102
- this.storage.delete(key)
103
- },
104
-
105
- /**
106
- * @param btn
107
- *
108
- * @return { undefined } No return
109
- */
110
- runStorage: function (btn) {
111
- const form = btn.form;
112
- // If the form is not a form return false.
113
- if (!form) return;
114
-
115
- let set_els = form.querySelectorAll('[localstorage-set]')
116
- for (let el of set_els) {
117
- let key = el.getAttribute('localstorage-set');
118
- let value = el.getValue()
119
- // Sets the value of an item.
120
- if (value && key) {
121
- this.setItem(key, value);
122
- }
123
- }
124
- let get_els = form.querySelectorAll('[localstorage-get]')
125
- for (let el of get_els) {
126
- let key = el.getAttribute('localstorage-get');
127
- // If key is not set return false.
128
- if (!key) return;
129
- let value = this.getItem(key)
130
- // Set the value of the element.
131
- if (value != null) {
132
- el.setValue(value)
133
- }
134
- }
135
- let remove_els = form.querySelectorAll('[localstorage-remove]')
136
- for (let el of remove_els) {
137
- el.setValue('')
138
- let key = el.getAttribute('localstorage-remove');
139
- // Removes an item from the list.
140
- if (key) {
141
- this.removeItem(key)
142
- }
143
- }
144
-
145
- document.dispatchEvent(new CustomEvent('localStorage', {
146
- detail: {}
147
- }))
148
-
149
- },
150
-
151
- checkSupport: function () {
152
- // Check if the browser supports localStorage.
153
- if (!('localStorage' in window)) {
154
- console.log("This browser doesn't support localStorage.");
155
- this.support = false;
156
- } else {
157
- try {
158
- let test = window.localStorage.getItem('test')
159
- // If the CoCreateConfig. localStorage is false this method will set support to false.
160
- if (window.CoCreateConfig)
161
- // If the server supports local storage
162
- if (window.CoCreateConfig.localStorage === false)
163
- this.support = false;
164
- } catch (e) {
165
- this.support = false;
166
- } finally {
167
- // Initialize the component. If support is enabled the method init is called.
168
- if (this.support)
169
- this.init()
170
- }
171
- }
172
- }
173
- }
174
-
175
- action.init({
176
- name: "localStorage",
177
- endEvent: "localStorage",
178
- callback: (btn, data) => {
179
- CoCreateLocalStorage.runStorage(btn)
180
- },
181
- })
182
-
183
- action.init({
184
- name: "localStorageRemove",
185
- endEvent: "localStorageRemoved",
186
- callback: (btn, data) => {
187
- CoCreateLocalStorage.runStorage(btn)
188
- },
189
- })
190
-
191
- CoCreateLocalStorage.checkSupport()
192
-
1
+ import observer from '@cocreate/observer';
2
+ import action from '@cocreate/actions'
3
+
4
+ const CoCreateLocalStorage = {
5
+ support: true,
6
+ storage: new Map(),
7
+
8
+ /**
9
+ * Listen for storage events and update elements if needed. This is called on window. storage and when it's time to get / set data
10
+ */
11
+ init: function () {
12
+ const self = this
13
+ var elements = document.querySelectorAll('[localstorage-set], [localstorage-get]');
14
+ this.initElements(elements)
15
+ /**
16
+ * @param e
17
+ */
18
+ window.addEventListener('storage', function (e) {
19
+ elements = document.querySelectorAll(`[localstorage-get="${e.key}"]`)
20
+ for (let element of elements) {
21
+ let value = self.getItem(e.key)
22
+ // Set the value of the element.
23
+ if (value != null) {
24
+ element.setValue(value)
25
+ }
26
+ }
27
+ });
28
+ },
29
+
30
+ /**
31
+ * @param elements
32
+ */
33
+ initElements: function (elements) {
34
+ for (let element of elements)
35
+ this.initElement(element)
36
+ },
37
+
38
+ /**
39
+ * @param element
40
+ *
41
+ * @return { Object } The binding
42
+ */
43
+ initElement: function (element) {
44
+ this.getItem(element)
45
+ element.addEventListener('input', (e) => {
46
+ let isRealtime = element.getAttribute('realtime')
47
+ // Returns if realtime false.
48
+ if (isRealtime == "false") return;
49
+
50
+ let key = e.target.getAttribute('localstorage-set');
51
+ // Set the key and value in the localstorage.
52
+ if (key)
53
+ this.setItem(key, e.target.value);
54
+
55
+ let elements = document.querySelectorAll(`[localstorage-get="${key}"]`)
56
+ for (let el of elements) {
57
+ if (el != element) {
58
+ let value = this.getItem(key)
59
+ // Set the value of the element.
60
+ if (value != null) {
61
+ el.setValue(value)
62
+ }
63
+ }
64
+
65
+ }
66
+ })
67
+ },
68
+
69
+ /**
70
+ * @param key
71
+ *
72
+ * @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
73
+ */
74
+ getItem: function (key) {
75
+ // Returns the value of the key in the storage.
76
+ if (this.support)
77
+ return window.localStorage.getItem(key)
78
+ else
79
+ return this.storage.get(key)
80
+ },
81
+
82
+ /**
83
+ * @param key - key name to store the value under
84
+ * @param value - value to store
85
+ */
86
+ setItem: function (key, value) {
87
+ // Set the value of the item.
88
+ if (this.support)
89
+ window.localStorage.setItem(key, value);
90
+ else
91
+ this.storage.set(key, value)
92
+ },
93
+
94
+ /**
95
+ * @param key - The key name to delete from the storage
96
+ */
97
+ removeItem: function (key) {
98
+ // Removes an item from the storage.
99
+ if (this.support)
100
+ window.localStorage.removeItem(key)
101
+ else
102
+ this.storage.delete(key)
103
+ },
104
+
105
+ /**
106
+ * @param btn
107
+ *
108
+ * @return { undefined } No return
109
+ */
110
+ runStorage: function (btn) {
111
+ const form = btn.form;
112
+ // If the form is not a form return false.
113
+ if (!form) return;
114
+
115
+ let set_els = form.querySelectorAll('[localstorage-set]')
116
+ for (let el of set_els) {
117
+ let key = el.getAttribute('localstorage-set');
118
+ let value = el.getValue()
119
+ // Sets the value of an item.
120
+ if (value && key) {
121
+ this.setItem(key, value);
122
+ }
123
+ }
124
+ let get_els = form.querySelectorAll('[localstorage-get]')
125
+ for (let el of get_els) {
126
+ let key = el.getAttribute('localstorage-get');
127
+ // If key is not set return false.
128
+ if (!key) return;
129
+ let value = this.getItem(key)
130
+ // Set the value of the element.
131
+ if (value != null) {
132
+ el.setValue(value)
133
+ }
134
+ }
135
+ let remove_els = form.querySelectorAll('[localstorage-remove]')
136
+ for (let el of remove_els) {
137
+ el.setValue('')
138
+ let key = el.getAttribute('localstorage-remove');
139
+ // Removes an item from the list.
140
+ if (key) {
141
+ this.removeItem(key)
142
+ }
143
+ }
144
+
145
+ document.dispatchEvent(new CustomEvent('localStorage', {
146
+ detail: {}
147
+ }))
148
+
149
+ },
150
+
151
+ checkSupport: function () {
152
+ // Check if the browser supports localStorage.
153
+ if (!('localStorage' in window)) {
154
+ console.log("This browser doesn't support localStorage.");
155
+ this.support = false;
156
+ } else {
157
+ try {
158
+ let test = window.localStorage.getItem('test')
159
+ // If the CoCreateConfig. localStorage is false this method will set support to false.
160
+ if (window.CoCreateConfig)
161
+ // If the server supports local storage
162
+ if (window.CoCreateConfig.localStorage === false)
163
+ this.support = false;
164
+ } catch (e) {
165
+ this.support = false;
166
+ } finally {
167
+ // Initialize the component. If support is enabled the method init is called.
168
+ if (this.support)
169
+ this.init()
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ action.init({
176
+ name: "localStorage",
177
+ endEvent: "localStorage",
178
+ callback: (btn, data) => {
179
+ CoCreateLocalStorage.runStorage(btn)
180
+ },
181
+ })
182
+
183
+ action.init({
184
+ name: "localStorageRemove",
185
+ endEvent: "localStorageRemoved",
186
+ callback: (btn, data) => {
187
+ CoCreateLocalStorage.runStorage(btn)
188
+ },
189
+ })
190
+
191
+ CoCreateLocalStorage.checkSupport()
192
+
193
193
  export default CoCreateLocalStorage;