@dashadmin/dash-admin-state 1.3.25 → 1.3.28
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/DefaultThemeSettings.js +34 -1
- package/dist/defaults/defaultAuth.js +9 -1
- package/dist/defaults/defaultCommon.js +44 -1
- package/dist/defaults/defaultFormState.js +5 -1
- package/dist/defaults/defaultPage.js +9 -1
- package/dist/defaults/defaultSettings.js +51 -1
- package/dist/hooks/DashAdminStateSelectors.js +149 -1
- package/dist/hooks/useLocalStorage.js +69 -1
- package/dist/index.js +41 -691
- package/dist/redux/ReduxStoreAccesor.js +19 -1
- package/dist/redux/actions/ActionTypes.js +84 -1
- package/dist/redux/actions/Auth.js +6 -1
- package/dist/redux/actions/Common.js +51 -1
- package/dist/redux/actions/ComponentData.js +33 -1
- package/dist/redux/actions/Menu.js +5 -1
- package/dist/redux/actions/Page.js +7 -1
- package/dist/redux/actions/Resources.js +21 -1
- package/dist/redux/actions/Setting.js +90 -1
- package/dist/redux/actions/index.js +6 -1
- package/dist/redux/reducers/Auth.js +55 -1
- package/dist/redux/reducers/Common.js +134 -1
- package/dist/redux/reducers/ComponentData.js +59 -1
- package/dist/redux/reducers/FormData.js +32 -1
- package/dist/redux/reducers/Menu.js +22 -1
- package/dist/redux/reducers/Page.js +30 -1
- package/dist/redux/reducers/Resources.js +19 -1
- package/dist/redux/reducers/Settings.js +79 -1
- package/dist/redux/reducers/index.js +25 -1
- package/dist/redux/sagas/index.js +9 -1
- package/dist/redux/store/index.js +35 -1
- package/package.json +75 -57
- package/src/DefaultThemeSettings.tsx +33 -0
- package/src/defaults/defaultAuth.tsx +8 -0
- package/src/defaults/defaultCommon.tsx +55 -0
- package/src/defaults/defaultFormState.tsx +4 -0
- package/src/defaults/defaultPage.tsx +9 -0
- package/src/defaults/defaultSettings.tsx +61 -0
- package/src/hooks/DashAdminStateSelectors.tsx +142 -0
- package/src/hooks/useLocalStorage.tsx +79 -0
- package/src/index.tsx +34 -0
- package/src/redux/ReduxStoreAccesor.tsx +18 -0
- package/src/redux/actions/ActionTypes.tsx +47 -0
- package/src/redux/actions/Auth.tsx +5 -0
- package/src/redux/actions/Common.tsx +51 -0
- package/src/redux/actions/ComponentData.tsx +78 -0
- package/src/redux/actions/Menu.tsx +4 -0
- package/src/redux/actions/Page.tsx +6 -0
- package/src/redux/actions/Resources.tsx +19 -0
- package/src/redux/actions/Setting.tsx +91 -0
- package/src/redux/actions/index.tsx +7 -0
- package/src/redux/interfaces/IAuthState.tsx +7 -0
- package/src/redux/interfaces/ICommonState.tsx +25 -0
- package/src/redux/interfaces/IComponentData.tsx +32 -0
- package/src/redux/interfaces/IDASHAppState.tsx +53 -0
- package/src/redux/interfaces/IDashResourceGroupsIcons.tsx +5 -0
- package/src/redux/interfaces/IFormDataState.tsx +6 -0
- package/src/redux/interfaces/IPage.tsx +27 -0
- package/src/redux/interfaces/IResources.tsx +0 -0
- package/src/redux/interfaces/ISettings.tsx +27 -0
- package/src/redux/reducers/Auth.tsx +38 -0
- package/src/redux/reducers/Common.tsx +144 -0
- package/src/redux/reducers/ComponentData.tsx +52 -0
- package/src/redux/reducers/FormData.tsx +21 -0
- package/src/redux/reducers/Menu.tsx +27 -0
- package/src/redux/reducers/Page.tsx +17 -0
- package/src/redux/reducers/Resources.tsx +19 -0
- package/src/redux/reducers/Settings.tsx +78 -0
- package/src/redux/reducers/index.tsx +25 -0
- package/src/redux/sagas/index.tsx +8 -0
- package/src/redux/store/index.tsx +33 -0
|
@@ -1 +1,34 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
class DefaultThemeSettings {
|
|
5
|
+
}
|
|
6
|
+
__publicField(DefaultThemeSettings, "TAB_SIZE", 992);
|
|
7
|
+
__publicField(DefaultThemeSettings, "MOBILE_SIZE", 575);
|
|
8
|
+
__publicField(DefaultThemeSettings, "THEME_TYPE", "THEME_TYPE");
|
|
9
|
+
__publicField(DefaultThemeSettings, "THEME_TYPE_LIGHT", "light");
|
|
10
|
+
__publicField(DefaultThemeSettings, "THEME_TYPE_DARK", "dark");
|
|
11
|
+
__publicField(DefaultThemeSettings, "THEME_TYPE_DASH_DEFAULT", "light");
|
|
12
|
+
__publicField(DefaultThemeSettings, "THEME_TYPE_SEMI_DARK", "THEME_TYPE_SEMI_DARK");
|
|
13
|
+
__publicField(DefaultThemeSettings, "THEME_COLOR", "THEME_COLOR");
|
|
14
|
+
__publicField(DefaultThemeSettings, "LAYOUT_TYPE", "LAYOUT_TYPE");
|
|
15
|
+
__publicField(DefaultThemeSettings, "LAYOUT_TYPE_FRAMED", "framed-layout");
|
|
16
|
+
__publicField(DefaultThemeSettings, "LAYOUT_TYPE_BOXED", "boxed-layout");
|
|
17
|
+
__publicField(DefaultThemeSettings, "LAYOUT_TYPE_FULL", "full-layout");
|
|
18
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE", "NAV_STYLE");
|
|
19
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_FIXED", "NAV_STYLE_FIXED");
|
|
20
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_MINI_SIDEBAR", "NAV_STYLE_MINI_SIDEBAR");
|
|
21
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_DRAWER", "NAV_STYLE_DRAWER");
|
|
22
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_NO_HEADER_MINI_SIDEBAR", "NAV_STYLE_NO_HEADER_MINI_SIDEBAR");
|
|
23
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_NO_HEADER_EXPANDED_SIDEBAR", "NAV_STYLE_NO_HEADER_EXPANDED_SIDEBAR");
|
|
24
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_DEFAULT_HORIZONTAL", "NAV_STYLE_DEFAULT_HORIZONTAL");
|
|
25
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_DARK_HORIZONTAL", "NAV_STYLE_DARK_HORIZONTAL");
|
|
26
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_INSIDE_HEADER_HORIZONTAL", "NAV_STYLE_INSIDE_HEADER_HORIZONTAL");
|
|
27
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_BELOW_HEADER", "NAV_STYLE_BELOW_HEADER");
|
|
28
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_ABOVE_HEADER", "NAV_STYLE_ABOVE_HEADER");
|
|
29
|
+
__publicField(DefaultThemeSettings, "NAV_STYLE_COLLAPSABLE", "NAV_STYLE_COLLAPSABLE");
|
|
30
|
+
__publicField(DefaultThemeSettings, "UPDATE_RTL_STATUS", "UPDATE_RTL_STATUS");
|
|
31
|
+
var DefaultThemeSettings_default = DefaultThemeSettings;
|
|
32
|
+
export {
|
|
33
|
+
DefaultThemeSettings_default as default
|
|
34
|
+
};
|
|
@@ -1 +1,44 @@
|
|
|
1
|
-
import{Fragment
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
const defaultCommon = {
|
|
3
|
+
appPath: "/",
|
|
4
|
+
error: "",
|
|
5
|
+
loading: false,
|
|
6
|
+
message: "",
|
|
7
|
+
navExpanded: true,
|
|
8
|
+
width: typeof window !== "undefined" ? window.innerWidth : 1920,
|
|
9
|
+
height: typeof window !== "undefined" ? window.innerHeight : 1080,
|
|
10
|
+
content_width: null,
|
|
11
|
+
content_height: null,
|
|
12
|
+
pathname: "/",
|
|
13
|
+
componentsState: {},
|
|
14
|
+
headerToolBar: null,
|
|
15
|
+
headerToolBarReplace: false,
|
|
16
|
+
navSize: "small",
|
|
17
|
+
// Panel settings with sidebar dimensions
|
|
18
|
+
// These values can be overridden by CSS variables at runtime
|
|
19
|
+
panelSettings: {
|
|
20
|
+
// Branding
|
|
21
|
+
appName: "Dash App",
|
|
22
|
+
horizontalLogo: /* @__PURE__ */ jsx(Fragment, { children: "\u{1F5A5}" }),
|
|
23
|
+
squaredLogo: /* @__PURE__ */ jsx(Fragment, { children: "\u{1F5A5}" }),
|
|
24
|
+
loginBackground: void 0,
|
|
25
|
+
// Sidebar dimensions (can be overridden via CSS variables)
|
|
26
|
+
sidebarLargeWidth: 255,
|
|
27
|
+
sidebarSmallWidth: 64,
|
|
28
|
+
sidebarHorizontalHeight: 120,
|
|
29
|
+
// Logo dimensions
|
|
30
|
+
logoVerticalMaxWidth: 130,
|
|
31
|
+
logoVerticalMaxHeight: 130,
|
|
32
|
+
logoHorizontalMaxWidth: 200,
|
|
33
|
+
logoHorizontalMaxHeight: 60,
|
|
34
|
+
// Content padding (derived from sidebar)
|
|
35
|
+
paddingHorizontal: 255,
|
|
36
|
+
paddingVertical: 120,
|
|
37
|
+
// Position
|
|
38
|
+
sidebarPosition: "left"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var defaultCommon_default = defaultCommon;
|
|
42
|
+
export {
|
|
43
|
+
defaultCommon_default as default
|
|
44
|
+
};
|
|
@@ -1 +1,51 @@
|
|
|
1
|
-
import{DASHAdminSystemConstants
|
|
1
|
+
import { DASHAdminSystemConstants } from "dash-constants";
|
|
2
|
+
const defaultSettings = {
|
|
3
|
+
// Loading state
|
|
4
|
+
loading: false,
|
|
5
|
+
// Navigation and layout
|
|
6
|
+
navStyle: DASHAdminSystemConstants.panel.NAV_STYLE_FIXED,
|
|
7
|
+
layoutType: DASHAdminSystemConstants.panel.LAYOUT_TYPE_FULL,
|
|
8
|
+
themeType: DASHAdminSystemConstants.panel.THEME_TYPE_DARK,
|
|
9
|
+
themeColor: "",
|
|
10
|
+
isDirectionRTL: false,
|
|
11
|
+
// Layout settings (dimensions, breakpoints, etc.)
|
|
12
|
+
layoutSettings: {
|
|
13
|
+
// Sidebar dimensions
|
|
14
|
+
sidebarLargeWidth: 255,
|
|
15
|
+
sidebarSmallWidth: 64,
|
|
16
|
+
sidebarHorizontalHeight: 120,
|
|
17
|
+
// Logo dimensions
|
|
18
|
+
logoVerticalMaxWidth: 130,
|
|
19
|
+
logoVerticalMaxHeight: 130,
|
|
20
|
+
logoHorizontalMaxWidth: 200,
|
|
21
|
+
logoHorizontalMaxHeight: 60,
|
|
22
|
+
// Content padding (based on sidebar)
|
|
23
|
+
paddingHorizontal: 255,
|
|
24
|
+
paddingVertical: 120,
|
|
25
|
+
// Breakpoints
|
|
26
|
+
mobileBreakpoint: 768,
|
|
27
|
+
tabletBreakpoint: 1024
|
|
28
|
+
},
|
|
29
|
+
// Localization
|
|
30
|
+
locale: "es",
|
|
31
|
+
availableLocales: [
|
|
32
|
+
{
|
|
33
|
+
locale: "es",
|
|
34
|
+
languageId: "spanish",
|
|
35
|
+
name: "Espa\xF1ol",
|
|
36
|
+
icon: "es"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
locale: "en",
|
|
40
|
+
languageId: "english",
|
|
41
|
+
name: "English",
|
|
42
|
+
icon: "en"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
// Translations (populated by i18n provider)
|
|
46
|
+
translations: {}
|
|
47
|
+
};
|
|
48
|
+
var defaultSettings_default = defaultSettings;
|
|
49
|
+
export {
|
|
50
|
+
defaultSettings_default as default
|
|
51
|
+
};
|
|
@@ -1 +1,149 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
18
|
+
import { useSelector } from "react-redux";
|
|
19
|
+
import { useMemo } from "react";
|
|
20
|
+
import { isEqual } from "lodash";
|
|
21
|
+
const useLayoutState = () => {
|
|
22
|
+
return useSelector(
|
|
23
|
+
(state) => {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
return {
|
|
26
|
+
navStyle: state.settings.navStyle,
|
|
27
|
+
layoutType: state.settings.layoutType,
|
|
28
|
+
themeType: state.settings.themeType,
|
|
29
|
+
layoutSettings: state.settings.layoutSettings,
|
|
30
|
+
navExpanded: (_d = (_c = (_a = state.common) == null ? void 0 : _a.navExpanded) != null ? _c : (_b = state.common) == null ? void 0 : _b.navExpanded) != null ? _d : true,
|
|
31
|
+
navSize: state.common.navSize,
|
|
32
|
+
panelSettings: state.common.panelSettings
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
isEqual
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const useAuthState = () => {
|
|
39
|
+
return useSelector(
|
|
40
|
+
(state) => ({
|
|
41
|
+
authenticated: state.auth.authenticated,
|
|
42
|
+
user: state.auth.user
|
|
43
|
+
}),
|
|
44
|
+
isEqual
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const useSettingsState = () => {
|
|
48
|
+
return useSelector(
|
|
49
|
+
(state) => ({
|
|
50
|
+
groupIcons: state.settings.groupIcons,
|
|
51
|
+
locale: state.settings.locale,
|
|
52
|
+
themeColor: state.settings.themeColor,
|
|
53
|
+
availableLocales: state.settings.availableLocales,
|
|
54
|
+
isDirectionRTL: state.settings.isDirectionRTL
|
|
55
|
+
}),
|
|
56
|
+
isEqual
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
const useCommonState = () => {
|
|
60
|
+
return useSelector(
|
|
61
|
+
(state) => ({
|
|
62
|
+
appPath: state.common.appPath,
|
|
63
|
+
width: state.common.width,
|
|
64
|
+
height: state.common.height,
|
|
65
|
+
headerToolBar: state.common.headerToolBar,
|
|
66
|
+
panelSettings: state.common.panelSettings
|
|
67
|
+
}),
|
|
68
|
+
isEqual
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
const usePageState = () => {
|
|
72
|
+
return useSelector(
|
|
73
|
+
(state) => ({
|
|
74
|
+
title: state.page.title,
|
|
75
|
+
icon: state.page.icon,
|
|
76
|
+
subTitle: state.page.subTitle
|
|
77
|
+
}),
|
|
78
|
+
isEqual
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
const useResourcesState = () => {
|
|
82
|
+
return useSelector(
|
|
83
|
+
(state) => ({
|
|
84
|
+
items: state.resources.items
|
|
85
|
+
}),
|
|
86
|
+
isEqual
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
const useLogoSettings = () => {
|
|
90
|
+
const { panelSettings } = useCommonState();
|
|
91
|
+
return useMemo(() => ({
|
|
92
|
+
horizontalLogo: (panelSettings == null ? void 0 : panelSettings.horizontalLogo) || /* @__PURE__ */ jsx(Fragment, {}),
|
|
93
|
+
squaredLogo: (panelSettings == null ? void 0 : panelSettings.squaredLogo) || /* @__PURE__ */ jsx(Fragment, {}),
|
|
94
|
+
loginBackground: panelSettings == null ? void 0 : panelSettings.loginBackground
|
|
95
|
+
}), [panelSettings]);
|
|
96
|
+
};
|
|
97
|
+
const usePanelSettings = () => {
|
|
98
|
+
const { panelSettings } = useCommonState();
|
|
99
|
+
return useMemo(() => ({
|
|
100
|
+
// Sidebar position: 'left' | 'right' | 'top' | 'bottom'
|
|
101
|
+
sidebarPosition: (panelSettings == null ? void 0 : panelSettings.sidebarPosition) || "left",
|
|
102
|
+
// Sidebar dimensions
|
|
103
|
+
sidebarLargeWidth: (panelSettings == null ? void 0 : panelSettings.sidebarLargeWidth) || 255,
|
|
104
|
+
sidebarSmallWidth: (panelSettings == null ? void 0 : panelSettings.sidebarSmallWidth) || 60,
|
|
105
|
+
sidebarHorizontalHeight: (panelSettings == null ? void 0 : panelSettings.sidebarHorizontalHeight) || 120,
|
|
106
|
+
// Logo dimensions for vertical sidebar (left/right)
|
|
107
|
+
logoVerticalMaxWidth: (panelSettings == null ? void 0 : panelSettings.logoVerticalMaxWidth) || 130,
|
|
108
|
+
logoVerticalMaxHeight: (panelSettings == null ? void 0 : panelSettings.logoVerticalMaxHeight) || 130,
|
|
109
|
+
// Logo dimensions for horizontal sidebar (top/bottom)
|
|
110
|
+
logoHorizontalMaxWidth: (panelSettings == null ? void 0 : panelSettings.logoHorizontalMaxWidth) || 200,
|
|
111
|
+
logoHorizontalMaxHeight: (panelSettings == null ? void 0 : panelSettings.logoHorizontalMaxHeight) || 60,
|
|
112
|
+
// Padding configuration
|
|
113
|
+
paddingHorizontal: (panelSettings == null ? void 0 : panelSettings.paddingHorizontal) || 255,
|
|
114
|
+
paddingVertical: (panelSettings == null ? void 0 : panelSettings.paddingVertical) || 120,
|
|
115
|
+
// App name
|
|
116
|
+
appName: (panelSettings == null ? void 0 : panelSettings.appName) || "DASH"
|
|
117
|
+
}), [panelSettings]);
|
|
118
|
+
};
|
|
119
|
+
const useThemeState = () => {
|
|
120
|
+
const layoutState = useLayoutState();
|
|
121
|
+
const logoSettings = useLogoSettings();
|
|
122
|
+
return useMemo(() => __spreadValues(__spreadValues({}, layoutState), logoSettings), [layoutState, logoSettings]);
|
|
123
|
+
};
|
|
124
|
+
const useNavigationState = () => {
|
|
125
|
+
return useSelector(
|
|
126
|
+
(state) => {
|
|
127
|
+
var _a, _b, _c, _d;
|
|
128
|
+
return {
|
|
129
|
+
navExpanded: (_d = (_c = (_a = state.common) == null ? void 0 : _a.navExpanded) != null ? _c : (_b = state.common) == null ? void 0 : _b.navExpanded) != null ? _d : true,
|
|
130
|
+
navSize: state.common.navSize,
|
|
131
|
+
navStyle: state.settings.navStyle,
|
|
132
|
+
layoutSettings: state.settings.layoutSettings
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
isEqual
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
useAuthState,
|
|
140
|
+
useCommonState,
|
|
141
|
+
useLayoutState,
|
|
142
|
+
useLogoSettings,
|
|
143
|
+
useNavigationState,
|
|
144
|
+
usePageState,
|
|
145
|
+
usePanelSettings,
|
|
146
|
+
useResourcesState,
|
|
147
|
+
useSettingsState,
|
|
148
|
+
useThemeState
|
|
149
|
+
};
|
|
@@ -1 +1,69 @@
|
|
|
1
|
-
import{useCallback
|
|
1
|
+
import { useCallback, useEffect, useState, useMemo } from "react";
|
|
2
|
+
import { dashStorage } from "dash-utils";
|
|
3
|
+
const isBrowser = typeof window !== "undefined";
|
|
4
|
+
const isLocalstorageAvailable = () => {
|
|
5
|
+
if (!isBrowser) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const test = `test-${Date.now()}`;
|
|
9
|
+
try {
|
|
10
|
+
dashStorage.setItem(test, test);
|
|
11
|
+
dashStorage.removeItem(test);
|
|
12
|
+
return true;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const useLocalStorage = (key, initialValue = "") => {
|
|
18
|
+
const available = isLocalstorageAvailable();
|
|
19
|
+
const getValueFromLocalstorage = useCallback(() => {
|
|
20
|
+
try {
|
|
21
|
+
if (!available) {
|
|
22
|
+
return initialValue;
|
|
23
|
+
}
|
|
24
|
+
const item = dashStorage.getItem(key);
|
|
25
|
+
return item ? JSON.parse(item) : initialValue;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return initialValue;
|
|
28
|
+
}
|
|
29
|
+
}, [available, initialValue, key]);
|
|
30
|
+
const [storedValue, setStoredValue] = useState(getValueFromLocalstorage());
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const value = getValueFromLocalstorage();
|
|
33
|
+
setStoredValue(value);
|
|
34
|
+
}, [available, getValueFromLocalstorage]);
|
|
35
|
+
const changeHandler = useCallback(
|
|
36
|
+
(e) => {
|
|
37
|
+
const { key: changeKey, newValue } = e;
|
|
38
|
+
if (key === changeKey) {
|
|
39
|
+
setStoredValue(JSON.parse(newValue));
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
[key]
|
|
43
|
+
);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (available) {
|
|
46
|
+
window.addEventListener("storage", changeHandler);
|
|
47
|
+
return () => {
|
|
48
|
+
window.removeEventListener("storage", changeHandler);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}, [available]);
|
|
52
|
+
return useMemo(() => {
|
|
53
|
+
const setValue = (value) => {
|
|
54
|
+
if (!available) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
58
|
+
if (valueToStore !== storedValue) {
|
|
59
|
+
setStoredValue(valueToStore);
|
|
60
|
+
window.dashStorage.setItem(key, JSON.stringify(valueToStore));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return [storedValue, setValue];
|
|
64
|
+
}, [storedValue, available, key]);
|
|
65
|
+
};
|
|
66
|
+
var useLocalStorage_default = useLocalStorage;
|
|
67
|
+
export {
|
|
68
|
+
useLocalStorage_default as default
|
|
69
|
+
};
|