SideBar.js 3.4 KB

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