@smallstack/components
Advanced tools
Comparing version 0.1.22 to 0.1.23
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@smallstack/common"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","underscore"],t):t(e["@smallstack/common"]={},e["@smallstack/common"],e._)}(this,function(e,t,n){"use strict";!function(e){e[e.IN=0]="IN",e[e.OUT=1]="OUT"}(e.ComponentSocketDirection||(e.ComponentSocketDirection={})),function(e){e[e.NUMBER=0]="NUMBER",e[e.NUMBER_ARRAY=1]="NUMBER_ARRAY",e[e.STRING=2]="STRING",e[e.STRING_ARRAY=3]="STRING_ARRAY",e[e.BOOLEAN=4]="BOOLEAN",e[e.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",e[e.OBJECT=6]="OBJECT",e[e.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(e.ComponentSocketType||(e.ComponentSocketType={}));var o=function(){function t(){}return t.create=function(e,n,o,i){var r=new t;return r.name=e,r.direction=o,r.type=n,r.values=i,r},t.createInput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.IN,i)},t.createOutput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.OUT,i)},t.componentSocketTypeToString=function(t){switch(t){case e.ComponentSocketType.BOOLEAN:return"boolean";case e.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case e.ComponentSocketType.NUMBER:return"number";case e.ComponentSocketType.NUMBER_ARRAY:return"number[]";case e.ComponentSocketType.OBJECT:return"object";case e.ComponentSocketType.OBJECT_ARRAY:return"object[]";case e.ComponentSocketType.STRING:return"string";case e.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+t)},t}(),i=function(){function e(){this.components={}}return e.instance=function(){return t.IOC.get("componentsRegistry")},e.register=function(e,n){t.IOC.onRegister("componentsRegistry",function(t){t.register(e,n)})},e.prototype.register=function(e,n){t.Logger.info("ComponentsRegistry","Registered component: "+e),this.components[e]=n},e.prototype.getAllComponentNames=function(){return n.keys(this.components)},e.prototype.getAllComponents=function(){return n.values(this.components)},e.prototype.getComponentByName=function(e){var t=this.components[e];if(t)return t;throw new Error("ComponentsRegistry - Could not find component by name: "+e)},e.prototype.isRegistered=function(e){return void 0!==this.components[e]},e.prototype.getComponentsByType=function(e){return n.reject(this.components,function(t){return t.getType()!==e})},e.prototype.getComponentsByTypes=function(e){return n.filter(this.components,function(t){return-1!==e.indexOf(t.getType())})},e}(),r=function(){function e(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return e.instance=function(){return t.IOC.get("eventService")},e.prototype.addSocketConnection=function(e){t.Logger.debug("EventService","registering socket connection",e),this.socketConnections.push(e)},e.prototype.clearSocketConnections=function(e){void 0===e?(t.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(t.Logger.debug("EventService","clearing socket connections for componentId '"+e+"'"),this.socketConnections=n.reject(this.socketConnections,function(t){return t.sourceComponentInstanceId===e||t.targetComponentInstanceId===e}))},e.prototype.getSocketConnectionsBySource=function(e,t){return n.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===e&&n.sourceSocketName===t})},e.prototype.getSocketConnectionsByTarget=function(e,t){return n.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===e&&n.targetSocketName===t})},e.prototype.dispatchSocketEvent=function(e,n,o){for(var i=0,r=this.getSocketConnectionsBySource(e,n);i<r.length;i++){var c=r[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(c.targetComponentInstanceId,c.targetSocketName)]?this.sendSocketEvent(c.targetComponentInstanceId,c.targetSocketName,o):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+c.targetComponentInstanceId+"' and targetSocketName '"+c.targetSocketName+"'!")}},e.prototype.sendSocketEvent=function(e,n,o,i){void 0===i&&(i=!1);var r=this.getSocketConnectionIdentifier(e,n),c=this.socketConnectionCallbacks[r];c?c(o):i?(this.afterSocketRegistrationCallbacks[r]||(this.afterSocketRegistrationCallbacks[r]=[]),this.afterSocketRegistrationCallbacks[r].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+r+"'!")},e.prototype.watchSocketEvent=function(e,t,o){var i="dynamic-target-component-"+n.random(-1e4,1e4),r="dynamicAbsorber";this.registerSocketConnectionHandler(i,r,o),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:i,targetSocketName:r})},e.prototype.dispatchPageEvent=function(e,t){void 0!==this.pageEventCallbacks[e]&&n.each(this.pageEventCallbacks[e],function(e){e(t)})},e.prototype.registerSocketConnectionHandler=function(e,o,i){t.Logger.debug("EventService","Registering "+e+"->"+o);var r=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[r]=i,n.each(this.afterSocketRegistrationCallbacks[r],function(e){i(e)}),this.afterSocketRegistrationCallbacks[r]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var i=this;t.Logger.debug("EventService","Removing socket handler for "+e+"->"+(void 0!==o?o:"[ALL]")),n.each(this.socketConnectionCallbacks,function(t,n){void 0!==o&&n===i.getSocketConnectionIdentifier(e,o)&&delete i.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete i.socketConnectionCallbacks[n]})},e.prototype.registerPageEventHandler=function(e,t,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[e]||n)&&(this.pageEventCallbacks[e]=[]),this.pageEventCallbacks[e].push(t)},e.prototype.getSocketConnectionIdentifier=function(e,t){if(void 0===e)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===t)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return e+"_"+t},e}(),c=function(e,t,n,o){var i,r=arguments.length,c=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(c=(r<3?i(c):r>3?i(t,n,c):i(t,n))||c);return r>3&&c&&Object.defineProperty(t,n,c),c},a=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},s=function(){function n(){this.data={},this.initialized=!1}return n.getSockets=function(){return[]},n.getConfiguration=function(){return[]},n.getComponentName=function(){throw new Error("Please overload the static method BaseComponent.getComponentName(), name: "+this.name+", caller: "+JSON.stringify(this.caller))},n.register=function(){i.register(this.getComponentName(),this)},n.prototype.init=function(t){var n=this;if(this.initialized)throw new Error("Cannot initialize BaseComponentController twice!");if(t&&(t.componentId&&(this.componentId=t.componentId),t.data&&(this.data=t.data)),"function"==typeof this.getSockets)for(var o=function(t){t.direction===e.ComponentSocketDirection.IN&&r.instance().registerSocketConnectionHandler(i.componentId,t.name,function(e){n.onSocketEvent(t.name,e)})},i=this,c=0,a=this.getSockets();c<a.length;c++){o(a[c])}this.initialized=!0,"function"==typeof this.afterInitialization&&this.afterInitialization()},n.prototype.getData=function(e){if(this.data&&void 0!==this.data[e])return this.data[e]},n.prototype.sendOutput=function(e,n){t.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:e,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,e,n)},c([t.Autowired(),a("design:type",Object)],n.prototype,"notificationService",void 0),c([t.Autowired(),a("design:type",r)],n.prototype,"eventService",void 0),c([t.Autowired(),a("design:type",Object)],n.prototype,"dataBridge",void 0),n}(),p=function(){function e(){this.type=e.types.STRING}return e.createStringConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.STRING,o.defaultValue=n,o},e.createSelectConfiguration=function(t,n,o){var i=new e;return i.key=t,i.type=e.types.SELECT,i.defaultValue=n,i.possibleValues=o,i},e.createTextareaConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.TEXTAREA,o.defaultValue=n,o},e.createNumberConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.NUMBER,o.defaultValue=n,o},e.createObjectConfiguration=function(t,n){void 0===n&&(n={});var o=new e;return o.key=t,o.type=e.types.OBJECT,o.defaultValue=n,o},e.createBooleanConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.BOOLEAN,o.defaultValue=n,o},e.createI18nStringConfiguration=function(t,n){void 0===n&&(n={});var o=new e;return o.key=t,o.type=e.types.I18N,o.defaultValue=n,o},e.types={STRING:"string",BOOLEAN:"boolean",SELECT:"select",TEXTAREA:"textarea",NUMBER:"number",OBJECT:"object",I18N:"localizedtextarea",LIST:"list"},e}();!function(e){e[e.ANGULAR=0]="ANGULAR",e[e.REACT=1]="REACT",e[e.INVISIBLE=2]="INVISIBLE",e[e.CMS=3]="CMS"}(e.ComponentType||(e.ComponentType={})),e.BaseComponent=s,e.ComponentConfiguration=p,e.ComponentSocket=o,e.ComponentsRegistry=i,e.EventService=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@smallstack/common"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","underscore"],t):t(e["@smallstack/common"]={},e["@smallstack/common"],e._)}(this,function(e,t,n){"use strict";!function(e){e[e.IN=0]="IN",e[e.OUT=1]="OUT"}(e.ComponentSocketDirection||(e.ComponentSocketDirection={})),function(e){e[e.NUMBER=0]="NUMBER",e[e.NUMBER_ARRAY=1]="NUMBER_ARRAY",e[e.STRING=2]="STRING",e[e.STRING_ARRAY=3]="STRING_ARRAY",e[e.BOOLEAN=4]="BOOLEAN",e[e.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",e[e.OBJECT=6]="OBJECT",e[e.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(e.ComponentSocketType||(e.ComponentSocketType={}));var o=function(){function t(){}return t.create=function(e,n,o,i){var r=new t;return r.name=e,r.direction=o,r.type=n,r.values=i,r},t.createInput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.IN,i)},t.createOutput=function(n,o,i){return t.create(n,o,e.ComponentSocketDirection.OUT,i)},t.componentSocketTypeToString=function(t){switch(t){case e.ComponentSocketType.BOOLEAN:return"boolean";case e.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case e.ComponentSocketType.NUMBER:return"number";case e.ComponentSocketType.NUMBER_ARRAY:return"number[]";case e.ComponentSocketType.OBJECT:return"object";case e.ComponentSocketType.OBJECT_ARRAY:return"object[]";case e.ComponentSocketType.STRING:return"string";case e.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+t)},t}(),i=function(){function e(){this.components={}}return e.instance=function(){return t.IOC.get("componentsRegistry")},e.register=function(e,n){t.IOC.onRegister("componentsRegistry",function(t){t.register(e,n)})},e.prototype.register=function(e,n){t.Logger.debug("ComponentsRegistry","Registered component: "+e),this.components[e]=n},e.prototype.getAllComponentNames=function(){return n.keys(this.components)},e.prototype.getAllComponents=function(){return n.values(this.components)},e.prototype.getComponentByName=function(e){var t=this.components[e];if(t)return t;throw new Error("ComponentsRegistry - Could not find component by name: "+e)},e.prototype.isRegistered=function(e){return void 0!==this.components[e]},e.prototype.getComponentsByType=function(e){return n.reject(this.components,function(t){return t.getType()!==e})},e.prototype.getComponentsByTypes=function(e){return n.filter(this.components,function(t){return-1!==e.indexOf(t.getType())})},e}(),r=function(){function e(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return e.instance=function(){return t.IOC.get("eventService")},e.prototype.addSocketConnection=function(e){t.Logger.debug("EventService","registering socket connection",e),this.socketConnections.push(e)},e.prototype.clearSocketConnections=function(e){void 0===e?(t.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(t.Logger.debug("EventService","clearing socket connections for componentId '"+e+"'"),this.socketConnections=n.reject(this.socketConnections,function(t){return t.sourceComponentInstanceId===e||t.targetComponentInstanceId===e}))},e.prototype.getSocketConnectionsBySource=function(e,t){return n.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===e&&n.sourceSocketName===t})},e.prototype.getSocketConnectionsByTarget=function(e,t){return n.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===e&&n.targetSocketName===t})},e.prototype.dispatchSocketEvent=function(e,n,o){for(var i=0,r=this.getSocketConnectionsBySource(e,n);i<r.length;i++){var c=r[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(c.targetComponentInstanceId,c.targetSocketName)]?this.sendSocketEvent(c.targetComponentInstanceId,c.targetSocketName,o):t.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+c.targetComponentInstanceId+"' and targetSocketName '"+c.targetSocketName+"'!")}},e.prototype.sendSocketEvent=function(e,n,o,i){void 0===i&&(i=!1);var r=this.getSocketConnectionIdentifier(e,n),c=this.socketConnectionCallbacks[r];c?c(o):i?(this.afterSocketRegistrationCallbacks[r]||(this.afterSocketRegistrationCallbacks[r]=[]),this.afterSocketRegistrationCallbacks[r].push(o)):t.Logger.warning("EventService","No callback registered for socketIdentifier '"+r+"'!")},e.prototype.watchSocketEvent=function(e,t,o){var i="dynamic-target-component-"+n.random(-1e4,1e4),r="dynamicAbsorber";this.registerSocketConnectionHandler(i,r,o),this.addSocketConnection({sourceComponentInstanceId:e,sourceSocketName:t,targetComponentInstanceId:i,targetSocketName:r})},e.prototype.dispatchPageEvent=function(e,t){void 0!==this.pageEventCallbacks[e]&&n.each(this.pageEventCallbacks[e],function(e){e(t)})},e.prototype.registerSocketConnectionHandler=function(e,o,i){t.Logger.debug("EventService","Registering "+e+"->"+o);var r=this.getSocketConnectionIdentifier(e,o);this.socketConnectionCallbacks[r]=i,n.each(this.afterSocketRegistrationCallbacks[r],function(e){i(e)}),this.afterSocketRegistrationCallbacks[r]=[]},e.prototype.removeSocketConnectionHandler=function(e,o){var i=this;t.Logger.debug("EventService","Removing socket handler for "+e+"->"+(void 0!==o?o:"[ALL]")),n.each(this.socketConnectionCallbacks,function(t,n){void 0!==o&&n===i.getSocketConnectionIdentifier(e,o)&&delete i.socketConnectionCallbacks[n],void 0===o&&0===n.indexOf(e+"_")&&delete i.socketConnectionCallbacks[n]})},e.prototype.registerPageEventHandler=function(e,t,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[e]||n)&&(this.pageEventCallbacks[e]=[]),this.pageEventCallbacks[e].push(t)},e.prototype.getSocketConnectionIdentifier=function(e,t){if(void 0===e)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===t)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return e+"_"+t},e}(),c=function(e,t,n,o){var i,r=arguments.length,c=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(c=(r<3?i(c):r>3?i(t,n,c):i(t,n))||c);return r>3&&c&&Object.defineProperty(t,n,c),c},a=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},s=function(){function n(){this.data={},this.initialized=!1}return n.getSockets=function(){return[]},n.getConfiguration=function(){return[]},n.getComponentName=function(){throw new Error("Please overload the static method BaseComponent.getComponentName(), name: "+this.name+", caller: "+JSON.stringify(this.caller))},n.register=function(){i.register(this.getComponentName(),this)},n.prototype.init=function(t){var n=this;if(this.initialized)throw new Error("Cannot initialize BaseComponentController twice!");if(t&&(t.componentId&&(this.componentId=t.componentId),t.data&&(this.data=t.data)),"function"==typeof this.getSockets)for(var o=function(t){t.direction===e.ComponentSocketDirection.IN&&r.instance().registerSocketConnectionHandler(i.componentId,t.name,function(e){n.onSocketEvent(t.name,e)})},i=this,c=0,a=this.getSockets();c<a.length;c++){o(a[c])}this.initialized=!0,"function"==typeof this.afterInitialization&&this.afterInitialization()},n.prototype.getData=function(e){if(this.data&&void 0!==this.data[e])return this.data[e]},n.prototype.sendOutput=function(e,n){t.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:e,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,e,n)},c([t.Autowired(),a("design:type",Object)],n.prototype,"notificationService",void 0),c([t.Autowired(),a("design:type",r)],n.prototype,"eventService",void 0),c([t.Autowired(),a("design:type",Object)],n.prototype,"dataBridge",void 0),n}(),p=function(){function e(){this.type=e.types.STRING}return e.createStringConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.STRING,o.defaultValue=n,o},e.createSelectConfiguration=function(t,n,o){var i=new e;return i.key=t,i.type=e.types.SELECT,i.defaultValue=n,i.possibleValues=o,i},e.createTextareaConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.TEXTAREA,o.defaultValue=n,o},e.createNumberConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.NUMBER,o.defaultValue=n,o},e.createObjectConfiguration=function(t,n){void 0===n&&(n={});var o=new e;return o.key=t,o.type=e.types.OBJECT,o.defaultValue=n,o},e.createBooleanConfiguration=function(t,n){var o=new e;return o.key=t,o.type=e.types.BOOLEAN,o.defaultValue=n,o},e.createI18nStringConfiguration=function(t,n){void 0===n&&(n={});var o=new e;return o.key=t,o.type=e.types.I18N,o.defaultValue=n,o},e.types={STRING:"string",BOOLEAN:"boolean",SELECT:"select",TEXTAREA:"textarea",NUMBER:"number",OBJECT:"object",I18N:"localizedtextarea",LIST:"list"},e}();!function(e){e[e.ANGULAR=0]="ANGULAR",e[e.REACT=1]="REACT",e[e.INVISIBLE=2]="INVISIBLE",e[e.CMS=3]="CMS"}(e.ComponentType||(e.ComponentType={})),e.BaseComponent=s,e.ComponentConfiguration=p,e.ComponentSocket=o,e.ComponentsRegistry=i,e.EventService=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@smallstack/components", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"description": "Base functionality for smallstack components", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle/index.umd.js", |
Sorry, the diff of this file is not supported yet