react-wire-persisted 1.3.0 → 1.5.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/README.md
CHANGED
|
@@ -5,7 +5,17 @@
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```shell
|
|
8
|
-
$
|
|
8
|
+
$ pnpm add -D @forminator/react-wire react-wire-persisted
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Building
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
$ pnpm build
|
|
15
|
+
$ npm version patch # patch, minor, major
|
|
16
|
+
$ git push
|
|
17
|
+
$ git push --tags
|
|
18
|
+
$ npm publish
|
|
9
19
|
```
|
|
10
20
|
|
|
11
21
|
## Usage
|
|
@@ -29,7 +29,7 @@ const m = {}, p = (s) => {
|
|
|
29
29
|
}, d = (s) => {
|
|
30
30
|
const e = typeof s;
|
|
31
31
|
return s === null ? !0 : Array.isArray(s) || e === "object" ? !1 : e !== "function";
|
|
32
|
-
},
|
|
32
|
+
}, j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
33
33
|
__proto__: null,
|
|
34
34
|
addKey: p,
|
|
35
35
|
fakeLocalStorage: g,
|
|
@@ -130,7 +130,7 @@ class v extends h {
|
|
|
130
130
|
try {
|
|
131
131
|
return window.localStorage;
|
|
132
132
|
} catch {
|
|
133
|
-
return console.warn("LocalStorageProvider: localStorage not supported"), g;
|
|
133
|
+
return console.warn(new Error("LocalStorageProvider: localStorage not supported")), g;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
setNamespace(e) {
|
|
@@ -172,7 +172,7 @@ class v extends h {
|
|
|
172
172
|
_resetAll(e = !0, t = [], r = !1) {
|
|
173
173
|
const n = `${this.namespace}.`;
|
|
174
174
|
Object.keys(localStorage).forEach((o) => {
|
|
175
|
-
const l = this.namespace ? o.startsWith(n) : !0, a =
|
|
175
|
+
const l = this.namespace ? o.startsWith(n) : !0, a = t?.includes(o) || !1;
|
|
176
176
|
!l || a || (e ? Object.prototype.hasOwnProperty.call(this.registry, o) ? this.storage.setItem(o, this.registry[o]) : this.storage.removeItem(o) : (this.storage.removeItem(o), r && delete this.registry[o]));
|
|
177
177
|
});
|
|
178
178
|
}
|
|
@@ -189,27 +189,26 @@ const A = {
|
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
let y = v, i = new y(), u = { ...A }, f = [];
|
|
192
|
-
const w = () => i.namespace,
|
|
192
|
+
const w = () => i.namespace, K = () => i, P = () => u, _ = (s) => {
|
|
193
193
|
i.setNamespace(s), i = new y(s || w());
|
|
194
|
-
},
|
|
194
|
+
}, E = (s) => {
|
|
195
195
|
if (u = {
|
|
196
196
|
...u,
|
|
197
197
|
...s
|
|
198
198
|
}, u.logging.enabled)
|
|
199
199
|
for (console.info("Flushing", f.length, "pending logs"); f.length; )
|
|
200
200
|
console.log(...f.shift());
|
|
201
|
-
},
|
|
201
|
+
}, x = (...s) => {
|
|
202
202
|
u.logging.enabled ? console.log(...s) : f.push(s);
|
|
203
|
-
},
|
|
204
|
-
if (!s && typeof s != "number")
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
203
|
+
}, V = (s, e = null) => {
|
|
204
|
+
if (!s && typeof s != "number") throw new Error(
|
|
205
|
+
`createPersistedWire: Key cannot be a falsey value (${s}}`
|
|
206
|
+
);
|
|
208
207
|
i.register(s, e);
|
|
209
208
|
const t = b(e), r = () => t.getValue(), n = (c) => (i.setItem(s, c), t.setValue(c)), o = (c) => {
|
|
210
209
|
t.subscribe(c);
|
|
211
210
|
}, l = i.getItem(s), a = l === null ? e : l;
|
|
212
|
-
return
|
|
211
|
+
return x("react-wire-persisted: create", s, {
|
|
213
212
|
value: e,
|
|
214
213
|
storedValue: l,
|
|
215
214
|
initialValue: a
|
|
@@ -221,12 +220,12 @@ const w = () => i.namespace, x = () => i, _ = () => u, K = (s) => {
|
|
|
221
220
|
};
|
|
222
221
|
};
|
|
223
222
|
export {
|
|
224
|
-
|
|
223
|
+
V as createPersistedWire,
|
|
225
224
|
A as defaultOptions,
|
|
226
225
|
w as getNamespace,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
P as getOptions,
|
|
227
|
+
K as getStorage,
|
|
228
|
+
_ as setNamespace,
|
|
229
|
+
E as setOptions,
|
|
230
|
+
j as utils
|
|
232
231
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@forminator/react-wire")):typeof define=="function"&&define.amd?define(["exports","@forminator/react-wire"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n["react-wire-persisted"]={},n.reactWire))})(this,function(n,a){"use strict";(function(){const s={};try{if(process){process.env=Object.assign({},process.env),Object.assign(process.env,s);return}}catch{}globalThis.process={env:s}})();const
|
|
1
|
+
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@forminator/react-wire")):typeof define=="function"&&define.amd?define(["exports","@forminator/react-wire"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n["react-wire-persisted"]={},n.reactWire))})(this,function(n,a){"use strict";(function(){const s={};try{if(process){process.env=Object.assign({},process.env),Object.assign(process.env,s);return}}catch{}globalThis.process={env:s}})();const h={},y=s=>{h[s]=s},w=s=>y(s),v=()=>h,A=(s,e=null)=>{const t=e||h;return s?Object.keys(t).reduce((r,o)=>({...r,[o]:`${s}.${t[o]}`}),{}):t},c={getItem:s=>c[s],setItem:(s,e)=>{c[s]=e},removeItem:s=>{delete c[s]}},b=s=>{const e=typeof s;return s===null?!0:Array.isArray(s)||e==="object"?!1:e!=="function"},N=Object.freeze(Object.defineProperty({__proto__:null,addKey:y,fakeLocalStorage:c,getKeys:v,getPrefixedKeys:A,isPrimitive:b,key:w},Symbol.toStringTag,{value:"Module"}));class p{constructor(e,t){if(new.target===p)throw TypeError("StorageProvider is abstract. Extend this class to implement it");this.namespace=e||null,this.registry=t||{}}setNamespace(e){}register(e,t){this.registry[e]=t}getItem(e){}setItem(e,t){}removeItem(e,t=!1){}getAll(){}_resetAll(e=!0,t=[],r=!1){}resetAll(e=[]){}removeAll(e=[]){}}class j extends p{constructor(e=null,t={}){super(e,t),this.storage=this.getStorage()}getStorage(){try{return window.localStorage}catch{return console.warn(new Error("LocalStorageProvider: localStorage not supported")),c}}setNamespace(e){if(!this.namespace){this.namespace=e;return}if(this.namespace===e)return;const t=JSON.parse(JSON.stringify(this.getAll()));this.removeAll();for(const[r,o]of Object.entries(t)){const i=r.replace(this.namespace,e);this.setItem(i,o)}this.namespace=e}getItem(e){const t=this.storage.getItem(e);if(t==null)return null;try{return JSON.parse(t)}catch{return t}}setItem(e,t){let r=t;return r!=null&&(r=b(t)?t:JSON.stringify(t)),this.storage.setItem(e,r)}removeItem(e,t=!1){return t&&delete this.registry[e],this.storage.removeItem(e)}getAll(){const e=`${this.namespace}.`;return Object.keys(this.storage).reduce((t,r)=>((!this.namespace||r.startsWith(e))&&(t[r]=this.storage.getItem(r)),t),{})}_resetAll(e=!0,t=[],r=!1){const o=`${this.namespace}.`;Object.keys(localStorage).forEach(i=>{const u=this.namespace?i.startsWith(o):!0,f=t?.includes(i)||!1;!u||f||(e?Object.prototype.hasOwnProperty.call(this.registry,i)?this.storage.setItem(i,this.registry[i]):this.storage.removeItem(i):(this.storage.removeItem(i),r&&delete this.registry[i]))})}resetAll(e=[],t=!1){this._resetAll(!0,e||[],t)}removeAll(e=[],t=!1){this._resetAll(!1,e||[],t)}}const O={logging:{enabled:!1}};let I=j,l=new I,g={...O},m=[];const S=()=>l.namespace,P=()=>l,K=()=>g,W=s=>{l.setNamespace(s),l=new I(s||S())},_=s=>{if(g={...g,...s},g.logging.enabled)for(console.info("Flushing",m.length,"pending logs");m.length;)console.log(...m.shift())},E=(...s)=>{g.logging.enabled?console.log(...s):m.push(s)},T=(s,e=null)=>{if(!s&&typeof s!="number")throw new Error(`createPersistedWire: Key cannot be a falsey value (${s}}`);l.register(s,e);const t=a.createWire(e),r=()=>t.getValue(),o=d=>(l.setItem(s,d),t.setValue(d)),i=d=>{t.subscribe(d)},u=l.getItem(s),f=u===null?e:u;return E("react-wire-persisted: create",s,{value:e,storedValue:u,initialValue:f}),f!==e&&o(f),{...t,getValue:r,setValue:o,subscribe:i}};n.createPersistedWire=T,n.defaultOptions=O,n.getNamespace=S,n.getOptions=K,n.getStorage=P,n.setNamespace=W,n.setOptions=_,n.utils=N,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-wire-persisted",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "Wesley Bliss <wesley.bliss@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"main": "./dist/react-wire-persisted.umd.cjs",
|
|
7
8
|
"module": "./dist/react-wire-persisted.mjs",
|
|
8
9
|
"files": [
|
|
@@ -18,32 +19,31 @@
|
|
|
18
19
|
"scripts": {
|
|
19
20
|
"dev": "vite --host --config config/vite.config.development.js",
|
|
20
21
|
"build": "vite build --config config/vite.config.production.js",
|
|
21
|
-
"test:unit": "NODE_ENV=test vitest run
|
|
22
|
-
"test:unit:only": "NODE_ENV=test vitest run
|
|
23
|
-
"test:unit:coverage": "NODE_ENV=test vitest run --
|
|
22
|
+
"test:unit": "NODE_ENV=test vitest run",
|
|
23
|
+
"test:unit:only": "NODE_ENV=test vitest run -t ",
|
|
24
|
+
"test:unit:coverage": "NODE_ENV=test vitest run --no-color --reporter=junit --coverage --outputFile=coverage/report.xml"
|
|
24
25
|
},
|
|
25
|
-
"dependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@forminator/react-wire": "^0.
|
|
28
|
-
"@testing-library/jest-dom": "^
|
|
29
|
-
"@testing-library/react": "^
|
|
30
|
-
"@testing-library/user-event": "^14.
|
|
31
|
-
"@vitejs/plugin-react": "^
|
|
32
|
-
"@vitest/coverage-c8": "^0.
|
|
33
|
-
"browserslist": "^4.
|
|
34
|
-
"c8": "^
|
|
35
|
-
"dotenv": "^
|
|
36
|
-
"esbuild": "^0.
|
|
37
|
-
"jest": "^
|
|
38
|
-
"jest-environment-jsdom": "^
|
|
39
|
-
"np": "^
|
|
40
|
-
"react": "^
|
|
41
|
-
"react-dom": "^
|
|
27
|
+
"@forminator/react-wire": "^0.7.0",
|
|
28
|
+
"@testing-library/jest-dom": "^6.6.4",
|
|
29
|
+
"@testing-library/react": "^16.3.0",
|
|
30
|
+
"@testing-library/user-event": "^14.6.1",
|
|
31
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
32
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
33
|
+
"browserslist": "^4.25.1",
|
|
34
|
+
"c8": "^10.1.3",
|
|
35
|
+
"dotenv": "^17.2.1",
|
|
36
|
+
"esbuild": "^0.25.8",
|
|
37
|
+
"jest": "^30.0.5",
|
|
38
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
39
|
+
"np": "^10.2.0",
|
|
40
|
+
"react": "^19.1.1",
|
|
41
|
+
"react-dom": "^19.1.1",
|
|
42
42
|
"rollup-plugin-inject-process-env": "^1.3.1",
|
|
43
43
|
"snapshot-diff": "^0.10.0",
|
|
44
|
-
"vite": "^
|
|
44
|
+
"vite": "^7.0.6",
|
|
45
45
|
"vite-jest": "^0.1.4",
|
|
46
|
-
"vitest": "^
|
|
46
|
+
"vitest": "^3.2.4"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@forminator/react-wire": "^0.5.0-alpha.1",
|
|
@@ -61,5 +61,8 @@
|
|
|
61
61
|
"last 1 firefox version",
|
|
62
62
|
"last 1 safari version"
|
|
63
63
|
]
|
|
64
|
+
},
|
|
65
|
+
"pnpm": {
|
|
66
|
+
"neverBuiltDependencies": []
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -21,7 +21,7 @@ class LocalStorageProvider extends StorageProvider {
|
|
|
21
21
|
return window.localStorage
|
|
22
22
|
} catch (e) {
|
|
23
23
|
/* istanbul ignore next */
|
|
24
|
-
console.warn('LocalStorageProvider: localStorage not supported')
|
|
24
|
+
console.warn(new Error('LocalStorageProvider: localStorage not supported'))
|
|
25
25
|
/* istanbul ignore next */
|
|
26
26
|
return fakeLocalStorage
|
|
27
27
|
}
|