@plq/use-persisted-state 1.3.0 → 1.4.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/LICENSE +1 -1
- package/README.md +165 -50
- package/esm/index.d.mts +13 -0
- package/esm/index.mjs +10 -0
- package/esm/storages/browser-storage.d.mts +1 -0
- package/esm/storages/browser-storage.mjs +5 -0
- package/esm/storages/chrome-storage.d.mts +1 -0
- package/esm/storages/chrome-storage.mjs +5 -0
- package/esm/storages/local-storage.d.mts +1 -0
- package/esm/storages/local-storage.mjs +3 -0
- package/esm/storages/session-storage.d.mts +1 -0
- package/esm/storages/session-storage.mjs +3 -0
- package/lib/@types/storage.d.ts.map +1 -1
- package/lib/create-async-persisted-state.d.ts +2 -2
- package/lib/create-async-persisted-state.d.ts.map +1 -1
- package/lib/create-async-persisted-state.js +62 -12
- package/lib/create-async-persisted-state.js.map +1 -1
- package/lib/create-persisted-state.d.ts +2 -2
- package/lib/create-persisted-state.d.ts.map +1 -1
- package/lib/create-persisted-state.js +31 -13
- package/lib/create-persisted-state.js.map +1 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/storages/browser-storage.d.ts +2 -2
- package/lib/storages/browser-storage.d.ts.map +1 -1
- package/lib/storages/browser-storage.js +6 -26
- package/lib/storages/browser-storage.js.map +1 -1
- package/lib/storages/chrome-storage.d.ts +2 -2
- package/lib/storages/chrome-storage.d.ts.map +1 -1
- package/lib/storages/chrome-storage.js +10 -27
- package/lib/storages/chrome-storage.js.map +1 -1
- package/lib/storages/local-storage.d.ts +1 -1
- package/lib/storages/local-storage.d.ts.map +1 -1
- package/lib/storages/local-storage.js +3 -1
- package/lib/storages/local-storage.js.map +1 -1
- package/lib/storages/session-storage.d.ts +1 -1
- package/lib/storages/session-storage.d.ts.map +1 -1
- package/lib/storages/session-storage.js +3 -1
- package/lib/storages/session-storage.js.map +1 -1
- package/lib/utils/change-notifier.d.ts +18 -0
- package/lib/utils/change-notifier.d.ts.map +1 -0
- package/lib/utils/change-notifier.js +38 -0
- package/lib/utils/change-notifier.js.map +1 -0
- package/lib/utils/create-web-storage.d.ts +10 -2
- package/lib/utils/create-web-storage.d.ts.map +1 -1
- package/lib/utils/create-web-storage.js +72 -75
- package/lib/utils/create-web-storage.js.map +1 -1
- package/lib/utils/extension-storage.d.ts +38 -0
- package/lib/utils/extension-storage.d.ts.map +1 -0
- package/lib/utils/extension-storage.js +66 -0
- package/lib/utils/extension-storage.js.map +1 -0
- package/lib/utils/get-new-item.d.ts.map +1 -1
- package/lib/utils/get-new-item.js.map +1 -1
- package/lib/utils/get-new-value.d.ts +1 -1
- package/lib/utils/get-new-value.d.ts.map +1 -1
- package/lib/utils/get-persisted-value.d.ts +8 -1
- package/lib/utils/get-persisted-value.d.ts.map +1 -1
- package/lib/utils/get-persisted-value.js +19 -5
- package/lib/utils/get-persisted-value.js.map +1 -1
- package/lib/utils/is-async-storage.d.ts +7 -0
- package/lib/utils/is-async-storage.d.ts.map +1 -1
- package/lib/utils/is-async-storage.js +51 -20
- package/lib/utils/is-async-storage.js.map +1 -1
- package/lib/utils/storage-event-router.d.ts +17 -0
- package/lib/utils/storage-event-router.d.ts.map +1 -0
- package/lib/utils/storage-event-router.js +54 -0
- package/lib/utils/storage-event-router.js.map +1 -0
- package/lib/utils/use-storage-handler.d.ts +3 -3
- package/lib/utils/use-storage-handler.d.ts.map +1 -1
- package/lib/utils/use-storage-handler.js +80 -26
- package/lib/utils/use-storage-handler.js.map +1 -1
- package/package.json +97 -41
- package/src/@types/storage.ts +13 -13
- package/src/create-async-persisted-state.ts +81 -18
- package/src/create-persisted-state.ts +48 -22
- package/src/index.ts +12 -7
- package/src/storages/browser-storage.ts +8 -36
- package/src/storages/chrome-storage.ts +24 -46
- package/src/storages/local-storage.ts +3 -1
- package/src/storages/session-storage.ts +3 -1
- package/src/utils/change-notifier.ts +43 -0
- package/src/utils/create-web-storage.ts +74 -77
- package/src/utils/extension-storage.ts +79 -0
- package/src/utils/get-new-item.ts +1 -1
- package/src/utils/get-new-value.ts +1 -1
- package/src/utils/get-persisted-value.ts +22 -7
- package/src/utils/is-async-storage.ts +72 -27
- package/src/utils/storage-event-router.ts +67 -0
- package/src/utils/use-storage-handler.ts +112 -36
- package/storages/browser-storage.d.ts +1 -0
- package/storages/browser-storage.js +11 -0
- package/storages/chrome-storage.d.ts +1 -0
- package/storages/chrome-storage.js +11 -0
- package/storages/local-storage.d.ts +1 -0
- package/storages/local-storage.js +9 -0
- package/storages/session-storage.d.ts +1 -0
- package/storages/session-storage.js +9 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AsyncStorage } from '../@types/storage';
|
|
1
|
+
import type { AsyncStorage } from '../@types/storage';
|
|
2
2
|
declare const local: AsyncStorage;
|
|
3
3
|
declare const sync: AsyncStorage;
|
|
4
4
|
declare const managed: AsyncStorage;
|
|
5
|
-
export { local, sync, managed
|
|
5
|
+
export { local, sync, managed };
|
|
6
6
|
//# sourceMappingURL=browser-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-storage.d.ts","sourceRoot":"","sources":["../../src/storages/browser-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"browser-storage.d.ts","sourceRoot":"","sources":["../../src/storages/browser-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAiBrD,QAAA,MAAM,KAAK,cAAgD,CAAA;AAC3D,QAAA,MAAM,IAAI,cAA8C,CAAA;AACxD,QAAA,MAAM,OAAO,cAAoD,CAAA;AAEjE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,37 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.managed = exports.sync = exports.local = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
sync: new Set(),
|
|
7
|
-
managed: new Set(),
|
|
8
|
-
};
|
|
9
|
-
function fireStorageEvent(changes, area) {
|
|
10
|
-
listeners[area].forEach(listener => {
|
|
11
|
-
listener(changes);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
4
|
+
const extension_storage_1 = require("../utils/extension-storage");
|
|
5
|
+
const registry = (0, extension_storage_1.createListenerRegistry)();
|
|
14
6
|
browser.storage.onChanged.addListener((changes, area) => {
|
|
15
|
-
|
|
7
|
+
registry.fire((0, extension_storage_1.toStorageChanges)(changes), area);
|
|
16
8
|
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
addListener(listener) {
|
|
20
|
-
listeners[area].add(listener);
|
|
21
|
-
},
|
|
22
|
-
removeListener(listener) {
|
|
23
|
-
listeners[area].delete(listener);
|
|
24
|
-
},
|
|
25
|
-
hasListener(listener) {
|
|
26
|
-
return listeners[area].has(listener);
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
9
|
+
// browser.storage is promise-based, unlike its callback-based chrome counterpart.
|
|
30
10
|
const createStorage = (storage, area) => ({
|
|
31
|
-
get: storage.get,
|
|
11
|
+
get: async (keys) => (0, extension_storage_1.toStoredItems)(await storage.get(keys)),
|
|
32
12
|
set: storage.set,
|
|
33
13
|
remove: storage.remove,
|
|
34
|
-
onChanged: createOnChanged(area),
|
|
14
|
+
onChanged: registry.createOnChanged(area),
|
|
35
15
|
});
|
|
36
16
|
const local = createStorage(browser.storage.local, 'local');
|
|
37
17
|
exports.local = local;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-storage.js","sourceRoot":"","sources":["../../src/storages/browser-storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"browser-storage.js","sourceRoot":"","sources":["../../src/storages/browser-storage.ts"],"names":[],"mappings":";;;AACA,kEAA+G;AAE/G,MAAM,QAAQ,GAAG,IAAA,0CAAsB,GAAE,CAAA;AAEzC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACtD,QAAQ,CAAC,IAAI,CAAC,IAAA,oCAAgB,EAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AAChD,CAAC,CAAC,CAAA;AAEF,kFAAkF;AAClF,MAAM,aAAa,GAAG,CAAC,OAAoC,EAAE,IAAU,EAAgB,EAAE,CAAC,CAAC;IACzF,GAAG,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE,CAAC,IAAA,iCAAa,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACzD,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,MAAM,EAAE,OAAO,CAAC,MAAM;IACtB,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC;CAC1C,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAIlD,sBAAK;AAHd,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAGxC,oBAAI;AAFpB,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE3C,0BAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AsyncStorage } from '../@types/storage';
|
|
1
|
+
import type { AsyncStorage } from '../@types/storage';
|
|
2
2
|
declare const local: AsyncStorage;
|
|
3
3
|
declare const sync: AsyncStorage;
|
|
4
4
|
declare const managed: AsyncStorage;
|
|
5
|
-
export { local, sync, managed
|
|
5
|
+
export { local, sync, managed };
|
|
6
6
|
//# sourceMappingURL=chrome-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chrome-storage.d.ts","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"chrome-storage.d.ts","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AA+BrD,QAAA,MAAM,KAAK,cAA+C,CAAA;AAC1D,QAAA,MAAM,IAAI,cAA6C,CAAA;AACvD,QAAA,MAAM,OAAO,cAAmD,CAAA;AAEhE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.managed = exports.sync = exports.local = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
sync: new Set(),
|
|
7
|
-
managed: new Set(),
|
|
8
|
-
};
|
|
9
|
-
function fireStorageEvent(changes, area) {
|
|
10
|
-
listeners[area].forEach(listener => {
|
|
11
|
-
listener(changes);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
4
|
+
const extension_storage_1 = require("../utils/extension-storage");
|
|
5
|
+
const registry = (0, extension_storage_1.createListenerRegistry)();
|
|
14
6
|
chrome.storage.onChanged.addListener((changes, area) => {
|
|
15
|
-
|
|
7
|
+
registry.fire((0, extension_storage_1.toStorageChanges)(changes), area);
|
|
16
8
|
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
addListener(listener) {
|
|
20
|
-
listeners[area].add(listener);
|
|
21
|
-
},
|
|
22
|
-
removeListener(listener) {
|
|
23
|
-
listeners[area].delete(listener);
|
|
24
|
-
},
|
|
25
|
-
hasListener(listener) {
|
|
26
|
-
return listeners[area].has(listener);
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
9
|
+
// chrome.storage is callback-based, unlike its promise-based firefox counterpart.
|
|
30
10
|
const createStorage = (storage, area) => ({
|
|
31
|
-
|
|
11
|
+
// Declared async, like the firefox adapter, so that asking whether this
|
|
12
|
+
// storage is asynchronous can be answered from the function itself instead of
|
|
13
|
+
// by calling it — a call here costs a round trip to the extension process.
|
|
14
|
+
get: async (keys) => new Promise(resolve => {
|
|
32
15
|
storage.get(keys, items => {
|
|
33
|
-
resolve(items);
|
|
16
|
+
resolve((0, extension_storage_1.toStoredItems)(items));
|
|
34
17
|
});
|
|
35
18
|
}),
|
|
36
19
|
set: items => new Promise(resolve => {
|
|
@@ -39,7 +22,7 @@ const createStorage = (storage, area) => ({
|
|
|
39
22
|
remove: keys => new Promise(resolve => {
|
|
40
23
|
storage.remove(keys, resolve);
|
|
41
24
|
}),
|
|
42
|
-
onChanged: createOnChanged(area),
|
|
25
|
+
onChanged: registry.createOnChanged(area),
|
|
43
26
|
});
|
|
44
27
|
const local = createStorage(chrome.storage.local, 'local');
|
|
45
28
|
exports.local = local;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chrome-storage.js","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"chrome-storage.js","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":";;;AACA,kEAA+G;AAE/G,MAAM,QAAQ,GAAG,IAAA,0CAAsB,GAAE,CAAA;AAEzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACrD,QAAQ,CAAC,IAAI,CAAC,IAAA,oCAAgB,EAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AAChD,CAAC,CAAC,CAAA;AAEF,kFAAkF;AAClF,MAAM,aAAa,GAAG,CAAC,OAAmC,EAAE,IAAU,EAAgB,EAAE,CAAC,CAAC;IACxF,wEAAwE;IACxE,8EAA8E;IAC9E,2EAA2E;IAC3E,GAAG,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE,CAChB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;YACxB,OAAO,CAAC,IAAA,iCAAa,EAAC,KAAK,CAAC,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC;IACJ,GAAG,EAAE,KAAK,CAAC,EAAE,CACX,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC;IACJ,MAAM,EAAE,IAAI,CAAC,EAAE,CACb,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC,CAAC;IACJ,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC;CAC1C,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAIjD,sBAAK;AAHd,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAGvC,oBAAI;AAFpB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE1C,0BAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";AAIA,wBAA4F"}
|
|
@@ -4,5 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const create_web_storage_1 = __importDefault(require("../utils/create-web-storage"));
|
|
7
|
-
|
|
7
|
+
// The typeof guard keeps this import from throwing on server runtimes (SSR),
|
|
8
|
+
// where the browser storage globals are not defined.
|
|
9
|
+
exports.default = (0, create_web_storage_1.default)(typeof localStorage !== 'undefined' ? localStorage : undefined);
|
|
8
10
|
//# sourceMappingURL=local-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,kBAAe,IAAA,4BAAa,EAAC,YAAY,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,6EAA6E;AAC7E,qDAAqD;AACrD,kBAAe,IAAA,4BAAa,EAAC,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";AAIA,wBAAgG"}
|
|
@@ -4,5 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const create_web_storage_1 = __importDefault(require("../utils/create-web-storage"));
|
|
7
|
-
|
|
7
|
+
// The typeof guard keeps this import from throwing on server runtimes (SSR),
|
|
8
|
+
// where the browser storage globals are not defined.
|
|
9
|
+
exports.default = (0, create_web_storage_1.default)(typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
|
|
8
10
|
//# sourceMappingURL=session-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,kBAAe,IAAA,4BAAa,EAAC,cAAc,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,6EAA6E;AAC7E,qDAAqD;AACrD,kBAAe,IAAA,4BAAa,EAAC,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StorageChange, StorageChangeEvent } from '../@types/storage';
|
|
2
|
+
export interface ChangeNotifier {
|
|
3
|
+
fire(changes: {
|
|
4
|
+
[key: string]: StorageChange;
|
|
5
|
+
}): void;
|
|
6
|
+
hasListeners(): boolean;
|
|
7
|
+
onChanged: StorageChangeEvent;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Holds the subscribers of a single change source. Each adapter — and, for the
|
|
11
|
+
* extension backends, each storage area — owns one, so a change never reaches
|
|
12
|
+
* listeners that subscribed elsewhere.
|
|
13
|
+
*
|
|
14
|
+
* Routing a backend's events to the right notifier stays with the adapter: the
|
|
15
|
+
* extensions demultiplex one event by area name, the DOM one by storage object.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createChangeNotifier(): ChangeNotifier;
|
|
18
|
+
//# sourceMappingURL=change-notifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-notifier.d.ts","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAyB,MAAM,mBAAmB,CAAA;AAEjG,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,GAAG,IAAI,CAAA;IACrD,YAAY,IAAI,OAAO,CAAA;IACvB,SAAS,EAAE,kBAAkB,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CA0BrD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createChangeNotifier = createChangeNotifier;
|
|
4
|
+
/**
|
|
5
|
+
* Holds the subscribers of a single change source. Each adapter — and, for the
|
|
6
|
+
* extension backends, each storage area — owns one, so a change never reaches
|
|
7
|
+
* listeners that subscribed elsewhere.
|
|
8
|
+
*
|
|
9
|
+
* Routing a backend's events to the right notifier stays with the adapter: the
|
|
10
|
+
* extensions demultiplex one event by area name, the DOM one by storage object.
|
|
11
|
+
*/
|
|
12
|
+
function createChangeNotifier() {
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
return {
|
|
15
|
+
fire(changes) {
|
|
16
|
+
for (const listener of listeners) {
|
|
17
|
+
listener(changes);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
// Lets an adapter release a shared resource once nobody is listening; the
|
|
21
|
+
// set behind onChanged stays the only count, so the two cannot drift.
|
|
22
|
+
hasListeners() {
|
|
23
|
+
return listeners.size > 0;
|
|
24
|
+
},
|
|
25
|
+
onChanged: {
|
|
26
|
+
addListener(listener) {
|
|
27
|
+
listeners.add(listener);
|
|
28
|
+
},
|
|
29
|
+
removeListener(listener) {
|
|
30
|
+
listeners.delete(listener);
|
|
31
|
+
},
|
|
32
|
+
hasListener(listener) {
|
|
33
|
+
return listeners.has(listener);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=change-notifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-notifier.js","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":";;AAgBA,oDA0BC;AAlCD;;;;;;;GAOG;AACH,SAAgB,oBAAoB;IAClC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;IAElD,OAAO;QACL,IAAI,CAAC,OAAO;YACV,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,QAAQ,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QACD,0EAA0E;QAC1E,sEAAsE;QACtE,YAAY;YACV,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAA;QAC3B,CAAC;QACD,SAAS,EAAE;YACT,WAAW,CAAC,QAAQ;gBAClB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACzB,CAAC;YACD,cAAc,CAAC,QAAQ;gBACrB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC;YACD,WAAW,CAAC,QAAQ;gBAClB,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAChC,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { Storage } from '../@types/storage';
|
|
2
|
-
|
|
1
|
+
import type { Storage } from '../@types/storage';
|
|
2
|
+
/**
|
|
3
|
+
* Adapts a Web Storage area to the library's `Storage` contract.
|
|
4
|
+
*
|
|
5
|
+
* Pass `undefined` where the global is missing, as it is on a server: the
|
|
6
|
+
* adapter then reads back nothing and **silently discards every write**, so a
|
|
7
|
+
* consumer keeps its initial value instead of the import throwing. Listeners
|
|
8
|
+
* are still accepted and reported, they simply never fire.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (storage: globalThis.Storage | undefined) => Storage;
|
|
3
11
|
export default _default;
|
|
4
12
|
//# sourceMappingURL=create-web-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-web-storage.d.ts","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"create-web-storage.d.ts","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAqC,MAAM,mBAAmB,CAAA;AAQnF;;;;;;;GAOG;yBACa,SAAS,UAAU,CAAC,OAAO,GAAG,SAAS,KAAG,OAAO;AAAjE,wBAqFC"}
|
|
@@ -1,92 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
3
|
+
const change_notifier_1 = require("./change-notifier");
|
|
4
|
+
const storage_event_router_1 = require("./storage-event-router");
|
|
5
|
+
function toKeyList(keys) {
|
|
6
|
+
return Array.isArray(keys) ? keys : [keys];
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Adapts a Web Storage area to the library's `Storage` contract.
|
|
10
|
+
*
|
|
11
|
+
* Pass `undefined` where the global is missing, as it is on a server: the
|
|
12
|
+
* adapter then reads back nothing and **silently discards every write**, so a
|
|
13
|
+
* consumer keeps its initial value instead of the import throwing. Listeners
|
|
14
|
+
* are still accepted and reported, they simply never fire.
|
|
15
|
+
*/
|
|
16
|
+
exports.default = (storage) => {
|
|
17
|
+
// Per-instance notifier: the localStorage and sessionStorage adapters must not
|
|
18
|
+
// share listeners, or a write to one area notifies subscribers of the other.
|
|
19
|
+
const notifier = (0, change_notifier_1.createChangeNotifier)();
|
|
20
|
+
// Only a missing global is inert. Anything else a caller passes has to fail
|
|
21
|
+
// on first use instead of swallowing their writes.
|
|
22
|
+
if (storage === undefined) {
|
|
23
|
+
return {
|
|
24
|
+
get: () => ({}),
|
|
25
|
+
set: () => { },
|
|
26
|
+
remove: () => { },
|
|
27
|
+
onChanged: notifier.onChanged,
|
|
16
28
|
};
|
|
17
|
-
fireStorageEvent(changes);
|
|
18
29
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const route = { storage, fire: notifier.fire };
|
|
31
|
+
// The DOM subscription is shared and reference counted: an adapter joins it
|
|
32
|
+
// with its first listener and lets go with its last, so factory calls nobody
|
|
33
|
+
// listens to leave nothing attached to the global object.
|
|
34
|
+
const onChanged = {
|
|
35
|
+
addListener(listener) {
|
|
36
|
+
notifier.onChanged.addListener(listener);
|
|
37
|
+
(0, storage_event_router_1.addRoute)(route);
|
|
38
|
+
},
|
|
39
|
+
removeListener(listener) {
|
|
40
|
+
notifier.onChanged.removeListener(listener);
|
|
41
|
+
if (!notifier.hasListeners())
|
|
42
|
+
(0, storage_event_router_1.removeRoute)(route);
|
|
43
|
+
},
|
|
44
|
+
hasListener(listener) {
|
|
45
|
+
return notifier.onChanged.hasListener(listener);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
get: keys => {
|
|
50
|
+
const result = {};
|
|
51
|
+
for (const key of toKeyList(keys)) {
|
|
52
|
+
const item = storage.getItem(key);
|
|
53
|
+
// `null` is the only answer that means absence: an empty string is a
|
|
54
|
+
// value the caller stored, and reporting it as a missing key loses it.
|
|
55
|
+
if (item !== null)
|
|
38
56
|
result[key] = item;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return result;
|
|
47
|
-
},
|
|
48
|
-
set: items => {
|
|
49
|
-
const changes = {};
|
|
50
|
-
Object.entries(items).forEach(([key, value]) => {
|
|
51
|
-
const oldValue = typeof storage !== 'undefined' ? storage.getItem(key) : undefined;
|
|
52
|
-
if (typeof storage !== 'undefined') {
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
},
|
|
60
|
+
set: items => {
|
|
61
|
+
const changes = {};
|
|
62
|
+
for (const [key, value] of Object.entries(items)) {
|
|
63
|
+
const oldValue = storage.getItem(key);
|
|
53
64
|
storage.setItem(key, value);
|
|
54
65
|
changes[key] = {
|
|
55
66
|
oldValue,
|
|
56
67
|
newValue: value,
|
|
57
68
|
};
|
|
58
69
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (typeof storage !== 'undefined') {
|
|
69
|
-
storage.removeItem(key);
|
|
70
|
-
changes[key] = {
|
|
71
|
-
oldValue,
|
|
72
|
-
newValue: null,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const oldValue = typeof storage !== 'undefined' ? storage.getItem(keys) : undefined;
|
|
79
|
-
if (typeof storage !== 'undefined') {
|
|
80
|
-
storage.removeItem(keys);
|
|
81
|
-
changes[keys] = {
|
|
70
|
+
if (Object.keys(changes).length > 0)
|
|
71
|
+
notifier.fire(changes);
|
|
72
|
+
},
|
|
73
|
+
remove: keys => {
|
|
74
|
+
const changes = {};
|
|
75
|
+
for (const key of toKeyList(keys)) {
|
|
76
|
+
const oldValue = storage.getItem(key);
|
|
77
|
+
storage.removeItem(key);
|
|
78
|
+
changes[key] = {
|
|
82
79
|
oldValue,
|
|
83
80
|
newValue: null,
|
|
84
81
|
};
|
|
85
82
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
83
|
+
if (Object.keys(changes).length > 0)
|
|
84
|
+
notifier.fire(changes);
|
|
85
|
+
},
|
|
86
|
+
onChanged,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
92
89
|
//# sourceMappingURL=create-web-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-web-storage.js","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-web-storage.js","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { StorageChange, StorageChangeEvent } from '../@types/storage';
|
|
2
|
+
declare const TRACKED_AREAS: readonly ["local", "sync", "managed"];
|
|
3
|
+
export type Area = (typeof TRACKED_AREAS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* Extension storage holds arbitrary JSON, while this library only ever writes
|
|
6
|
+
* serialized strings. Anything else under a key belongs to other code and is
|
|
7
|
+
* reported as absent — which is what effectively happened before, once such a
|
|
8
|
+
* value reached `JSON.parse` and the hook fell back to its initial value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toStoredValue(value: unknown): string | null | undefined;
|
|
11
|
+
export declare function toStorageChanges(changes: {
|
|
12
|
+
[key: string]: {
|
|
13
|
+
oldValue?: unknown;
|
|
14
|
+
newValue?: unknown;
|
|
15
|
+
};
|
|
16
|
+
}): {
|
|
17
|
+
[key: string]: StorageChange;
|
|
18
|
+
};
|
|
19
|
+
export declare function toStoredItems(items: {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}): {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
export interface ListenerRegistry {
|
|
25
|
+
fire(changes: {
|
|
26
|
+
[key: string]: StorageChange;
|
|
27
|
+
}, area: string): void;
|
|
28
|
+
createOnChanged(area: Area): StorageChangeEvent;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Demultiplexes an extension's single `onChanged` event, which names the area
|
|
32
|
+
* that changed, to one notifier per area. Each adapter owns its own registry,
|
|
33
|
+
* so a change in one browser's storage never reaches listeners registered on
|
|
34
|
+
* another's.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createListenerRegistry(): ListenerRegistry;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=extension-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-storage.d.ts","sourceRoot":"","sources":["../../src/utils/extension-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAG1E,QAAA,MAAM,aAAa,uCAAwC,CAAA;AAE3D,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAQjD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAIvE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GAAG;IACxG,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAC7B,CAWA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAQ1F;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnE,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAA;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAiBzD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toStoredValue = toStoredValue;
|
|
4
|
+
exports.toStorageChanges = toStorageChanges;
|
|
5
|
+
exports.toStoredItems = toStoredItems;
|
|
6
|
+
exports.createListenerRegistry = createListenerRegistry;
|
|
7
|
+
const change_notifier_1 = require("./change-notifier");
|
|
8
|
+
const TRACKED_AREAS = ['local', 'sync', 'managed'];
|
|
9
|
+
// Both browsers also report `session` changes, an area this library does not
|
|
10
|
+
// expose. Dispatching one would read an undefined notifier and throw.
|
|
11
|
+
function isTrackedArea(area) {
|
|
12
|
+
return TRACKED_AREAS.includes(area);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extension storage holds arbitrary JSON, while this library only ever writes
|
|
16
|
+
* serialized strings. Anything else under a key belongs to other code and is
|
|
17
|
+
* reported as absent — which is what effectively happened before, once such a
|
|
18
|
+
* value reached `JSON.parse` and the hook fell back to its initial value.
|
|
19
|
+
*/
|
|
20
|
+
function toStoredValue(value) {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return;
|
|
23
|
+
return typeof value === 'string' ? value : null;
|
|
24
|
+
}
|
|
25
|
+
function toStorageChanges(changes) {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const [key, change] of Object.entries(changes)) {
|
|
28
|
+
result[key] = {
|
|
29
|
+
oldValue: toStoredValue(change.oldValue),
|
|
30
|
+
newValue: toStoredValue(change.newValue),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function toStoredItems(items) {
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, value] of Object.entries(items)) {
|
|
38
|
+
if (typeof value === 'string')
|
|
39
|
+
result[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Demultiplexes an extension's single `onChanged` event, which names the area
|
|
45
|
+
* that changed, to one notifier per area. Each adapter owns its own registry,
|
|
46
|
+
* so a change in one browser's storage never reaches listeners registered on
|
|
47
|
+
* another's.
|
|
48
|
+
*/
|
|
49
|
+
function createListenerRegistry() {
|
|
50
|
+
const notifiers = {
|
|
51
|
+
local: (0, change_notifier_1.createChangeNotifier)(),
|
|
52
|
+
sync: (0, change_notifier_1.createChangeNotifier)(),
|
|
53
|
+
managed: (0, change_notifier_1.createChangeNotifier)(),
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
fire(changes, area) {
|
|
57
|
+
if (!isTrackedArea(area))
|
|
58
|
+
return;
|
|
59
|
+
notifiers[area].fire(changes);
|
|
60
|
+
},
|
|
61
|
+
createOnChanged(area) {
|
|
62
|
+
return notifiers[area].onChanged;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=extension-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-storage.js","sourceRoot":"","sources":["../../src/utils/extension-storage.ts"],"names":[],"mappings":";;AAmBA,sCAIC;AAED,4CAaC;AAED,sCAQC;AAaD,wDAiBC;AA7ED,uDAA6E;AAE7E,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAU,CAAA;AAI3D,6EAA6E;AAC7E,sEAAsE;AACtE,SAAS,aAAa,CAAC,IAAY;IACjC,OAAQ,aAAmC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAM;IAE/B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAAsE;IAGrG,MAAM,MAAM,GAAqC,EAAE,CAAA;IAEnD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,GAAG,CAAC,GAAG;YACZ,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC;SACzC,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAgB,aAAa,CAAC,KAAiC;IAC7D,MAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACpD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAOD;;;;;GAKG;AACH,SAAgB,sBAAsB;IACpC,MAAM,SAAS,GAAuC;QACpD,KAAK,EAAE,IAAA,sCAAoB,GAAE;QAC7B,IAAI,EAAE,IAAA,sCAAoB,GAAE;QAC5B,OAAO,EAAE,IAAA,sCAAoB,GAAE;KAChC,CAAA;IAED,OAAO;QACL,IAAI,CAAC,OAAO,EAAE,IAAI;YAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;gBAAE,OAAM;YAEhC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,CAAC;QACD,eAAe,CAAC,IAAI;YAClB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-new-item.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"get-new-item.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAenF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-new-item.js","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":";;AAAA,4BAeC;AAfD,
|
|
1
|
+
{"version":3,"file":"get-new-item.js","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":";;AAAA,4BAeC;AAfD,mBAA4B,GAAW,EAAE,aAAqB,EAAE,QAAW;IACzE,IAAI,OAAiC,CAAA;IAErC,IAAI,CAAC;QACH,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,OAAO,GAAG,EAAE,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACrB,CAAC,GAAG,CAAC,EAAE,QAAQ;KAChB,CAAC,CACH,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-new-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"get-new-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,CAAC,OAAO,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAU1E"}
|