@smartbooks-ai/layout 0.1.1 → 0.1.2
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/components/PageWithMenuLayout/PageWithMenuLayout.d.ts.map +1 -1
- package/dist/components/PageWithMenuLayout/PageWithMenuLayout.js +1 -1
- package/dist/components/PageWithMenuLayout/useMenuToggle.d.ts.map +1 -1
- package/dist/components/PageWithMenuLayout/useMenuToggle.js +2 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useLocalStorage.d.ts +12 -0
- package/dist/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/hooks/useLocalStorage.js +86 -0
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageWithMenuLayout.d.ts","sourceRoot":"","sources":["../../../src/components/PageWithMenuLayout/PageWithMenuLayout.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"PageWithMenuLayout.d.ts","sourceRoot":"","sources":["../../../src/components/PageWithMenuLayout/PageWithMenuLayout.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAalE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,MAAM,uBAAuB,GAAG;IACpC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,UAAU,EAAE,aAAa,CAAC;IAC1B,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,eAAe,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,uBAAuB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAqGhE,CAAC"}
|
|
@@ -6,10 +6,10 @@ import IconButton from '@mui/material/IconButton';
|
|
|
6
6
|
import MenuList from '@mui/material/MenuList';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { NavLink, Outlet, useNavigate } from 'react-router';
|
|
9
|
-
import useLocalStorage from 'use-local-storage';
|
|
10
9
|
import { AppsSelect, CompanySelect, LogoHeaderImage, LogoHeaderText, MenuItemWithChildren, UserProfileSelect, } from './index';
|
|
11
10
|
import * as Styled from './styles';
|
|
12
11
|
import { useMenuToggle } from './useMenuToggle';
|
|
12
|
+
import { useLocalStorage } from '../../hooks';
|
|
13
13
|
export const PageWithMenuLayout = ({ resolvedCompanyCode, topMenu, bottomMenu, profile, switchToCompany, logout, additionalOutletContent, applicationTitle, applications, }) => {
|
|
14
14
|
const { isExpanded, openMenu, toggleIsExpanded } = useMenuToggle();
|
|
15
15
|
const navigate = useNavigate();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMenuToggle.d.ts","sourceRoot":"","sources":["../../../src/components/PageWithMenuLayout/useMenuToggle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useMenuToggle.d.ts","sourceRoot":"","sources":["../../../src/components/PageWithMenuLayout/useMenuToggle.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa;;;;CAczB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useToggle } from '../../hooks';
|
|
3
|
+
import { useProfile } from '../../security/ProfileContext';
|
|
3
4
|
export const useMenuToggle = () => {
|
|
4
5
|
const { value: isExpanded, toggle: toggleIsExpanded, switchOn: openMenu, switchOff: closeMenu } = useToggle(true);
|
|
5
6
|
const { profile } = useProfile();
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Serializer<T> = (object: T | undefined) => string;
|
|
2
|
+
type Parser<T> = (val: string) => T | undefined;
|
|
3
|
+
type Setter<T> = React.Dispatch<React.SetStateAction<T | undefined>>;
|
|
4
|
+
type Options<T> = Partial<{
|
|
5
|
+
serializer: Serializer<T>;
|
|
6
|
+
parser: Parser<T>;
|
|
7
|
+
logger: (error: unknown) => void;
|
|
8
|
+
syncData: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
declare function useLocalStorage<T>(key: string, defaultValue: T, options?: Options<T>): [T, Setter<T>];
|
|
11
|
+
export { useLocalStorage };
|
|
12
|
+
//# sourceMappingURL=useLocalStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,SAAS,KAAK,MAAM,CAAC;AACvD,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,CAAC;AAChD,KAAK,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;AAErE,KAAK,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC;IACxB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC,CAAC;AAEH,iBAAS,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA6FhG,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// https://github.com/nas5w/use-local-storage/blob/main/src/index.ts
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
function useLocalStorage(key, defaultValue, options) {
|
|
4
|
+
const opts = useMemo(() => {
|
|
5
|
+
return {
|
|
6
|
+
serializer: JSON.stringify,
|
|
7
|
+
parser: JSON.parse,
|
|
8
|
+
logger: console.log,
|
|
9
|
+
syncData: true,
|
|
10
|
+
...options,
|
|
11
|
+
};
|
|
12
|
+
}, [options]);
|
|
13
|
+
const { serializer, parser, logger, syncData } = opts;
|
|
14
|
+
const rawValueRef = useRef(null);
|
|
15
|
+
const [value, setValue] = useState(() => {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return defaultValue;
|
|
18
|
+
try {
|
|
19
|
+
rawValueRef.current = window.localStorage.getItem(key);
|
|
20
|
+
const res = rawValueRef.current ? parser(rawValueRef.current) : defaultValue;
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger(e);
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (typeof window === 'undefined')
|
|
30
|
+
return;
|
|
31
|
+
const updateLocalStorage = () => {
|
|
32
|
+
// Browser ONLY dispatch storage events to other tabs, NOT current tab.
|
|
33
|
+
// We need to manually dispatch storage event for current tab
|
|
34
|
+
if (value !== undefined) {
|
|
35
|
+
const newValue = serializer(value);
|
|
36
|
+
const oldValue = rawValueRef.current;
|
|
37
|
+
rawValueRef.current = newValue;
|
|
38
|
+
window.localStorage.setItem(key, newValue);
|
|
39
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
40
|
+
storageArea: window.localStorage,
|
|
41
|
+
url: window.location.href,
|
|
42
|
+
key,
|
|
43
|
+
newValue,
|
|
44
|
+
oldValue,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
window.localStorage.removeItem(key);
|
|
49
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
50
|
+
storageArea: window.localStorage,
|
|
51
|
+
url: window.location.href,
|
|
52
|
+
key,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
updateLocalStorage();
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
logger(e);
|
|
61
|
+
}
|
|
62
|
+
}, [value, key, serializer, rawValueRef, logger]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!syncData)
|
|
65
|
+
return;
|
|
66
|
+
const handleStorageChange = (e) => {
|
|
67
|
+
if (e.key !== key || e.storageArea !== window.localStorage)
|
|
68
|
+
return;
|
|
69
|
+
try {
|
|
70
|
+
if (e.newValue !== rawValueRef.current) {
|
|
71
|
+
rawValueRef.current = e.newValue;
|
|
72
|
+
setValue(e.newValue ? parser(e.newValue) : undefined);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
logger(e);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
if (typeof window === 'undefined')
|
|
80
|
+
return;
|
|
81
|
+
window.addEventListener('storage', handleStorageChange);
|
|
82
|
+
return () => window.removeEventListener('storage', handleStorageChange);
|
|
83
|
+
}, [key, syncData, parser, rawValueRef, logger]);
|
|
84
|
+
return [value, setValue];
|
|
85
|
+
}
|
|
86
|
+
export { useLocalStorage };
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "smartbooks",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@smartbooks-ai/api-client": "0.1.
|
|
5
|
-
"use-local-storage": "^3.0.0",
|
|
4
|
+
"@smartbooks-ai/api-client": "0.1.2",
|
|
6
5
|
"use-resize-observer": "^9.1.0"
|
|
7
6
|
},
|
|
8
7
|
"devDependencies": {
|
|
@@ -52,5 +51,5 @@
|
|
|
52
51
|
},
|
|
53
52
|
"type": "module",
|
|
54
53
|
"types": "./dist/index.d.ts",
|
|
55
|
-
"version": "0.1.
|
|
54
|
+
"version": "0.1.2"
|
|
56
55
|
}
|