@tanstack/router-devtools 1.7.1 → 1.8.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/dist/cjs/Explorer.cjs +246 -0
- package/dist/cjs/Explorer.cjs.map +1 -0
- package/dist/cjs/devtools.cjs +1150 -0
- package/dist/cjs/devtools.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/styledComponents.cjs +93 -0
- package/dist/cjs/styledComponents.cjs.map +1 -0
- package/dist/cjs/theme.cjs +28 -0
- package/dist/cjs/theme.cjs.map +1 -0
- package/dist/cjs/useLocalStorage.cjs +45 -0
- package/dist/cjs/useLocalStorage.cjs.map +1 -0
- package/dist/cjs/useMediaQuery.cjs +27 -0
- package/dist/cjs/useMediaQuery.cjs.map +1 -0
- package/dist/cjs/utils.cjs +110 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/esm/Explorer.d.ts +53 -0
- package/dist/esm/Explorer.js +229 -0
- package/dist/esm/Explorer.js.map +1 -0
- package/dist/esm/devtools.d.ts +65 -0
- package/dist/esm/devtools.js +1150 -0
- package/{build/cjs → dist/esm}/devtools.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +6 -0
- package/{build/cjs → dist/esm}/index.js.map +1 -1
- package/dist/esm/styledComponents.d.ts +7 -0
- package/dist/esm/styledComponents.js +93 -0
- package/{build/cjs → dist/esm}/styledComponents.js.map +1 -1
- package/dist/esm/theme.d.ts +34 -0
- package/dist/esm/theme.js +28 -0
- package/dist/esm/theme.js.map +1 -0
- package/dist/esm/useLocalStorage.d.ts +1 -0
- package/dist/esm/useLocalStorage.js +46 -0
- package/dist/esm/useLocalStorage.js.map +1 -0
- package/dist/esm/useMediaQuery.d.ts +1 -0
- package/dist/esm/useMediaQuery.js +28 -0
- package/{build/cjs → dist/esm}/useMediaQuery.js.map +1 -1
- package/dist/esm/utils.d.ts +23 -0
- package/dist/esm/utils.js +110 -0
- package/{build/cjs → dist/esm}/utils.js.map +1 -1
- package/package.json +40 -21
- package/build/cjs/Explorer.js +0 -218
- package/build/cjs/Explorer.js.map +0 -1
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -29
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/devtools.js +0 -828
- package/build/cjs/index.js +0 -19
- package/build/cjs/styledComponents.js +0 -76
- package/build/cjs/theme.js +0 -45
- package/build/cjs/theme.js.map +0 -1
- package/build/cjs/useLocalStorage.js +0 -54
- package/build/cjs/useLocalStorage.js.map +0 -1
- package/build/cjs/useMediaQuery.js +0 -54
- package/build/cjs/utils.js +0 -131
- package/build/esm/index.js +0 -1265
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4838
- package/build/stats-react.json +0 -706
- package/build/umd/index.development.js +0 -1598
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -22
- package/build/umd/index.production.js.map +0 -1
- /package/{build/types/Explorer.d.ts → dist/cjs/Explorer.d.cts} +0 -0
- /package/{build/types/devtools.d.ts → dist/cjs/devtools.d.cts} +0 -0
- /package/{build/types/index.d.ts → dist/cjs/index.d.cts} +0 -0
- /package/{build/types/styledComponents.d.ts → dist/cjs/styledComponents.d.cts} +0 -0
- /package/{build/types/theme.d.ts → dist/cjs/theme.d.cts} +0 -0
- /package/{build/types/useLocalStorage.d.ts → dist/cjs/useLocalStorage.d.cts} +0 -0
- /package/{build/types/useMediaQuery.d.ts → dist/cjs/useMediaQuery.d.cts} +0 -0
- /package/{build/types/utils.d.ts → dist/cjs/utils.d.cts} +0 -0
package/build/cjs/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var devtools = require('./devtools.js');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.TanStackRouterDevtools = devtools.TanStackRouterDevtools;
|
|
18
|
-
exports.TanStackRouterDevtoolsPanel = devtools.TanStackRouterDevtoolsPanel;
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var utils = require('./utils.js');
|
|
14
|
-
|
|
15
|
-
const Panel = utils.styled('div', (_props, theme) => ({
|
|
16
|
-
fontSize: 'clamp(12px, 1.5vw, 14px)',
|
|
17
|
-
fontFamily: `sans-serif`,
|
|
18
|
-
display: 'flex',
|
|
19
|
-
backgroundColor: theme.background,
|
|
20
|
-
color: theme.foreground
|
|
21
|
-
}), {
|
|
22
|
-
'(max-width: 700px)': {
|
|
23
|
-
flexDirection: 'column'
|
|
24
|
-
},
|
|
25
|
-
'(max-width: 600px)': {
|
|
26
|
-
fontSize: '.9em'
|
|
27
|
-
// flexDirection: 'column',
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
const ActivePanel = utils.styled('div', () => ({
|
|
31
|
-
flex: '1 1 500px',
|
|
32
|
-
display: 'flex',
|
|
33
|
-
flexDirection: 'column',
|
|
34
|
-
overflow: 'auto',
|
|
35
|
-
height: '100%'
|
|
36
|
-
}), {
|
|
37
|
-
'(max-width: 700px)': (_props, theme) => ({
|
|
38
|
-
borderTop: `2px solid ${theme.gray}`
|
|
39
|
-
})
|
|
40
|
-
});
|
|
41
|
-
const Button = utils.styled('button', (props, theme) => ({
|
|
42
|
-
appearance: 'none',
|
|
43
|
-
fontSize: '.9em',
|
|
44
|
-
fontWeight: 'bold',
|
|
45
|
-
background: theme.gray,
|
|
46
|
-
border: '0',
|
|
47
|
-
borderRadius: '.3em',
|
|
48
|
-
color: 'white',
|
|
49
|
-
padding: '.5em',
|
|
50
|
-
opacity: props.disabled ? '.5' : undefined,
|
|
51
|
-
cursor: 'pointer'
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
// export const QueryKeys = styled('span', {
|
|
55
|
-
// display: 'inline-block',
|
|
56
|
-
// fontSize: '0.9em',
|
|
57
|
-
// })
|
|
58
|
-
|
|
59
|
-
// export const QueryKey = styled('span', {
|
|
60
|
-
// display: 'inline-flex',
|
|
61
|
-
// alignItems: 'center',
|
|
62
|
-
// padding: '.2em .4em',
|
|
63
|
-
// fontWeight: 'bold',
|
|
64
|
-
// textShadow: '0 0 10px black',
|
|
65
|
-
// borderRadius: '.2em',
|
|
66
|
-
// })
|
|
67
|
-
|
|
68
|
-
const Code = utils.styled('code', {
|
|
69
|
-
fontSize: '.9em'
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
exports.ActivePanel = ActivePanel;
|
|
73
|
-
exports.Button = Button;
|
|
74
|
-
exports.Code = Code;
|
|
75
|
-
exports.Panel = Panel;
|
|
76
|
-
//# sourceMappingURL=styledComponents.js.map
|
package/build/cjs/theme.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
14
|
-
var React = require('react');
|
|
15
|
-
|
|
16
|
-
const defaultTheme = {
|
|
17
|
-
background: '#222222',
|
|
18
|
-
backgroundAlt: '#292929',
|
|
19
|
-
foreground: 'white',
|
|
20
|
-
gray: '#444',
|
|
21
|
-
grayAlt: '#444',
|
|
22
|
-
inputBackgroundColor: '#fff',
|
|
23
|
-
inputTextColor: '#000',
|
|
24
|
-
success: '#80cb00',
|
|
25
|
-
danger: '#ff0085',
|
|
26
|
-
active: '#0099ff',
|
|
27
|
-
warning: '#ffb200'
|
|
28
|
-
};
|
|
29
|
-
const ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
|
|
30
|
-
function ThemeProvider({
|
|
31
|
-
theme,
|
|
32
|
-
...rest
|
|
33
|
-
}) {
|
|
34
|
-
return /*#__PURE__*/React.createElement(ThemeContext.Provider, _rollupPluginBabelHelpers.extends({
|
|
35
|
-
value: theme
|
|
36
|
-
}, rest));
|
|
37
|
-
}
|
|
38
|
-
function useTheme() {
|
|
39
|
-
return React.useContext(ThemeContext);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
exports.ThemeProvider = ThemeProvider;
|
|
43
|
-
exports.defaultTheme = defaultTheme;
|
|
44
|
-
exports.useTheme = useTheme;
|
|
45
|
-
//# sourceMappingURL=theme.js.map
|
package/build/cjs/theme.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sources":["../../src/theme.tsx"],"sourcesContent":["import React from 'react'\n\nexport const defaultTheme = {\n background: '#222222',\n backgroundAlt: '#292929',\n foreground: 'white',\n gray: '#444',\n grayAlt: '#444',\n inputBackgroundColor: '#fff',\n inputTextColor: '#000',\n success: '#80cb00',\n danger: '#ff0085',\n active: '#0099ff',\n warning: '#ffb200',\n} as const\n\nexport type Theme = typeof defaultTheme\ninterface ProviderProps {\n theme: Theme\n children?: React.ReactNode\n}\n\nconst ThemeContext = React.createContext(defaultTheme)\n\nexport function ThemeProvider({ theme, ...rest }: ProviderProps) {\n return <ThemeContext.Provider value={theme} {...rest} />\n}\n\nexport function useTheme() {\n return React.useContext(ThemeContext)\n}\n"],"names":["defaultTheme","background","backgroundAlt","foreground","gray","grayAlt","inputBackgroundColor","inputTextColor","success","danger","active","warning","ThemeContext","React","createContext","ThemeProvider","theme","rest","createElement","Provider","_extends","value","useTheme","useContext"],"mappings":";;;;;;;;;;;;;;;AAEO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,UAAU,EAAE,SAAS;AACrBC,EAAAA,aAAa,EAAE,SAAS;AACxBC,EAAAA,UAAU,EAAE,OAAO;AACnBC,EAAAA,IAAI,EAAE,MAAM;AACZC,EAAAA,OAAO,EAAE,MAAM;AACfC,EAAAA,oBAAoB,EAAE,MAAM;AAC5BC,EAAAA,cAAc,EAAE,MAAM;AACtBC,EAAAA,OAAO,EAAE,SAAS;AAClBC,EAAAA,MAAM,EAAE,SAAS;AACjBC,EAAAA,MAAM,EAAE,SAAS;AACjBC,EAAAA,OAAO,EAAE,SAAA;AACX,EAAU;AAQV,MAAMC,YAAY,gBAAGC,KAAK,CAACC,aAAa,CAACd,YAAY,CAAC,CAAA;AAE/C,SAASe,aAAaA,CAAC;EAAEC,KAAK;EAAE,GAAGC,IAAAA;AAAoB,CAAC,EAAE;EAC/D,oBAAOJ,KAAA,CAAAK,aAAA,CAACN,YAAY,CAACO,QAAQ,EAAAC,iCAAA,CAAA;AAACC,IAAAA,KAAK,EAAEL,KAAAA;GAAWC,EAAAA,IAAI,CAAG,CAAC,CAAA;AAC1D,CAAA;AAEO,SAASK,QAAQA,GAAG;AACzB,EAAA,OAAOT,KAAK,CAACU,UAAU,CAACX,YAAY,CAAC,CAAA;AACvC;;;;;;"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var React = require('react');
|
|
16
|
-
|
|
17
|
-
const getItem = key => {
|
|
18
|
-
try {
|
|
19
|
-
const itemValue = localStorage.getItem(key);
|
|
20
|
-
if (typeof itemValue === 'string') {
|
|
21
|
-
return JSON.parse(itemValue);
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
} catch {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function useLocalStorage(key, defaultValue) {
|
|
29
|
-
const [value, setValue] = React.useState();
|
|
30
|
-
React.useEffect(() => {
|
|
31
|
-
const initialValue = getItem(key);
|
|
32
|
-
if (typeof initialValue === 'undefined' || initialValue === null) {
|
|
33
|
-
setValue(typeof defaultValue === 'function' ? defaultValue() : defaultValue);
|
|
34
|
-
} else {
|
|
35
|
-
setValue(initialValue);
|
|
36
|
-
}
|
|
37
|
-
}, [defaultValue, key]);
|
|
38
|
-
const setter = React.useCallback(updater => {
|
|
39
|
-
setValue(old => {
|
|
40
|
-
let newVal = updater;
|
|
41
|
-
if (typeof updater == 'function') {
|
|
42
|
-
newVal = updater(old);
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
localStorage.setItem(key, JSON.stringify(newVal));
|
|
46
|
-
} catch {}
|
|
47
|
-
return newVal;
|
|
48
|
-
});
|
|
49
|
-
}, [key]);
|
|
50
|
-
return [value, setter];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.default = useLocalStorage;
|
|
54
|
-
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.js","sources":["../../src/useLocalStorage.ts"],"sourcesContent":["import React from 'react'\n\nconst getItem = (key: string): unknown => {\n try {\n const itemValue = localStorage.getItem(key)\n if (typeof itemValue === 'string') {\n return JSON.parse(itemValue)\n }\n return undefined\n } catch {\n return undefined\n }\n}\n\nexport default function useLocalStorage<T>(\n key: string,\n defaultValue: T | undefined,\n): [T | undefined, (newVal: T | ((prevVal: T) => T)) => void] {\n const [value, setValue] = React.useState<T>()\n\n React.useEffect(() => {\n const initialValue = getItem(key) as T | undefined\n\n if (typeof initialValue === 'undefined' || initialValue === null) {\n setValue(\n typeof defaultValue === 'function' ? defaultValue() : defaultValue,\n )\n } else {\n setValue(initialValue)\n }\n }, [defaultValue, key])\n\n const setter = React.useCallback(\n (updater: any) => {\n setValue((old) => {\n let newVal = updater\n\n if (typeof updater == 'function') {\n newVal = updater(old)\n }\n try {\n localStorage.setItem(key, JSON.stringify(newVal))\n } catch {}\n\n return newVal\n })\n },\n [key],\n )\n\n return [value, setter]\n}\n"],"names":["getItem","key","itemValue","localStorage","JSON","parse","undefined","useLocalStorage","defaultValue","value","setValue","React","useState","useEffect","initialValue","setter","useCallback","updater","old","newVal","setItem","stringify"],"mappings":";;;;;;;;;;;;;;;;AAEA,MAAMA,OAAO,GAAIC,GAAW,IAAc;EACxC,IAAI;AACF,IAAA,MAAMC,SAAS,GAAGC,YAAY,CAACH,OAAO,CAACC,GAAG,CAAC,CAAA;AAC3C,IAAA,IAAI,OAAOC,SAAS,KAAK,QAAQ,EAAE;AACjC,MAAA,OAAOE,IAAI,CAACC,KAAK,CAACH,SAAS,CAAC,CAAA;AAC9B,KAAA;AACA,IAAA,OAAOI,SAAS,CAAA;AAClB,GAAC,CAAC,MAAM;AACN,IAAA,OAAOA,SAAS,CAAA;AAClB,GAAA;AACF,CAAC,CAAA;AAEc,SAASC,eAAeA,CACrCN,GAAW,EACXO,YAA2B,EACiC;EAC5D,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,KAAK,CAACC,QAAQ,EAAK,CAAA;EAE7CD,KAAK,CAACE,SAAS,CAAC,MAAM;AACpB,IAAA,MAAMC,YAAY,GAAGd,OAAO,CAACC,GAAG,CAAkB,CAAA;IAElD,IAAI,OAAOa,YAAY,KAAK,WAAW,IAAIA,YAAY,KAAK,IAAI,EAAE;MAChEJ,QAAQ,CACN,OAAOF,YAAY,KAAK,UAAU,GAAGA,YAAY,EAAE,GAAGA,YACxD,CAAC,CAAA;AACH,KAAC,MAAM;MACLE,QAAQ,CAACI,YAAY,CAAC,CAAA;AACxB,KAAA;AACF,GAAC,EAAE,CAACN,YAAY,EAAEP,GAAG,CAAC,CAAC,CAAA;AAEvB,EAAA,MAAMc,MAAM,GAAGJ,KAAK,CAACK,WAAW,CAC7BC,OAAY,IAAK;IAChBP,QAAQ,CAAEQ,GAAG,IAAK;MAChB,IAAIC,MAAM,GAAGF,OAAO,CAAA;AAEpB,MAAA,IAAI,OAAOA,OAAO,IAAI,UAAU,EAAE;AAChCE,QAAAA,MAAM,GAAGF,OAAO,CAACC,GAAG,CAAC,CAAA;AACvB,OAAA;MACA,IAAI;QACFf,YAAY,CAACiB,OAAO,CAACnB,GAAG,EAAEG,IAAI,CAACiB,SAAS,CAACF,MAAM,CAAC,CAAC,CAAA;OAClD,CAAC,MAAM,EAAC;AAET,MAAA,OAAOA,MAAM,CAAA;AACf,KAAC,CAAC,CAAA;AACJ,GAAC,EACD,CAAClB,GAAG,CACN,CAAC,CAAA;AAED,EAAA,OAAO,CAACQ,KAAK,EAAEM,MAAM,CAAC,CAAA;AACxB;;;;"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var React = require('react');
|
|
16
|
-
|
|
17
|
-
function useMediaQuery(query) {
|
|
18
|
-
// Keep track of the preference in state, start with the current match
|
|
19
|
-
const [isMatch, setIsMatch] = React.useState(() => {
|
|
20
|
-
if (typeof window !== 'undefined') {
|
|
21
|
-
return window.matchMedia && window.matchMedia(query).matches;
|
|
22
|
-
}
|
|
23
|
-
return;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Watch for changes
|
|
27
|
-
React.useEffect(() => {
|
|
28
|
-
if (typeof window !== 'undefined') {
|
|
29
|
-
if (!window.matchMedia) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Create a matcher
|
|
34
|
-
const matcher = window.matchMedia(query);
|
|
35
|
-
|
|
36
|
-
// Create our handler
|
|
37
|
-
const onChange = ({
|
|
38
|
-
matches
|
|
39
|
-
}) => setIsMatch(matches);
|
|
40
|
-
|
|
41
|
-
// Listen for changes
|
|
42
|
-
matcher.addListener(onChange);
|
|
43
|
-
return () => {
|
|
44
|
-
// Stop listening for changes
|
|
45
|
-
matcher.removeListener(onChange);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return;
|
|
49
|
-
}, [isMatch, query, setIsMatch]);
|
|
50
|
-
return isMatch;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.default = useMediaQuery;
|
|
54
|
-
//# sourceMappingURL=useMediaQuery.js.map
|
package/build/cjs/utils.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/router-devtools/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var React = require('react');
|
|
14
|
-
var theme = require('./theme.js');
|
|
15
|
-
var useMediaQuery = require('./useMediaQuery.js');
|
|
16
|
-
|
|
17
|
-
const isServer = typeof window === 'undefined';
|
|
18
|
-
function getStatusColor(match, theme) {
|
|
19
|
-
return match.status === 'pending' || match.isFetching ? theme.active : match.status === 'error' ? theme.danger : match.status === 'success' ? theme.success : theme.gray;
|
|
20
|
-
}
|
|
21
|
-
function getRouteStatusColor(matches, route, theme) {
|
|
22
|
-
const found = matches.find(d => d.routeId === route.id);
|
|
23
|
-
if (!found) return theme.gray;
|
|
24
|
-
return getStatusColor(found, theme);
|
|
25
|
-
}
|
|
26
|
-
function styled(type, newStyles, queries = {}) {
|
|
27
|
-
return /*#__PURE__*/React.forwardRef(({
|
|
28
|
-
style,
|
|
29
|
-
...rest
|
|
30
|
-
}, ref) => {
|
|
31
|
-
const theme$1 = theme.useTheme();
|
|
32
|
-
const mediaStyles = Object.entries(queries).reduce((current, [key, value]) => {
|
|
33
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
34
|
-
return useMediaQuery.default(key) ? {
|
|
35
|
-
...current,
|
|
36
|
-
...(typeof value === 'function' ? value(rest, theme$1) : value)
|
|
37
|
-
} : current;
|
|
38
|
-
}, {});
|
|
39
|
-
return /*#__PURE__*/React.createElement(type, {
|
|
40
|
-
...rest,
|
|
41
|
-
style: {
|
|
42
|
-
...(typeof newStyles === 'function' ? newStyles(rest, theme$1) : newStyles),
|
|
43
|
-
...style,
|
|
44
|
-
...mediaStyles
|
|
45
|
-
},
|
|
46
|
-
ref
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function useIsMounted() {
|
|
51
|
-
const mountedRef = React.useRef(false);
|
|
52
|
-
const isMounted = React.useCallback(() => mountedRef.current, []);
|
|
53
|
-
React[isServer ? 'useEffect' : 'useLayoutEffect'](() => {
|
|
54
|
-
mountedRef.current = true;
|
|
55
|
-
return () => {
|
|
56
|
-
mountedRef.current = false;
|
|
57
|
-
};
|
|
58
|
-
}, []);
|
|
59
|
-
return isMounted;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Displays a string regardless the type of the data
|
|
64
|
-
* @param {unknown} value Value to be stringified
|
|
65
|
-
*/
|
|
66
|
-
const displayValue = value => {
|
|
67
|
-
const name = Object.getOwnPropertyNames(Object(value));
|
|
68
|
-
const newValue = typeof value === 'bigint' ? `${value.toString()}n` : value;
|
|
69
|
-
try {
|
|
70
|
-
return JSON.stringify(newValue, name);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return `unable to stringify`;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* This hook is a safe useState version which schedules state updates in microtasks
|
|
78
|
-
* to prevent updating a component state while React is rendering different components
|
|
79
|
-
* or when the component is not mounted anymore.
|
|
80
|
-
*/
|
|
81
|
-
function useSafeState(initialState) {
|
|
82
|
-
const isMounted = useIsMounted();
|
|
83
|
-
const [state, setState] = React.useState(initialState);
|
|
84
|
-
const safeSetState = React.useCallback(value => {
|
|
85
|
-
scheduleMicrotask(() => {
|
|
86
|
-
if (isMounted()) {
|
|
87
|
-
setState(value);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}, [isMounted]);
|
|
91
|
-
return [state, safeSetState];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Schedules a microtask.
|
|
96
|
-
* This can be useful to schedule state updates after rendering.
|
|
97
|
-
*/
|
|
98
|
-
function scheduleMicrotask(callback) {
|
|
99
|
-
Promise.resolve().then(callback).catch(error => setTimeout(() => {
|
|
100
|
-
throw error;
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
function multiSortBy(arr, accessors = [d => d]) {
|
|
104
|
-
return arr.map((d, i) => [d, i]).sort(([a, ai], [b, bi]) => {
|
|
105
|
-
for (const accessor of accessors) {
|
|
106
|
-
const ao = accessor(a);
|
|
107
|
-
const bo = accessor(b);
|
|
108
|
-
if (typeof ao === 'undefined') {
|
|
109
|
-
if (typeof bo === 'undefined') {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
return 1;
|
|
113
|
-
}
|
|
114
|
-
if (ao === bo) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
return ao > bo ? 1 : -1;
|
|
118
|
-
}
|
|
119
|
-
return ai - bi;
|
|
120
|
-
}).map(([d]) => d);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
exports.displayValue = displayValue;
|
|
124
|
-
exports.getRouteStatusColor = getRouteStatusColor;
|
|
125
|
-
exports.getStatusColor = getStatusColor;
|
|
126
|
-
exports.isServer = isServer;
|
|
127
|
-
exports.multiSortBy = multiSortBy;
|
|
128
|
-
exports.styled = styled;
|
|
129
|
-
exports.useIsMounted = useIsMounted;
|
|
130
|
-
exports.useSafeState = useSafeState;
|
|
131
|
-
//# sourceMappingURL=utils.js.map
|