SideBar.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. import BaseSystem from './System';
  10. let {
  11. CoreSystem,
  12. ViewSystem,
  13. ViewNode,
  14. DataTypes
  15. } = Library;
  16. export default class SideBar extends BaseSystem {
  17. constructor(CoreSystem, ToolBox){
  18. super();
  19. this.CoreSystem = CoreSystem;
  20. this.ToolBox = ToolBox;
  21. }
  22. editNode(text,key){
  23. this.viewNode.props[key] = text;
  24. this.forceUpdate();
  25. }
  26. render(){
  27. let ModuleSystem = this.CoreSystem.ModuleSystem;
  28. let CurrentView = this.CoreSystem.getCurrentView();
  29. let selectedNode = this.ToolBox.selectedNode;
  30. console.log("TOOLBOX" , this.ToolBox);
  31. let Structure = {};
  32. let viewNodeProps = {};
  33. if (selectedNode) {
  34. if (selectedNode.isCol && CurrentView.has(selectedNode)) {
  35. this.ColNode = selectedNode;
  36. this.RowNode = CurrentView.getParent(this.ColNode);
  37. if(selectedNode.content && selectedNode.content.value) {
  38. this.viewNode = selectedNode.content;
  39. let ctor = ModuleSystem.fromViewNode(this.viewNode);
  40. viewNodeProps = ModuleSystem.validateProps(ctor, this.viewNode.props);
  41. Structure = ctor.Inputs;
  42. }
  43. } else if(selectedNode.isRow) {
  44. this.RowNode = selectedNode;
  45. console.log("SELECTTTTT", selectedNode)
  46. }
  47. }
  48. let data = Object.keys(Structure || {}).map((key,index) => {
  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. switch(Structure[key].type){
  58. case DataTypes.Types.Integer:
  59. editorProps.number = viewNodeProps[key];
  60. break;
  61. case DataTypes.Types.Text:
  62. editorProps.text = viewNodeProps[key];
  63. break;
  64. default:
  65. //Must create a generic Vuiew Component
  66. return (<View></View>)
  67. }
  68. return <Editor {...editorProps} key={index + key + this.ColNode.id}/>
  69. })
  70. return (
  71. <View>
  72. <Text style={SideBarStyle.title}>Side Bar</Text>
  73. <View>
  74. {this.RowNode && <View key={this.RowNode.id}>
  75. <Text>Row</Text>
  76. <TextEditor title="Inner Columns"
  77. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  78. onChange={(cols) => {
  79. CurrentView.setColumns(this.RowNode, parseInt(cols))
  80. this.forceUpdate();
  81. }}/>
  82. </View>}
  83. {this.ColNode && <View key={this.ColNode.id}>
  84. <Text>Col</Text>
  85. <Text>Nothing Yet</Text>
  86. </View>}
  87. </View>
  88. <View style={PropertiesContainer.container}>
  89. {data}
  90. </View>
  91. </View>
  92. )
  93. }
  94. }
  95. const SelectedStyle = StyleSheet.create({
  96. container:{
  97. padding:5,
  98. borderWidth:2,
  99. borderColor:'green'
  100. }
  101. })
  102. const PropertiesContainer = StyleSheet.create({
  103. container:{
  104. marginTop:20,
  105. borderTopWidth:0.8,
  106. borderColor:'#D0D0D0'
  107. },
  108. child:{
  109. padding:10
  110. }
  111. })
  112. const SideBarStyle = StyleSheet.create({
  113. container:{
  114. padding:1,
  115. flex:1,
  116. flexDirection:'row'
  117. },
  118. title:{
  119. fontSize:20,
  120. textAlign:'center',
  121. fontFamily:'halvetica',
  122. color:'black',
  123. borderBottomWidth:1,
  124. borderBottomColor:'black'
  125. },
  126. body:{
  127. paddingLeft:5,
  128. paddingRight:5
  129. }
  130. })