123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- //import CoreSystem from 'core-system';
- import ToolBox from './ToolBox';
- import Keyboard from './keyboard';
- import Mouse from './mouse';
- import React from 'react';
- import {Dimensions, StyleSheet, View, Text , Button, TouchableOpacity
- } from 'react-native';
- import { Icon } from 'react-native-elements'
- import Library from 'trapilib/dist/lib';
- import SideBar from './SideBar';
- import MainBar from './MainBar';
- import ModuleBar from './ModuleBar';
- import { ViewNode, Node } from 'trapilib/dist/lib/systems/ViewSystem';
- import Environment from './Environment';
- import BaseSystem from './System';
- let {
- CoreSystem,
- ViewSystem,
- } = Library;
- export default class Gui extends BaseSystem {
- constructor() {
- super();
- this.phoneRef = React.createRef();
- this.phone = this.phoneRef;
- this.toolboxRef = React.createRef();
- this.toolbox = this.toolboxRef;
- this.disabledTools = true;
- this.CoreSystem = new CoreSystem(true);
- this.CoreSystem.onUpdate(() => {
- this.forceUpdate();
- })
- this.Keyboard = new Keyboard().listen();
- this.Keyboard.on(27, () => {
- this.disabledTools = !this.disabledTools;
- if(this.disabledTools) {
- this.CoreSystem.ActionSystem.enable();
- } else {
- this.CoreSystem.ActionSystem.disable();
- }
- this.forceUpdate();
- });
- this.ToolBox = new ToolBox(this.CoreSystem);
- this.MainBar = new MainBar(this.CoreSystem);
- this.ModuleBar = new ModuleBar(this.CoreSystem); // Add CoreSystem deps
- this.SideBar = new SideBar(this.CoreSystem, this.ToolBox);
- this.Environment = new Environment(this.CoreSystem, this.ToolBox, this.phoneRef);
- this.Environment.onUpdate(() => this.forceUpdate())
- this.SideBar.onUpdate(() => this.forceUpdate())
- this.ToolBox.onUpdate( () => {
- this.SideBar.tool = this.ToolBox.activeTool;
- this.forceUpdate();
- });
- this.ModuleBar.onUpdate(() => this.forceUpdate())
-
- this.MainBar.onUpdate(() => this.forceUpdate())
- this.MainBar.onSave( () => {
- this.saveEnv();
- this.forceUpdate()
- })
- this.load();
- // Setup mainContainer
- let cview = this.CoreSystem.getCurrentView();
- let container = cview.getDefaultContainer();
- let mainContent = new ViewNode(Math.random(), 'BaseContainer', {width: 375, height: 667});
- cview.setContent(mainContent, container);
- }
- onMount() {
- this.forceUpdate();
- if(this.phone){
- // thats fine
- this.ToolBoxMouse = new Mouse(this.toolbox.current);
- this.phoneMouse = new Mouse(this.phone.current).droppable();
- }
- if(this.ToolBoxMouse !== undefined){
- this.ToolBoxMouse.listen()
- .on('LeftDown',(e) => this.ToolManagement(e))
- this.phoneMouse.listen()
- .on('LeftDown',(e) => this.ToolManagement(e))
- .on('Drop', (e) => this.dropContent(e))
- }
- }
- saveEnv(){
- let env = this.CoreSystem.export();
- localStorage.setItem('environment', JSON.stringify(env));
- this.forceUpdate();
- try{
- this.CoreSystem.import(JSON.parse(js));
- this.forceUpdate();
- } catch(e) {
- console.log(e);
- }
- }
- ToolManagement(e){
- if(this.ToolBox.activeTool !== null && !this.disabledTools){
- this.processElement(e)
- }
- }
- load() {
- try{
- let env = localStorage.getItem('environment');
- if( env === null){
- // this.CoreSystem.import(JSON.parse(jsLoad));
- this.CoreSystem.fresh();
- }else{
- this.CoreSystem.import(JSON.parse(env));
- }
- this.forceUpdate();
- } catch(e) {
- console.log(e);
- }
- }
- processElement(event){
- let Node = this.CoreSystem.ray({event});
- let NewNode = this.ToolBox.editNode(Node);
- this.forceUpdate();
- }
- dropContent({event, data}) {
- data = JSON.parse(data);
- let targetNode = this.CoreSystem.ray({event});
- // targetNode.content
- targetNode.props.selected = true;
-
- let node = new ViewNode(Math.random(), data.ctor, {}, data.namespace);
- let containerNode = new Node(Math.random(), {}, node);
- let View = this.CoreSystem.getCurrentView();
- View.addViewNode(containerNode, targetNode);
-
- this.forceUpdate();
- }
- mobileRender(){
- return this.Environment.render();
- }
- renderSideBar(){
- return this.SideBar.render();
- }
- renderMainBar(){
- return this.MainBar.render();
- }
- renderToolBox(){
- return (
- <div ref = {this.toolboxRef}>
- <View style={styles.toolbarView}>
- {this.ToolBox.render()}
- </View>
- </div>)
- }
- renderModuleBar(){
- return (
- <View >
- {this.ModuleBar.render()}
- </View>
- )
- }
- removeFrame(routeName) {
- this.CoreSystem.removePage(routeName);
- this.forceUpdate();
- }
- addFrame(routeName) {
- if(!routeName)
- routeName = "Page " + (Object.keys(this.CoreSystem.Routing.topology.nodes).length + 1);
- let VS = new Library.View();
- let container = VS.getDefaultContainer();
- container.props.selected = true;
- let mainContent = new ViewNode(Math.random(), 'BaseContainer', {width: 375, height: 667});
- VS.setContent(mainContent, container);
- this.CoreSystem.addPage(routeName,VS);
- this.CoreSystem.goto(routeName);
- this.forceUpdate()
- }
- renderPageBar(){
- let currentView = this.CoreSystem.Routing.getCurrentView();
- let pages = Object.keys(this.CoreSystem.Routing.topology.nodes).map((route,index) => {
- let view = this.CoreSystem.Routing.getView(route)
- let background = view === currentView ? PageButtons.activePage :(null)
- let textColor = view === currentView ? PageButtons.selectedText :(null)
- return (
- <View key={route} style={[PageButtons.page , background ] } onClick = {(e) => {
- console.log(e);
- this.CoreSystem.goto(route);
- this.forceUpdate()
- }}>
- <View style = {{ flex:1,
- justifyContent:'space-around',
- flexDirection: 'row',
- alignItems:'center'}}>
- <Text style={[PageButtons.text, textColor]}>{route}</Text>
- {view !== currentView && <Text style={[PageButtons.text, textColor, {color: '#77000066'}]} onClick={(e) => {
- this.removeFrame(route);
- e.stopPropagation();
- return false;
- }}>X</Text>}
- </View>
- </View>
- )
- })
- return (
- <View style={PageButtons.container}>
- <View style={{borderRightWidth:"1px",
- borderColor:"#B4b4b4",
- backgroundColor:'white', paddingTop: 4}}>
- <Icon name='filter' color="#36BBAD" />
- </View>
- {pages}
- <View style={PageButtons.addNew} onClick = {() => this.addFrame()}>
- <View style= {PageButtons.addNewContainer}>
- <Text style={PageButtons.addNewText}>Add new </Text>
- <Icon color="white" name='add' iconStyle={{fontSize: 12, paddingTop: 8}}/>
- </View>
- </View>
- </View>);
- }
- }
- const PageButtons = StyleSheet.create({
- container:{
- flex:1,
- flexDirection:'row',
- width:40
- },
- activePage:{
- backgroundColor:"#36BBAD"
- },
- text:{
- fontSize:14,
- letterSpacing: 0,
- color: '#D9D9D9',
- opacity: 1,
- fontFamily: 'light'
- },
- selectedText: {
- color: "#FFFFFF"
- },
- page:{
- borderRightWidth:"1px",
- borderColor:"#B4b4b4",
- backgroundColor:"#F8F8F8",
- cursor:'pointer',
- overflow:'hidden',
- width:160,
- height:48,
- },
- addNew:{
- backgroundColor:"#D6D6D6",
- cursor:'pointer',
- width:160,
- height:48,
- },
- addNewContainer:{
- flex:1,
- flexDirection:'row',
- justifyContent:"center",
- alignItems:'center'
- },
- addNewText:{
- fontSize:14,
- letterSpacing: 0,
- color: 'white',
- opacity: 1,
- fontFamily: 'thin'
- }
- })
- //const jsLoad = '{"Routing":{"topology":{"nodes":{"test":{"id":"test","routeName":"test","uri":"test","view":"VS1","defaultLink":null},"sample":{"id":"sample","routeName":"sample","uri":"sample","view":"VS2","defaultLink":null}},"links":{"test":{"out":[],"in":[]},"sample":{"out":[],"in":[]}}},"home":"test"},"Views":{"views":{"VS1":{"tree":{"nodes":{"A":{"id":"A","depth":0,"value":"RootComp","namespace":"default","props":{}},"B":{"id":"B","depth":1,"value":"ViewComp","namespace":"default","props":{"text":"ASD LOOK AT ME LOOK OO O.O (O.O)"}},"C":{"id":"C","depth":1,"value":"ViewComp","namespace":"default","props":{}}},"links":{"A":{"out":[{"to":"B","from":"A"},{"to":"C","from":"A"}],"in":[]},"B":{"out":[],"in":[{"to":"B","from":"A"}]},"C":{"out":[],"in":[{"to":"C","from":"A"}]}},"levels":[["A"],["B","C"]],"rootId":"A"}},"VS2":{"tree":{"nodes":{"P":{"id":"P","depth":0,"value":"RootComp","namespace":"default","props":{}}},"links":{"P":{"out":[],"in":[]}},"levels":[["P"]],"rootId":"P"}}}}}';
- //jsLoad Test
- const jsLoad = ``;
- const MudleBarStyle = StyleSheet.create({
- container:{
- backgroundColor:'red'
- }
- })
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'space-between',
- flexDirection: 'row'
- },
- toolbarView: {
- justifyContent: 'space-around',
- alignItems: 'center',
- padding: 16
- },
- mainView: {
- backgroundColor: '#065b69',
- alignSelf:'stretch',
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center'
- },
- mobileView: {
- backgroundColor: 'white',
- borderWidth: 4,
- borderColor: 'orange',
- flex:1,
- alignSelf: 'stretch',
- },
- attributesView: {
- width:256,
- alignSelf: 'stretch',
- flexDirection: 'column',
- }
- });
|