1 |
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.View=exports["default"]=exports.Node=exports.ViewNode=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _react=_interopRequireDefault(require("react"));var _tree=require("../helpers/tree");var _Row=_interopRequireDefault(require("../../modules/Row"));var _Col=_interopRequireDefault(require("../../modules/Col"));var _BaseHolder=_interopRequireDefault(require("../../modules/BaseHolder"));var _reactNative=require("react-native");var _jsxFileName="/Users/konstantinosschoinas/Desktop/modular/TrapiLib/lib/systems/ViewSystem.js";function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2["default"])(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}function log(){var _console;(_console=console).log.apply(_console,arguments);}var ViewNode=function(_TreeNode){(0,_inherits2["default"])(ViewNode,_TreeNode);function ViewNode(id,value,props){var _this;var namespace=arguments.length>3&&arguments[3]!==undefined?arguments[3]:"default";(0,_classCallCheck2["default"])(this,ViewNode);_this=(0,_possibleConstructorReturn2["default"])(this,(0,_getPrototypeOf2["default"])(ViewNode).call(this,id));_this.value=value;_this.namespace=namespace;_this.props=props||{};return _this;}return ViewNode;}(_tree.TreeNode);exports.ViewNode=ViewNode;var Node=function(_TreeNode2){(0,_inherits2["default"])(Node,_TreeNode2);function Node(id,props,content){var _this2;(0,_classCallCheck2["default"])(this,Node);_this2=(0,_possibleConstructorReturn2["default"])(this,(0,_getPrototypeOf2["default"])(Node).call(this,id));_this2.ctor=_BaseHolder["default"];_this2.props=props||{};if(content){_this2.content=content;}return _this2;}return Node;}(_tree.TreeNode);exports.Node=Node;var ViewSystem=function(){function ViewSystem(MS,ES){(0,_classCallCheck2["default"])(this,ViewSystem);this.views={};this.ModuleSystem=MS;this.EventSystem=ES;}(0,_createClass2["default"])(ViewSystem,[{key:"getNode",value:function getNode(ViewId,NodeId){return this.views[ViewId].getNode(NodeId);}},{key:"getView",value:function getView(name){return this.views[name];}},{key:"addView",value:function addView(name,view){this.views[name]=view;return view;}},{key:"removeView",value:function removeView(name){var view=this.views[name];delete this.views[name];return view;}},{key:"render",value:function render(name){return this.views[name].render(this.ModuleSystem,this.EventSystem);}},{key:"export",value:function _export(){var views={};for(var i in this.views){views[i]=this.views[i]["export"]();}return{views:views};}},{key:"import",value:function _import(data){var views=data.views;for(var i in views){this.views[i]=new View()["import"](views[i]);}return this;}},{key:"ray",value:function ray(viewId,x,y,id){var tree=this.views[viewId].ViewTree;}}]);return ViewSystem;}();exports["default"]=ViewSystem;var View=function(){function View(){(0,_classCallCheck2["default"])(this,View);this.ViewTree=new _tree.Tree();var rootNode=new Node(Math.random(),{stretchContainer:true,selected:true});this.addViewNode(rootNode);this.defaultContainer=rootNode;}(0,_createClass2["default"])(View,[{key:"getDefaultContainer",value:function getDefaultContainer(){return this.defaultContainer;}},{key:"getRoot",value:function getRoot(){return this.ViewTree.root;}},{key:"getNode",value:function getNode(id){return this.ViewTree.getNode(id);}},{key:"has",value:function has(node){if((0,_typeof2["default"])(node)!=="object")return this.getNode(node);return this.getNode(node.id);}},{key:"render",value:function render(MS,ES){var node=this.ViewTree.root;return _react["default"].createElement(Renderer,{ModuleSystem:MS,EventSystem:ES,node:node,tree:this.ViewTree,__source:{fileName:_jsxFileName,lineNumber:115}});}},{key:"addViewNode",value:function addViewNode(node){var parentNode=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;this.ViewTree.insert(node,parentNode);return this;}},{key:"setContent",value:function setContent(content,container){container.content=content;return this;}},{key:"getParent",value:function getParent(node){return this.getNode(this.ViewTree.getParent(node));}},{key:"getRows",value:function getRows(column){log("Deprecated for now");return true;if(!column.isCol){throw new Error("You must pass a ColNode to this function");}return this.getChildren(column);}},{key:"setRows",value:function setRows(column){var rows=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;log("Deprecated for now");return true;if(!column.isCol)throw new Error("You must pass a ColNode to this function");if(rows<1)throw new Error("Only positive rows");var colChildren=this.getChildren(column);if(colChildren.length>rows){for(var i=rows;i<colChildren.length;i++){var row=colChildren[i];if(row.content){if(confirm("Are you sure you want to remove this row it has content?"))this.remove(row);}else{this.remove(row);}}}else{for(var i=colChildren.length;i<rows;i++){this.addViewNode(new Node(Math.random(),true),column);}}return this.getRows(column);}},{key:"getColumns",value:function getColumns(row){log("Deprecated for now");return true;if(!row.isRow){throw new Error("You must pass a RowNode to this function");}return this.getChildren(row);}},{key:"setColumns",value:function setColumns(row){var columns=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;log("Deprecated for now");return true;if(!row.isRow)throw new Error("You must pass a RowNode to this function");if(columns<1)throw new Error("Only positive cols");var rowChildren=this.getChildren(row);if(rowChildren.length>columns){for(var i=columns;i<rowChildren.length;i++){var col=rowChildren[i];if(col.content){if(confirm("Are you sure you want to remove this col it has content?"))this.remove(col);}else{this.remove(col);}}}else{for(var i=rowChildren.length;i<columns;i++){this.addViewNode(new Node(Math.random()),row);}}return this.getColumns(row);}},{key:"addGrid",value:function addGrid(column,rowSize,columnSize){var _this3=this;log("Deprecated for now");return true;this.setRows(column,rowSize).forEach(function(row){return _this3.setColumns(row,columnSize).forEach(function(col){return col.content=new ViewNode(Math.random(),"BaseContainer",{});});});}},{key:"remove",value:function remove(node){if(node===root){console.log("Cannot remove Root node",node);return this;}this.ViewTree.remove(node);return this;}},{key:"replace",value:function replace(oldNode,newNode){this.ViewTree.replaceNode(oldNode,newNode);return this;}},{key:"getChildren",value:function getChildren(node){return this.ViewTree.getChildren(node);}},{key:"import",value:function _import(data,parentNode){var tree=data.tree;if(!parentNode)this.ViewTree=new _tree.Tree();try{this.ViewTree["import"](tree,Node,parentNode);this.defaultContainer=this.ViewTree.root;}catch(e){log(e);throw new Error("ViewSystem import error : ",e);}return this;}},{key:"export",value:function _export(node){var tree=this.ViewTree["export"](node);return{tree:tree};}}]);return View;}();exports.View=View;var Renderer=function Renderer(props){var node=props.node,tree=props.tree,ModuleSystem=props.ModuleSystem,EventSystem=props.EventSystem;var childrens=tree.getChildren(node);var childrenReact=childrens.map(function(child){return _react["default"].createElement(Renderer,{node:child,tree:tree,key:child.id,ModuleSystem:ModuleSystem,EventSystem:EventSystem,__source:{fileName:_jsxFileName,lineNumber:257}});});var viewNode=node.content;var ViewNodeReact;if(viewNode){ModuleSystem.createRef(viewNode.id);ViewNodeReact=ModuleSystem.createElement(viewNode.value,_objectSpread({},viewNode.props,{ModuleID:viewNode.id,EventSystem:EventSystem}),[],viewNode.namespace,viewNode.id);}ModuleSystem.createRef(node.id);return ModuleSystem.createElementCtor(node.ctor,_objectSpread({},node.props,{depth:node.depth,content:ViewNodeReact,ID:node.id}),childrenReact,node.id);};var styles=_reactNative.StyleSheet.create({colWrapper:{"position":"absolute","left":0,"bottom":0,"right":0,"top":0}});
|