Nikatlas 5 years ago
parent
commit
4b6bd747ab

File diff suppressed because it is too large
+ 0 - 0
dist/lib/Module.js


File diff suppressed because it is too large
+ 0 - 0
dist/lib/Types.js


File diff suppressed because it is too large
+ 0 - 0
dist/lib/systems/ModuleSystem.js


File diff suppressed because it is too large
+ 0 - 0
dist/lib/systems/ViewSystem.js


File diff suppressed because it is too large
+ 0 - 0
dist/modules/NativeBase/index.js


+ 16 - 1
lib/Module.js

@@ -25,6 +25,20 @@ export default class Module extends React.Component{
 		}
 		}
 	}
 	}
 
 
+	getId() {
+		return this.props.ModuleID;
+	}
+
+	renderModule(ctor, namespace = "default", props = {}) {
+		let VS = this.props.CoreSystem.ViewSystem;
+		if(!this.props.CoreSystem.ModuleSystem.get(ctor, namespace)) return null;
+		return VS.renderModule({
+          	value: ctor,
+          	namespace,
+          	props
+        }, this.getId() +"C"+ (this.counter++));
+	}
+
 	createAction(action) {
 	createAction(action) {
 		if(!this.props.CoreSystem) {
 		if(!this.props.CoreSystem) {
 			console.warning("This module was constructed without a CoreSystem");
 			console.warning("This module was constructed without a CoreSystem");
@@ -40,7 +54,8 @@ export default class Module extends React.Component{
 	display() {
 	display() {
 		throw new Error("You must extend this base Module and override display method!");
 		throw new Error("You must extend this base Module and override display method!");
 	}
 	}
-	render() { 
+	render() {
+		this.counter = 0;
 		return <View ModuleID={this.props.ModuleID} style={[{overflow:'hidden'}]} MY_WRAPPER_FROM_BASE_MODULE={true}>
 		return <View ModuleID={this.props.ModuleID} style={[{overflow:'hidden'}]} MY_WRAPPER_FROM_BASE_MODULE={true}>
 			{this.display()}
 			{this.display()}
 		</View>
 		</View>

+ 30 - 1
lib/Types.js

@@ -12,7 +12,8 @@ let Types = {
 	Float: 10,
 	Float: 10,
 	Modules: 11,
 	Modules: 11,
 	Whatever: 12,
 	Whatever: 12,
-	Action: 13
+	Action: 13,
+	Module: 14
 }
 }
 
 
 
 
@@ -180,6 +181,33 @@ class JSArray extends Type{
 	}
 	}
 }
 }
 
 
+
+class Module extends Type{
+	constructor(){
+		super(Types.Module)
+	}
+
+	parse(data) {
+
+		let {
+			value,
+			namespace
+		} = data || {};
+		return {
+			value,
+			namespace
+		};
+	}
+
+	resolve(value){
+		if(typeof value === "object" && value.value)
+			return true;
+		else if ((value === undefined || value === null) && !this.isRequired)
+			return true;
+		return false;
+	}
+}
+
 export default {
 export default {
 	Action,
 	Action,
 	Bool,
 	Bool,
@@ -189,6 +217,7 @@ export default {
 	Text,
 	Text,
 	Types,
 	Types,
 	Type,
 	Type,
+	Module,
 	Array: JSArray
 	Array: JSArray
 }
 }
 
 

+ 1 - 1
lib/systems/ModuleSystem.js

@@ -45,7 +45,7 @@ export default class ModuleSystem {
 	}
 	}
 
 
 	get(modName, namespace = "default") {
 	get(modName, namespace = "default") {
-		return this.constructors[namespace][modName];
+		return this.constructors[namespace] && this.constructors[namespace][modName];
 	}
 	}
 
 
 	fromViewNode(vn) {
 	fromViewNode(vn) {

+ 66 - 24
lib/systems/ViewSystem.js

@@ -34,6 +34,7 @@ export default class ViewSystem {
 		this.CoreSystem = CS;
 		this.CoreSystem = CS;
 		this.ModuleSystem = CS.ModuleSystem;
 		this.ModuleSystem = CS.ModuleSystem;
 		this.EventSystem = CS.EventSystem;
 		this.EventSystem = CS.EventSystem;
+		this.ghosts = {};
 	}
 	}
 
 
 	getNode(ViewId, NodeId) {
 	getNode(ViewId, NodeId) {
@@ -58,6 +59,27 @@ export default class ViewSystem {
 		return this.views[name].render(this.CoreSystem);
 		return this.views[name].render(this.CoreSystem);
 	}
 	}
 
 
+	renderModule(mod, id) {
+		let selfView = this.CoreSystem.getCurrentView();
+		let nodeId = "___"+id+"Node";
+		let {
+			value,
+			props,
+			namespace
+		} = mod;
+		if(!selfView.ghosts[nodeId]) {
+			let viewNode = new ViewNode(id, value, props, namespace);
+			let node = new Node(nodeId, {}, viewNode);
+			selfView.ghosts[nodeId] = node;
+		}
+		let vn = selfView.ghosts[nodeId].content;
+		vn.value = value;
+		vn.namespace = namespace;
+
+		let ViewNodeReact = renderContent(selfView.ghosts[nodeId], this.CoreSystem, selfView);
+		return renderNode(selfView.ghosts[nodeId], this.CoreSystem, ViewNodeReact);
+	}
+
 	export() {
 	export() {
 		let views = {};
 		let views = {};
 
 
@@ -92,6 +114,8 @@ export class View {
 		let rootNode = new Node(Math.random(), {stretchContainer: false, selected: true}); // row
 		let rootNode = new Node(Math.random(), {stretchContainer: false, selected: true}); // row
 		this.addViewNode(rootNode);
 		this.addViewNode(rootNode);
 		this.defaultContainer = rootNode;
 		this.defaultContainer = rootNode;
+
+		this.ghosts = {};
 	}
 	}
 
 
 	getDefaultContainer() {
 	getDefaultContainer() {
@@ -102,7 +126,7 @@ export class View {
 		return this.ViewTree.root;
 		return this.ViewTree.root;
 	}
 	}
 	getNode(id) {
 	getNode(id) {
-		return this.ViewTree.getNode(id);
+		return this.ghosts[id] || this.ViewTree.getNode(id);
 	}
 	}
 
 
 	has(node) {
 	has(node) {
@@ -126,6 +150,7 @@ export class View {
 	}
 	}
 
 
 	getParent(node) {
 	getParent(node) {
+		if(!this.has(node)) return false;
 		return this.getNode(this.ViewTree.getParent(node));
 		return this.getNode(this.ViewTree.getParent(node));
 	}
 	}
 
 
@@ -222,12 +247,15 @@ export class View {
 	}
 	}
 
 
 	import(data, parentNode) {
 	import(data, parentNode) {
-		let { tree } = data;
+		let { tree, ghosts } = data;
 		if(!parentNode)
 		if(!parentNode)
 			this.ViewTree = new Tree();
 			this.ViewTree = new Tree();
 		try {
 		try {
 			this.ViewTree.import(tree, Node, parentNode);
 			this.ViewTree.import(tree, Node, parentNode);
 			this.defaultContainer = this.ViewTree.root;
 			this.defaultContainer = this.ViewTree.root;
+			for(var i in ghosts) {
+				this.ghosts[i] = new Node().import(ghosts[i]);
+			}
 		} catch(e) {
 		} catch(e) {
 			log(e);
 			log(e);
 			throw new Error("ViewSystem import error : ", e);
 			throw new Error("ViewSystem import error : ", e);
@@ -237,8 +265,15 @@ export class View {
 
 
 	export(node) {
 	export(node) {
 		let tree = this.ViewTree.export(node);
 		let tree = this.ViewTree.export(node);
+		
+		let ghostsExported = {};
+		for(var i in this.ghosts) {
+			ghostsExported[i] = this.ghosts[i].export();
+		}
+
 		return {
 		return {
-			tree
+			tree,
+			ghosts: ghostsExported
 		};
 		};
 	}
 	}
 }
 }
@@ -266,26 +301,14 @@ let Renderer = (props) => {
 	let ViewNodeReact;
 	let ViewNodeReact;
 	// IF CONTENT
 	// IF CONTENT
 	if(viewNode) {
 	if(viewNode) {
-		// Create ref
-		ModuleSystem.createRef(viewNode.id);
-		// Crete element
-		ViewNodeReact = ModuleSystem.createElement(
-			viewNode.value,
-			{ 
-				...viewNode.props,
-				ModuleID: viewNode.id,
-				NodeID: node.id,
-				EventSystem: EventSystem,
-				CoreSystem: CoreSystem,
-				View: selfView
-			},
-			null, // children
-			viewNode.namespace,
-			viewNode.id
-		);
-	}
-	ModuleSystem.createRef(node.id);
-	return ModuleSystem.createElementCtor(
+		ViewNodeReact = renderContent(node, CoreSystem, selfView);
+	}
+	return renderNode(node, CoreSystem, ViewNodeReact, childrenReact);
+}
+
+let renderNode = (node, CoreSystem, ViewNodeReact, childrenReact) => {
+	CoreSystem.ModuleSystem.createRef(node.id);
+	return CoreSystem.ModuleSystem.createElementCtor(
 		node.ctor, 
 		node.ctor, 
 		{
 		{
 			...node.props,
 			...node.props,
@@ -298,7 +321,26 @@ let Renderer = (props) => {
 		node.id
 		node.id
 	);
 	);
 }
 }
-
+let renderContent = (node, CoreSystem, selfView) => {
+	let viewNode = node.content;
+	// Create ref
+	CoreSystem.ModuleSystem.createRef(viewNode.id);
+	// Crete element
+	return CoreSystem.ModuleSystem.createElement(
+		viewNode.value,
+		{ 
+			...viewNode.props,
+			ModuleID: viewNode.id,
+			NodeID: node.id,
+			EventSystem: CoreSystem.EventSystem,
+			CoreSystem: CoreSystem,
+			View: selfView
+		},
+		null, // children
+		viewNode.namespace,
+		viewNode.id
+	);
+}
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({
 	colWrapper: {
 	colWrapper: {
 		"position": "absolute",
 		"position": "absolute",

+ 13 - 3
modules/NativeBase/index.js

@@ -119,6 +119,7 @@ export class Button extends Module {
 export class Card extends Module {
 export class Card extends Module {
 	constructor(props) {
 	constructor(props) {
 		super(props);
 		super(props);
+		this.CoreSystem = props.CoreSystem;
 	}
 	}
 	display() {
 	display() {
 		let {
 		let {
@@ -127,6 +128,9 @@ export class Card extends Module {
 			footer,
 			footer,
 			...rest
 			...rest
 		} = this.props;
 		} = this.props;
+
+		let item = this.renderModule('Button','NativeBase');
+		console.log("ITEM : ", item);
 		return  <CardCtor {...rest}>
 		return  <CardCtor {...rest}>
             <CardItemCtor header>
             <CardItemCtor header>
               <TextCtor>{header}</TextCtor>
               <TextCtor>{header}</TextCtor>
@@ -135,6 +139,7 @@ export class Card extends Module {
               <BodyCtor>
               <BodyCtor>
                 <TextCtor>
                 <TextCtor>
                   {body}
                   {body}
+                  {item}
                 </TextCtor>
                 </TextCtor>
               </BodyCtor>
               </BodyCtor>
             </CardItemCtor>
             </CardItemCtor>
@@ -328,11 +333,15 @@ export class Item extends Module {
 	display() {
 	display() {
 		let {
 		let {
 			placeholder,
 			placeholder,
+			mod,
 			...rest
 			...rest
 		} = this.props;
 		} = this.props;
-		return <ItemCtor {...rest}>
-			<InputCtor placeholder={placeholder}/>
-		</ItemCtor>;
+		console.log("RENDERMOD:", mod);
+		return <ContentCtor>
+		<ItemCtor {...rest}>
+			{mod ? this.renderModule(mod.value, mod.namespace) : null}
+		</ItemCtor>
+		</ContentCtor>;
 	}
 	}
 }
 }
 export class Label extends Module {
 export class Label extends Module {
@@ -641,6 +650,7 @@ IconNB.Inputs = {
 	
 	
 }
 }
 Item.Inputs = {
 Item.Inputs = {
+	mod: new Types.Module(),
 	inlineLabel: new Types.Bool(),
 	inlineLabel: new Types.Bool(),
 	floatingLabel: new Types.Bool(),
 	floatingLabel: new Types.Bool(),
 	stackedLabel: new Types.Bool(),
 	stackedLabel: new Types.Bool(),

Some files were not shown because too many files changed in this diff