Skip to content
Snippets Groups Projects
Commit 603fade7 authored by Ray Schamp's avatar Ray Schamp
Browse files

Add default toolbox categories

Also make the toolbox actually get used by scratch-blocks, and update the import of scratch-blocks to use the new shimming method.
parent 4a353753
No related branches found
No related tags found
No related merge requests found
const defaultsDeep = require('lodash.defaultsdeep'); const defaultsDeep = require('lodash.defaultsdeep');
const React = require('react'); const React = require('react');
const ScratchBlocks = require('scratch-blocks/blocks_compressed_vertical'); const ScratchBlocks = require('scratch-blocks');
class Blocks extends React.Component { class Blocks extends React.Component {
constructor (props) { componentDidUpdate (prevProps) {
super(props); if (!prevProps.options.toolbox && this.props.options.toolbox) {
this.mountBlocks = this.mountBlocks.bind(this); let workspaceConfig = defaultsDeep({}, Blocks.defaultOptions, this.props.options);
} this.workspace = ScratchBlocks.inject(this.refs.scratchBlocks, workspaceConfig);
mountBlocks (component) { if (this.props.vm) {
this.workspace = ScratchBlocks.inject( this.workspace.addChangeListener(this.props.vm.blockListener);
component, }
defaultsDeep({}, this.props.options, Blocks.defaultOptions)
);
if (this.props.vm) {
this.workspace.addChangeListener(this.props.vm.blockListener);
} }
} }
render () { render () {
return ( return (
<div <div
className="scratch-blocks" className="scratch-blocks"
ref={this.mountBlocks} /> ref="scratchBlocks"
/>
); );
} }
} }
Blocks.propTypes = { Blocks.propTypes = {
options: React.PropTypes.shape({ options: React.PropTypes.shape({
toolbox: React.PropTypes.element, // The toolbox is actually an element, but React doesn't agree :/
toolbox: React.PropTypes.object,
media: React.PropTypes.string, media: React.PropTypes.string,
zoom: React.PropTypes.shape({ zoom: React.PropTypes.shape({
controls: React.PropTypes.boolean, controls: React.PropTypes.boolean,
......
...@@ -4,13 +4,19 @@ const Blocks = require('./blocks'); ...@@ -4,13 +4,19 @@ const Blocks = require('./blocks');
const Toolbox = require('./toolbox'); const Toolbox = require('./toolbox');
class GUI extends React.Component { class GUI extends React.Component {
constructor (props) {
this.state = {};
}
componentDidMount () {
this.setState({toolbox: this._toolbox});
}
render () { render () {
return ( return (
<div className="scratch-gui"> <div className="scratch-gui">
<Toolbox ref={toolbox => this.toolbox = toolbox} /> <Toolbox toolboxRef={(toolbox) => this._toolbox = toolbox} />
<Blocks <Blocks
options={{ options={{
toolbox: this.toolbox toolbox: this.state.toolbox
}} }}
vm={this.props.vm} vm={this.props.vm}
/> />
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment