@webiny/app 5.44.1-beta.2 → 5.44.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/index.d.ts +1 -0
- package/index.js +16 -1
- package/index.js.map +1 -1
- package/localStorage/feature/BrowserLocalStorageGateway.d.ts +9 -0
- package/localStorage/feature/BrowserLocalStorageGateway.js +93 -0
- package/localStorage/feature/BrowserLocalStorageGateway.js.map +1 -0
- package/localStorage/feature/LocalStorage.d.ts +11 -0
- package/localStorage/feature/LocalStorage.js +45 -0
- package/localStorage/feature/LocalStorage.js.map +1 -0
- package/localStorage/feature/LocalStorageRepository.d.ts +21 -0
- package/localStorage/feature/LocalStorageRepository.js +126 -0
- package/localStorage/feature/LocalStorageRepository.js.map +1 -0
- package/localStorage/feature/abstractions.d.ts +31 -0
- package/localStorage/feature/abstractions.js +7 -0
- package/localStorage/feature/abstractions.js.map +1 -0
- package/localStorage/feature/feature.d.ts +3 -0
- package/localStorage/feature/feature.js +16 -0
- package/localStorage/feature/feature.js.map +1 -0
- package/localStorage/presentation/LocalStorageProvider.d.ts +12 -0
- package/localStorage/presentation/LocalStorageProvider.js +36 -0
- package/localStorage/presentation/LocalStorageProvider.js.map +1 -0
- package/package.json +10 -9
- package/utils/getLocaleCode.js +1 -16
- package/utils/getLocaleCode.js.map +1 -1
package/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export * from "./core/createProvider";
|
|
|
15
15
|
export * from "./core/createProviderPlugin";
|
|
16
16
|
export * from "./renderApp";
|
|
17
17
|
export * from "./utils/createGenericContext";
|
|
18
|
+
export { useLocalStorage, LocalStorageProvider } from "./localStorage/presentation/LocalStorageProvider";
|
package/index.js
CHANGED
|
@@ -8,7 +8,9 @@ var _exportNames = {
|
|
|
8
8
|
ApolloLinkPlugin: true,
|
|
9
9
|
RoutePlugin: true,
|
|
10
10
|
ApolloCacheObjectIdPlugin: true,
|
|
11
|
-
ApolloCacheObject: true
|
|
11
|
+
ApolloCacheObject: true,
|
|
12
|
+
useLocalStorage: true,
|
|
13
|
+
LocalStorageProvider: true
|
|
12
14
|
};
|
|
13
15
|
Object.defineProperty(exports, "AddQuerySelectionPlugin", {
|
|
14
16
|
enumerable: true,
|
|
@@ -34,12 +36,24 @@ Object.defineProperty(exports, "ApolloLinkPlugin", {
|
|
|
34
36
|
return _ApolloLinkPlugin.ApolloLinkPlugin;
|
|
35
37
|
}
|
|
36
38
|
});
|
|
39
|
+
Object.defineProperty(exports, "LocalStorageProvider", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function get() {
|
|
42
|
+
return _LocalStorageProvider.LocalStorageProvider;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
37
45
|
Object.defineProperty(exports, "RoutePlugin", {
|
|
38
46
|
enumerable: true,
|
|
39
47
|
get: function get() {
|
|
40
48
|
return _RoutePlugin.RoutePlugin;
|
|
41
49
|
}
|
|
42
50
|
});
|
|
51
|
+
Object.defineProperty(exports, "useLocalStorage", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function get() {
|
|
54
|
+
return _LocalStorageProvider.useLocalStorage;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
43
57
|
var _AddQuerySelectionPlugin = require("./plugins/AddQuerySelectionPlugin");
|
|
44
58
|
var _ApolloLinkPlugin = require("./plugins/ApolloLinkPlugin");
|
|
45
59
|
var _RoutePlugin = require("./plugins/RoutePlugin");
|
|
@@ -176,5 +190,6 @@ Object.keys(_createGenericContext).forEach(function (key) {
|
|
|
176
190
|
}
|
|
177
191
|
});
|
|
178
192
|
});
|
|
193
|
+
var _LocalStorageProvider = require("./localStorage/presentation/LocalStorageProvider");
|
|
179
194
|
|
|
180
195
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_AddQuerySelectionPlugin","require","_ApolloLinkPlugin","_RoutePlugin","_ApolloCacheObjectIdPlugin","_reactComposition","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_App","_Plugins","_Plugin","_Provider","_AddRoute","_DebounceRender","_createProvider","_createProviderPlugin","_renderApp","_createGenericContext"],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin\";\nexport { RoutePlugin } from \"./plugins/RoutePlugin\";\nexport { ApolloCacheObjectIdPlugin, ApolloCacheObject } from \"./plugins/ApolloCacheObjectIdPlugin\";\n\n// Composition - we re-export this for ease of use\nexport * from \"@webiny/react-composition\";\nexport type { HigherOrderComponent, ComposeProps, ComposableFC } from \"@webiny/react-composition\";\n\n// App framework\nexport * from \"./App\";\nexport type { AppProps } from \"./App\";\nexport * from \"./core/Plugins\";\nexport * from \"./core/Plugin\";\nexport * from \"./core/Provider\";\nexport * from \"./core/AddRoute\";\nexport * from \"./core/DebounceRender\";\nexport * from \"./core/createProvider\";\nexport * from \"./core/createProviderPlugin\";\nexport * from \"./renderApp\";\nexport * from \"./utils/createGenericContext\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_AddQuerySelectionPlugin","require","_ApolloLinkPlugin","_RoutePlugin","_ApolloCacheObjectIdPlugin","_reactComposition","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_App","_Plugins","_Plugin","_Provider","_AddRoute","_DebounceRender","_createProvider","_createProviderPlugin","_renderApp","_createGenericContext","_LocalStorageProvider"],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin\";\nexport { RoutePlugin } from \"./plugins/RoutePlugin\";\nexport { ApolloCacheObjectIdPlugin, ApolloCacheObject } from \"./plugins/ApolloCacheObjectIdPlugin\";\n\n// Composition - we re-export this for ease of use\nexport * from \"@webiny/react-composition\";\nexport type { HigherOrderComponent, ComposeProps, ComposableFC } from \"@webiny/react-composition\";\n\n// App framework\nexport * from \"./App\";\nexport type { AppProps } from \"./App\";\nexport * from \"./core/Plugins\";\nexport * from \"./core/Plugin\";\nexport * from \"./core/Provider\";\nexport * from \"./core/AddRoute\";\nexport * from \"./core/DebounceRender\";\nexport * from \"./core/createProvider\";\nexport * from \"./core/createProviderPlugin\";\nexport * from \"./renderApp\";\nexport * from \"./utils/createGenericContext\";\nexport {\n useLocalStorage,\n LocalStorageProvider\n} from \"./localStorage/presentation/LocalStorageProvider\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,0BAAA,GAAAH,OAAA;AAGA,IAAAI,iBAAA,GAAAJ,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAF,iBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,iBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAZ,iBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAIA,IAAAS,IAAA,GAAAjB,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAW,IAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,I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,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAS,UAAA,CAAAjB,GAAA;IAAA;EAAA;AAAA;AACA,IAAAkB,qBAAA,GAAA1B,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAoB,qBAAA,EAAAnB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAkB,qBAAA,CAAAlB,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAU,qBAAA,CAAAlB,GAAA;IAAA;EAAA;AAAA;AACA,IAAAmB,qBAAA,GAAA3B,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILocalStorageGateway } from "./abstractions.js";
|
|
2
|
+
export declare class BrowserLocalStorageGateway implements ILocalStorageGateway {
|
|
3
|
+
get<T = string>(key: string): T | null;
|
|
4
|
+
set<T = string>(key: string, value: T): void;
|
|
5
|
+
remove(key: string): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
getAll(): Record<string, unknown>;
|
|
8
|
+
subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BrowserLocalStorageGateway = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var BrowserLocalStorageGateway = exports.BrowserLocalStorageGateway = /*#__PURE__*/function () {
|
|
11
|
+
function BrowserLocalStorageGateway() {
|
|
12
|
+
(0, _classCallCheck2.default)(this, BrowserLocalStorageGateway);
|
|
13
|
+
}
|
|
14
|
+
return (0, _createClass2.default)(BrowserLocalStorageGateway, [{
|
|
15
|
+
key: "get",
|
|
16
|
+
value: function get(key) {
|
|
17
|
+
var value = window.localStorage.getItem(key);
|
|
18
|
+
try {
|
|
19
|
+
return value ? JSON.parse(value) : null;
|
|
20
|
+
} catch (_unused) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
key: "set",
|
|
26
|
+
value: function set(key, value) {
|
|
27
|
+
var serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
28
|
+
window.localStorage.setItem(key, serialized);
|
|
29
|
+
|
|
30
|
+
// Dispatch local event so same-tab listeners are notified.
|
|
31
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
32
|
+
detail: {
|
|
33
|
+
key: key,
|
|
34
|
+
value: value,
|
|
35
|
+
action: "set"
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "remove",
|
|
41
|
+
value: function remove(key) {
|
|
42
|
+
window.localStorage.removeItem(key);
|
|
43
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
44
|
+
detail: {
|
|
45
|
+
key: key,
|
|
46
|
+
action: "remove"
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "clear",
|
|
52
|
+
value: function clear() {
|
|
53
|
+
window.localStorage.clear();
|
|
54
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
55
|
+
detail: {
|
|
56
|
+
action: "clear"
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "getAll",
|
|
62
|
+
value: function getAll() {
|
|
63
|
+
var result = {};
|
|
64
|
+
for (var i = 0; i < window.localStorage.length; i++) {
|
|
65
|
+
var key = window.localStorage.key(i);
|
|
66
|
+
var val = this.get(key);
|
|
67
|
+
if (val !== null) {
|
|
68
|
+
result[key] = val;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Subscribe to changes (cross-tab + same-tab)
|
|
75
|
+
}, {
|
|
76
|
+
key: "subscribe",
|
|
77
|
+
value: function subscribe(listener) {
|
|
78
|
+
var handler = function handler(ev) {
|
|
79
|
+
if (ev instanceof StorageEvent || ev instanceof CustomEvent) {
|
|
80
|
+
listener(ev);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
window.addEventListener("storage", handler);
|
|
84
|
+
window.addEventListener("localstorage:changed", handler);
|
|
85
|
+
return function () {
|
|
86
|
+
window.removeEventListener("storage", handler);
|
|
87
|
+
window.removeEventListener("localstorage:changed", handler);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
}();
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=BrowserLocalStorageGateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BrowserLocalStorageGateway","exports","_classCallCheck2","default","_createClass2","key","value","get","window","localStorage","getItem","JSON","parse","_unused","set","serialized","stringify","setItem","dispatchEvent","CustomEvent","detail","action","remove","removeItem","clear","getAll","result","i","length","val","subscribe","listener","handler","ev","StorageEvent","addEventListener","removeEventListener"],"sources":["BrowserLocalStorageGateway.ts"],"sourcesContent":["import { ILocalStorageGateway } from \"./abstractions.js\";\n\nexport class BrowserLocalStorageGateway implements ILocalStorageGateway {\n get<T = string>(key: string): T | null {\n const value = window.localStorage.getItem(key);\n try {\n return value ? (JSON.parse(value) as T) : null;\n } catch {\n return value as unknown as T;\n }\n }\n\n set<T = string>(key: string, value: T): void {\n const serialized = typeof value === \"string\" ? value : JSON.stringify(value);\n window.localStorage.setItem(key, serialized);\n\n // Dispatch local event so same-tab listeners are notified.\n window.dispatchEvent(\n new CustomEvent(\"localstorage:changed\", {\n detail: { key, value, action: \"set\" }\n })\n );\n }\n\n remove(key: string): void {\n window.localStorage.removeItem(key);\n window.dispatchEvent(\n new CustomEvent(\"localstorage:changed\", {\n detail: { key, action: \"remove\" }\n })\n );\n }\n\n clear(): void {\n window.localStorage.clear();\n window.dispatchEvent(\n new CustomEvent(\"localstorage:changed\", {\n detail: { action: \"clear\" }\n })\n );\n }\n\n getAll(): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (let i = 0; i < window.localStorage.length; i++) {\n const key = window.localStorage.key(i)!;\n const val = this.get(key);\n if (val !== null) {\n result[key] = val;\n }\n }\n return result;\n }\n\n // Subscribe to changes (cross-tab + same-tab)\n subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void {\n const handler = (ev: Event) => {\n if (ev instanceof StorageEvent || ev instanceof CustomEvent) {\n listener(ev);\n }\n };\n window.addEventListener(\"storage\", handler);\n window.addEventListener(\"localstorage:changed\", handler as any);\n\n return () => {\n window.removeEventListener(\"storage\", handler);\n window.removeEventListener(\"localstorage:changed\", handler as any);\n };\n }\n}\n"],"mappings":";;;;;;;;;IAEaA,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA;EAAA,SAAAA,2BAAA;IAAA,IAAAE,gBAAA,CAAAC,OAAA,QAAAH,0BAAA;EAAA;EAAA,WAAAI,aAAA,CAAAD,OAAA,EAAAH,0BAAA;IAAAK,GAAA;IAAAC,KAAA,EACnC,SAAAC,GAAGA,CAAaF,GAAW,EAAY;MACnC,IAAMC,KAAK,GAAGE,MAAM,CAACC,YAAY,CAACC,OAAO,CAACL,GAAG,CAAC;MAC9C,IAAI;QACA,OAAOC,KAAK,G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AG,CAAC,CAAC;MAC1C,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGnB,MAAM,CAACC,YAAY,CAACmB,MAAM,EAAED,CAAC,EAAE,EAAE;QACjD,IAAMtB,GAAG,GAAGG,MAAM,CAACC,YAAY,CAACJ,GAAG,CAACsB,CAAC,CAAE;QACvC,IAAME,GAAG,GAAG,IAAI,CAACtB,GAAG,CAACF,GAAG,CAAC;QACzB,IAAIwB,GAAG,KAAK,IAAI,EAAE;UACdH,MAAM,CAACrB,GAAG,CAAC,GAAGwB,GAAG;QACrB;MACJ;MACA,OAAOH,MAAM;IACjB;;IAEA;EAAA;IAAArB,GAAA;IAAAC,KAAA,EACA,SAAAwB,SAASA,CAACC,QAAqD,EAAc;MACzE,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CAAIC,EAAS,EAAK;QAC3B,IAAIA,EAAE,YAAYC,YAAY,IAAID,EAAE,YAAYd,WAAW,EAAE;UACzDY,QAAQ,CAACE,EAAE,CAAC;QAChB;MACJ,CAAC;MACDzB,MAAM,CAAC2B,gBAAgB,CAAC,SAAS,EAAEH,OAAO,CAAC;MAC3CxB,MAAM,CAAC2B,gBAAgB,CAAC,sBAAsB,EAAEH,OAAc,CAAC;MAE/D,OAAO,YAAM;QACTxB,MAAM,CAAC4B,mBAAmB,CAAC,SAAS,EAAEJ,OAAO,CAAC;QAC9CxB,MAAM,CAAC4B,mBAAmB,CAAC,sBAAsB,EAAEJ,OAAc,CAAC;MACtE,CAAC;IACL;EAAC;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ILocalStorage } from "./abstractions.js";
|
|
2
|
+
import type { ILocalStorageRepository } from "./abstractions.js";
|
|
3
|
+
export declare class LocalStorage implements ILocalStorage {
|
|
4
|
+
private readonly repo;
|
|
5
|
+
constructor(repo: ILocalStorageRepository);
|
|
6
|
+
get<T = string>(key: string): T | undefined;
|
|
7
|
+
set<T = string>(key: string, value: T): void;
|
|
8
|
+
remove(key: string): void;
|
|
9
|
+
clear(): void;
|
|
10
|
+
keys(): string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LocalStorage = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _mobx = require("mobx");
|
|
11
|
+
var LocalStorage = exports.LocalStorage = /*#__PURE__*/function () {
|
|
12
|
+
function LocalStorage(repo) {
|
|
13
|
+
(0, _classCallCheck2.default)(this, LocalStorage);
|
|
14
|
+
this.repo = repo;
|
|
15
|
+
(0, _mobx.makeAutoObservable)(this);
|
|
16
|
+
}
|
|
17
|
+
return (0, _createClass2.default)(LocalStorage, [{
|
|
18
|
+
key: "get",
|
|
19
|
+
value: function get(key) {
|
|
20
|
+
return this.repo.get(key);
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "set",
|
|
24
|
+
value: function set(key, value) {
|
|
25
|
+
this.repo.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "remove",
|
|
29
|
+
value: function remove(key) {
|
|
30
|
+
this.repo.remove(key);
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "clear",
|
|
34
|
+
value: function clear() {
|
|
35
|
+
this.repo.clear();
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "keys",
|
|
39
|
+
value: function keys() {
|
|
40
|
+
return this.repo.keys();
|
|
41
|
+
}
|
|
42
|
+
}]);
|
|
43
|
+
}();
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=LocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mobx","require","LocalStorage","exports","repo","_classCallCheck2","default","makeAutoObservable","_createClass2","key","value","get","set","remove","clear","keys"],"sources":["LocalStorage.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport type { ILocalStorage } from \"~/localStorage/feature/abstractions.js\";\nimport type { ILocalStorageRepository } from \"~/localStorage/feature/abstractions.js\";\n\nexport class LocalStorage implements ILocalStorage {\n constructor(private readonly repo: ILocalStorageRepository) {\n makeAutoObservable(this);\n }\n\n get<T = string>(key: string) {\n return this.repo.get<T>(key);\n }\n\n set<T = string>(key: string, value: T) {\n this.repo.set(key, value);\n }\n\n remove(key: string) {\n this.repo.remove(key);\n }\n\n clear() {\n this.repo.clear();\n }\n\n keys() {\n return this.repo.keys();\n }\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAA0C,IAI7BC,YAAY,GAAAC,OAAA,CAAAD,YAAA;EACrB,SAAAA,aAA6BE,IAA6B,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAJ,YAAA;IAAA,KAA/BE,IAA6B,GAA7BA,IAA6B;IACtD,IAAAG,wBAAkB,EAAC,IAAI,CAAC;EAC5B;EAAC,WAAAC,aAAA,CAAAF,OAAA,EAAAJ,YAAA;IAAAO,GAAA;IAAAC,KAAA,EAED,SAAAC,GAAGA,CAAaF,GAAW,EAAE;MACzB,OAAO,IAAI,CAACL,IAAI,CAACO,GAAG,CAAIF,GAAG,CAAC;IAChC;EAAC;IAAAA,GAAA;IAAAC,KAAA,EAED,SAAAE,GAAGA,CAAaH,GAAW,EAAEC,KAAQ,EAAE;MACnC,IAAI,CAACN,IAAI,CAACQ,GAAG,CAACH,GAAG,EAAEC,KAAK,CAAC;IAC7B;EAAC;IAAAD,GAAA;IAAAC,KAAA,EAED,SAAAG,MAAMA,CAACJ,GAAW,EAAE;MAChB,IAAI,CAACL,IAAI,CAACS,MAAM,CAACJ,GAAG,CAAC;IACzB;EAAC;IAAAA,GAAA;IAAAC,KAAA,EAED,SAAAI,KAAKA,CAAA,EAAG;MACJ,IAAI,CAACV,IAAI,CAACU,KAAK,CAAC,CAAC;IACrB;EAAC;IAAAL,GAAA;IAAAC,KAAA,EAED,SAAAK,IAAIA,CAAA,EAAG;MACH,OAAO,IAAI,CAACX,IAAI,CAACW,IAAI,CAAC,CAAC;IAC3B;EAAC;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ILocalStorageRepository } from "./abstractions";
|
|
2
|
+
import type { ILocalStorageGateway } from "./abstractions";
|
|
3
|
+
import type { ILocalStorageConfig } from "./abstractions";
|
|
4
|
+
export declare class LocalStorageRepository implements ILocalStorageRepository {
|
|
5
|
+
private gateway;
|
|
6
|
+
private readonly prefix;
|
|
7
|
+
private store;
|
|
8
|
+
private unsubscribe?;
|
|
9
|
+
constructor(gateway: ILocalStorageGateway, config: ILocalStorageConfig);
|
|
10
|
+
private withPrefix;
|
|
11
|
+
private stripPrefix;
|
|
12
|
+
private bootstrap;
|
|
13
|
+
private subscribeToChanges;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
has(key: string): boolean;
|
|
16
|
+
get<T = string>(key: string): T | undefined;
|
|
17
|
+
set<T = string>(key: string, value: T): void;
|
|
18
|
+
remove(key: string): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
keys(): string[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LocalStorageRepository = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
var _mobx = require("mobx");
|
|
13
|
+
var LocalStorageRepository = exports.LocalStorageRepository = /*#__PURE__*/function () {
|
|
14
|
+
function LocalStorageRepository(gateway, config) {
|
|
15
|
+
(0, _classCallCheck2.default)(this, LocalStorageRepository);
|
|
16
|
+
(0, _defineProperty2.default)(this, "store", new Map());
|
|
17
|
+
this.gateway = gateway;
|
|
18
|
+
this.prefix = config.prefix || "";
|
|
19
|
+
(0, _mobx.makeAutoObservable)(this);
|
|
20
|
+
this.bootstrap();
|
|
21
|
+
this.subscribeToChanges();
|
|
22
|
+
}
|
|
23
|
+
return (0, _createClass2.default)(LocalStorageRepository, [{
|
|
24
|
+
key: "withPrefix",
|
|
25
|
+
value: function withPrefix(key) {
|
|
26
|
+
return this.prefix ? "".concat(this.prefix, ":").concat(key) : key;
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "stripPrefix",
|
|
30
|
+
value: function stripPrefix(key) {
|
|
31
|
+
return this.prefix ? key.replace(new RegExp("^".concat(this.prefix, ":")), "") : key;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "bootstrap",
|
|
35
|
+
value: function bootstrap() {
|
|
36
|
+
var all = this.gateway.getAll();
|
|
37
|
+
for (var _i = 0, _Object$entries = Object.entries(all); _i < _Object$entries.length; _i++) {
|
|
38
|
+
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
39
|
+
key = _Object$entries$_i[0],
|
|
40
|
+
value = _Object$entries$_i[1];
|
|
41
|
+
if (!this.prefix || key.startsWith(this.prefix + ":")) {
|
|
42
|
+
this.store.set(this.stripPrefix(key), value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "subscribeToChanges",
|
|
48
|
+
value: function subscribeToChanges() {
|
|
49
|
+
var _this = this;
|
|
50
|
+
this.unsubscribe = this.gateway.subscribe(function (ev) {
|
|
51
|
+
(0, _mobx.runInAction)(function () {
|
|
52
|
+
if (ev instanceof StorageEvent && ev.key) {
|
|
53
|
+
if (!_this.prefix || ev.key.startsWith(_this.prefix + ":")) {
|
|
54
|
+
var cleanKey = _this.stripPrefix(ev.key);
|
|
55
|
+
if (ev.newValue !== null) {
|
|
56
|
+
try {
|
|
57
|
+
_this.store.set(cleanKey, JSON.parse(ev.newValue));
|
|
58
|
+
} catch (_unused) {
|
|
59
|
+
_this.store.set(cleanKey, ev.newValue);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
_this.store.delete(cleanKey);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (ev instanceof CustomEvent) {
|
|
67
|
+
var _ev$detail = ev.detail,
|
|
68
|
+
key = _ev$detail.key,
|
|
69
|
+
value = _ev$detail.value,
|
|
70
|
+
action = _ev$detail.action;
|
|
71
|
+
if (!_this.prefix || key.startsWith(_this.prefix + ":")) {
|
|
72
|
+
var _cleanKey = _this.stripPrefix(key);
|
|
73
|
+
if (action === "set") {
|
|
74
|
+
_this.store.set(_cleanKey, value);
|
|
75
|
+
}
|
|
76
|
+
if (action === "remove") {
|
|
77
|
+
_this.store.delete(_cleanKey);
|
|
78
|
+
}
|
|
79
|
+
if (action === "clear") {
|
|
80
|
+
_this.store.clear();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "destroy",
|
|
89
|
+
value: function destroy() {
|
|
90
|
+
this.unsubscribe?.();
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "has",
|
|
94
|
+
value: function has(key) {
|
|
95
|
+
return this.store.has(key);
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "get",
|
|
99
|
+
value: function get(key) {
|
|
100
|
+
return this.store.get(key);
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "set",
|
|
104
|
+
value: function set(key, value) {
|
|
105
|
+
this.gateway.set(this.withPrefix(key), value);
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "remove",
|
|
109
|
+
value: function remove(key) {
|
|
110
|
+
this.gateway.remove(this.withPrefix(key));
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "clear",
|
|
114
|
+
value: function clear() {
|
|
115
|
+
this.gateway.clear();
|
|
116
|
+
this.store.clear();
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "keys",
|
|
120
|
+
value: function keys() {
|
|
121
|
+
return Array.from(this.store.keys());
|
|
122
|
+
}
|
|
123
|
+
}]);
|
|
124
|
+
}();
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=LocalStorageRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mobx","require","LocalStorageRepository","exports","gateway","config","_classCallCheck2","default","_defineProperty2","Map","prefix","makeAutoObservable","bootstrap","subscribeToChanges","_createClass2","key","value","withPrefix","concat","stripPrefix","replace","RegExp","all","getAll","_i","_Object$entries","Object","entries","length","_Object$entries$_i","_slicedToArray2","startsWith","store","set","_this","unsubscribe","subscribe","ev","runInAction","StorageEvent","cleanKey","newValue","JSON","parse","_unused","delete","CustomEvent","_ev$detail","detail","action","clear","destroy","has","get","remove","keys","Array","from"],"sources":["LocalStorageRepository.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { ILocalStorageRepository } from \"./abstractions\";\nimport type { ILocalStorageGateway } from \"./abstractions\";\nimport type { ILocalStorageConfig } from \"./abstractions\";\n\nexport class LocalStorageRepository implements ILocalStorageRepository {\n private readonly prefix: string;\n private store = new Map<string, unknown>();\n private unsubscribe?: () => void;\n\n constructor(private gateway: ILocalStorageGateway, config: ILocalStorageConfig) {\n this.prefix = config.prefix || \"\";\n makeAutoObservable(this);\n\n this.bootstrap();\n this.subscribeToChanges();\n }\n\n private withPrefix(key: string): string {\n return this.prefix ? `${this.prefix}:${key}` : key;\n }\n\n private stripPrefix(key: string): string {\n return this.prefix ? key.replace(new RegExp(`^${this.prefix}:`), \"\") : key;\n }\n\n private bootstrap() {\n const all = this.gateway.getAll();\n for (const [key, value] of Object.entries(all)) {\n if (!this.prefix || key.startsWith(this.prefix + \":\")) {\n this.store.set(this.stripPrefix(key), value);\n }\n }\n }\n\n private subscribeToChanges() {\n this.unsubscribe = this.gateway.subscribe(ev => {\n runInAction(() => {\n if (ev instanceof StorageEvent && ev.key) {\n if (!this.prefix || ev.key.startsWith(this.prefix + \":\")) {\n const cleanKey = this.stripPrefix(ev.key);\n if (ev.newValue !== null) {\n try {\n this.store.set(cleanKey, JSON.parse(ev.newValue));\n } catch {\n this.store.set(cleanKey, ev.newValue);\n }\n } else {\n this.store.delete(cleanKey);\n }\n }\n }\n if (ev instanceof CustomEvent) {\n const { key, value, action } = ev.detail;\n if (!this.prefix || key.startsWith(this.prefix + \":\")) {\n const cleanKey = this.stripPrefix(key);\n if (action === \"set\") {\n this.store.set(cleanKey, value);\n }\n if (action === \"remove\") {\n this.store.delete(cleanKey);\n }\n if (action === \"clear\") {\n this.store.clear();\n }\n }\n }\n });\n });\n }\n\n destroy() {\n this.unsubscribe?.();\n }\n\n has(key: string) {\n return this.store.has(key);\n }\n\n get<T = string>(key: string) {\n return this.store.get(key) as T | undefined;\n }\n\n set<T = string>(key: string, value: T) {\n this.gateway.set(this.withPrefix(key), value);\n }\n\n remove(key: string) {\n this.gateway.remove(this.withPrefix(key));\n }\n\n clear() {\n this.gateway.clear();\n this.store.clear();\n }\n\n keys(): string[] {\n return Array.from(this.store.keys());\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAAu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I,CAAChB,UAAU,CAACF,GAAG,CAAC,EAAEC,KAAK,CAAC;IACjD;EAAC;IAAAD,GAAA;IAAAC,KAAA,EAED,SAAAsC,MAAMA,CAACvC,GAAW,EAAE;MAChB,IAAI,CAACX,OAAO,CAACkD,MAAM,CAAC,IAAI,CAACrC,UAAU,CAACF,GAAG,CAAC,CAAC;IAC7C;EAAC;IAAAA,GAAA;IAAAC,KAAA,EAED,SAAAkC,KAAKA,CAAA,EAAG;MACJ,IAAI,CAAC9C,OAAO,CAAC8C,KAAK,CAAC,CAAC;MACpB,IAAI,CAAClB,KAAK,CAACkB,KAAK,CAAC,CAAC;IACtB;EAAC;IAAAnC,GAAA;IAAAC,KAAA,EAED,SAAAuC,IAAIA,CAAA,EAAa;MACb,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACzB,KAAK,CAACuB,IAAI,CAAC,CAAC,CAAC;IACxC;EAAC;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Gateway: raw IO into localStorage (or other storage). */
|
|
2
|
+
export interface ILocalStorageGateway {
|
|
3
|
+
get<T = string>(key: string): T | null;
|
|
4
|
+
set<T = string>(key: string, value: T): void;
|
|
5
|
+
remove(key: string): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
getAll(): Record<string, unknown>;
|
|
8
|
+
subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;
|
|
9
|
+
}
|
|
10
|
+
/** Repository: reactive state (MobX), synchronized with gateway. */
|
|
11
|
+
export interface ILocalStorageRepository {
|
|
12
|
+
has(key: string): boolean;
|
|
13
|
+
get<T = string>(key: string): T | undefined;
|
|
14
|
+
set<T = string>(key: string, value: T): void;
|
|
15
|
+
remove(key: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
keys(): string[];
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
/** Service: thin façade, delegates to repository for consumers. */
|
|
21
|
+
export interface ILocalStorage {
|
|
22
|
+
get<T = string>(key: string): T | undefined;
|
|
23
|
+
set<T = string>(key: string, value: T): void;
|
|
24
|
+
remove(key: string): void;
|
|
25
|
+
clear(): void;
|
|
26
|
+
keys(): string[];
|
|
27
|
+
}
|
|
28
|
+
/** Config: configure key prefixes, etc. */
|
|
29
|
+
export interface ILocalStorageConfig {
|
|
30
|
+
prefix?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["abstractions.ts"],"sourcesContent":["/** Gateway: raw IO into localStorage (or other storage). */\nexport interface ILocalStorageGateway {\n get<T = string>(key: string): T | null;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n getAll(): Record<string, unknown>;\n subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;\n}\n\n/** Repository: reactive state (MobX), synchronized with gateway. */\nexport interface ILocalStorageRepository {\n has(key: string): boolean;\n get<T = string>(key: string): T | undefined;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n keys(): string[];\n destroy(): void;\n}\n\n/** Service: thin façade, delegates to repository for consumers. */\nexport interface ILocalStorage {\n get<T = string>(key: string): T | undefined;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n keys(): string[];\n}\n\n/** Config: configure key prefixes, etc. */\nexport interface ILocalStorageConfig {\n prefix?: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createLocalStorage = void 0;
|
|
7
|
+
var _BrowserLocalStorageGateway = require("./BrowserLocalStorageGateway.js");
|
|
8
|
+
var _LocalStorageRepository = require("./LocalStorageRepository.js");
|
|
9
|
+
var _LocalStorage = require("./LocalStorage.js");
|
|
10
|
+
var createLocalStorage = exports.createLocalStorage = function createLocalStorage(config) {
|
|
11
|
+
var gateway = new _BrowserLocalStorageGateway.BrowserLocalStorageGateway();
|
|
12
|
+
var repository = new _LocalStorageRepository.LocalStorageRepository(gateway, config);
|
|
13
|
+
return new _LocalStorage.LocalStorage(repository);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_BrowserLocalStorageGateway","require","_LocalStorageRepository","_LocalStorage","createLocalStorage","exports","config","gateway","BrowserLocalStorageGateway","repository","LocalStorageRepository","LocalStorage"],"sources":["feature.ts"],"sourcesContent":["import { BrowserLocalStorageGateway } from \"./BrowserLocalStorageGateway.js\";\nimport { LocalStorageRepository } from \"./LocalStorageRepository.js\";\nimport { LocalStorage } from \"./LocalStorage.js\";\nimport type { ILocalStorageConfig } from \"./abstractions.js\";\n\nexport const createLocalStorage = (config: ILocalStorageConfig) => {\n const gateway = new BrowserLocalStorageGateway();\n const repository = new LocalStorageRepository(gateway, config);\n\n return new LocalStorage(repository);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,2BAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAGO,IAAMG,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG,SAArBA,kBAAkBA,CAAIE,MAA2B,EAAK;EAC/D,IAAMC,OAAO,GAAG,IAAIC,sDAA0B,CAAC,CAAC;EAChD,IAAMC,UAAU,GAAG,IAAIC,8CAAsB,CAACH,OAAO,EAAED,MAAM,CAAC;EAE9D,OAAO,IAAIK,0BAAY,CAACF,UAAU,CAAC;AACvC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ILocalStorage } from "../feature/abstractions.js";
|
|
3
|
+
export interface LocalStorageProviderProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LocalStorageContext {
|
|
8
|
+
prefix: string;
|
|
9
|
+
localStorage: ILocalStorage;
|
|
10
|
+
}
|
|
11
|
+
export declare const LocalStorageProvider: ({ prefix, children }: LocalStorageProviderProps) => React.JSX.Element;
|
|
12
|
+
export declare const useLocalStorage: () => LocalStorageContext;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useLocalStorage = exports.LocalStorageProvider = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _feature = require("../feature/feature.js");
|
|
10
|
+
var LocalStorageContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
11
|
+
var LocalStorageProvider = exports.LocalStorageProvider = function LocalStorageProvider(_ref) {
|
|
12
|
+
var prefix = _ref.prefix,
|
|
13
|
+
children = _ref.children;
|
|
14
|
+
var parent = (0, _react.useContext)(LocalStorageContext);
|
|
15
|
+
var newPrefix = [parent?.prefix, prefix].filter(Boolean).join("/");
|
|
16
|
+
var localStorage = (0, _react.useMemo)(function () {
|
|
17
|
+
return (0, _feature.createLocalStorage)({
|
|
18
|
+
prefix: newPrefix
|
|
19
|
+
});
|
|
20
|
+
}, [newPrefix]);
|
|
21
|
+
return /*#__PURE__*/_react.default.createElement(LocalStorageContext.Provider, {
|
|
22
|
+
value: {
|
|
23
|
+
prefix: newPrefix,
|
|
24
|
+
localStorage: localStorage
|
|
25
|
+
}
|
|
26
|
+
}, children);
|
|
27
|
+
};
|
|
28
|
+
var useLocalStorage = exports.useLocalStorage = function useLocalStorage() {
|
|
29
|
+
var context = (0, _react.useContext)(LocalStorageContext);
|
|
30
|
+
if (!context) {
|
|
31
|
+
throw new Error("useLocalStorage must be used within LocalStorageProvider");
|
|
32
|
+
}
|
|
33
|
+
return context;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=LocalStorageProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_feature","LocalStorageContext","React","createContext","undefined","LocalStorageProvider","exports","_ref","prefix","children","parent","useContext","newPrefix","filter","Boolean","join","localStorage","useMemo","createLocalStorage","default","createElement","Provider","value","useLocalStorage","context","Error"],"sources":["LocalStorageProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ILocalStorage } from \"~/localStorage/feature/abstractions.js\";\nimport { useMemo } from \"react\";\nimport { createLocalStorage } from \"~/localStorage/feature/feature.js\";\nimport { useContext } from \"react\";\n\nexport interface LocalStorageProviderProps {\n children: React.ReactNode;\n prefix?: string;\n}\n\nexport interface LocalStorageContext {\n prefix: string;\n localStorage: ILocalStorage;\n}\n\nconst LocalStorageContext = React.createContext<LocalStorageContext | undefined>(undefined);\n\nexport const LocalStorageProvider = ({ prefix, children }: LocalStorageProviderProps) => {\n const parent = useContext(LocalStorageContext);\n const newPrefix = [parent?.prefix, prefix].filter(Boolean).join(\"/\");\n\n const localStorage = useMemo(() => createLocalStorage({ prefix: newPrefix }), [newPrefix]);\n\n return (\n <LocalStorageContext.Provider value={{ prefix: newPrefix, localStorage }}>\n {children}\n </LocalStorageContext.Provider>\n );\n};\n\nexport const useLocalStorage = () => {\n const context = useContext(LocalStorageContext);\n if (!context) {\n throw new Error(\"useLocalStorage must be used within LocalStorageProvider\");\n }\n\n return context;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AAaA,IAAME,mBAAmB,gBAAGC,cAAK,CAACC,aAAa,CAAkCC,SAAS,CAAC;AAEpF,IAAMC,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAG,SAAvBA,oBAAoBA,CAAAE,IAAA,EAAwD;EAAA,IAAlDC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EACnD,IAAMC,MAAM,GAAG,IAAAC,iBAAU,EAACV,mBAAmB,CAAC;EAC9C,IAAMW,SAAS,GAAG,CAACF,MAAM,EAAEF,MAAM,EAAEA,MAAM,CAAC,CAACK,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAEpE,IAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC;IAAA,OAAM,IAAAC,2BAAkB,EAAC;MAAEV,MAAM,EAAEI;IAAU,CAAC,CAAC;EAAA,GAAE,CAACA,SAAS,CAAC,CAAC;EAE1F,oBACIf,MAAA,CAAAsB,OAAA,CAAAC,aAAA,CAACnB,mBAAmB,CAACoB,QAAQ;IAACC,KAAK,EAAE;MAAEd,MAAM,EAAEI,SAAS;MAAEI,YAAY,EAAZA;IAAa;EAAE,GACpEP,QACyB,CAAC;AAEvC,CAAC;AAEM,IAAMc,eAAe,GAAAjB,OAAA,CAAAiB,eAAA,GAAG,SAAlBA,eAAeA,CAAA,EAAS;EACjC,IAAMC,OAAO,GAAG,IAAAb,iBAAU,EAACV,mBAAmB,CAAC;EAC/C,IAAI,CAACuB,OAAO,EAAE;IACV,MAAM,IAAIC,KAAK,CAAC,0DAA0D,CAAC;EAC/E;EAEA,OAAOD,OAAO;AAClB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app",
|
|
3
|
-
"version": "5.44.1
|
|
3
|
+
"version": "5.44.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"@apollo/react-hooks": "3.1.5",
|
|
18
18
|
"@emotion/styled": "11.10.6",
|
|
19
19
|
"@types/react": "18.2.79",
|
|
20
|
-
"@webiny/i18n": "5.44.1
|
|
21
|
-
"@webiny/i18n-react": "5.44.1
|
|
22
|
-
"@webiny/plugins": "5.44.1
|
|
23
|
-
"@webiny/react-composition": "5.44.1
|
|
24
|
-
"@webiny/react-router": "5.44.1
|
|
25
|
-
"@webiny/ui": "5.44.1
|
|
20
|
+
"@webiny/i18n": "5.44.1",
|
|
21
|
+
"@webiny/i18n-react": "5.44.1",
|
|
22
|
+
"@webiny/plugins": "5.44.1",
|
|
23
|
+
"@webiny/react-composition": "5.44.1",
|
|
24
|
+
"@webiny/react-router": "5.44.1",
|
|
25
|
+
"@webiny/ui": "5.44.1",
|
|
26
26
|
"apollo-cache": "1.3.5",
|
|
27
27
|
"apollo-cache-inmemory": "1.6.6",
|
|
28
28
|
"apollo-client": "2.6.10",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"invariant": "2.2.4",
|
|
38
38
|
"lodash": "4.17.21",
|
|
39
39
|
"minimatch": "5.1.6",
|
|
40
|
+
"mobx": "6.9.0",
|
|
40
41
|
"nanoid": "3.3.11",
|
|
41
42
|
"react": "18.2.0",
|
|
42
43
|
"react-dom": "18.2.0",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/lodash": "4.17.13",
|
|
48
49
|
"@types/warning": "3.0.0",
|
|
49
|
-
"@webiny/project-utils": "5.44.1
|
|
50
|
+
"@webiny/project-utils": "5.44.1",
|
|
50
51
|
"rimraf": "6.0.1",
|
|
51
52
|
"typescript": "5.3.3"
|
|
52
53
|
},
|
|
@@ -65,5 +66,5 @@
|
|
|
65
66
|
]
|
|
66
67
|
}
|
|
67
68
|
},
|
|
68
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "1ba366a49390663381688d78df87878040176ef4"
|
|
69
70
|
}
|
package/utils/getLocaleCode.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.getLocaleCode = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
7
|
var _isLocalhost = require("./isLocalhost");
|
|
10
8
|
var getLocaleCode = exports.getLocaleCode = function getLocaleCode() {
|
|
11
9
|
// 1. Get locale via the `__locale` query param. Useful when doing page previews.
|
|
@@ -19,20 +17,7 @@ var getLocaleCode = exports.getLocaleCode = function getLocaleCode() {
|
|
|
19
17
|
if (locale) {
|
|
20
18
|
return locale;
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
// 3. Get locale via `window.localStorage.webiny_i18n_locale`. Used within the Admin app.
|
|
24
|
-
var localesByContext = window.localStorage.webiny_i18n_locale;
|
|
25
|
-
if (localesByContext) {
|
|
26
|
-
// The `localesByContext` is a string that contains locales for all available
|
|
27
|
-
// "locale contexts", for example: `default:en-US;content:en-US;`. Here, we
|
|
28
|
-
// want to extract the locale for the "content" locale context.
|
|
29
|
-
var _localesByContext$mat = localesByContext.match(/content:(.*?);/),
|
|
30
|
-
_localesByContext$mat2 = (0, _slicedToArray2.default)(_localesByContext$mat, 2),
|
|
31
|
-
matchedLocale = _localesByContext$mat2[1];
|
|
32
|
-
return matchedLocale;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_LOCALE_CODE`
|
|
20
|
+
// 3. Finally, for development purposes, we take the `WEBINY_WEBSITE_LOCALE_CODE`
|
|
36
21
|
// and `WEBINY_ADMIN_LOCALE_CODE` environment variables into consideration.
|
|
37
22
|
if ((0, _isLocalhost.isLocalhost)()) {
|
|
38
23
|
return process.env.WEBINY_WEBSITE_LOCALE_CODE || process.env.WEBINY_ADMIN_LOCALE_CODE || null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_isLocalhost","require","getLocaleCode","exports","locale","URLSearchParams","location","search","get","window","__PS_RENDER_LOCALE__","
|
|
1
|
+
{"version":3,"names":["_isLocalhost","require","getLocaleCode","exports","locale","URLSearchParams","location","search","get","window","__PS_RENDER_LOCALE__","isLocalhost","process","env","WEBINY_WEBSITE_LOCALE_CODE","WEBINY_ADMIN_LOCALE_CODE"],"sources":["getLocaleCode.ts"],"sourcesContent":["import { isLocalhost } from \"./isLocalhost\";\n\ndeclare global {\n interface Window {\n __PS_RENDER_LOCALE__: string;\n }\n}\n\nexport const getLocaleCode = (): string | null => {\n // 1. Get locale via the `__locale` query param. Useful when doing page previews.\n let locale = new URLSearchParams(location.search).get(\"__locale\");\n if (locale) {\n return locale;\n }\n\n // 2. Get locale via `window.__PS_RENDER_LOCALE__`. Used with prerendered pages.\n locale = window.__PS_RENDER_LOCALE__;\n if (locale) {\n return locale;\n }\n // 3. Finally, for development purposes, we take the `WEBINY_WEBSITE_LOCALE_CODE`\n // and `WEBINY_ADMIN_LOCALE_CODE` environment variables into consideration.\n if (isLocalhost()) {\n return (\n process.env.WEBINY_WEBSITE_LOCALE_CODE || process.env.WEBINY_ADMIN_LOCALE_CODE || null\n );\n }\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQO,IAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,SAAhBA,aAAaA,CAAA,EAAwB;EAC9C;EACA,IAAIE,MAAM,GAAG,IAAIC,eAAe,CAACC,QAAQ,CAACC,MAAM,CAAC,CAACC,GAAG,CAAC,UAAU,CAAC;EACjE,IAAIJ,MAAM,EAAE;IACR,OAAOA,MAAM;EACjB;;EAEA;EACAA,MAAM,GAAGK,MAAM,CAACC,oBAAoB;EACpC,IAAIN,MAAM,EAAE;IACR,OAAOA,MAAM;EACjB;EACA;EACA;EACA,IAAI,IAAAO,wBAAW,EAAC,CAAC,EAAE;IACf,OACIC,OAAO,CAACC,GAAG,CAACC,0BAA0B,IAAIF,OAAO,CAACC,GAAG,CAACE,wBAAwB,IAAI,IAAI;EAE9F;EAEA,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
|