SideBar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React from 'react';
  2. import {StyleSheet, View, Text} from 'react-native';
  3. import Library from 'trapilib/dist/lib';
  4. import { TextInput } from 'react-native';
  5. import TextEditor from '../Components/TextEditor';
  6. // import Numbers from '../Components/Numbers';
  7. // import ColorEditor from '../Components/ColorEditor';
  8. import TypeHandler from '../Components/TypeHandler.js';
  9. let {
  10. CoreSystem,
  11. ViewSystem,
  12. ViewNode,
  13. DataTypes
  14. } = Library;
  15. export default class SideBar{
  16. constructor(CoreSystem){
  17. this.CoreSystem = CoreSystem;
  18. }
  19. onUpdate(fn){
  20. this.__onUpdate = fn
  21. }
  22. forceUpdate(props){
  23. this.__onUpdate && this.__onUpdate(props);
  24. }
  25. editNode(text,key){
  26. this.viewNode.props[key] = text;
  27. this.forceUpdate();
  28. }
  29. render(){
  30. console.log("DO I EVER COME HEREEEEEEE")
  31. let tool = this.tool;
  32. let ModuleSystem = this.CoreSystem.ModuleSystem;
  33. let CurrentView = this.CoreSystem.getCurrentView();
  34. let Routing = this.CoreSystem.Routing;
  35. let Structure = {};
  36. if (tool) {
  37. console.log(tool)
  38. if (tool.selectedNode && tool.selectedNode.isCol && CurrentView.has(tool.selectedNode)) {
  39. this.ColNode = tool.selectedNode;
  40. this.RowNode = CurrentView.getParent(this.ColNode);
  41. if(tool.selectedNode.content && tool.selectedNode.content.value) {
  42. this.viewNode = tool.selectedNode.content;
  43. console.log("NEVERRRRRRRRRRRRRRRR")
  44. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  45. }
  46. }
  47. }
  48. let data = Object.keys(Structure || {}).map((key) => {
  49. let Editor = TypeHandler(Structure[key]);
  50. let editorProps = {
  51. title: key,
  52. onChange: (value) => {
  53. console.log(typeof value);
  54. this.editNode(value, key);
  55. }
  56. };
  57. console.log(DataTypes)
  58. switch(Structure[key].type){
  59. case DataTypes.Types.Integer:
  60. editorProps.number = this.viewNode.props[key];
  61. break;
  62. case DataTypes.Types.Text:
  63. editorProps.text = this.viewNode.props[key];
  64. break;
  65. default:
  66. //Must create a generic Vuiew Component
  67. return (<View></View>)
  68. }
  69. return <Editor {...editorProps}/>
  70. })
  71. return (
  72. <View>
  73. <Text style={SideBarStyle.title}>Side Bar</Text>
  74. <View>
  75. <Text>Container style</Text>
  76. {this.RowNode && <View>
  77. <Text>Row</Text>
  78. <TextEditor title="Inner Columns"
  79. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  80. onChange={(cols) => {
  81. CurrentView.setColumns(this.RowNode, parseInt(cols))
  82. this.forceUpdate();
  83. }}/>
  84. </View>}
  85. <View>
  86. <Text>Col</Text>
  87. </View>
  88. </View>
  89. <View style={PropertiesContainer.container}>
  90. {data}
  91. </View>
  92. </View>
  93. )
  94. }
  95. }
  96. const SelectedStyle = StyleSheet.create({
  97. container:{
  98. padding:5,
  99. borderWidth:2,
  100. borderColor:'green'
  101. }
  102. })
  103. const PropertiesContainer = StyleSheet.create({
  104. container:{
  105. marginTop:20,
  106. borderTopWidth:0.8,
  107. borderColor:'#D0D0D0'
  108. },
  109. child:{
  110. padding:10
  111. }
  112. })
  113. const SideBarStyle = StyleSheet.create({
  114. container:{
  115. padding:1,
  116. flex:1,
  117. flexDirection:'row'
  118. },
  119. title:{
  120. fontSize:20,
  121. textAlign:'center',
  122. fontFamily:'halvetica',
  123. color:'black',
  124. borderBottomWidth:1,
  125. borderBottomColor:'black'
  126. },
  127. body:{
  128. paddingLeft:5,
  129. paddingRight:5
  130. }
  131. })