@smallstack/components
Advanced tools
Comparing version 0.3.14 to 0.3.15
@@ -18,5 +18,9 @@ export declare enum ComponentSocketDirection { | ||
static createInput(name: string, type: ComponentSocketType, values?: any[]): ComponentSocket; | ||
static createInputs(names: string[], type: ComponentSocketType, values?: any[]): ComponentSocket[]; | ||
static createInputs(namesObject: { | ||
[socketName: string]: string; | ||
}, type: ComponentSocketType, values?: any[]): ComponentSocket[]; | ||
static createOutput(name: string, type: ComponentSocketType, values?: any[]): ComponentSocket; | ||
static createOutputs(names: string[], type: ComponentSocketType, values?: any[]): ComponentSocket[]; | ||
static createOutputs(namesObject: { | ||
[socketName: string]: string; | ||
}, type: ComponentSocketType, values?: any[]): ComponentSocket[]; | ||
static componentSocketTypeToString(type: ComponentSocketType): string; | ||
@@ -23,0 +27,0 @@ name: string; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@smallstack/common"),require("@smallstack/i18n"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","@smallstack/i18n","underscore"],e):e(t["@smallstack/common"]={},t["@smallstack/common"],t.i18n,t._)}(this,function(t,e,n,o){"use strict";function i(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),e.IOC.onRegister("typesystem",function(n){!0===t.registerTypes&&n.addType(e.Type.fromDocument({model:{name:"ComponentInstance",schema:[{name:"name",type:"string"},{name:"children",type:"ComponentInstance[]",optional:!0,defaultValue:[]},{name:"data",type:"any",optional:!0}]},packageName:"@smallstack/components"})),!0===t.registerModels&&e.IOC.register("ComponentInstance",l)})}!function(t){t[t.IN=0]="IN",t[t.OUT=1]="OUT"}(t.ComponentSocketDirection||(t.ComponentSocketDirection={})),function(t){t[t.NUMBER=0]="NUMBER",t[t.NUMBER_ARRAY=1]="NUMBER_ARRAY",t[t.STRING=2]="STRING",t[t.STRING_ARRAY=3]="STRING_ARRAY",t[t.BOOLEAN=4]="BOOLEAN",t[t.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",t[t.OBJECT=6]="OBJECT",t[t.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(t.ComponentSocketType||(t.ComponentSocketType={}));var r=function(){function e(){}return e.create=function(t,n,o,i){var r=new e;return r.name=t,r.direction=o,r.type=n,r.values=i,r},e.createInput=function(n,o,i){return e.create(n,o,t.ComponentSocketDirection.IN,i)},e.createInputs=function(n,o,i){for(var r=[],c=0,a=n;c<a.length;c++){var s=a[c];r.push(e.create(s,o,t.ComponentSocketDirection.IN,i))}return r},e.createOutput=function(n,o,i){return e.create(n,o,t.ComponentSocketDirection.OUT,i)},e.createOutputs=function(n,o,i){for(var r=[],c=0,a=n;c<a.length;c++){var s=a[c];r.push(e.create(s,o,t.ComponentSocketDirection.IN,i))}return r},e.componentSocketTypeToString=function(e){switch(e){case t.ComponentSocketType.BOOLEAN:return"boolean";case t.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case t.ComponentSocketType.NUMBER:return"number";case t.ComponentSocketType.NUMBER_ARRAY:return"number[]";case t.ComponentSocketType.OBJECT:return"object";case t.ComponentSocketType.OBJECT_ARRAY:return"object[]";case t.ComponentSocketType.STRING:return"string";case t.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+e)},e}(),c=function(){function t(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return t.instance=function(){return e.IOC.get("eventService")},t.prototype.addSocketConnection=function(t){e.Logger.debug("EventService","registering socket connection",t),this.socketConnections.push(t)},t.prototype.clearSocketConnections=function(t){void 0===t?(e.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(e.Logger.debug("EventService","clearing socket connections for componentId '"+t+"'"),this.socketConnections=o.reject(this.socketConnections,function(e){return e.sourceComponentInstanceId===t||e.targetComponentInstanceId===t}))},t.prototype.getSocketConnectionsBySource=function(t,e){return o.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===t&&n.sourceSocketName===e})},t.prototype.getSocketConnectionsByTarget=function(t,e){return o.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===t&&n.targetSocketName===e})},t.prototype.dispatchSocketEvent=function(t,n,o){for(var i=0,r=this.getSocketConnectionsBySource(t,n);i<r.length;i++){var c=r[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(c.targetComponentInstanceId,c.targetSocketName)]?this.sendSocketEvent(c.targetComponentInstanceId,c.targetSocketName,o):e.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+c.targetComponentInstanceId+"' and targetSocketName '"+c.targetSocketName+"'!")}},t.prototype.sendSocketEvent=function(t,n,o,i){void 0===i&&(i=!1);var r=this.getSocketConnectionIdentifier(t,n),c=this.socketConnectionCallbacks[r];c?c(o):i?(this.afterSocketRegistrationCallbacks[r]||(this.afterSocketRegistrationCallbacks[r]=[]),this.afterSocketRegistrationCallbacks[r].push(o)):e.Logger.warning("EventService","No callback registered for socketIdentifier '"+r+"'!")},t.prototype.watchSocketEvent=function(t,e,n){var i="dynamic-target-component-"+o.random(-1e4,1e4),r="dynamicAbsorber";this.registerSocketConnectionHandler(i,r,n),this.addSocketConnection({sourceComponentInstanceId:t,sourceSocketName:e,targetComponentInstanceId:i,targetSocketName:r})},t.prototype.dispatchPageEvent=function(t,e){void 0!==this.pageEventCallbacks[t]&&o.each(this.pageEventCallbacks[t],function(t){t(e)})},t.prototype.registerSocketConnectionHandler=function(t,n,i){e.Logger.debug("EventService","Registering "+t+"->"+n);var r=this.getSocketConnectionIdentifier(t,n);this.socketConnectionCallbacks[r]=i,o.each(this.afterSocketRegistrationCallbacks[r],function(t){i(t)}),this.afterSocketRegistrationCallbacks[r]=[]},t.prototype.removeSocketConnectionHandler=function(t,n){var i=this;e.Logger.debug("EventService","Removing socket handler for "+t+"->"+(void 0!==n?n:"[ALL]")),o.each(this.socketConnectionCallbacks,function(e,o){void 0!==n&&o===i.getSocketConnectionIdentifier(t,n)&&delete i.socketConnectionCallbacks[o],void 0===n&&0===o.indexOf(t+"_")&&delete i.socketConnectionCallbacks[o]})},t.prototype.registerPageEventHandler=function(t,e,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[t]||n)&&(this.pageEventCallbacks[t]=[]),this.pageEventCallbacks[t].push(e)},t.prototype.getSocketConnectionIdentifier=function(t,e){if(void 0===t)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===e)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return t+"_"+e},t}(),a=function(t,e,n,o){var i,r=arguments.length,c=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(c=(r<3?i(c):r>3?i(e,n,c):i(e,n))||c);return r>3&&c&&Object.defineProperty(e,n,c),c},s=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},p=function(){function o(){this.data={},this.initialized=!1}return o.prototype.init=function(n){var o=this;if(this.initialized&&e.Logger.warning("BaseComponent","Initializing BaseComponentController twice!"),n&&(n.componentId&&(this.componentId=n.componentId),n.data&&(this.data=n.data)),this.componentSockets instanceof Array&&this.componentSockets.length>0)for(var i=function(e){e.direction===t.ComponentSocketDirection.IN&&c.instance().registerSocketConnectionHandler(r.componentId,e.name,function(t){o.onSocketEvent(e.name,t)})},r=this,a=0,s=this.componentSockets;a<s.length;a++){i(s[a])}this.initialized=!0,"function"==typeof this.afterInitialization?(e.Logger.info("BaseComponent","Executing afterInitialization method!"),this.afterInitialization()):e.Logger.warning("BaseComponent","No afterInitialization method found!"),e.Logger.info("BaseComponent","Initialized component : "+this.getComponentName()+"["+this.componentId+"]")},o.prototype.getData=function(t){if(this.data&&void 0!==this.data[t])return this.data[t]},o.prototype.sendOutput=function(t,n){e.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:t,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,t,n)},o.prototype.t=function(t,e){return this.localizationService.t(t,e)},o.prototype.getComponentSockets=function(){return this.constructor.componentSockets},o.prototype.getComponentName=function(){return this.constructor.componentName},o.prototype.getComponentConfigurations=function(){return this.constructor.componentConfigurations},a([e.Autowired(),s("design:type",Object)],o.prototype,"notificationService",void 0),a([e.Autowired(),s("design:type",c)],o.prototype,"eventService",void 0),a([e.Autowired(),s("design:type",Object)],o.prototype,"dataBridge",void 0),a([e.Autowired(),s("design:type",n.LocalizationService)],o.prototype,"localizationService",void 0),o}(),u=function(){function t(){this.components={}}return t.instance=function(){return e.IOC.get("componentsRegistry")},t.register=function(t,n){e.IOC.onRegister("componentsRegistry",function(e){e.register(t,n)})},t.prototype.register=function(t,n){e.Logger.debug("ComponentsRegistry","Registered component: "+t),this.components[t]=n},t.prototype.getAllComponentNames=function(){return o.keys(this.components)},t.prototype.getAllComponents=function(){return o.values(this.components)},t.prototype.getComponentByName=function(t){var e=this.components[t];if(e)return e;throw new Error("ComponentsRegistry - Could not find component by name: "+t)},t.prototype.isRegistered=function(t){return void 0!==this.components[t]},t.prototype.getComponentsByType=function(t){return o.reject(this.components,function(e){return e.getType()!==t})},t.prototype.getComponentsByTypes=function(t){return o.filter(this.components,function(e){return-1!==t.indexOf(e.getType())})},t}();!function(t){t[t.ANGULAR=0]="ANGULAR",t[t.REACT=1]="REACT",t[t.INVISIBLE=2]="INVISIBLE",t[t.CMS=3]="CMS"}(t.ComponentType||(t.ComponentType={}));var f=function(t,e,n,o){var i,r=arguments.length,c=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(c=(r<3?i(c):r>3?i(e,n,c):i(e,n))||c);return r>3&&c&&Object.defineProperty(e,n,c),c},m=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},d=function(){function t(){this.children=[],this._hasSubDocuments=!1,this._isStored=!1}return t.fromDocument=function(t){if(void 0===t||null===t)throw new Error("doc cannot be undefined/null while calling GeneratedComponentInstance.fromDocument(doc)!");var e=new l;return void 0!==t._id&&(e._isStored=!0,e._id=t._id),void 0!==t.name&&(e.name=t.name),t.children instanceof Array&&(e.children=[],o.each(t.children,function(t){e.children.push(l.fromDocument(t))})),void 0!==t.data&&(e.data=t.data),e},t.prototype.toDocument=function(){var t={};return t.name=this.name,t.children=[],o.each(this.children,function(e){"function"==typeof e.toDocument?t.children.push(e.toDocument()):t.children.push(e)}),t.data=this.data,this.isStored()&&(t._id=this._id),JSON.parse(JSON.stringify(t))},t.prototype.clone=function(){return l.fromDocument(this.toDocument())},t.prototype.saveSnapshot=function(){this._snapshot=this.toDocument()},t.prototype.restoreSnapshot=function(){if(!this._snapshot)throw new Error("Could not restore snapshot of model since no snapshot was saved before!");o.extend(this,this._snapshot)},t.prototype.hasSubDocuments=function(){return this._hasSubDocuments},t.prototype.isStored=function(){return this._isStored},t.getModelName=function(){return"ComponentInstance"},t.prototype.getModelName=function(){return"ComponentInstance"},t.prototype.getForeignLabel=function(){return this.getModelName()+" ID:"+this._id},t.getModelClass=function(){return e.IOC.get("ComponentInstance")},t.prototype.getModelClass=function(){return e.IOC.get("ComponentInstance")},t.asType=function(){return e.Typesystem.instance().getTypeByModelName("ComponentInstance")},f([e.Autowired(),m("design:type",Object)],t.prototype,"dataBridge",void 0),t}(),g=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return g(e,t),e}(d);t.BaseComponent=p,t.ComponentConfiguration=function(n){return function(o,i){if(n){if(!n.componentName)throw new Error("No componentName given in @ComponentConfiguration decorator!");if(!new RegExp(/^[A-Z]{1}[a-zA-Z]{3,}$/g).test(n.componentName))throw new Error("ComponentName must start with a capital letter, has to be at least 4 characters long and can only contain characters, got: "+n.componentName);if(o.componentName=n.componentName,e.IOC.onRegister("componentsRegistry",function(t){t.register(n.componentName,o)}),n.sockets||(n.sockets=[]),o.componentSockets=n.sockets,"function"==typeof o.prototype.setComponentSockets&&o.prototype.setComponentSockets(n.sockets),n.configurations||(n.configurations=[]),o.componentConfigurations=n.configurations,n.navigation instanceof Array&&n.navigation.length>0&&e.IOC.onRegister("navigationService",function(t){for(var e=0,i=n.navigation;e<i.length;e++){var r=i[e];void 0===r.getComponent()&&r.setComponent(o),t.addNavigationEntry(r)}}),void 0!==o.__annotations__&&o.__annotations__ instanceof Array&&o.__annotations__.length>0)for(var r=0,c=o.__annotations__;r<c.length;r++){var a=c[r];if(a&&"Component"===a.ngMetadataName){if(n.sockets instanceof Array&&n.sockets.length>0){void 0===a.inputs&&(a.inputs=[]),void 0===a.outputs&&(a.outputs=[]);for(var s=0,p=n.sockets;s<p.length;s++){var u=p[s];u.direction===t.ComponentSocketDirection.IN?a.inputs.push("sockets_input_"+u.name+":"+u.name):u.direction===t.ComponentSocketDirection.OUT&&a.outputs.push("sockets_output_"+u.name+":"+u.name)}}void 0===a.selector&&(a.selector=n.componentName)}}}else e.Logger.warning("ComponentConfiguration","No options given!")}},t.ComponentSocket=r,t.ComponentsRegistry=u,t.EventService=c,t.initComponentsPackage=function(){e.IOC.register("eventService",new c),e.IOC.register("componentsRegistry",new u)},t.initializeSmallstackComponentsPackage=function(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),i(t)},t.initializeComponentInstances=i,t.ComponentInstance=l,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@smallstack/common"),require("@smallstack/i18n"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","@smallstack/i18n","underscore"],e):e(t["@smallstack/common"]={},t["@smallstack/common"],t.i18n,t._)}(this,function(t,e,n,o){"use strict";function i(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),e.IOC.onRegister("typesystem",function(n){!0===t.registerTypes&&n.addType(e.Type.fromDocument({model:{name:"ComponentInstance",schema:[{name:"name",type:"string"},{name:"children",type:"ComponentInstance[]",optional:!0,defaultValue:[]},{name:"data",type:"any",optional:!0}]},packageName:"@smallstack/components"})),!0===t.registerModels&&e.IOC.register("ComponentInstance",l)})}!function(t){t[t.IN=0]="IN",t[t.OUT=1]="OUT"}(t.ComponentSocketDirection||(t.ComponentSocketDirection={})),function(t){t[t.NUMBER=0]="NUMBER",t[t.NUMBER_ARRAY=1]="NUMBER_ARRAY",t[t.STRING=2]="STRING",t[t.STRING_ARRAY=3]="STRING_ARRAY",t[t.BOOLEAN=4]="BOOLEAN",t[t.BOOLEAN_ARRAY=5]="BOOLEAN_ARRAY",t[t.OBJECT=6]="OBJECT",t[t.OBJECT_ARRAY=7]="OBJECT_ARRAY"}(t.ComponentSocketType||(t.ComponentSocketType={}));var r=function(){function e(){}return e.create=function(t,n,o,i){var r=new e;return r.name=t,r.direction=o,r.type=n,r.values=i,r},e.createInput=function(n,o,i){return e.create(n,o,t.ComponentSocketDirection.IN,i)},e.createInputs=function(n,i,r){for(var c=[],a=0,s=o.values(n);a<s.length;a++){var p=s[a];c.push(e.create(p,i,t.ComponentSocketDirection.IN,r))}return c},e.createOutput=function(n,o,i){return e.create(n,o,t.ComponentSocketDirection.OUT,i)},e.createOutputs=function(n,i,r){for(var c=[],a=0,s=o.values(n);a<s.length;a++){var p=s[a];c.push(e.create(p,i,t.ComponentSocketDirection.IN,r))}return c},e.componentSocketTypeToString=function(e){switch(e){case t.ComponentSocketType.BOOLEAN:return"boolean";case t.ComponentSocketType.BOOLEAN_ARRAY:return"boolean[]";case t.ComponentSocketType.NUMBER:return"number";case t.ComponentSocketType.NUMBER_ARRAY:return"number[]";case t.ComponentSocketType.OBJECT:return"object";case t.ComponentSocketType.OBJECT_ARRAY:return"object[]";case t.ComponentSocketType.STRING:return"string";case t.ComponentSocketType.STRING_ARRAY:return"string[]"}throw new Error("UNKNOWN TYPE: "+e)},e}(),c=function(){function t(){this.socketConnections=[],this.socketConnectionCallbacks={},this.afterSocketRegistrationCallbacks={},this.pageEventCallbacks={}}return t.instance=function(){return e.IOC.get("eventService")},t.prototype.addSocketConnection=function(t){e.Logger.debug("EventService","registering socket connection",t),this.socketConnections.push(t)},t.prototype.clearSocketConnections=function(t){void 0===t?(e.Logger.debug("EventService","clearing all socket connections"),this.socketConnections=[]):(e.Logger.debug("EventService","clearing socket connections for componentId '"+t+"'"),this.socketConnections=o.reject(this.socketConnections,function(e){return e.sourceComponentInstanceId===t||e.targetComponentInstanceId===t}))},t.prototype.getSocketConnectionsBySource=function(t,e){return o.filter(this.socketConnections,function(n){return n.sourceComponentInstanceId===t&&n.sourceSocketName===e})},t.prototype.getSocketConnectionsByTarget=function(t,e){return o.filter(this.socketConnections,function(n){return n.targetComponentInstanceId===t&&n.targetSocketName===e})},t.prototype.dispatchSocketEvent=function(t,n,o){for(var i=0,r=this.getSocketConnectionsBySource(t,n);i<r.length;i++){var c=r[i];this.socketConnectionCallbacks[this.getSocketConnectionIdentifier(c.targetComponentInstanceId,c.targetSocketName)]?this.sendSocketEvent(c.targetComponentInstanceId,c.targetSocketName,o):e.Logger.error("EventService","Could not find socket event callback for targetComponentInstanceId '"+c.targetComponentInstanceId+"' and targetSocketName '"+c.targetSocketName+"'!")}},t.prototype.sendSocketEvent=function(t,n,o,i){void 0===i&&(i=!1);var r=this.getSocketConnectionIdentifier(t,n),c=this.socketConnectionCallbacks[r];c?c(o):i?(this.afterSocketRegistrationCallbacks[r]||(this.afterSocketRegistrationCallbacks[r]=[]),this.afterSocketRegistrationCallbacks[r].push(o)):e.Logger.warning("EventService","No callback registered for socketIdentifier '"+r+"'!")},t.prototype.watchSocketEvent=function(t,e,n){var i="dynamic-target-component-"+o.random(-1e4,1e4),r="dynamicAbsorber";this.registerSocketConnectionHandler(i,r,n),this.addSocketConnection({sourceComponentInstanceId:t,sourceSocketName:e,targetComponentInstanceId:i,targetSocketName:r})},t.prototype.dispatchPageEvent=function(t,e){void 0!==this.pageEventCallbacks[t]&&o.each(this.pageEventCallbacks[t],function(t){t(e)})},t.prototype.registerSocketConnectionHandler=function(t,n,i){e.Logger.debug("EventService","Registering "+t+"->"+n);var r=this.getSocketConnectionIdentifier(t,n);this.socketConnectionCallbacks[r]=i,o.each(this.afterSocketRegistrationCallbacks[r],function(t){i(t)}),this.afterSocketRegistrationCallbacks[r]=[]},t.prototype.removeSocketConnectionHandler=function(t,n){var i=this;e.Logger.debug("EventService","Removing socket handler for "+t+"->"+(void 0!==n?n:"[ALL]")),o.each(this.socketConnectionCallbacks,function(e,o){void 0!==n&&o===i.getSocketConnectionIdentifier(t,n)&&delete i.socketConnectionCallbacks[o],void 0===n&&0===o.indexOf(t+"_")&&delete i.socketConnectionCallbacks[o]})},t.prototype.registerPageEventHandler=function(t,e,n){void 0===n&&(n=!1),(void 0===this.pageEventCallbacks[t]||n)&&(this.pageEventCallbacks[t]=[]),this.pageEventCallbacks[t].push(e)},t.prototype.getSocketConnectionIdentifier=function(t,e){if(void 0===t)throw new Error("componentInstanceId is undefined while creating SocketConnectionIdentifier!");if(void 0===e)throw new Error("socketName is undefined while creating SocketConnectionIdentifier!");return t+"_"+e},t}(),a=function(t,e,n,o){var i,r=arguments.length,c=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(c=(r<3?i(c):r>3?i(e,n,c):i(e,n))||c);return r>3&&c&&Object.defineProperty(e,n,c),c},s=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},p=function(){function o(){this.data={},this.initialized=!1}return o.prototype.init=function(n){var o=this;if(this.initialized&&e.Logger.warning("BaseComponent","Initializing BaseComponentController twice!"),n&&(n.componentId&&(this.componentId=n.componentId),n.data&&(this.data=n.data)),this.componentSockets instanceof Array&&this.componentSockets.length>0)for(var i=function(e){e.direction===t.ComponentSocketDirection.IN&&c.instance().registerSocketConnectionHandler(r.componentId,e.name,function(t){o.onSocketEvent(e.name,t)})},r=this,a=0,s=this.componentSockets;a<s.length;a++){i(s[a])}this.initialized=!0,"function"==typeof this.afterInitialization?(e.Logger.info("BaseComponent","Executing afterInitialization method!"),this.afterInitialization()):e.Logger.warning("BaseComponent","No afterInitialization method found!"),e.Logger.info("BaseComponent","Initialized component : "+this.getComponentName()+"["+this.componentId+"]")},o.prototype.getData=function(t){if(this.data&&void 0!==this.data[t])return this.data[t]},o.prototype.sendOutput=function(t,n){e.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentId,socketName:t,socketData:n}),this.eventService.dispatchSocketEvent(this.componentId,t,n)},o.prototype.t=function(t,e){return this.localizationService.t(t,e)},o.prototype.getComponentSockets=function(){return this.constructor.componentSockets},o.prototype.getComponentName=function(){return this.constructor.componentName},o.prototype.getComponentConfigurations=function(){return this.constructor.componentConfigurations},a([e.Autowired(),s("design:type",Object)],o.prototype,"notificationService",void 0),a([e.Autowired(),s("design:type",c)],o.prototype,"eventService",void 0),a([e.Autowired(),s("design:type",Object)],o.prototype,"dataBridge",void 0),a([e.Autowired(),s("design:type",n.LocalizationService)],o.prototype,"localizationService",void 0),o}(),u=function(){function t(){this.components={}}return t.instance=function(){return e.IOC.get("componentsRegistry")},t.register=function(t,n){e.IOC.onRegister("componentsRegistry",function(e){e.register(t,n)})},t.prototype.register=function(t,n){e.Logger.debug("ComponentsRegistry","Registered component: "+t),this.components[t]=n},t.prototype.getAllComponentNames=function(){return o.keys(this.components)},t.prototype.getAllComponents=function(){return o.values(this.components)},t.prototype.getComponentByName=function(t){var e=this.components[t];if(e)return e;throw new Error("ComponentsRegistry - Could not find component by name: "+t)},t.prototype.isRegistered=function(t){return void 0!==this.components[t]},t.prototype.getComponentsByType=function(t){return o.reject(this.components,function(e){return e.getType()!==t})},t.prototype.getComponentsByTypes=function(t){return o.filter(this.components,function(e){return-1!==t.indexOf(e.getType())})},t}();!function(t){t[t.ANGULAR=0]="ANGULAR",t[t.REACT=1]="REACT",t[t.INVISIBLE=2]="INVISIBLE",t[t.CMS=3]="CMS"}(t.ComponentType||(t.ComponentType={}));var f=function(t,e,n,o){var i,r=arguments.length,c=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(c=(r<3?i(c):r>3?i(e,n,c):i(e,n))||c);return r>3&&c&&Object.defineProperty(e,n,c),c},m=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},d=function(){function t(){this.children=[],this._hasSubDocuments=!1,this._isStored=!1}return t.fromDocument=function(t){if(void 0===t||null===t)throw new Error("doc cannot be undefined/null while calling GeneratedComponentInstance.fromDocument(doc)!");var e=new l;return void 0!==t._id&&(e._isStored=!0,e._id=t._id),void 0!==t.name&&(e.name=t.name),t.children instanceof Array&&(e.children=[],o.each(t.children,function(t){e.children.push(l.fromDocument(t))})),void 0!==t.data&&(e.data=t.data),e},t.prototype.toDocument=function(){var t={};return t.name=this.name,t.children=[],o.each(this.children,function(e){"function"==typeof e.toDocument?t.children.push(e.toDocument()):t.children.push(e)}),t.data=this.data,this.isStored()&&(t._id=this._id),JSON.parse(JSON.stringify(t))},t.prototype.clone=function(){return l.fromDocument(this.toDocument())},t.prototype.saveSnapshot=function(){this._snapshot=this.toDocument()},t.prototype.restoreSnapshot=function(){if(!this._snapshot)throw new Error("Could not restore snapshot of model since no snapshot was saved before!");o.extend(this,this._snapshot)},t.prototype.hasSubDocuments=function(){return this._hasSubDocuments},t.prototype.isStored=function(){return this._isStored},t.getModelName=function(){return"ComponentInstance"},t.prototype.getModelName=function(){return"ComponentInstance"},t.prototype.getForeignLabel=function(){return this.getModelName()+" ID:"+this._id},t.getModelClass=function(){return e.IOC.get("ComponentInstance")},t.prototype.getModelClass=function(){return e.IOC.get("ComponentInstance")},t.asType=function(){return e.Typesystem.instance().getTypeByModelName("ComponentInstance")},f([e.Autowired(),m("design:type",Object)],t.prototype,"dataBridge",void 0),t}(),g=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return g(e,t),e}(d);t.BaseComponent=p,t.ComponentConfiguration=function(n){return function(o,i){if(n){if(!n.componentName)throw new Error("No componentName given in @ComponentConfiguration decorator!");if(!new RegExp(/^[A-Z]{1}[a-zA-Z]{3,}$/g).test(n.componentName))throw new Error("ComponentName must start with a capital letter, has to be at least 4 characters long and can only contain characters, got: "+n.componentName);if(o.componentName=n.componentName,e.IOC.onRegister("componentsRegistry",function(t){t.register(n.componentName,o)}),n.sockets||(n.sockets=[]),o.componentSockets=n.sockets,"function"==typeof o.prototype.setComponentSockets&&o.prototype.setComponentSockets(n.sockets),n.configurations||(n.configurations=[]),o.componentConfigurations=n.configurations,n.navigation instanceof Array&&n.navigation.length>0&&e.IOC.onRegister("navigationService",function(t){for(var e=0,i=n.navigation;e<i.length;e++){var r=i[e];void 0===r.getComponent()&&r.setComponent(o),t.addNavigationEntry(r)}}),void 0!==o.__annotations__&&o.__annotations__ instanceof Array&&o.__annotations__.length>0)for(var r=0,c=o.__annotations__;r<c.length;r++){var a=c[r];if(a&&"Component"===a.ngMetadataName){if(n.sockets instanceof Array&&n.sockets.length>0){void 0===a.inputs&&(a.inputs=[]),void 0===a.outputs&&(a.outputs=[]);for(var s=0,p=n.sockets;s<p.length;s++){var u=p[s];u.direction===t.ComponentSocketDirection.IN?a.inputs.push("sockets_input_"+u.name+":"+u.name):u.direction===t.ComponentSocketDirection.OUT&&a.outputs.push("sockets_output_"+u.name+":"+u.name)}}void 0===a.selector&&(a.selector=n.componentName)}}}else e.Logger.warning("ComponentConfiguration","No options given!")}},t.ComponentSocket=r,t.ComponentsRegistry=u,t.EventService=c,t.initComponentsPackage=function(){e.IOC.register("eventService",new c),e.IOC.register("componentsRegistry",new u)},t.initializeSmallstackComponentsPackage=function(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),i(t)},t.initializeComponentInstances=i,t.ComponentInstance=l,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@smallstack/components", | ||
"version": "0.3.14", | ||
"version": "0.3.15", | ||
"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
71762
322