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. // 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. let viewNodeProps = {};
  37. if (tool) {
  38. console.log(tool)
  39. if (tool.selectedNode && tool.selectedNode.isCol && CurrentView.has(tool.selectedNode)) {
  40. this.ColNode = tool.selectedNode;
  41. this.RowNode = CurrentView.getParent(this.ColNode);
  42. if(tool.selectedNode.content && tool.selectedNode.content.value) {
  43. this.viewNode = tool.selectedNode.content;
  44. console.log("NEVERRRRRRRRRRRRRRRR")
  45. let ctor = ModuleSystem.get(this.viewNode.value, this.viewNode.namespace);
  46. viewNodeProps = ModuleSystem.validateProps(ctor, this.viewNode.props);
  47. console.log(viewNodeProps)
  48. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  49. }
  50. }
  51. }
  52. let data = Object.keys(Structure || {}).map((key,index) => {
  53. let Editor = TypeHandler(Structure[key]);
  54. let editorProps = {
  55. title: key,
  56. onChange: (value) => {
  57. console.log(typeof value);
  58. this.editNode(value, key);
  59. }
  60. };
  61. switch(Structure[key].type){
  62. case DataTypes.Types.Integer:
  63. editorProps.number = viewNodeProps[key];
  64. break;
  65. case DataTypes.Types.Text:
  66. editorProps.text = viewNodeProps[key];
  67. break;
  68. default:
  69. //Must create a generic Vuiew Component
  70. return (<View></View>)
  71. }
  72. return <Editor {...editorProps} key={index + key + this.ColNode.id}/>
  73. })
  74. return (
  75. <View>
  76. <Text style={SideBarStyle.title}>Side Bar</Text>
  77. <View>
  78. <Text>Container style</Text>
  79. {this.RowNode && <View>
  80. <Text>Row</Text>
  81. <TextEditor title="Inner Columns"
  82. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  83. onChange={(cols) => {
  84. CurrentView.setColumns(this.RowNode, parseInt(cols))
  85. this.forceUpdate();
  86. }}/>
  87. </View>}
  88. <View>
  89. <Text>Col</Text>
  90. </View>
  91. </View>
  92. <View style={PropertiesContainer.container}>
  93. {data}
  94. </View>
  95. </View>
  96. )
  97. }
  98. }
  99. const SelectedStyle = StyleSheet.create({
  100. container:{
  101. padding:5,
  102. borderWidth:2,
  103. borderColor:'green'
  104. }
  105. })
  106. const PropertiesContainer = StyleSheet.create({
  107. container:{
  108. marginTop:20,
  109. borderTopWidth:0.8,
  110. borderColor:'#D0D0D0'
  111. },
  112. child:{
  113. padding:10
  114. }
  115. })
  116. const SideBarStyle = StyleSheet.create({
  117. container:{
  118. padding:1,
  119. flex:1,
  120. flexDirection:'row'
  121. },
  122. title:{
  123. fontSize:20,
  124. textAlign:'center',
  125. fontFamily:'halvetica',
  126. color:'black',
  127. borderBottomWidth:1,
  128. borderBottomColor:'black'
  129. },
  130. body:{
  131. paddingLeft:5,
  132. paddingRight:5
  133. }
  134. })