awv3
Version:
AWV client CAD framework
1 lines • 3.25 kB
JavaScript
;function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}exports.__esModule=!0;var _regenerator=require("babel-runtime/regenerator"),_regenerator2=_interopRequireDefault(_regenerator),_keys=require("babel-runtime/core-js/object/keys"),_keys2=_interopRequireDefault(_keys),_promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_asyncToGenerator2=require("babel-runtime/helpers/asyncToGenerator"),_asyncToGenerator3=_interopRequireDefault(_asyncToGenerator2),_extends3=require("babel-runtime/helpers/extends"),_extends4=_interopRequireDefault(_extends3),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_plugin=require("../plugin"),Integration=function(){function e(t){if((0,_classCallCheck3.default)(this,e),this.options=(0,_extends4.default)({view:void 0,socket:void 0,enabled:!0,style:"position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; display: none;"},t),!this.options.view)throw"Integration needs a view passed in: new Integration({ view: ... })!";this.plugins={},this.active=void 0,this.dialogs={default:void 0},this.view=this.options.view,this.canvas=this.view.canvas,this.dom=document.createElement("div"),this.dom.style.cssText=this.options.style,this.view.dom.appendChild(this.dom),this.enabled=this.options.enabled,this.enabled&&this.enable()}return e.prototype.destroy=function(){function e(){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(){var t=this;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_promise2.default.all((0,_keys2.default)(this.plugins).map(function(e){return t.plugins[e].destroy()}));case 2:this.plugins={},this.view.dom.removeChild(this.dom);case 4:case"end":return e.stop()}},e,this)}));return e}(),e.prototype.use=function(){for(var e=this,t=arguments.length,i=Array(t),n=0;n<t;n++)i[n]=arguments[n];i.forEach(function(t){var i,n;t.integration=e,t.on((i={},i[_plugin.Plugin.Events.Destroyed]=function(){t.removeListeners(),delete e.plugins[t.name]},i[_plugin.Plugin.Events.Enabled]=function(){e.active&&e.active!==t&&e.active.disable(),e.active=t},i[_plugin.Plugin.Events.Disabled]=function(){e.active===t&&(e.active=void 0,e.dialogs.default=void 0)},i[_plugin.Plugin.Events.RequestDialog]=function(t){return e.showDialog(t)},i)),e.plugins=(0,_extends4.default)({},e.plugins,(n={},n[t.name]=t,n))})},e.prototype.showDialog=function(e){this.dialogs.default=e},e.prototype.show=function(){this.dom.style.display="visible"},e.prototype.hide=function(){this.dom.style.display="none"},e.prototype.enable=function(){this.enabled=!0,this.show()},e.prototype.disable=function(){function e(){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(){var t=this;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.enabled=!1,e.next=3,_promise2.default.all((0,_keys2.default)(this.plugins).map(function(e){return t.plugins[e].disable()}));case 3:this.hide();case 4:case"end":return e.stop()}},e,this)}));return e}(),e}();exports.default=Integration;