Skip to content

Commit 5176afd

Browse files
committed
use redux diff-logger
1 parent 50656aa commit 5176afd

File tree

14 files changed

+340
-17
lines changed

14 files changed

+340
-17
lines changed

lib/options/configureStore.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/options/configureStore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
"atom-plugin-command-line": "1.0.2",
3333
"coderoad-cli": "0.10.0",
3434
"marked": "0.3.6",
35-
"material-ui": "0.15.4",
35+
"material-ui": "0.16.0",
3636
"node-file-exists": "1.1.0",
3737
"react": "15.3.2",
3838
"react-dom": "15.3.2",
3939
"react-redux": "4.4.5",
4040
"react-router-sans-urls": "0.1.2",
4141
"react-tap-event-plugin": "1.0.0",
4242
"redux": "3.6.0",
43-
"redux-logger": "2.6.1",
43+
"redux-logger": "2.7.0",
4444
"redux-thunk": "2.1.0",
4545
"reselect": "2.5.4"
4646
},
@@ -49,8 +49,8 @@
4949
"electron-chromedriver": "^1.4.0",
5050
"eslint": "^3.6.1",
5151
"eslint-plugin-react": "^6.3.0",
52-
"jest": "^15.1.1",
53-
"jest-cli": "^15.1.1",
52+
"jest": "^16.0.1",
53+
"jest-cli": "^16.0.1",
5454
"react-addons-test-utils": "15.3.2",
5555
"react-test-renderer": "15.3.2",
5656
"redux-mock-store": "^1.2.1",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Radium from 'radium';
2+
import * as React from 'react';
3+
4+
import {Markdown} from '../index';
5+
import {Card, CardHeader, CardText} from 'material-ui/Card';
6+
7+
const styles = {
8+
card: {
9+
margin: '5px',
10+
},
11+
};
12+
13+
@Radium()
14+
const ContentCard: React.StatelessComponent<{
15+
title: string, content?: string
16+
}> = ({title, content}) => (
17+
<Card style={styles.card}>
18+
{title ? <CardHeader title={title} /> : null}
19+
<CardText>
20+
<Markdown children={content || ''} />
21+
</CardText>
22+
</Card>
23+
);
24+
export default ContentCard;
25+
26+
// ContentCard.propTypes = {
27+
// title: React.PropTypes.string,
28+
// content: React.PropTypes.string.optional,
29+
// };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react';
2+
3+
import highlight from './syntax-highlighter';
4+
5+
const CodeBlock: React.StatelessComponent<{
6+
children: string, style?: React.CSSProperties, lang: string
7+
}> = ({style, children, lang}) => (
8+
<pre>
9+
<code
10+
style={style ? style : {}}
11+
dangerouslySetInnerHTML={{__html: highlight(children, lang)}}
12+
/>
13+
</pre>
14+
);
15+
export default CodeBlock;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as marked from 'marked';
2+
3+
import highlight from './syntax-highlighter';
4+
5+
const options = {
6+
breaks: true,
7+
gfm: true,
8+
highlight,
9+
tables: true,
10+
sanitize: true,
11+
smartLists: true,
12+
};
13+
14+
export default function (text: string): string {
15+
return typeof text !== 'string' ? '' : marked(text.toString(), options);
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
3+
import formatText from './formatText';
4+
5+
const Markdown: React.StatelessComponent<{
6+
children: string, style?: React.CSSProperties
7+
}> = ({style, children}) => (
8+
<span
9+
className='cr-markdown'
10+
style={style ? style : {}}
11+
dangerouslySetInnerHTML={{__html: formatText(children)}}
12+
/>
13+
);
14+
export default Markdown;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {editor} from '../../../index';
2+
3+
export default function highlight(text: string, lang: string): string {
4+
const scopeName = `source.${lang}`;
5+
// get grammar
6+
const grammar = editor.grammar.getFromScope(scopeName);
7+
// no grammar, return text
8+
if (!grammar) {
9+
return text;
10+
}
11+
// get tokens
12+
const lineTokens = editor.grammar.tokenizeLines(grammar, text);
13+
if (lineTokens.length > 0) {
14+
const lastLineTokens = lineTokens[lineTokens.length - 1];
15+
if (lastLineTokens.length === 1 && lastLineTokens[0].value === '') {
16+
lineTokens.pop();
17+
}
18+
}
19+
let html = '<pre class="editor editor-colors">';
20+
21+
lineTokens.forEach(line => {
22+
html += '<div class="line">';
23+
line.forEach(({value, scopes}) => {
24+
// account for spaces
25+
if (!value) {
26+
value = ' ';
27+
}
28+
// wrap text with class spans
29+
scopes.forEach(scope => {
30+
html += `<span class="${scope.replace(/\./g, ' ')}">`;
31+
});
32+
// text
33+
html += `${value}`;
34+
// closing tags
35+
scopes.forEach(scope => {
36+
html += '</span>';
37+
});
38+
});
39+
});
40+
html += '</div></pre>';
41+
return html;
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react';
2+
import {connect} from 'react-redux';
3+
4+
import {routeSet} from '../../actions';
5+
import RaisedButton from 'material-ui/RaisedButton';
6+
7+
class RouteButton extends React.Component<{
8+
label: string, route: string, routeSet: any, style: React.CSSProperties
9+
}, {}> {
10+
public render() {
11+
const {label, route, style, routeSet} = this.props;
12+
return (
13+
<RaisedButton
14+
label={label}
15+
style={style || {}}
16+
onTouchTap={routeSet.bind(this, route)}
17+
secondary={true}
18+
/>
19+
);
20+
}
21+
}
22+
23+
// RouteButton.propTypes = {
24+
// label: React.PropTypes.string,
25+
// route: React.PropTypes.string,
26+
// routeSet: React.PropTypes.func.optional,
27+
// style: React.PropTypes.object.optional,
28+
// };
29+
30+
const mapStateToProps = (state, props) => ({
31+
label: props.label,
32+
route: props.route,
33+
style: props.style || {}
34+
});
35+
const mapDispatchToProps = {routeSet};
36+
37+
export default connect(mapStateToProps, mapDispatchToProps)(RouteButton);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react';
2+
3+
interface IStyles {
4+
editor: React.CSSProperties;
5+
};
6+
7+
const styles: IStyles = {
8+
editor: {
9+
textAlign: 'left',
10+
},
11+
};
12+
13+
export default class TextEditor extends React.Component<{
14+
name: string, text?: string, lang: string, onSave?: () => any,
15+
placeholder?: string,
16+
}, {}> {
17+
18+
// create a new TextEditor
19+
public ed = atom.workspace.buildTextEditor();
20+
public get(): string {
21+
return this.ed.getText();
22+
}
23+
public render() {
24+
return <div id={this.props.name} style={styles.editor} />;
25+
}
26+
private componentDidMount() {
27+
const {name, text, lang, placeholder} = this.props;
28+
// specify language
29+
this.ed.setGrammar(
30+
atom.grammars.grammarForScopeName(`source.${lang}`)
31+
);
32+
if (text) {
33+
this.ed.setText(text || '');
34+
}
35+
if (placeholder) {
36+
this.ed.setPlaceholderText(placeholder);
37+
}
38+
// append editor to rendered div
39+
document.querySelector(`#${name}`).appendChild(this.ed.getElement());
40+
}
41+
}

src/options/configureStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const configureStore = ({reducer, devMode}) => {
88

99
// use logger if devMode
1010
if (devMode) {
11-
const logger = (createLogger as any)();
11+
const logger = (createLogger as any)({diff: true});
1212
middlewares.push(logger);
1313
} else {
1414
process.env.NODE_ENV = 'production';

src/typings/globals/radium/index.d.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Generated by typings
2+
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/092e7f33ba65b4162419b7c5d56e8f1a55ffdbf9/radium/radium.d.ts
3+
declare module 'radium' {
4+
import * as React from 'react';
5+
6+
7+
namespace Radium {
8+
interface StyleRules {
9+
[index: string]: React.CSSProperties;
10+
}
11+
12+
/**
13+
* Style component properties
14+
*/
15+
export interface StyleProps {
16+
/**
17+
* An object of styles, or an object of CSS rules to render. Each key of the rules object is a CSS
18+
* selector and the value is an object of styles. If rules is empty, the component will render nothing.
19+
*/
20+
rules: React.CSSProperties | StyleRules;
21+
/**
22+
* A string that any included selectors in rules will be appended to.
23+
* Use to scope styles in the component to a particular element. A good use case might be to generate a unique
24+
* ID for a component to scope any styles to the particular component that owns the <Style> component instance.
25+
*/
26+
scopeSelector?: string;
27+
}
28+
29+
/**
30+
* <Style />
31+
*/
32+
export class Style extends React.Component<StyleProps, any> {
33+
}
34+
35+
/**
36+
* StyleRoot component properties
37+
*/
38+
export interface StyleRootProps extends React.HTMLProps<StyleRoot> {
39+
}
40+
/**
41+
* <StyleRoot />
42+
*/
43+
export class StyleRoot extends React.Component<StyleRootProps, any> {
44+
}
45+
46+
/**
47+
* Radium configuration
48+
*/
49+
export interface RadiumConfig {
50+
/**
51+
* Allow to replace matchMedia function that Radium uses. The default one is window.matchMedia
52+
* @param mediaQuery
53+
*/
54+
matchMedia?: (mediaQuery: string) => MediaQueryList;
55+
/**
56+
* Set the user agent passed to inline-style-prefixer to perform prefixing on style objects.
57+
* Mainly used during server rendering
58+
*/
59+
userAgent?: string;
60+
/**
61+
* List of plugins
62+
*/
63+
plugins?: Array<any>;
64+
}
65+
66+
/**
67+
* Query Radium's knowledge of the browser state for a given element key.
68+
* This is particularly useful if you would like to set styles for one element when another element is in a particular state,
69+
* e.g. show a message when a button is hovered.
70+
*
71+
* Note that the target element specified by elementKey must have the state you'd like to check defined in
72+
* its style object so that Radium knows to add the handlers. It can be empty, e.g. ':hover': {}.
73+
* @param state you'll usually pass this.state, but sometimes you may want to pass a previous state, like in shouldComponentUpdate, componentWillUpdate, and componentDidUpdate
74+
* @param elementKey if you used multiple elements, pass the same key="" or ref="". If you only have one element, you can leave it blank ('main' will be inferred)
75+
* @param value one of the following: :active, :focus, and :hover
76+
*/
77+
export function getState(state: any, elementKey: string | void, value: ":active" | ":focus" | ":hover"): boolean;
78+
79+
/**
80+
* Create a keyframes animation for use in an inline style.
81+
* @param keyframes
82+
* @param name
83+
*/
84+
export function keyframes(keyframes: StyleRules, name?: string): Object;
85+
86+
// Radium 0.17 Test mode
87+
/**
88+
* Used to control internal Radium state and behavior during tests. It is only available in non-production builds.
89+
*/
90+
interface RadiumTestMode {
91+
/**
92+
* Clears the global Radium state, currently only the cache of media query listeners.
93+
*/
94+
clearState(): void;
95+
/**
96+
* Enables "test mode", which doesn’t throw or warn as much. Currently it just doesn’t throw when using addCSS without StyleRoot.
97+
*/
98+
enable(): void;
99+
/**
100+
* Disables "test mode"
101+
*/
102+
disable(): void;
103+
}
104+
105+
var TestMode: RadiumTestMode;
106+
107+
}
108+
// @Radium decorator
109+
function Radium<TElement extends Function>(component: TElement): TElement;
110+
function Radium(config: Radium.RadiumConfig): (component?: any) => any;
111+
112+
export = Radium;
113+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"resolution": "main",
3+
"tree": {
4+
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/092e7f33ba65b4162419b7c5d56e8f1a55ffdbf9/radium/radium.d.ts",
5+
"raw": "registry:dt/radium#0.18.1+20160907102602",
6+
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/092e7f33ba65b4162419b7c5d56e8f1a55ffdbf9/radium/radium.d.ts"
7+
}
8+
}

0 commit comments

Comments
 (0)