mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 08:30:02 +03:00
Merge e993425245
into b1367c61d4
This commit is contained in:
commit
851ea112d4
|
@ -1,6 +1,12 @@
|
||||||
import React, { PropTypes, findDOMNode } from 'react';
|
import React, { PropTypes, findDOMNode } from 'react';
|
||||||
import LogMonitorEntry from './LogMonitorEntry';
|
import LogMonitorEntry from './LogMonitorEntry';
|
||||||
|
|
||||||
|
const ulStyle = {
|
||||||
|
listStyle: "none",
|
||||||
|
padding: "20px 0 20px",
|
||||||
|
position: "relative"
|
||||||
|
};
|
||||||
|
|
||||||
export default class LogMonitor {
|
export default class LogMonitor {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
@ -137,7 +143,9 @@ export default class LogMonitor {
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{elements}
|
<ul style={ulStyle}>
|
||||||
|
{elements}
|
||||||
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
{computedStates.length > 1 &&
|
{computedStates.length > 1 &&
|
||||||
<a onClick={::this.handleRollback}
|
<a onClick={::this.handleRollback}
|
||||||
|
|
|
@ -1,121 +1,188 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes, Component } from 'react';
|
||||||
|
|
||||||
|
const preStyle = {
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
color: "white",
|
||||||
|
border: 0,
|
||||||
|
margin: 0,
|
||||||
|
padding: 0
|
||||||
|
};
|
||||||
|
const h4Style = {
|
||||||
|
fontWeight: 500,
|
||||||
|
lineHeight: 1.1,
|
||||||
|
fontSize: "18px",
|
||||||
|
marginTop: "10px",
|
||||||
|
marginBottom: "10px"
|
||||||
|
}
|
||||||
|
const liStyle = {
|
||||||
|
marginBottom: "20px",
|
||||||
|
position: "relative"
|
||||||
|
};
|
||||||
|
const wrap1Style = {
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
overflow: "auto"
|
||||||
|
};
|
||||||
|
const wrap2Style = {
|
||||||
|
display: "table",
|
||||||
|
tableLayout: "fixed",
|
||||||
|
width: "100%"
|
||||||
|
};
|
||||||
|
const wrap3Style = {
|
||||||
|
width: "100%",
|
||||||
|
display: "table-cell"
|
||||||
|
};
|
||||||
|
const wrap3StyleMax = {
|
||||||
|
width: "800px",
|
||||||
|
display: "table-cell"
|
||||||
|
};
|
||||||
|
|
||||||
function hsvToRgb(h, s, v) {
|
function hsvToRgb(h, s, v) {
|
||||||
const i = Math.floor(h);
|
const i = Math.floor(h);
|
||||||
const f = h - i;
|
const f = h - i;
|
||||||
const p = v * (1 - s);
|
const p = v * (1 - s);
|
||||||
const q = v * (1 - f * s);
|
const q = v * (1 - f * s);
|
||||||
const t = v * (1 - (1 - f) * s);
|
const t = v * (1 - (1 - f) * s);
|
||||||
const mod = i % 6;
|
const mod = i % 6;
|
||||||
const r = [v, q, p, p, t, v][mod];
|
const r = [v, q, p, p, t, v][mod];
|
||||||
const g = [t, v, v, q, p, p][mod];
|
const g = [t, v, v, q, p, p][mod];
|
||||||
const b = [p, p, t, v, v, q][mod];
|
const b = [p, p, t, v, v, q][mod];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
r: Math.round(r * 255),
|
r: Math.round(r * 255),
|
||||||
g: Math.round(g * 255),
|
g: Math.round(g * 255),
|
||||||
b: Math.round(b * 255)
|
b: Math.round(b * 255)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function colorFromString(token) {
|
function colorFromString(token) {
|
||||||
const splitToken = token.split('');
|
const splitToken = token.split('');
|
||||||
const finalToken = splitToken.concat(splitToken.reverse());
|
const finalToken = splitToken.concat(splitToken.reverse());
|
||||||
|
|
||||||
const number = finalToken.reduce(
|
const number = finalToken.reduce(
|
||||||
(sum, char) => sum + char.charCodeAt(0),
|
(sum, char) => sum + char.charCodeAt(0),
|
||||||
0
|
0
|
||||||
) * Math.abs(Math.sin(token.length));
|
) * Math.abs(Math.sin(token.length));
|
||||||
|
|
||||||
const h = Math.round((number * (180 / Math.PI) * token.length) % 360);
|
const h = Math.round((number * (180 / Math.PI) * token.length) % 360);
|
||||||
const s = number % 100 / 100;
|
const s = number % 100 / 100;
|
||||||
const v = 1;
|
const v = 1;
|
||||||
|
|
||||||
return hsvToRgb(h, s, v);
|
return hsvToRgb(h, s, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LogMonitorEntry {
|
export default class LogMonitorEntry extends Component {
|
||||||
static propTypes = {
|
constructor(props) {
|
||||||
index: PropTypes.number.isRequired,
|
super(props);
|
||||||
state: PropTypes.object.isRequired,
|
this.state = {
|
||||||
action: PropTypes.object.isRequired,
|
maximizedAction: false,
|
||||||
select: PropTypes.func.isRequired,
|
maximizedState: false
|
||||||
error: PropTypes.string,
|
|
||||||
onActionClick: PropTypes.func.isRequired,
|
|
||||||
collapsed: PropTypes.bool
|
|
||||||
};
|
|
||||||
|
|
||||||
printState(state, error) {
|
|
||||||
let errorText = error;
|
|
||||||
if (!errorText) {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(this.props.select(state));
|
|
||||||
} catch (err) {
|
|
||||||
errorText = 'Error selecting state.';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
static propTypes = {
|
||||||
<span style={{
|
index: PropTypes.number.isRequired,
|
||||||
|
state: PropTypes.object.isRequired,
|
||||||
|
action: PropTypes.object.isRequired,
|
||||||
|
select: PropTypes.func.isRequired,
|
||||||
|
error: PropTypes.string,
|
||||||
|
onActionClick: PropTypes.func.isRequired,
|
||||||
|
collapsed: PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
|
printState(state, error) {
|
||||||
|
let errorText = error;
|
||||||
|
if (!errorText) {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(this.props.select(state), null, 2);
|
||||||
|
} catch (err) {
|
||||||
|
errorText = 'Error selecting state.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span style={{
|
||||||
fontStyle: 'italic'
|
fontStyle: 'italic'
|
||||||
}}>
|
}}>
|
||||||
({errorText})
|
({errorText})
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleActionClick() {
|
handleCollapseClick() {
|
||||||
const { index, onActionClick } = this.props;
|
const { index, onActionClick } = this.props;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
onActionClick(index);
|
onActionClick(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { index, error, action, state, collapsed } = this.props;
|
const { index, error, action, state, collapsed } = this.props;
|
||||||
const { r, g, b } = colorFromString(action.type);
|
const { maximizedAction, maximizedState } = this.state;
|
||||||
|
if (!action.type) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { r, g, b } = colorFromString(action.type);
|
||||||
|
const colorStyle = {color: `rgb(${r}, ${g}, ${b})`};
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
textDecoration: collapsed ? 'line-through' : 'none'
|
|
||||||
}}>
|
|
||||||
<a onClick={::this.handleActionClick}
|
|
||||||
style={{
|
|
||||||
opacity: collapsed ? 0.5 : 1,
|
|
||||||
marginTop: '1em',
|
|
||||||
display: 'block',
|
|
||||||
paddingBottom: '1em',
|
|
||||||
paddingTop: '1em',
|
|
||||||
color: `rgb(${r}, ${g}, ${b})`,
|
|
||||||
cursor: (index > 0) ? 'pointer' : 'default',
|
|
||||||
WebkitUserSelect: 'none'
|
|
||||||
}}>
|
|
||||||
{JSON.stringify(action)}
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{!collapsed &&
|
// Heading
|
||||||
<p style={{
|
const actionComponent = !maximizedAction ? (
|
||||||
textAlign: 'center',
|
<h4 style={{...h4Style, color: `rgb(${r}, ${g}, ${b})`,}}>
|
||||||
transform: 'rotate(180deg)'
|
{"+ " + action.type}
|
||||||
}}>
|
</h4>
|
||||||
⇧
|
) : (
|
||||||
</p>
|
<pre style={preStyle}>
|
||||||
}
|
<a style={colorStyle}>
|
||||||
|
{"- " + JSON.stringify(action, null, 2)}
|
||||||
|
</a>
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
|
||||||
{!collapsed &&
|
// Action
|
||||||
<div style={{
|
const stateComponent = !maximizedState ? (
|
||||||
paddingBottom: '1em',
|
<h4 style={{...h4Style, color: "white"}}>
|
||||||
paddingTop: '1em',
|
{"+ State: object {...}"}
|
||||||
color: 'lightyellow'
|
</h4>
|
||||||
}}>
|
) : (
|
||||||
{this.printState(state, error)}
|
<pre style={preStyle}>
|
||||||
</div>
|
{"- " + this.printState(state, error)}
|
||||||
}
|
</pre>
|
||||||
|
);
|
||||||
|
|
||||||
<hr style={{
|
const collapsedComponent = !collapsed ? <span>✔ Enabled</span> : <span>✘ Disabled</span>;
|
||||||
marginBottom: '2em'
|
|
||||||
}} />
|
return (
|
||||||
</div>
|
<li style={liStyle}>
|
||||||
);
|
<div style={wrap1Style}>
|
||||||
}
|
<div style={wrap2Style}>
|
||||||
|
<div style={maximizedAction || maximizedState ? wrap3StyleMax : wrap3Style}>
|
||||||
|
<a onClick={::this.handleCollapseClick} href="javascript:;">
|
||||||
|
{collapsedComponent}
|
||||||
|
</a>
|
||||||
|
<a onClick={()=>this.setState({maximizedAction: !maximizedAction})} href="javascript:;">
|
||||||
|
{actionComponent}
|
||||||
|
</a>
|
||||||
|
<a onClick={()=>this.setState({maximizedState: !maximizedState})} href="javascript:;">
|
||||||
|
{stateComponent}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getTimestring(d) {
|
||||||
|
var x = document.getElementById("demo");
|
||||||
|
var h = addZero(d.getHours(), 2);
|
||||||
|
var m = addZero(d.getMinutes(), 2);
|
||||||
|
var s = addZero(d.getSeconds(), 2);
|
||||||
|
var ms = addZero(d.getMilliseconds(), 3);
|
||||||
|
return h + ":" + m + ":" + s + ":" + ms;
|
||||||
|
}
|
||||||
|
function addZero(x, n) {
|
||||||
|
if (x.toString().length < n) {
|
||||||
|
x = "0" + x;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user