@smallstack/components
Advanced tools
Comparing version 0.3.22 to 0.3.23
@@ -1,5 +0,9 @@ | ||
import { ConfigurationField, DataBridge, NotificationService } from "@smallstack/common"; | ||
import { ConfigurationField } from "@smallstack/common"; | ||
import { EventService, EventSocket } from "@smallstack/events"; | ||
import { LocalizationOptions, LocalizationService } from "@smallstack/i18n"; | ||
import { ComponentInitOptions } from "./ComponentInitOptions"; | ||
import { BehaviorSubject } from "rxjs"; | ||
import { ComponentInstance } from "./types/models/ComponentInstance"; | ||
export declare enum ComponentRenderMode { | ||
VIEW = "view", | ||
EDITABLE = "editable", | ||
} | ||
export declare class BaseComponent { | ||
@@ -18,18 +22,13 @@ /** | ||
static componentConfigurations: ConfigurationField[]; | ||
/** | ||
* The componentId property will get filled by the @ComponentConfiguration annotation during class creation | ||
*/ | ||
componentId: string; | ||
protected notificationService: NotificationService; | ||
componentInstance$: BehaviorSubject<ComponentInstance>; | ||
componentInstance: ComponentInstance; | ||
renderMode: ComponentRenderMode; | ||
renderMode$: BehaviorSubject<ComponentRenderMode>; | ||
protected eventService: EventService; | ||
protected dataBridge: DataBridge; | ||
protected localizationService: LocalizationService; | ||
protected data: { | ||
[key: string]: any; | ||
}; | ||
private initialized; | ||
init(options?: ComponentInitOptions): void; | ||
constructor(); | ||
init(componentInstance: ComponentInstance): void; | ||
getData(key: string): any; | ||
setData(key: string, value: any): void; | ||
sendOutput(socketName: string, socketData: any): void; | ||
t(key: string, options?: LocalizationOptions): string; | ||
protected getComponentSockets(): EventSocket[]; | ||
@@ -36,0 +35,0 @@ protected getComponentName(): string; |
export * from "./BaseComponent"; | ||
export * from "./ComponentConfiguration"; | ||
export * from "./ComponentInitOptions"; | ||
export * from "./ComponentsRegistry"; | ||
@@ -5,0 +4,0 @@ export * from "./ComponentType"; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@smallstack/common"),require("@smallstack/events"),require("@smallstack/i18n"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","@smallstack/events","@smallstack/i18n","underscore"],e):e(t["@smallstack/common"]={},t["@smallstack/common"],t.events,t.i18n,t._)}(this,function(t,e,n,o,i){"use strict";function r(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)})}var s=function(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var c=t.length-1;c>=0;c--)(i=t[c])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s},c=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},a=function(){function t(){this.data={},this.initialized=!1}return t.prototype.init=function(t){var o=this;this.initialized&&e.Logger.warning("BaseComponent","Initializing BaseComponentController twice!"),t&&(t.componentId&&(this.componentId=t.componentId),t.data&&(this.data=t.data));var i=this.getComponentSockets();if(i instanceof Array&&i.length>0)for(var r=function(t){t.direction===n.EventSocket.enums.direction.IN&&s.eventService.registerSocketConnectionHandler(s.componentId,t.name,function(e){o.onSocketEvent(t.name,e)})},s=this,c=0,a=i;c<a.length;c++){r(a[c])}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+"]")},t.prototype.getData=function(t){if(this.data&&void 0!==this.data[t])return this.data[t]},t.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)},t.prototype.t=function(t,e){return this.localizationService.t(t,e)},t.prototype.getComponentSockets=function(){return this.constructor.componentSockets},t.prototype.getComponentName=function(){return this.constructor.componentName},t.prototype.getComponentConfigurations=function(){return this.constructor.componentConfigurations},s([e.Autowired(),c("design:type",Object)],t.prototype,"notificationService",void 0),s([e.Autowired(),c("design:type",n.EventService)],t.prototype,"eventService",void 0),s([e.Autowired(),c("design:type",Object)],t.prototype,"dataBridge",void 0),s([e.Autowired(),c("design:type",o.LocalizationService)],t.prototype,"localizationService",void 0),t}(),p=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 i.keys(this.components)},t.prototype.getAllComponents=function(){return i.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 i.reject(this.components,function(e){return e.getType()!==t})},t.prototype.getComponentsByTypes=function(t){return i.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 u=function(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var c=t.length-1;c>=0;c--)(i=t[c])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s},m=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},f=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=[],i.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=[],i.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!");i.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")},u([e.Autowired(),m("design:type",Object)],t.prototype,"dataBridge",void 0),t}(),d=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 d(e,t),e}(f);t.BaseComponent=a,t.ComponentConfiguration=function(t){return function(o,i){if(t){if(!t.componentName)throw new Error("No componentName given in @ComponentConfiguration decorator!");if(!new RegExp(/^[A-Z]{1}[a-zA-Z]{3,}$/g).test(t.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: "+t.componentName);if(o.componentName=t.componentName,e.IOC.onRegister("componentsRegistry",function(e){e.register(t.componentName,o)}),t.sockets||(t.sockets=[]),o.componentSockets=t.sockets,"function"==typeof o.prototype.setComponentSockets&&o.prototype.setComponentSockets(t.sockets),t.configurations||(t.configurations=[]),o.componentConfigurations=t.configurations,void 0!==o.__annotations__&&o.__annotations__ instanceof Array&&o.__annotations__.length>0)for(var r=0,s=o.__annotations__;r<s.length;r++){var c=s[r];if(c&&"Component"===c.ngMetadataName){if(t.sockets instanceof Array&&t.sockets.length>0){void 0===c.inputs&&(c.inputs=[]),void 0===c.outputs&&(c.outputs=[]);for(var a=0,p=t.sockets;a<p.length;a++){var u=p[a];u.direction===n.EventSocket.enums.direction.IN?c.inputs.push("sockets_input_"+u.name+":"+u.name):u.direction===n.EventSocket.enums.direction.OUT&&c.outputs.push("sockets_output_"+u.name+":"+u.name)}}void 0===c.selector&&(c.selector=t.componentName)}}}else e.Logger.warning("ComponentConfiguration","No options given!")}},t.ComponentsRegistry=p,t.initComponentsPackage=function(){e.IOC.register("componentsRegistry",new p)},t.initializeSmallstackComponentsPackage=function(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),r(t)},t.initializeComponentInstances=r,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/events"),require("rxjs"),require("underscore")):"function"==typeof define&&define.amd?define(["exports","@smallstack/common","@smallstack/events","rxjs","underscore"],e):e(t["@smallstack/common"]={},t["@smallstack/common"],t.events,t.rxjs,t._)}(this,function(t,e,n,o,i){"use strict";function r(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)})}var s=function(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var c=t.length-1;c>=0;c--)(i=t[c])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s},c=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)};!function(t){t.VIEW="view",t.EDITABLE="editable"}(t.ComponentRenderMode||(t.ComponentRenderMode={}));var a=function(){function i(){var e=this;this.componentInstance$=new o.BehaviorSubject(void 0),this.renderMode=t.ComponentRenderMode.VIEW,this.renderMode$=new o.BehaviorSubject(t.ComponentRenderMode.VIEW),this.initialized=!1,this.componentInstance$.subscribe(function(t){return e.componentInstance=t}),this.renderMode$.subscribe(function(t){return e.renderMode=t})}return i.prototype.init=function(t){var o=this;this.initialized&&e.Logger.warning("BaseComponent","Initializing BaseComponentController twice!"),this.componentInstance$.next(t);var i=this.getComponentSockets();if(i instanceof Array&&i.length>0)for(var r=function(t){t.direction===n.EventSocket.enums.direction.IN&&s.eventService.registerSocketConnectionHandler(s.componentInstance._id,t.name,function(e){o.onSocketEvent(t.name,e)})},s=this,c=0,a=i;c<a.length;c++){r(a[c])}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.componentInstance._id+"]")},i.prototype.getData=function(t){if(this.componentInstance&&this.componentInstance.data&&void 0!==this.componentInstance.data[t])return this.componentInstance.data[t]},i.prototype.setData=function(t,e){if(void 0===this.componentInstance)throw new Error("componentInstance not set in BaseComponent!");void 0===this.componentInstance.data&&(this.componentInstance.data={}),this.componentInstance.data[t]=e},i.prototype.sendOutput=function(t,n){e.Logger.info("BaseComponent","Sending data:",{componentInstanceId:this.componentInstance._id,socketName:t,socketData:n}),this.eventService.dispatchSocketEvent(this.componentInstance._id,t,n)},i.prototype.getComponentSockets=function(){return this.constructor.componentSockets},i.prototype.getComponentName=function(){return this.constructor.componentName},i.prototype.getComponentConfigurations=function(){return this.constructor.componentConfigurations},s([e.Autowired(),c("design:type",n.EventService)],i.prototype,"eventService",void 0),i}(),p=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 i.keys(this.components)},t.prototype.getAllComponents=function(){return i.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 i.reject(this.components,function(e){return e.getType()!==t})},t.prototype.getComponentsByTypes=function(t){return i.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 u=function(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var c=t.length-1;c>=0;c--)(i=t[c])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s},m=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},f=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=[],i.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=[],i.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!");i.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")},u([e.Autowired(),m("design:type",Object)],t.prototype,"dataBridge",void 0),t}(),d=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 d(e,t),e}(f);t.BaseComponent=a,t.ComponentConfiguration=function(t){return function(o,i){if(t){if(!t.componentName)throw new Error("No componentName given in @ComponentConfiguration decorator!");if(!new RegExp(/^[A-Z]{1}[a-zA-Z]{3,}$/g).test(t.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: "+t.componentName);if(o.componentName=t.componentName,e.IOC.onRegister("componentsRegistry",function(e){e.register(t.componentName,o)}),t.sockets||(t.sockets=[]),o.componentSockets=t.sockets,"function"==typeof o.prototype.setComponentSockets&&o.prototype.setComponentSockets(t.sockets),t.configurations||(t.configurations=[]),o.componentConfigurations=t.configurations,void 0!==o.__annotations__&&o.__annotations__ instanceof Array&&o.__annotations__.length>0)for(var r=0,s=o.__annotations__;r<s.length;r++){var c=s[r];if(c&&"Component"===c.ngMetadataName){if(t.sockets instanceof Array&&t.sockets.length>0){void 0===c.inputs&&(c.inputs=[]),void 0===c.outputs&&(c.outputs=[]);for(var a=0,p=t.sockets;a<p.length;a++){var u=p[a];u.direction===n.EventSocket.enums.direction.IN?c.inputs.push("sockets_input_"+u.name+":"+u.name):u.direction===n.EventSocket.enums.direction.OUT&&c.outputs.push("sockets_output_"+u.name+":"+u.name)}}void 0===c.selector&&(c.selector=t.componentName)}}}else e.Logger.warning("ComponentConfiguration","No options given!")}},t.ComponentsRegistry=p,t.initComponentsPackage=function(){e.IOC.register("componentsRegistry",new p)},t.initializeSmallstackComponentsPackage=function(t){void 0===t&&(t={createCollections:!0,registerModels:!0,registerServices:!0,registerTypes:!0}),r(t)},t.initializeComponentInstances=r,t.ComponentInstance=l,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@smallstack/components", | ||
"version": "0.3.22", | ||
"version": "0.3.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
45937
16
203