2022-05-16 00:47:09 +03:00
|
|
|
import React, { CSSProperties, useRef } from 'react';
|
2018-12-22 03:10:49 +03:00
|
|
|
import { connect } from 'react-redux';
|
2021-09-25 07:12:30 +03:00
|
|
|
import pkg from '@redux-devtools/inspector-monitor/package.json';
|
2020-08-10 16:36:03 +03:00
|
|
|
import Button from 'react-bootstrap/Button';
|
|
|
|
import FormGroup from 'react-bootstrap/FormGroup';
|
|
|
|
import FormControl from 'react-bootstrap/FormControl';
|
|
|
|
import FormLabel from 'react-bootstrap/FormLabel';
|
|
|
|
import Form from 'react-bootstrap/Form';
|
|
|
|
import Col from 'react-bootstrap/Col';
|
|
|
|
import InputGroup from 'react-bootstrap/InputGroup';
|
2020-08-31 00:49:06 +03:00
|
|
|
import Row from 'react-bootstrap/Row';
|
2018-12-22 03:10:49 +03:00
|
|
|
import * as base16 from 'base16';
|
2022-01-10 18:41:53 +03:00
|
|
|
import { inspectorThemes } from '@redux-devtools/inspector-monitor';
|
2022-05-16 00:47:09 +03:00
|
|
|
import { useLocation, useNavigate } from 'react-router-dom';
|
2020-08-31 00:49:06 +03:00
|
|
|
import getOptions, { Options } from './getOptions';
|
|
|
|
import {
|
|
|
|
AddFunctionAction,
|
|
|
|
AddHugeObjectAction,
|
|
|
|
AddImmutableMapAction,
|
|
|
|
AddIteratorAction,
|
|
|
|
AddNativeMapAction,
|
|
|
|
AddRecursiveAction,
|
|
|
|
AddSymbolAction,
|
|
|
|
ChangeImmutableNestedAction,
|
|
|
|
ChangeNestedAction,
|
|
|
|
DemoAppState,
|
|
|
|
HugePayloadAction,
|
|
|
|
IncrementAction,
|
|
|
|
PopAction,
|
|
|
|
PushAction,
|
|
|
|
PushHugeArrayAction,
|
|
|
|
ReplaceAction,
|
|
|
|
ShuffleArrayAction,
|
|
|
|
TimeoutUpdateAction,
|
|
|
|
ToggleTimeoutUpdateAction,
|
|
|
|
} from './reducers';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
const styles: {
|
|
|
|
wrapper: CSSProperties;
|
|
|
|
header: CSSProperties;
|
|
|
|
content: CSSProperties;
|
|
|
|
buttons: CSSProperties;
|
|
|
|
muted: CSSProperties;
|
|
|
|
button: CSSProperties;
|
|
|
|
links: CSSProperties;
|
|
|
|
link: CSSProperties;
|
|
|
|
input: CSSProperties;
|
|
|
|
} = {
|
2018-12-22 03:10:49 +03:00
|
|
|
wrapper: {
|
|
|
|
height: '100vh',
|
|
|
|
width: '80%',
|
|
|
|
margin: '0 auto',
|
2020-08-08 23:26:39 +03:00
|
|
|
paddingTop: '1px',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
header: {},
|
2018-12-22 03:10:49 +03:00
|
|
|
content: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2020-08-08 23:26:39 +03:00
|
|
|
height: '50%',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
buttons: {
|
|
|
|
display: 'flex',
|
|
|
|
width: '40rem',
|
|
|
|
justifyContent: 'center',
|
2020-08-08 23:26:39 +03:00
|
|
|
flexWrap: 'wrap',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
muted: {
|
2020-08-08 23:26:39 +03:00
|
|
|
color: '#CCCCCC',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
button: {
|
2020-08-08 23:26:39 +03:00
|
|
|
margin: '0.5rem',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
links: {
|
2020-08-08 23:26:39 +03:00
|
|
|
textAlign: 'center',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
margin: '0 0.5rem',
|
|
|
|
cursor: 'pointer',
|
2020-08-08 23:26:39 +03:00
|
|
|
display: 'block',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
input: {
|
|
|
|
display: 'inline-block',
|
|
|
|
textAlign: 'left',
|
2020-08-08 23:26:39 +03:00
|
|
|
width: '30rem',
|
|
|
|
},
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const themeOptions = [
|
2020-08-08 23:26:39 +03:00
|
|
|
...Object.keys(inspectorThemes).map((value) => ({
|
2019-01-10 21:51:14 +03:00
|
|
|
value,
|
2020-08-31 00:49:06 +03:00
|
|
|
label: inspectorThemes[value as keyof typeof inspectorThemes].scheme,
|
2019-01-10 21:51:14 +03:00
|
|
|
})),
|
2018-12-22 03:10:49 +03:00
|
|
|
null,
|
|
|
|
...Object.keys(base16)
|
2020-08-31 00:49:06 +03:00
|
|
|
.map((value) => ({
|
|
|
|
value,
|
|
|
|
label: base16[value as keyof typeof base16].scheme,
|
|
|
|
}))
|
2020-08-08 23:26:39 +03:00
|
|
|
.filter((opt) => opt.label),
|
2018-12-22 03:10:49 +03:00
|
|
|
];
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const ROOT =
|
2020-09-10 19:37:19 +03:00
|
|
|
process.env.NODE_ENV === 'production'
|
|
|
|
? '/redux-devtools-inspector-monitor/'
|
|
|
|
: '/';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
function buildUrl(options: Options) {
|
2019-01-10 21:51:14 +03:00
|
|
|
return (
|
|
|
|
`${ROOT}?` +
|
|
|
|
[
|
|
|
|
options.useExtension ? 'ext' : '',
|
|
|
|
options.supportImmutable ? 'immutable' : '',
|
|
|
|
options.theme ? 'theme=' + options.theme : '',
|
2020-08-08 23:26:39 +03:00
|
|
|
options.dark ? 'dark' : '',
|
2019-01-10 21:51:14 +03:00
|
|
|
]
|
2020-08-08 23:26:39 +03:00
|
|
|
.filter((s) => s)
|
2019-01-10 21:51:14 +03:00
|
|
|
.join('&')
|
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
interface Props
|
|
|
|
extends Omit<DemoAppState, 'addFunction' | 'addSymbol' | 'shuffleArray'> {
|
|
|
|
toggleTimeoutUpdate: (timeoutUpdateEnabled: boolean) => void;
|
|
|
|
timeoutUpdate: () => void;
|
|
|
|
increment: () => void;
|
|
|
|
push: () => void;
|
|
|
|
pop: () => void;
|
|
|
|
replace: () => void;
|
|
|
|
changeNested: () => void;
|
|
|
|
pushHugeArray: () => void;
|
|
|
|
addIterator: () => void;
|
|
|
|
addHugeObject: () => void;
|
|
|
|
addRecursive: () => void;
|
|
|
|
addNativeMap: () => void;
|
|
|
|
addImmutableMap: () => void;
|
|
|
|
changeImmutableNested: () => void;
|
|
|
|
hugePayload: () => void;
|
|
|
|
addFunction: () => void;
|
|
|
|
addSymbol: () => void;
|
|
|
|
shuffleArray: () => void;
|
|
|
|
}
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
function DemoApp(props: Props) {
|
|
|
|
const timeout = useRef<number | undefined>();
|
|
|
|
const location = useLocation();
|
|
|
|
const navigate = useNavigate();
|
2020-08-31 00:49:06 +03:00
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const toggleExtension = () => {
|
|
|
|
const options = getOptions(location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
window.location.href = buildUrl({
|
|
|
|
...options,
|
|
|
|
useExtension: !options.useExtension,
|
|
|
|
});
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const toggleImmutableSupport = () => {
|
|
|
|
const options = getOptions(location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
navigate(
|
2019-01-10 21:51:14 +03:00
|
|
|
buildUrl({ ...options, supportImmutable: !options.supportImmutable })
|
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const toggleTheme = () => {
|
|
|
|
const options = getOptions(location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
navigate(buildUrl({ ...options, dark: !options.dark }));
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const setTheme = (options: Options, theme: string) => {
|
|
|
|
navigate(buildUrl({ ...options, theme }));
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const toggleTimeoutUpdate = () => {
|
|
|
|
const enabled = !props.timeoutUpdateEnabled;
|
|
|
|
props.toggleTimeoutUpdate(enabled);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
if (enabled) {
|
2022-05-16 00:47:09 +03:00
|
|
|
timeout.current = window.setInterval(props.timeoutUpdate, 1000);
|
2018-12-22 03:10:49 +03:00
|
|
|
} else {
|
2022-05-16 00:47:09 +03:00
|
|
|
clearTimeout(timeout.current);
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
2019-01-10 21:51:14 +03:00
|
|
|
};
|
2022-05-16 00:47:09 +03:00
|
|
|
|
|
|
|
const options = getOptions(location);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={styles.wrapper}>
|
|
|
|
<h1 style={styles.header}>
|
|
|
|
{pkg.name || <span style={styles.muted}>Package Name</span>}
|
|
|
|
</h1>
|
|
|
|
<h5>
|
|
|
|
{pkg.description || (
|
|
|
|
<span style={styles.muted}>Package Description</span>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
<div style={styles.links}>
|
|
|
|
<div style={styles.input}>
|
|
|
|
<Form>
|
|
|
|
<FormGroup as={Row}>
|
|
|
|
<Col as={FormLabel} sm={3}>
|
|
|
|
Theme:
|
|
|
|
</Col>
|
|
|
|
<Col sm={9}>
|
|
|
|
<InputGroup>
|
|
|
|
<FormControl
|
|
|
|
as="select"
|
|
|
|
onChange={(event) =>
|
|
|
|
setTheme(options, event.currentTarget.value)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{themeOptions.map((theme) => (
|
|
|
|
<option
|
|
|
|
key={(theme && theme.label) || 'empty'}
|
|
|
|
label={(theme && theme.label) || '──────────'}
|
|
|
|
value={theme ? theme.value : undefined}
|
|
|
|
disabled={!theme}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</FormControl>
|
|
|
|
<a onClick={toggleTheme} style={styles.link}>
|
|
|
|
{options.dark ? 'Light theme' : 'Dark theme'}
|
|
|
|
</a>
|
|
|
|
</InputGroup>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div style={styles.content}>
|
|
|
|
<div style={styles.buttons}>
|
|
|
|
<Button onClick={props.increment} style={styles.button}>
|
|
|
|
Increment
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.push} style={styles.button}>
|
|
|
|
Push
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.pop} style={styles.button}>
|
|
|
|
Pop
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.replace} style={styles.button}>
|
|
|
|
Replace
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.changeNested} style={styles.button}>
|
|
|
|
Change Nested
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.pushHugeArray} style={styles.button}>
|
|
|
|
Push Huge Array
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addHugeObject} style={styles.button}>
|
|
|
|
Add Huge Object
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addIterator} style={styles.button}>
|
|
|
|
Add Iterator
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addRecursive} style={styles.button}>
|
|
|
|
Add Recursive
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addNativeMap} style={styles.button}>
|
|
|
|
Add Native Map
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addImmutableMap} style={styles.button}>
|
|
|
|
Add Immutable Map
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.changeImmutableNested} style={styles.button}>
|
|
|
|
Change Immutable Nested
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.hugePayload} style={styles.button}>
|
|
|
|
Huge Payload
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addFunction} style={styles.button}>
|
|
|
|
Add Function
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.addSymbol} style={styles.button}>
|
|
|
|
Add Symbol
|
|
|
|
</Button>
|
|
|
|
<Button onClick={toggleTimeoutUpdate} style={styles.button}>
|
|
|
|
Timeout Update {props.timeoutUpdateEnabled ? 'On' : 'Off'}
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.shuffleArray} style={styles.button}>
|
|
|
|
Shuffle Array
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div style={styles.links}>
|
|
|
|
<a onClick={toggleExtension} style={styles.link}>
|
|
|
|
{(options.useExtension ? 'Disable' : 'Enable') +
|
|
|
|
' Chrome Extension (will reload this page)'}
|
|
|
|
</a>
|
|
|
|
<a onClick={toggleImmutableSupport} style={styles.link}>
|
|
|
|
{(options.supportImmutable ? 'Disable' : 'Enable') +
|
|
|
|
' Full Immutable Support'}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
export default connect((state: DemoAppState) => state, {
|
|
|
|
toggleTimeoutUpdate: (
|
|
|
|
timeoutUpdateEnabled: boolean
|
|
|
|
): ToggleTimeoutUpdateAction => ({
|
2020-08-05 16:12:31 +03:00
|
|
|
type: 'TOGGLE_TIMEOUT_UPDATE',
|
2020-08-08 23:26:39 +03:00
|
|
|
timeoutUpdateEnabled,
|
2020-08-05 16:12:31 +03:00
|
|
|
}),
|
2020-08-31 00:49:06 +03:00
|
|
|
timeoutUpdate: (): TimeoutUpdateAction => ({ type: 'TIMEOUT_UPDATE' }),
|
|
|
|
increment: (): IncrementAction => ({ type: 'INCREMENT' }),
|
|
|
|
push: (): PushAction => ({ type: 'PUSH' }),
|
|
|
|
pop: (): PopAction => ({ type: 'POP' }),
|
|
|
|
replace: (): ReplaceAction => ({ type: 'REPLACE' }),
|
|
|
|
changeNested: (): ChangeNestedAction => ({ type: 'CHANGE_NESTED' }),
|
|
|
|
pushHugeArray: (): PushHugeArrayAction => ({ type: 'PUSH_HUGE_ARRAY' }),
|
|
|
|
addIterator: (): AddIteratorAction => ({ type: 'ADD_ITERATOR' }),
|
|
|
|
addHugeObject: (): AddHugeObjectAction => ({ type: 'ADD_HUGE_OBJECT' }),
|
|
|
|
addRecursive: (): AddRecursiveAction => ({ type: 'ADD_RECURSIVE' }),
|
|
|
|
addNativeMap: (): AddNativeMapAction => ({ type: 'ADD_NATIVE_MAP' }),
|
|
|
|
addImmutableMap: (): AddImmutableMapAction => ({ type: 'ADD_IMMUTABLE_MAP' }),
|
|
|
|
changeImmutableNested: (): ChangeImmutableNestedAction => ({
|
|
|
|
type: 'CHANGE_IMMUTABLE_NESTED',
|
|
|
|
}),
|
|
|
|
hugePayload: (): HugePayloadAction => ({
|
2020-08-05 16:12:31 +03:00
|
|
|
type: 'HUGE_PAYLOAD',
|
2020-08-08 23:26:39 +03:00
|
|
|
payload: Array.from({ length: 10000 }).map((_, i) => i),
|
2020-08-05 16:12:31 +03:00
|
|
|
}),
|
2020-08-31 00:49:06 +03:00
|
|
|
addFunction: (): AddFunctionAction => ({ type: 'ADD_FUNCTION' }),
|
|
|
|
addSymbol: (): AddSymbolAction => ({ type: 'ADD_SYMBOL' }),
|
|
|
|
shuffleArray: (): ShuffleArrayAction => ({ type: 'SHUFFLE_ARRAY' }),
|
2022-05-16 00:47:09 +03:00
|
|
|
})(DemoApp);
|