App.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React , { useState } from 'react';
  2. import { StyleSheet, Text, View as Div, TextInput, Button } from 'react-native';
  3. import RoutingSystem from './lib/systems/RoutingSystem.js';
  4. import ViewSystem, { View, Node, ViewNode, RowNode, ColNode } from './lib/systems/ViewSystem.js';
  5. import CoreSystem from './lib/systems/CoreSystem.js';
  6. /*********** Custom View Tree ****/
  7. import { Tree } from './lib/helpers/tree';
  8. import TextComp from './modules/Text';
  9. import ViewComp from './modules/View';
  10. import RootComp from './modules/RootComp';
  11. import ImageComp from './modules/Image';
  12. import ButtonComp from './modules/Button';
  13. let NodeB = new ViewNode("B","ViewComp", {text: "ASD LOOK AT ME LOOK OO O.O (O.O)"});
  14. let NodeC = new ViewNode("C","ViewComp",{text:"Manipulationg the dom"});
  15. let NodeD = new ViewNode("D","ViewComp",{text:"Manipulationg the dom"});
  16. let NodeE = new ViewNode("E","ViewComp",{text:"Manipulationg the dom"});
  17. let NodeM = new ViewNode("M","ViewComp",{text:"Manipulationg the dom"});
  18. let NodeK = new ViewNode("K","ViewComp",{text:"Manipulationg the dom"});
  19. const CustomStyle = StyleSheet.create({
  20. container:{
  21. flex:1,
  22. backgroundColor:'red'
  23. },
  24. text:{
  25. color:'blue'
  26. }
  27. })
  28. const RootStyle = StyleSheet.create({
  29. container:{
  30. flex:1,
  31. backgroundColor:'blue'
  32. },
  33. text:{
  34. color:'black'
  35. }
  36. })
  37. let RootNode = new ViewNode("A","RootComp",{text:"This is the asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdStarting point!!!Try add on me ",style:RootStyle});
  38. let TestNode = new ViewNode("H","Text",{style:CustomStyle,text:"Edited Text Node Will be here"})
  39. let EditNode = new ViewNode("N","ViewComp",{text:"Manipulationg the dom sdadwad"});
  40. let ImageNode = new ViewNode("asdasd","Image");
  41. // let Row1 = new RowNode("RootRow");
  42. // let Col11 = new ColNode("Col11");
  43. // let Col12 = new ColNode("Col12");
  44. // let Row2 = new RowNode("RootRow2");
  45. // let Col21 = new ColNode("Col21");
  46. // let Col22 = new ColNode("Col22");
  47. // Col21.content = RootNode;
  48. // Col12.content = TestNode;
  49. let nodeA = new Node("A", {justifyContent: 'flex-end', stretchContainer: true, selected: true});
  50. let nodeB = new Node("B", {justifyContent: 'flex-end' , selected: true}, ImageNode);
  51. let nodeC = new Node("C", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  52. let nodeD = new Node("D");
  53. let nodeE = new Node("E", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  54. let VS = new View();
  55. let root = VS.defaultContainer;
  56. VS
  57. .addViewNode(nodeA, root)
  58. .addViewNode(nodeB, nodeA)
  59. .addViewNode(nodeC, nodeA)
  60. .addViewNode(nodeD, nodeA);
  61. let datata = VS.export();
  62. let VS2 = new View();
  63. VS2
  64. .addViewNode(nodeE, VS2.defaultContainer)
  65. .import(datata, nodeE.id);
  66. // let rowss = VS.setRows(root, 1)[0];
  67. // VS.setColumns(rowss, 2);
  68. // root.props.selected = true;
  69. // let cols = VS.getChildren(rowss);
  70. // VS.setRows(cols[0], 3);
  71. // VS.setRows(cols[1], 2);
  72. // VS.setRows(cols[2], 2);
  73. // cols.forEach((col) => col.props.selected = true);
  74. // cols.forEach((col) => VS.getRows(col).forEach((r) => {VS.setColumns(r,1);r.props.selected = true}));
  75. // cols.forEach((col) => VS.getRows(col).forEach((r) => VS.getColumns(r).forEach((c) => c.props.selected = true)));
  76. // let ee = VS.getRows(cols[1]);
  77. // VS.setColumns(ee[0], 1);
  78. // let cc = VS.getColumns(ee[0]);
  79. // cc[0].content = ImageNode;
  80. // cols[0].content = RootNode;
  81. // cols[1].content = RootNode;
  82. // cols[2].content = ImageNode;
  83. // console.log("ASDASDASDA -> ", cols);
  84. // VS.addViewNode(Row1);
  85. // VS.addViewNode(Col11,Row1);
  86. // VS.addViewNode(Col12,Row1);
  87. // VS.addViewNode(Row2,Col11);
  88. // VS.addViewNode(Col21,Row2);
  89. // VS.addViewNode(Col22,Row2);
  90. // VS.addViewNode(RootNode);
  91. /*VS.addViewNode(NodeB,RootNode)
  92. VS.addViewNode(NodeE,RootNode)
  93. VS.addViewNode(NodeD,NodeB)
  94. VS.addViewNode(NodeK,NodeB)
  95. console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@")
  96. console.log(VS)
  97. //VS.replace(NodeB,TestNode)
  98. VS.replace(NodeK,EditNode)
  99. */
  100. //***************//
  101. /*********************** Custom View tree Ends ************/
  102. //************************************** Routing Ends
  103. let CS = new CoreSystem()
  104. .addPage('test', VS2, 'VS1')
  105. .setHome('test');
  106. let data = CS.export();
  107. console.log("Original");
  108. console.log(data);
  109. let js = JSON.stringify(data);
  110. console.log("String");
  111. console.log(js);
  112. let NCS = new CoreSystem()
  113. let againdata = JSON.parse(js);
  114. console.log("Again");
  115. console.log(againdata)
  116. NCS.import(againdata);
  117. window.onclick = (event) => {
  118. console.log("Mouse event --- ", event);
  119. let res = NCS.ray({event}); // returns ViewNode
  120. console.log(res);
  121. }
  122. const useForceUpdate = (text) => useState(text)[1];
  123. export default function App() {
  124. let [text, setText] = useState('');
  125. let forceUpdate = useForceUpdate(text);
  126. let currentView = NCS.render();
  127. let currentView2 = CS.render();
  128. // console.log(currentView)
  129. return (
  130. <Div style={styles.container}>
  131. <TextInput
  132. style={{height: 40, borderColor: 'gray', borderWidth: 1}}
  133. onChangeText={(txt) => setText(txt)}
  134. value={text}
  135. />
  136. <Button title={'Change Route'} onPress={() => {
  137. //VS.setColumns(root, text);
  138. // CS.goto(text);
  139. // NCS.goto(text);
  140. //forceUpdate(text)
  141. }}></Button>
  142. <Text>Open up App.js to start working on your app!</Text>
  143. <Text>Open up App.js to start working on your app!</Text>
  144. {React.createElement(ButtonComp)}
  145. <Text>Open up App.js to start working on your app!</Text>
  146. {React.createElement(TextComp)}
  147. <Text>sdadada</Text>
  148. {React.createElement(ViewComp)}
  149. {React.createElement(RootComp)}
  150. <Div style={{width: 200, height:400}}>
  151. {React.createElement(ImageComp)}
  152. </Div>
  153. <Text>Open up App.js to start working on your app!</Text>
  154. <Div style={{width:500, height:600}}>
  155. {currentView}
  156. </Div>
  157. <Div>
  158. <Text>------------------</Text>
  159. <Text>------------------</Text>
  160. </Div>
  161. <Div style={{width:500, height:600}}>
  162. {currentView2}
  163. </Div>
  164. </Div>
  165. );
  166. }
  167. const ImageStyle = StyleSheet.create({
  168. ImageCont:{
  169. width:250,
  170. height:250
  171. }
  172. })
  173. const styles = StyleSheet.create({
  174. container: {
  175. flex: 1,
  176. backgroundColor: '#fff',
  177. alignItems: 'center',
  178. justifyContent: 'center',
  179. },
  180. });