1 |
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _react=_interopRequireDefault(require("react"));var _Module=_interopRequireDefault(require("../Module"));var _Types=require("../Types");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;}var ModuleSystem=function(){function ModuleSystem(){(0,_classCallCheck2.default)(this,ModuleSystem);this.constructors={};this.refs={};}(0,_createClass2.default)(ModuleSystem,[{key:"isAcceptedModule",value:function isAcceptedModule(ctor){return ctor.prototype instanceof _Module.default||ctor.prototype instanceof _react.default.Component||typeof ctor==="function";}},{key:"loadModule",value:function loadModule(name,ctor){var namespace=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"default";if(!this.isAcceptedModule(ctor)){throw new Error("This is not a module: ",ctor);}if(!this.constructors[namespace])this.constructors[namespace]={};if(this.constructors[namespace][name]){log("Duplicate module: ",ctor);return true;}this.constructors[namespace][name]=ctor;}},{key:"load",value:function load(Dictionary){var Namespace=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"default";for(var i in Dictionary){var ctor=Dictionary[i];if(!this.isAcceptedModule(ctor)&&typeof ctor==="object"){console.log("Loading new namespace : ",i);this.load(Dictionary[i],i);}else if(this.isAcceptedModule(ctor)){this.loadModule(i,Dictionary[i],Namespace);}}}},{key:"list",value:function list(){return this.constructors;}},{key:"get",value:function get(modName){var namespace=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"default";return this.constructors[namespace]&&this.constructors[namespace][modName];}},{key:"fromViewNode",value:function fromViewNode(vn){return this.get(vn.value,vn.namespace);}},{key:"createRef",value:function createRef(id){!this.refs[id]&&(this.refs[id]=_react.default.createRef());return this.refs[id];}},{key:"getRef",value:function getRef(id){return this.refs[id];}},{key:"createElement",value:function createElement(name,props,children){var namespace=arguments.length>3&&arguments[3]!==undefined?arguments[3]:"default";var ref=arguments.length>4?arguments[4]:undefined;var ctor=this.get(name,namespace);return this.createElementCtor(ctor,props,children,ref);}},{key:"createElementCtor",value:function createElementCtor(ctor,props,children,ref){var validatedProps=this.validateProps(ctor,props);if(ref){validatedProps=_objectSpread({},validatedProps,{ref:this.refs[ref]});}return _react.default.createElement(ctor,validatedProps,children);}},{key:"validateProps",value:function validateProps(ctor){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var res={};if(ctor&&ctor.Inputs){res=(0,_Types.Resolver)(ctor.Inputs,props);}return _objectSpread({},props,{},res);}}]);return ModuleSystem;}();exports.default=ModuleSystem;
|