Переглянути джерело

Update to One container system +Fix select bugs

Nikatlas 5 роки тому
батько
коміт
46ce63dfcf
5 змінених файлів з 106 додано та 89 видалено
  1. 15 12
      Systems/Environment.js
  2. 1 1
      Systems/Gui.js
  3. 74 51
      Systems/SideBar.js
  4. 0 9
      Tools/select.js
  5. 16 16
      yarn.lock

+ 15 - 12
Systems/Environment.js

@@ -3,6 +3,7 @@ import React from 'react';
 import { Button , View, Text, StyleSheet } from 'react-native';
 import {Icon} from 'react-native-elements';
 import BaseSystem from './System';
+import {Node} from 'trapilib/dist/lib/systems/ViewSystem'
 
 
 export default class Environment extends BaseSystem {
@@ -16,11 +17,9 @@ export default class Environment extends BaseSystem {
   addRow(){
     let View = this.CoreSystem.getCurrentView();
     let container = View.getDefaultContainer();
-    let rows = View.getRows(container);
-    View.setRows(container,rows.length + 1)
-    rows = View.getRows(container)
-    View.setColumns(rows[rows.length-1],1)
-    rows[rows.length-1].props.selected = true;
+    let node = new Node(Math.random()+ Math.random(), {selected: true})
+    console.log(node)
+    View.addViewNode(node, container);
     this.forceUpdate();  
   }
 
@@ -74,14 +73,14 @@ export default class Environment extends BaseSystem {
 	render() {
 		let CurrentView = this.CoreSystem.getCurrentView();
 		let defaultContainer = CurrentView.getDefaultContainer();
-		let Rows = CurrentView.getRows(defaultContainer);
+		let Rows = []; //CurrentView.getRows(defaultContainer);
     let Cols = [];
     // Check if selection is Row or Col and find ROW to getColumns
     if(this.ToolBox.selectedNode){
-      let selectedRowNode = this.ToolBox.selectedNode.isRow ? 
-      this.ToolBox.selectedNode : 
-      CurrentView.getParent(this.ToolBox.selectedNode);
-      Cols = CurrentView.getColumns(selectedRowNode);
+      // let selectedRowNode = this.ToolBox.selectedNode.isRow ? 
+      // this.ToolBox.selectedNode : 
+      // CurrentView.getParent(this.ToolBox.selectedNode);
+      // Cols = CurrentView.getColumns(selectedRowNode);
     }
 
 		return <View style={styles.container}>
@@ -99,11 +98,15 @@ export default class Environment extends BaseSystem {
               </View>
             </View>
             <View style={[styles.row, styles.colHolders]}>
-              {this.colHolders(Cols)}
+              {
+              //this.colHolders(Cols)
+              }
             </View>
 			      <View style={styles.row}>
 	          	<View style={[styles.col, styles.rowHolders]}>
-	          		{this.rowHolders(Rows)}
+	          		{
+                  //this.rowHolders(Rows)
+                }
 	          	</View>
 	          	<div ref={this.phoneRef}>
 	          		<View style={[styles.mobileView]}>

+ 1 - 1
Systems/Gui.js

@@ -129,7 +129,7 @@ export default class Gui extends BaseSystem {
     let node = new ViewNode(Math.random(), data.ctor, {}, data.namespace);
     Node.content = node;
     let View = this.CoreSystem.getCurrentView();
-    Node.isCol && Node.depth === 3 && View.addGrid(Node, 3,3);
+    //Node.isCol && Node.depth === 3 && View.addGrid(Node, 3,3);
 
     console.log(node);
 

+ 74 - 51
Systems/SideBar.js

@@ -1,7 +1,7 @@
 import React from 'react';
 import {StyleSheet, View, Text} from 'react-native';
 import Library from 'trapilib/dist/lib';
-import { TextInput } from 'react-native';
+import { TextInput, Image } from 'react-native';
 
 import TextEditor from '../Components/TextEditor';
 // import Numbers from '../Components/Numbers';
@@ -27,79 +27,102 @@ export default class SideBar extends BaseSystem {
 		this.ToolBox = ToolBox;
 	}
 
+	removeNode(node) {
+		let CurrentView = this.CoreSystem.getCurrentView();
+		console.log(node)
+		if (CurrentView.has(node)) {
+			CurrentView.remove(node);
+		}
+		this.forceUpdate();
+	}
 
-    editNode(text,key){
-		this.viewNode.props[key] = text;
+    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 (<View></View>)
+		}
+		return <Editor {...editorProps} key={key}/>
+    }
+
 	render(){
 		let ModuleSystem = this.CoreSystem.ModuleSystem;
 		let CurrentView = this.CoreSystem.getCurrentView();
 		
 		let selectedNode = this.ToolBox.selectedNode;
 		console.log("TOOLBOX" , this.ToolBox);
-		let Structure = {};
-		let viewNodeProps = {};
-
-		if (selectedNode) {
-			if (selectedNode.isCol && CurrentView.has(selectedNode)) {
-				this.ColNode = selectedNode;
-				this.RowNode = CurrentView.getParent(this.ColNode);
-				if(selectedNode.content && selectedNode.content.value) {
-					this.viewNode = selectedNode.content;
-					let ctor = ModuleSystem.fromViewNode(this.viewNode);
-					viewNodeProps = ModuleSystem.validateProps(ctor, this.viewNode.props);
-					Structure = ctor.Inputs;
-				}
-			} else if(selectedNode.isRow) {
-				this.RowNode = selectedNode;
-				console.log("SELECTTTTT", selectedNode)
+		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 data = Object.keys(Structure || {}).map((key,index) => {
-			let Editor = TypeHandler(Structure[key]);
-			let editorProps = {
-				title: key,
-				onChange: (value) => {
-					console.log(typeof value);
-					this.editNode(value, key);
-				}
-			};
-			switch(Structure[key].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 (<View></View>)
-			}
-			return <Editor {...editorProps} key={index + key + this.ColNode.id}/>
-		})
+		let contentData = Object.keys(Structure || {}).map((key,index) => 
+			<View key={selectedNode.id + key}>
+			{this.createHandler(Structure[key], viewNodeProps, key, (v, f) => 
+				this.editNode(selectedNode.content, v,f))}
+			</View>
+		)
+		let containerData =Object.keys(nodeStructure || {}).map((key, index) => 
+			<View key={selectedNode.id + key}>
+			{this.createHandler(nodeStructure[key], nodeProps, key, (v,f) => 
+				this.editNode(selectedNode, v, f))}
+			</View>
+		);
 		return (
   			<View>
   				<Text style={SideBarStyle.title}>Side Bar</Text>
   				<View>
-  					{this.RowNode && <View key={this.RowNode.id}>
-  						<Text>Row</Text>
+  					{this.ContainerNode && <View key={this.ContainerNode.id}>
+  						<Text>Container</Text>
   						<TextEditor title="Inner Columns" 
-  						text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''} 
+  						text={this.ContainerNode && CurrentView.getChildren(this.ContainerNode).length +''} 
   						onChange={(cols) => {
-  							CurrentView.setColumns(this.RowNode, parseInt(cols))
-  							this.forceUpdate();
+  							alert("Not working");
   						}}/>
-  					</View>}			
-  					{this.ColNode && <View key={this.ColNode.id}>
-  						<Text>Col</Text>
-  						<Text>Nothing Yet</Text>
+  						<Image  name='near me'
+		  				style={{width: 20, height: 20 , color:'#606060'}}
+		  				source= {require('../assets/icon.png')}
+		  				containerStyle={{}}
+		  				onClick={() => this.removeNode(this.ContainerNode)}
+		  				/>
   					</View>}
+  					{containerData}
   				</View>
 
 
   				<View style={PropertiesContainer.container}>
-  			 		{data}
+  			 		{contentData}
   			 	</View>
 
 

+ 0 - 9
Tools/select.js

@@ -49,7 +49,6 @@ export default class Select extends Tool{
 		
 		if( this.selectedNode ) {
 			this.selectedNode.props.selected = false;
-			this.selectedNodeParent.props.selected = false;
 		}
 
 		node.props = {
@@ -59,14 +58,6 @@ export default class Select extends Tool{
 		this.selectedNode = node;
 		let View = CS.getCurrentView();
 		this.selectedNodeParent = View.getParent(node);
-		
-		this.selectedNodeParent.props = {
-			...this.selectedNodeParent.props,
-			selected: true
-		}
-
-
-
 	}
 
 	render(){

+ 16 - 16
yarn.lock

@@ -1382,13 +1382,13 @@ braces@^2.3.1:
     to-regex "^3.0.1"
 
 browserslist@^4.6.0, browserslist@^4.6.6:
-  version "4.6.6"
-  resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.6.6.tgz#6e4bf467cde520bc9dbdf3747dafa03531cec453"
-  integrity sha512-D2Nk3W9JL9Fp/gIcWei8LrERCS+eXu9AM5cfXA8WEZ84lFks+ARnZ0q/R69m2SV3Wjma83QDDPxsNKXUwdIsyA==
+  version "4.7.0"
+  resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.7.0.tgz#9ee89225ffc07db03409f2fee524dc8227458a17"
+  integrity sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA==
   dependencies:
-    caniuse-lite "^1.0.30000984"
-    electron-to-chromium "^1.3.191"
-    node-releases "^1.1.25"
+    caniuse-lite "^1.0.30000989"
+    electron-to-chromium "^1.3.247"
+    node-releases "^1.1.29"
 
 bser@^2.0.0:
   version "2.1.0"
@@ -1479,7 +1479,7 @@ can-use-dom@^0.1.0:
   resolved "https://registry.yarnpkg.com/can-use-dom/-/can-use-dom-0.1.0.tgz#22cc4a34a0abc43950f42c6411024a3f6366b45a"
   integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo=
 
-caniuse-lite@^1.0.30000984:
+caniuse-lite@^1.0.30000989:
   version "1.0.30000989"
   resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz#b9193e293ccf7e4426c5245134b8f2a56c0ac4b9"
   integrity sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==
@@ -1901,10 +1901,10 @@ [email protected]:
   resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
   integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
 
-electron-to-chromium@^1.3.191:
-  version "1.3.245"
-  resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.245.tgz#1829c45165853c37f74e9f6736546917f78a03d4"
-  integrity sha512-W1Tjm8VhabzYmiqLUD/sT/KTKkvZ8QpSkbTfLELBrFdnrolfkCgcbxFE3NXAxL5xedWXF74wWn0j6oVrgBdemw==
+electron-to-chromium@^1.3.247:
+  version "1.3.248"
+  resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.248.tgz#1f5f950797e192e9a951b8a44fc08974b609adcb"
+  integrity sha512-+hQe6xqpODLw9Nr80KoT0/S+YarjNbI9wgZchkOopJLBLPgAsniK184P0IGVs/0NsoZf4lBnQhOsjen9a47Hrg==
 
 emoji-regex@^7.0.1:
   version "7.0.3"
@@ -4147,7 +4147,7 @@ node-pre-gyp@^0.12.0:
     semver "^5.3.0"
     tar "^4"
 
-node-releases@^1.1.25:
+node-releases@^1.1.29:
   version "1.1.29"
   resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.29.tgz#86a57c6587a30ecd6726449e5d293466b0a0bb86"
   integrity sha512-R5bDhzh6I+tpi/9i2hrrvGJ3yKPYzlVOORDkXhnZuwi5D3q1I5w4vYy24PJXTcLk9Q0kws9TO77T75bcK8/ysQ==
@@ -5006,9 +5006,9 @@ regex-not@^1.0.0, regex-not@^1.0.2:
     safe-regex "^1.1.0"
 
 regexp-tree@^0.1.6:
-  version "0.1.12"
-  resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.12.tgz#28eaaa6e66eeb3527c15108a3ff740d9e574e420"
-  integrity sha512-TsXZ8+cv2uxMEkLfgwO0E068gsNMLfuYwMMhiUxf0Kw2Vcgzq93vgl6wIlIYuPmfMqMjfQ9zAporiozqCnwLuQ==
+  version "0.1.13"
+  resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.13.tgz#5b19ab9377edc68bc3679256840bb29afc158d7f"
+  integrity sha512-hwdV/GQY5F8ReLZWO+W1SRoN5YfpOKY6852+tBFcma72DKBIcHjPRIlIvQN35bCOljuAfP2G2iB0FC/w236mUw==
 
 regexpu-core@^4.5.4:
   version "4.5.5"
@@ -5678,7 +5678,7 @@ [email protected]:
 
 "trapilib@git+http://git.onarbooks.com/Klapi/TrapiLib.git":
   version "1.0.7"
-  resolved "git+http://git.onarbooks.com/Klapi/TrapiLib.git#82bf016fbb69f5b6b93b0631a4a4ed204298792e"
+  resolved "git+http://git.onarbooks.com/Klapi/TrapiLib.git#4aa88a69234c36d35f5607e193699d34471f8fbc"
   dependencies:
     expo "^34.0.0-experiment.8"
     prop-types "^15.7.2"