SideBar.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import React from 'react';
  2. import {StyleSheet, View, Text} from 'react-native';
  3. import Library from 'trapilib/dist/lib';
  4. import { TextInput, Image } 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. removeNode(node) {
  23. let CurrentView = this.CoreSystem.getCurrentView();
  24. console.log(node)
  25. if (CurrentView.has(node)) {
  26. CurrentView.remove(node);
  27. }
  28. this.forceUpdate();
  29. }
  30. editNode(node, text,key){
  31. node.props[key] = text;
  32. this.forceUpdate();
  33. }
  34. createHandler(Structure, viewNodeProps, key, onChange) {
  35. let Editor = TypeHandler(Structure);
  36. let editorProps = {
  37. title: key,
  38. onChange: (value) => {
  39. console.log(typeof value);
  40. onChange && onChange(value, key)
  41. }
  42. };
  43. switch(Structure.type){
  44. case DataTypes.Types.Integer:
  45. editorProps.number = viewNodeProps[key];
  46. break;
  47. case DataTypes.Types.Text:
  48. editorProps.text = viewNodeProps[key];
  49. break;
  50. default:
  51. //Must create a generic Vuiew Component
  52. return (<View></View>)
  53. }
  54. return <Editor {...editorProps} key={key}/>
  55. }
  56. render(){
  57. let ModuleSystem = this.CoreSystem.ModuleSystem;
  58. let CurrentView = this.CoreSystem.getCurrentView();
  59. let selectedNode = this.ToolBox.selectedNode;
  60. console.log("TOOLBOX" , this.ToolBox);
  61. let Structure = {},
  62. nodeStructure = {};
  63. let viewNodeProps = {},
  64. nodeProps = {};
  65. if (selectedNode && CurrentView.has(selectedNode)) {
  66. this.ContainerNode = selectedNode;
  67. if(selectedNode.content && selectedNode.content.value) {
  68. let ctor = ModuleSystem.fromViewNode(selectedNode.content);
  69. viewNodeProps = ModuleSystem.validateProps(ctor, selectedNode.content.props);
  70. Structure = ctor.Inputs;
  71. }
  72. nodeProps = ModuleSystem.validateProps(selectedNode.ctor, selectedNode.props);
  73. nodeStructure = selectedNode.ctor.Inputs;
  74. } else {
  75. this.ContainerNode = null;
  76. }
  77. let contentData = Object.keys(Structure || {}).map((key,index) =>
  78. <View key={selectedNode.id + key}>
  79. {this.createHandler(Structure[key], viewNodeProps, key, (v, f) =>
  80. this.editNode(selectedNode.content, v,f))}
  81. </View>
  82. )
  83. let containerData =Object.keys(nodeStructure || {}).map((key, index) =>
  84. <View key={selectedNode.id + key}>
  85. {this.createHandler(nodeStructure[key], nodeProps, key, (v,f) =>
  86. this.editNode(selectedNode, v, f))}
  87. </View>
  88. );
  89. return (
  90. <View>
  91. <Text style={SideBarStyle.title}>Side Bar</Text>
  92. <View>
  93. {this.ContainerNode && <View key={this.ContainerNode.id}>
  94. <Text>Container</Text>
  95. <TextEditor title="Inner Columns"
  96. text={this.ContainerNode && CurrentView.getChildren(this.ContainerNode).length +''}
  97. onChange={(cols) => {
  98. alert("Not working");
  99. }}/>
  100. <Image name='near me'
  101. style={{width: 20, height: 20 , color:'#606060'}}
  102. source= {require('../assets/icon.png')}
  103. containerStyle={{}}
  104. onClick={() => this.removeNode(this.ContainerNode)}
  105. />
  106. </View>}
  107. {containerData}
  108. </View>
  109. <View style={PropertiesContainer.container}>
  110. {contentData}
  111. </View>
  112. </View>
  113. )
  114. }
  115. }
  116. const SelectedStyle = StyleSheet.create({
  117. container:{
  118. padding:5,
  119. borderWidth:2,
  120. borderColor:'green'
  121. }
  122. })
  123. const PropertiesContainer = StyleSheet.create({
  124. container:{
  125. marginTop:20,
  126. borderTopWidth:0.8,
  127. borderColor:'#D0D0D0'
  128. },
  129. child:{
  130. padding:10
  131. }
  132. })
  133. const SideBarStyle = StyleSheet.create({
  134. container:{
  135. padding:1,
  136. flex:1,
  137. flexDirection:'row'
  138. },
  139. title:{
  140. fontSize:20,
  141. textAlign:'center',
  142. fontFamily:'halvetica',
  143. color:'black',
  144. borderBottomWidth:1,
  145. borderBottomColor:'black'
  146. },
  147. body:{
  148. paddingLeft:5,
  149. paddingRight:5
  150. }
  151. })