techsbcn-storybook 2.15.4 → 2.16.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/dist/helpers/StorageHelper.d.ts +19 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type StorageType = 'local' | 'session';
|
|
2
|
+
export interface StorageOptions {
|
|
3
|
+
storage?: StorageType;
|
|
4
|
+
}
|
|
5
|
+
export interface SetStorageOptions extends StorageOptions {
|
|
6
|
+
/** Lifetime of the item in milliseconds. Without it the item never expires. */
|
|
7
|
+
ttl?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reads an item saved with `setStorageItem`. Returns null when it is missing, expired, corrupt or the storage is
|
|
11
|
+
* unavailable (private mode, blocked site data). Expired items are removed when read.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getStorageItem: <T>(key: string, options?: StorageOptions) => T | null;
|
|
14
|
+
/**
|
|
15
|
+
* Saves a JSON-serializable value, optionally expiring after `ttl` milliseconds. Returns false when it could not be
|
|
16
|
+
* saved (storage unavailable or quota exceeded).
|
|
17
|
+
*/
|
|
18
|
+
export declare const setStorageItem: <T>(key: string, value: T, options?: SetStorageOptions) => boolean;
|
|
19
|
+
export declare const removeStorageItem: (key: string, options?: StorageOptions) => void;
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -782,6 +782,52 @@ var removeNotification = (id) => notistack.closeSnackbar(id);
|
|
|
782
782
|
|
|
783
783
|
// src/helpers/PermissionHelpers.tsx
|
|
784
784
|
var hasPermission = (permission) => getSession()?.role.includes(permission) ?? false;
|
|
785
|
+
|
|
786
|
+
// src/helpers/StorageHelper.tsx
|
|
787
|
+
var getStorage = (type = "local") => {
|
|
788
|
+
try {
|
|
789
|
+
if (typeof window === "undefined") return null;
|
|
790
|
+
return type === "session" ? window.sessionStorage : window.localStorage;
|
|
791
|
+
} catch {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
var getStorageItem = (key, options) => {
|
|
796
|
+
const storage = getStorage(options?.storage);
|
|
797
|
+
try {
|
|
798
|
+
const raw = storage?.getItem(key);
|
|
799
|
+
if (raw == null) return null;
|
|
800
|
+
const entry = JSON.parse(raw);
|
|
801
|
+
if (entry.expiresAt !== void 0 && entry.expiresAt <= Date.now()) {
|
|
802
|
+
storage?.removeItem(key);
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
return entry.value ?? null;
|
|
806
|
+
} catch {
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var setStorageItem = (key, value, options) => {
|
|
811
|
+
const storage = getStorage(options?.storage);
|
|
812
|
+
if (!storage) return false;
|
|
813
|
+
try {
|
|
814
|
+
const entry = {
|
|
815
|
+
value,
|
|
816
|
+
expiresAt: options?.ttl ? Date.now() + options.ttl : void 0
|
|
817
|
+
};
|
|
818
|
+
storage.setItem(key, JSON.stringify(entry));
|
|
819
|
+
return true;
|
|
820
|
+
} catch {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
var removeStorageItem = (key, options) => {
|
|
825
|
+
try {
|
|
826
|
+
getStorage(options?.storage)?.removeItem(key);
|
|
827
|
+
} catch {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
};
|
|
785
831
|
var Spinner = () => /* @__PURE__ */ React10__default.default.createElement(material.Box, { sx: { textAlign: "center" } }, /* @__PURE__ */ React10__default.default.createElement(material.CircularProgress, { color: "primary", size: 20 }));
|
|
786
832
|
|
|
787
833
|
// src/components/tables/ImageTableComponent/ImageTableComponent.tsx
|
|
@@ -3033,12 +3079,15 @@ exports.getImageByBase64 = getImageByBase64;
|
|
|
3033
3079
|
exports.getImageByBlob = getImageByBlob;
|
|
3034
3080
|
exports.getJwtToken = getJwtToken;
|
|
3035
3081
|
exports.getSession = getSession;
|
|
3082
|
+
exports.getStorageItem = getStorageItem;
|
|
3036
3083
|
exports.hasPermission = hasPermission;
|
|
3037
3084
|
exports.logout = logout;
|
|
3038
3085
|
exports.readFileAsBase64 = readFileAsBase64;
|
|
3039
3086
|
exports.redirectDownload = redirectDownload;
|
|
3040
3087
|
exports.removeNotification = removeNotification;
|
|
3088
|
+
exports.removeStorageItem = removeStorageItem;
|
|
3041
3089
|
exports.saveSession = saveSession;
|
|
3090
|
+
exports.setStorageItem = setStorageItem;
|
|
3042
3091
|
exports.toBase64 = toBase64;
|
|
3043
3092
|
exports.useFilters = useFilters;
|
|
3044
3093
|
exports.useIsMounted = useIsMounted;
|