import React from 'react'; import {StyleSheet, View, Text} from 'react-native'; import Library from 'trapilib/dist/lib'; import { TextInput, Image } from 'react-native'; import TextEditor from '../Components/TextEditor'; // import Numbers from '../Components/Numbers'; // import ColorEditor from '../Components/ColorEditor'; import TypeHandler from '../Components/TypeHandler.js'; import BaseSystem from './System'; let { CoreSystem, ViewSystem, ViewNode, DataTypes } = Library; export default class SideBar extends BaseSystem { constructor(CoreSystem, ToolBox){ super(); this.CoreSystem = CoreSystem; this.ToolBox = ToolBox; } removeNode(node) { let CurrentView = this.CoreSystem.getCurrentView(); console.log(node) if (CurrentView.has(node)) { CurrentView.remove(node); } this.forceUpdate(); } editNode(node, text,key){ node.props[key] = text; this.forceUpdate(); } createHandler(Structure, viewNodeProps, key, onChange) { let Editor = TypeHandler(Structure); let editorProps = { title: key, onChange: (value) => { console.log(typeof value); onChange && onChange(value, key) } }; switch(Structure.type){ case DataTypes.Types.Integer: editorProps.number = viewNodeProps[key]; break; case DataTypes.Types.Text: editorProps.text = viewNodeProps[key]; break; default: //Must create a generic Vuiew Component return () } return } render(){ let ModuleSystem = this.CoreSystem.ModuleSystem; let CurrentView = this.CoreSystem.getCurrentView(); let selectedNode = this.ToolBox.selectedNode; console.log("TOOLBOX" , this.ToolBox); let Structure = {}, nodeStructure = {}; let viewNodeProps = {}, nodeProps = {}; if (selectedNode && CurrentView.has(selectedNode)) { this.ContainerNode = selectedNode; if(selectedNode.content && selectedNode.content.value) { let ctor = ModuleSystem.fromViewNode(selectedNode.content); viewNodeProps = ModuleSystem.validateProps(ctor, selectedNode.content.props); Structure = ctor.Inputs; } nodeProps = ModuleSystem.validateProps(selectedNode.ctor, selectedNode.props); nodeStructure = selectedNode.ctor.Inputs; } else { this.ContainerNode = null; } let contentData = Object.keys(Structure || {}).map((key,index) => {this.createHandler(Structure[key], viewNodeProps, key, (v, f) => this.editNode(selectedNode.content, v,f))} ) let containerData =Object.keys(nodeStructure || {}).map((key, index) => {this.createHandler(nodeStructure[key], nodeProps, key, (v,f) => this.editNode(selectedNode, v, f))} ); return ( Side Bar {this.ContainerNode && Container { alert("Not working"); }}/> this.removeNode(this.ContainerNode)} /> } {containerData} {contentData} ) } } const SelectedStyle = StyleSheet.create({ container:{ padding:5, borderWidth:2, borderColor:'green' } }) const PropertiesContainer = StyleSheet.create({ container:{ marginTop:20, borderTopWidth:0.8, borderColor:'#D0D0D0' }, child:{ padding:10 } }) const SideBarStyle = StyleSheet.create({ container:{ padding:1, flex:1, flexDirection:'row' }, title:{ fontSize:20, textAlign:'center', fontFamily:'halvetica', color:'black', borderBottomWidth:1, borderBottomColor:'black' }, body:{ paddingLeft:5, paddingRight:5 } })