import React from 'react';
import {StyleSheet, View, Text} from 'react-native';
import Library from 'trapilib/dist/lib';
import { TextInput, Image, Button } 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;
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
export default class SideBar extends BaseSystem {
constructor(CoreSystem, ToolBox){
super();
this.CoreSystem = CoreSystem;
this.ToolBox = ToolBox;
}
import() {
let CurrentView = this.CoreSystem.getCurrentView();
let text = window.prompt("Feed me plz");
if(text) {
CurrentView.import(JSON.parse(text), this.ContainerNode.id);
}
}
export() {
let CurrentView = this.CoreSystem.getCurrentView();
let data = CurrentView.export();
download("Export_" + new Date().toISOString()+".txt", JSON.stringify(data));
}
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) => {
onChange && onChange(value, key)
}
};
switch(Structure.type){
case DataTypes.Types.Array:
editorProps.value = viewNodeProps[key];
break;
case DataTypes.Types.Integer:
case DataTypes.Types.Bool:
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;
let Structure = {},
styles = {},
nodeStructure = {};
let viewNodeProps = {},
nodeProps = {};
if (selectedNode && CurrentView.has(selectedNode)) {
this.ContainerNode = selectedNode;
if(selectedNode.content && selectedNode.content.value) {
let ctor = ModuleSystem.fromViewNode(selectedNode.content);
console.log("YOUR LOOKINGH")
console.log(ctor)
styles = ctor.Styles;
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 StyleData = Object.keys(styles || {}).map((key,index) =>
)
console.log("@@@@@@@@@@@@@@@@@@")
console.log(StyleData)
console.log(styles)
console.log("!!!!!!!!!!!!!!!!!!!!")
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
}
{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
}
})