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
Branches
Tags
No related merge requests found
const defaultsDeep = require('lodash.defaultsdeep');
const React = require('react');
const ScratchBlocks = require('scratch-blocks/blocks_compressed_vertical');
const ScratchBlocks = require('scratch-blocks');
class Blocks extends React.Component {
constructor (props) {
super(props);
this.mountBlocks = this.mountBlocks.bind(this);
}
mountBlocks (component) {
this.workspace = ScratchBlocks.inject(
component,
defaultsDeep({}, this.props.options, Blocks.defaultOptions)
);
if (this.props.vm) {
this.workspace.addChangeListener(this.props.vm.blockListener);
componentDidUpdate (prevProps) {
if (!prevProps.options.toolbox && this.props.options.toolbox) {
let workspaceConfig = defaultsDeep({}, Blocks.defaultOptions, this.props.options);
this.workspace = ScratchBlocks.inject(this.refs.scratchBlocks, workspaceConfig);
if (this.props.vm) {
this.workspace.addChangeListener(this.props.vm.blockListener);
}
}
}
render () {
return (
<div
className="scratch-blocks"
ref={this.mountBlocks} />
ref="scratchBlocks"
/>
);
}
}
Blocks.propTypes = {
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,
zoom: React.PropTypes.shape({
controls: React.PropTypes.boolean,
......
......@@ -4,13 +4,19 @@ const Blocks = require('./blocks');
const Toolbox = require('./toolbox');
class GUI extends React.Component {
constructor (props) {
this.state = {};
}
componentDidMount () {
this.setState({toolbox: this._toolbox});
}
render () {
return (
<div className="scratch-gui">
<Toolbox ref={toolbox => this.toolbox = toolbox} />
<Toolbox toolboxRef={(toolbox) => this._toolbox = toolbox} />
<Blocks
options={{
toolbox: this.toolbox
toolbox: this.state.toolbox
}}
vm={this.props.vm}
/>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment