SideBar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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) => this.editNode(value, key)
  53. };
  54. console.log(DataTypes)
  55. switch(Structure[key].type){
  56. case DataTypes.Types.Integer:
  57. editorProps.number = this.viewNode.props[key];
  58. break;
  59. case DataTypes.Types.Text:
  60. editorProps.text = this.viewNode.props[key];
  61. break;
  62. default:
  63. //Must create a generic Vuiew Component
  64. return (<View></View>)
  65. }
  66. return <Editor {...editorProps}/>
  67. })
  68. return (
  69. <View>
  70. <Text style={SideBarStyle.title}>Side Bar</Text>
  71. <View>
  72. <Text>Container style</Text>
  73. {this.RowNode && <View>
  74. <Text>Row</Text>
  75. <TextEditor title="Inner Columns"
  76. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  77. onChange={(cols) => {
  78. CurrentView.setColumns(this.RowNode, parseInt(cols))
  79. this.forceUpdate();
  80. }}/>
  81. </View>}
  82. <View>
  83. <Text>Col</Text>
  84. </View>
  85. </View>
  86. <View style={PropertiesContainer.container}>
  87. {data}
  88. </View>
  89. </View>
  90. )
  91. }
  92. }
  93. const SelectedStyle = StyleSheet.create({
  94. container:{
  95. padding:5,
  96. borderWidth:2,
  97. borderColor:'green'
  98. }
  99. })
  100. const PropertiesContainer = StyleSheet.create({
  101. container:{
  102. marginTop:20,
  103. borderTopWidth:0.8,
  104. borderColor:'#D0D0D0'
  105. },
  106. child:{
  107. padding:10
  108. }
  109. })
  110. const SideBarStyle = StyleSheet.create({
  111. container:{
  112. padding:1,
  113. flex:1,
  114. flexDirection:'row'
  115. },
  116. title:{
  117. fontSize:20,
  118. textAlign:'center',
  119. fontFamily:'halvetica',
  120. color:'black',
  121. borderBottomWidth:1,
  122. borderBottomColor:'black'
  123. },
  124. body:{
  125. paddingLeft:5,
  126. paddingRight:5
  127. }
  128. })