Skip to content

Commit 004ad86

Browse files
committed
Add options and settings to playground
1 parent 754a92c commit 004ad86

22 files changed

+12512
-562
lines changed

playground/build.js

Lines changed: 10768 additions & 329 deletions
Large diffs are not rendered by default.

playground/build.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.

playground/build/css/playground.css

Lines changed: 334 additions & 35 deletions
Large diffs are not rendered by default.

playground/build/js/actions/PlaygroundActions.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,50 @@ import AppDispatcher from '../dispatcher/AppDispatcher';
22
import PlaygroundConstants from '../constants/PlaygroundConstants';
33

44
var TodoActions = {
5-
updateInput: function(input) {
5+
init: function() {
6+
AppDispatcher.dispatch({
7+
actionType: PlaygroundConstants.PLAYGROUND_INIT,
8+
});
9+
},
10+
11+
12+
keyboardActionFired: function() {
13+
AppDispatcher.dispatch({
14+
actionType: PlaygroundConstants.PLAYGROUND_KEYBOARD_ACTION
15+
});
16+
},
17+
18+
updateInput: function(value) {
619
AppDispatcher.dispatch({
720
actionType: PlaygroundConstants.PLAYGROUND_INPUT_UPDATED,
8-
input: input
21+
value: value
22+
});
23+
},
24+
25+
processInput: function() {
26+
AppDispatcher.dispatch({
27+
actionType: PlaygroundConstants.PLAYGROUND_START_PROCESS_INPUT
28+
});
29+
},
30+
31+
setPostcssCssVariablesPreserveOption: function(value) {
32+
AppDispatcher.dispatch({
33+
actionType: PlaygroundConstants.PLAYGROUND_SET_POSTCSS_CSS_VARIABLES_PRESERVE,
34+
value: value
35+
});
36+
},
37+
38+
setShouldLiveReloadOption: function(value) {
39+
AppDispatcher.dispatch({
40+
actionType: PlaygroundConstants.PLAYGROUND_SET_SHOULD_LIVE_RELOAD,
41+
value: value
42+
});
43+
},
44+
45+
setTabWidthOption: function(value) {
46+
AppDispatcher.dispatch({
47+
actionType: PlaygroundConstants.PLAYGROUND_SET_TAB_WIDTH,
48+
value: value
949
});
1050
}
1151
};

playground/build/js/components/EditorTextarea.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default class EditorTextarea extends React.Component {
1818
React.createElement("textarea", {
1919
className: this.props.className || '',
2020
onChange: this._onChange.bind(this),
21-
value: this.props.value
21+
value: this.props.value,
22+
style: this.props.style
2223
})
2324
);
2425
}
@@ -35,5 +36,6 @@ export default class EditorTextarea extends React.Component {
3536
EditorTextarea.propTypes = {
3637
onChange: React.PropTypes.func,
3738
className: React.PropTypes.string,
38-
value: React.PropTypes.string
39+
value: React.PropTypes.string,
40+
style: React.PropTypes.object
3941
};

playground/build/js/components/PlaygroundApp.js

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,68 @@ import classnames from 'classnames';
44

55
import '../../css/playground.css!';
66
import PlaygroundStore from '../stores/PlaygroundStore';
7+
import PlaygroundSettingsStore from '../stores/PlaygroundSettingsStore';
78
import PlaygroundActions from '../actions/PlaygroundActions';
89

910

11+
import PlaygroundHeader from './PlaygroundHeader';
1012
import EditorTextarea from './EditorTextarea';
1113

1214

13-
function getPlaygroundState(props, state) {
15+
16+
function gatherPlaygroundStoreState(props, state) {
1417
var newOutputResult = PlaygroundStore.getOutputResult();
1518

1619
return {
20+
postcssInputText: PlaygroundStore.getInputText(),
1721
postcssOutputResult: newOutputResult,
1822
// If there was an error in parsing, then use the last known good one
19-
prevSuccessfulPostcssOutputResult: newOutputResult.error ? state.postcssOutputResult : newOutputResult
23+
prevSuccessfulPostcssOutputResult: newOutputResult.get('error') ? state.postcssOutputResult : newOutputResult
24+
};
25+
}
26+
27+
function gatherPlaygroundSettingsStoreState(props, state) {
28+
return {
29+
postcssCssVariablesPreserve: PlaygroundSettingsStore.getPluginSettings().getIn(['postcss-css-variables', 'preserve']),
30+
shouldLiveReload: PlaygroundSettingsStore.getShouldLiveReload(),
31+
tabWidth: PlaygroundSettingsStore.getTabWidth()
2032
};
2133
}
2234

2335
export default class PlaygroundApp extends React.Component {
2436
constructor(props) {
2537
super(props);
26-
this.state = assign(getPlaygroundState(props, (this.state || {})), {
27-
shouldLiveReload: props.initialShouldLiveReload || true,
28-
postcssInputText: props.initialPostcssInputText || '',
29-
});
38+
this.state = assign(
39+
gatherPlaygroundStoreState(props, (this.state || {})),
40+
gatherPlaygroundSettingsStoreState(props, (this.state || {}))
41+
);
3042
}
3143

3244
componentDidMount() {
33-
PlaygroundStore.addChangeListener(this._onStoreChange.bind(this));
45+
PlaygroundStore.addChangeListener(this._onPlaygroundStoreChange.bind(this));
46+
PlaygroundSettingsStore.addChangeListener(this._onPlaygroundSettingsStoreChange.bind(this));
3447

3548
document.addEventListener('keyup', this._handleKeyUp.bind(this));
49+
50+
// Initialize the application
51+
PlaygroundActions.init();
3652
}
3753

3854
componentWillUnmount() {
39-
PlaygroundStore.removeChangeListener(this._onStoreChange);
55+
PlaygroundStore.removeChangeListener(this._onPlaygroundStoreChange.bind(this));
56+
PlaygroundSettingsStore.removeChangeListener(this._onPlaygroundSettingsStoreChange.bind(this));
4057

4158
document.removeEventListener('keyup', this._handleKeyUp.bind(this));
4259
}
4360

4461
render() {
4562
//console.log('render', this.state);
4663

47-
var doesInputHaveError = !!this.state.postcssOutputResult.error;
48-
var output = doesInputHaveError ? this.state.prevSuccessfulPostcssOutputResult.result : this.state.postcssOutputResult.result;
49-
64+
var doesInputHaveError = !!this.state.postcssOutputResult.get('error');
65+
var output = doesInputHaveError ? this.state.prevSuccessfulPostcssOutputResult.get('output') : this.state.postcssOutputResult.get('output');
5066

5167
var parsingErrorMarkup;
52-
if(this.state.postcssOutputResult.error) {
68+
if(this.state.postcssOutputResult.get('error')) {
5369
parsingErrorMarkup = (
5470
React.createElement("div", {
5571
className: "postcss-editor-pane-error",
@@ -60,40 +76,23 @@ export default class PlaygroundApp extends React.Component {
6076
React.createElement("div", {
6177
className: "postcss-editor-pane-error-message"
6278
},
63-
this.state.postcssOutputResult.error.toString()
79+
this.state.postcssOutputResult.get('error').toString()
6480
)
6581
)
6682
);
6783
}
6884

85+
86+
var tabWidthStyleValue = this.state.tabWidth === 'inherit' ? this.state.tabWidth : this.state.tabWidth + 'ch';
87+
6988
return (
7089
React.createElement("div", {className: "playground-app-wrapper"},
71-
React.createElement("header", {
72-
className: "playground-header"
73-
},
74-
React.createElement("h1", {
75-
className: "playground-header-heading"
76-
},
77-
React.createElement("a", {className: "playground-header-heading-primary-title", href: "https://github.com/MadLittleMods/postcss-css-variables"}, "postcss-css-variables"), " Playground - ", React.createElement("a", {href: "https://github.com/postcss/postcss"}, "PostCSS")
78-
),
79-
React.createElement("label", {
80-
className: "live-reload-toggle-checkbox",
81-
htmlFor: "id-live-reload-checkbox",
82-
onChange: this._onLiveReloadCheckboxChanged.bind(this)
83-
},
84-
React.createElement("input", {
85-
type: "checkbox",
86-
id: "id-live-reload-checkbox",
87-
checked: this.state.shouldLiveReload,
88-
onChange: this._onLiveReloadCheckboxChanged.bind(this)}
89-
)
90-
),
91-
React.createElement("button", {
92-
className: "playground-header-save-button",
93-
onClick: this._onSave.bind(this)
94-
},
95-
"Save"
96-
)
90+
91+
React.createElement(PlaygroundHeader, {
92+
tabWidth: this.state.tabWidth,
93+
shouldLiveReload: this.state.shouldLiveReload,
94+
95+
postcssCssVariablesPreserve: this.state.postcssCssVariablesPreserve}
9796
),
9897

9998
React.createElement("div", {className: "postcss-editor-area"},
@@ -107,7 +106,11 @@ export default class PlaygroundApp extends React.Component {
107106
ref: "postcssInputTextarea",
108107
className: "postcss-textarea",
109108
onChange: this._onInputChanged.bind(this),
110-
value: this.state.postcssInputText}
109+
value: this.state.postcssInputText,
110+
111+
style: {
112+
tabSize: tabWidthStyleValue
113+
}}
111114
)
112115
),
113116
React.createElement("div", {className: "postcss-editor-pane"},
@@ -119,7 +122,11 @@ export default class PlaygroundApp extends React.Component {
119122
React.createElement(EditorTextarea, {
120123
ref: "postcssOutputTextarea",
121124
className: classnames('postcss-textarea', {'is-not-current': doesInputHaveError}),
122-
value: output}
125+
value: output,
126+
127+
style: {
128+
tabSize: tabWidthStyleValue
129+
}}
123130
),
124131
parsingErrorMarkup
125132
)
@@ -128,36 +135,25 @@ export default class PlaygroundApp extends React.Component {
128135
);
129136
}
130137

131-
_onSave() {
132-
//console.log('saving');
133-
PlaygroundActions.updateInput(this.state.postcssInputText);
134-
}
135-
136138
_onInputChanged(text) {
137139
//console.log('input changed');
138-
this.setState({
139-
postcssInputText: text
140-
});
140+
PlaygroundActions.updateInput(text);
141141

142142
// Defaults to true if undefined
143143
if(this.state.shouldLiveReload) {
144-
PlaygroundActions.updateInput(text);
144+
PlaygroundActions.processInput();
145145
}
146146
}
147147

148-
_onLiveReloadCheckboxChanged() {
149-
this.setState({
150-
shouldLiveReload: event.target.checked
151-
});
152-
}
153-
154148
_handleKeyUp(e) {
155149
//console.log(e);
156150

157151
// escape
158152
if(e.keyCode === 27) {
159153
// Unfocus/blur the currently focused elemnt
160154
document.activeElement.blur();
155+
156+
PlaygroundActions.keyboardActionFired();
161157
}
162158

163159
// If nothing is focused currently
@@ -166,23 +162,31 @@ export default class PlaygroundApp extends React.Component {
166162
if(e.keyCode === 73) {
167163
//console.log('focus input');
168164
React.findDOMNode(this.refs.postcssInputTextarea).focus();
165+
166+
PlaygroundActions.keyboardActionFired();
169167
}
170168
// o
171169
else if(e.keyCode === 79) {
172170
//console.log('focus output');
173171
React.findDOMNode(this.refs.postcssOutputTextarea).focus();
172+
173+
PlaygroundActions.keyboardActionFired();
174174
}
175175
}
176176
}
177177

178-
_onStoreChange() {
178+
179+
_onPlaygroundStoreChange() {
179180
//console.log('change in PlaygroundStore');
180-
this.setState(getPlaygroundState(this.props, this.state));
181+
this.setState(gatherPlaygroundStoreState(this.props, this.state));
182+
}
183+
184+
_onPlaygroundSettingsStoreChange() {
185+
//console.log('change in PlaygroundSettingsStore');
186+
this.setState(gatherPlaygroundSettingsStoreState(this.props, this.state));
181187
}
182188
}
183189

184190
PlaygroundApp.propTypes = {
185-
// Defaults to true
186-
initialShouldLiveReload: React.PropTypes.bool,
187-
initialPostcssInputText: React.PropTypes.string
191+
// ...
188192
};

0 commit comments

Comments
 (0)