outsourcing BlocklyComponent to blockly/BlocklyWindow.js
This commit is contained in:
		
							parent
							
								
									a505fa7ad8
								
							
						
					
					
						commit
						cacde16ab2
					
				| @ -3,5 +3,5 @@ | |||||||
|   overflow: hidden; |   overflow: hidden; | ||||||
|   display: block; |   display: block; | ||||||
|   position: relative; |   position: relative; | ||||||
|   padding-bottom: 60px; /* height of your footer + 30px*/y |   padding-bottom: 60px; /* height of your footer + 30px*/ | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,6 +5,8 @@ import { BrowserRouter as Router } from 'react-router-dom'; | |||||||
| import { Provider } from 'react-redux'; | import { Provider } from 'react-redux'; | ||||||
| import store from './store'; | import store from './store'; | ||||||
| 
 | 
 | ||||||
|  | import './App.css'; | ||||||
|  | 
 | ||||||
| import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles'; | import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles'; | ||||||
| 
 | 
 | ||||||
| import Navbar from './components/Navbar'; | import Navbar from './components/Navbar'; | ||||||
| @ -27,9 +29,7 @@ function App() { | |||||||
|         <Router> |         <Router> | ||||||
|           <div className="wrapper"> |           <div className="wrapper"> | ||||||
|             <Navbar /> |             <Navbar /> | ||||||
|             <div style={{ margin: '0 22px' }}> |             <Routes /> | ||||||
|               <Routes /> |  | ||||||
|             </div> |  | ||||||
|             <Footer /> |             <Footer /> | ||||||
|           </div> |           </div> | ||||||
|         </Router> |         </Router> | ||||||
|  | |||||||
| @ -1,4 +1,6 @@ | |||||||
| #blocklyDiv { | #blocklyDiv { | ||||||
|   height: 60vH; |   height: 100%; | ||||||
|   width: 50%; |   min-height: 500px; | ||||||
|  |   width: 100%; | ||||||
|  |   border: 1px solid #4EAF47; | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,31 +1,28 @@ | |||||||
| import React, { Component } from 'react'; | import React, { Component } from 'react'; | ||||||
|  | import PropTypes from 'prop-types'; | ||||||
|  | import { connect } from 'react-redux'; | ||||||
|  | import { onChangeWorkspace } from '../../actions/workspaceActions'; | ||||||
| 
 | 
 | ||||||
| import BlocklyComponent, { Block, Value, Field, Shadow, Category } from './Blockly'; | import BlocklyComponent, { Block, Value, Field, Shadow, Category } from './'; | ||||||
| import * as Blockly from 'blockly/core'; | import * as Blockly from 'blockly/core'; | ||||||
| import * as De from './Blockly/msg/de'; // de locale files
 | import * as De from './msg/de'; // de locale files
 | ||||||
| //import * as En from './Blockly/msg/en'; // de locale files
 | //import * as En from './Blockly/msg/en'; // de locale files
 | ||||||
| import './Blockly/blocks/index'; | import './blocks/index'; | ||||||
| import './Blockly/generator/index'; | import './generator/index'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class BlocklyView extends Component { | class BlocklyWindow extends Component { | ||||||
|  | 
 | ||||||
|   constructor(props) { |   constructor(props) { | ||||||
|     super(props); |     super(props); | ||||||
|     this.simpleWorkspace = React.createRef(); |     this.simpleWorkspace = React.createRef(); | ||||||
|     this.state = { |  | ||||||
|       generatedCode: 'Click text' |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   componentDidMount() { |   componentDidMount() { | ||||||
|     let workspace = Blockly.getMainWorkspace(); |     const workspace = Blockly.getMainWorkspace(); | ||||||
|     workspace.addChangeListener(this.generateCode); |     workspace.addChangeListener((event) => { | ||||||
|   } |       this.props.onChangeWorkspace(event); | ||||||
| 
 |     }); | ||||||
|   generateCode = () => { |  | ||||||
|     var code = Blockly.Arduino.workspaceToCode(this.workspace); |  | ||||||
|     console.log(code); |  | ||||||
|     this.setState({ generatedCode: code }) |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   render() { |   render() { | ||||||
| @ -33,11 +30,25 @@ class BlocklyView extends Component { | |||||||
|       <BlocklyComponent ref={this.simpleWorkspace} |       <BlocklyComponent ref={this.simpleWorkspace} | ||||||
|         readOnly={false} |         readOnly={false} | ||||||
|         trashcan={true} |         trashcan={true} | ||||||
|  |         zoom={{ // https://developers.google.com/blockly/guides/configure/web/zoom
 | ||||||
|  |           controls: true, | ||||||
|  |           wheel: true, | ||||||
|  |           startScale: 1.0, | ||||||
|  |           maxScale: 3, | ||||||
|  |           minScale: 0.3, | ||||||
|  |           scaleSpeed: 1.2 | ||||||
|  |         }} | ||||||
|  |         grid={{ // https://developers.google.com/blockly/guides/configure/web/grid
 | ||||||
|  |           spacing: 20, | ||||||
|  |           length: 1, | ||||||
|  |           colour: '#4EAF47', // senseBox-green
 | ||||||
|  |           snap: false | ||||||
|  |         }} | ||||||
|         media={'media/'} |         media={'media/'} | ||||||
|         move={{ |         move={{ // https://developers.google.com/blockly/guides/configure/web/move
 | ||||||
|           scrollbars: true, |           scrollbars: true, | ||||||
|           drag: true, |           drag: true, | ||||||
|           wheel: true |           wheel: false | ||||||
|         }} |         }} | ||||||
|         initialXml={''} |         initialXml={''} | ||||||
|       > |       > | ||||||
| @ -65,4 +76,9 @@ class BlocklyView extends Component { | |||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default BlocklyView; | BlocklyWindow.propTypes = { | ||||||
|  |   onChangeWorkspace: PropTypes.func.isRequired | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | export default connect(null, { onChangeWorkspace })(BlocklyWindow); | ||||||
| @ -1,92 +1,30 @@ | |||||||
| import React, { Component } from 'react'; | import React, { Component } from 'react'; | ||||||
| import PropTypes from 'prop-types'; |  | ||||||
| import { connect } from 'react-redux'; |  | ||||||
| import { onChangeWorkspace } from '../actions/workspaceActions'; |  | ||||||
| 
 | 
 | ||||||
| import WorkspaceStats from './WorkspaceStats'; | import WorkspaceStats from './WorkspaceStats'; | ||||||
| import WorkspaceFunc from './WorkspaceFunc'; | import WorkspaceFunc from './WorkspaceFunc'; | ||||||
| import CodeViewer from './CodeViewer'; | import BlocklyWindow from './Blockly/BlocklyWindow'; | ||||||
| 
 |  | ||||||
| import BlocklyComponent, { Block, Value, Field, Shadow, Category } from './Blockly'; |  | ||||||
| import * as Blockly from 'blockly/core'; |  | ||||||
| import * as De from './Blockly/msg/de'; // de locale files
 |  | ||||||
| //import * as En from './Blockly/msg/en'; // de locale files
 |  | ||||||
| import './Blockly/blocks/index'; |  | ||||||
| import './Blockly/generator/index'; |  | ||||||
| 
 | 
 | ||||||
|  | import Grid from '@material-ui/core/Grid'; | ||||||
| 
 | 
 | ||||||
| class Home extends Component { | class Home extends Component { | ||||||
|   constructor(props) { |  | ||||||
|     super(props); |  | ||||||
| 
 | 
 | ||||||
|     this.simpleWorkspace = React.createRef(); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   componentDidMount() { |  | ||||||
|     const workspace = Blockly.getMainWorkspace(); |  | ||||||
|     workspace.addChangeListener((event) => { |  | ||||||
|       this.props.onChangeWorkspace(event); |  | ||||||
|     }); |  | ||||||
|   } |  | ||||||
| 
 | 
 | ||||||
|   render() { |   render() { | ||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <WorkspaceStats /> |         <WorkspaceStats /> | ||||||
|         <BlocklyComponent ref={this.simpleWorkspace} |         <Grid container spacing={2}> | ||||||
|           readOnly={false} |           <Grid item xs={12} md={6}> | ||||||
|           trashcan={true} |             <BlocklyWindow /> | ||||||
|           zoom={{ // https://developers.google.com/blockly/guides/configure/web/zoom
 |           </Grid> | ||||||
|             controls: true, |           <Grid item xs={12} md={6}> | ||||||
|             wheel: true, |             <div style={{height: '500px', border: '1px solid black'}}></div> | ||||||
|             startScale: 1.0, |           </Grid> | ||||||
|             maxScale: 3, |         </Grid> | ||||||
|             minScale: 0.3, |  | ||||||
|             scaleSpeed: 1.2 |  | ||||||
|           }} |  | ||||||
|           grid={{ // https://developers.google.com/blockly/guides/configure/web/grid
 |  | ||||||
|             spacing: 20, |  | ||||||
|             length: 1, |  | ||||||
|             colour: '#4EAF47', |  | ||||||
|             snap: false |  | ||||||
|           }} |  | ||||||
|           media={'media/'} |  | ||||||
|           move={{ // https://developers.google.com/blockly/guides/configure/web/move
 |  | ||||||
|             scrollbars: true, |  | ||||||
|             drag: true, |  | ||||||
|             wheel: false |  | ||||||
|           }} |  | ||||||
|           initialXml={''} |  | ||||||
|         > |  | ||||||
|           <Category name="loops" > |  | ||||||
|             <Block type="controls_for" /> |  | ||||||
|             <Block type="controls_repeat_ext" /> |  | ||||||
|             <Block type="controls_whileUntil" /> |  | ||||||
|           </Category> |  | ||||||
|           <Category name="senseBox" colour="120" > |  | ||||||
|             <Category name="Sensoren" colour="120" > |  | ||||||
|               <Block type="sensebox_sensor_temp_hum"></Block> |  | ||||||
|             </Category> |  | ||||||
|             <Block type="sensebox_telegram" /> |  | ||||||
|           </Category> |  | ||||||
|           <Category name="Logic" colour="#b063c5"> |  | ||||||
|             <Block type="control_if"></Block> |  | ||||||
|             <Block type="controls_ifelse"></Block> |  | ||||||
|             <Block type="logic_compare"></Block> |  | ||||||
|             <Block type="logic_operation"></Block> |  | ||||||
|             <Block type="logic_negate"></Block> |  | ||||||
|             <Block type="logic_boolean"></Block> |  | ||||||
|           </Category> |  | ||||||
|         </BlocklyComponent> |  | ||||||
|         <WorkspaceFunc /> |         <WorkspaceFunc /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Home.propTypes = { | export default Home; | ||||||
|   onChangeWorkspace: PropTypes.func.isRequired |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| export default connect(null, { onChangeWorkspace })(Home); |  | ||||||
|  | |||||||
| @ -9,10 +9,12 @@ class Routes extends Component { | |||||||
| 
 | 
 | ||||||
|   render() { |   render() { | ||||||
|     return ( |     return ( | ||||||
|       <Switch> |       <div style={{ margin: '0 22px' }}> | ||||||
|         <Route path="/" exact component={Home} /> |         <Switch> | ||||||
|         <Route component={NotFound} /> |           <Route path="/" exact component={Home} /> | ||||||
|       </Switch> |           <Route component={NotFound} /> | ||||||
|  |         </Switch> | ||||||
|  |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user