!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("rxjs"),require("rxjs/operators"),require("@scion/workbench-application-platform.api"),require("@scion/mouse-dispatcher")):"function"==typeof define&&define.amd?define("@scion/workbench-application.core",["exports","rxjs","rxjs/operators","@scion/workbench-application-platform.api","@scion/mouse-dispatcher"],t):t(((e=e||self).scion=e.scion||{},e.scion["workbench-application"]=e.scion["workbench-application"]||{},e.scion["workbench-application"].core={}),e.rxjs,e.rxjs.operators,e.workbenchApplicationPlatform_api,e.mouseDispatcher)}(this,(function(e,t,n,i,r){"use strict";var o=function(){function e(){}return e.randomUUID=function(){var e=Date.now();return window.performance&&"function"==typeof window.performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))},e}(),s=function(){},a=function(){function e(){this._destroy$=new t.Subject,this._stream$=new t.Subject,this._ancestorOrigin=c(),this.installHostMessageListener()}return e.prototype.installHostMessageListener=function(){var e=this;t.fromEvent(window,"message").pipe(n.takeUntil(this._destroy$)).subscribe((function(t){if(t.source!==window){if(e._ancestorOrigin&&t.origin!==e._ancestorOrigin)throw Error("[OriginError] Message of illegal origin received [expected="+e._ancestorOrigin+", actual="+t.origin+"]");var n=i.parseMessageEnvelopeElseNull(t.data);n&&("host"!==n.channel||"error"!==n.message.type?e._stream$.next(n):console&&console.error&&console.error(n.message.payload))}}))},Object.defineProperty(e.prototype,"receive$",{get:function(){return this._stream$.asObservable()},enumerable:!1,configurable:!0}),e.prototype.postMessage=function(e){e.protocol=i.PROTOCOL,window.parent.postMessage(e,this._ancestorOrigin||"*")},e.prototype.requestReceive$=function(e,r){var s=this,a=o.randomUUID();return e.replyToUid=a,e.protocol=i.PROTOCOL,new t.Observable((function(i){var o=new t.Subject;return s._stream$.pipe(n.filter((function(e){return"reply"===e.channel})),n.filter((function(e){return e.replyToUid===a})),r&&r.once?n.take(1):n.tap(),n.takeUntil(t.merge(o,s._destroy$))).subscribe(i),s.postMessage(e),function(){o.next()}}))},e.prototype.requestReply=function(e){var t=o.randomUUID();e.replyToUid=t,e.protocol=i.PROTOCOL;var r=this._stream$.pipe(n.filter((function(e){return"reply"===e.channel})),n.filter((function(e){return e.replyToUid===t})),n.first(),n.takeUntil(this._destroy$)).toPromise();return this.postMessage(e),r},e.prototype.onDestroy=function(){this._destroy$.next()},e}();function c(){return location.ancestorOrigins&&location.ancestorOrigins[0]}var p=new Map,u=new(function(){function e(){}return e.prototype.getService=function(e){var t=p.get(e);if(!t)throw Error("[NullServiceError] No service with the given symbol found. Did you forget to start workbench application module by calling 'Activator.start()'? [symbol="+e.name+"]");return t},e.prototype.register=function(e,t){void 0===t&&(t=e.constructor),p.set(t,e)},e.prototype.isRunningStandalone=function(){return window===window.parent},e.prototype.destroy=function(){var e=p.get(s);Array.from(p.values()).filter((function(t){return t!==e})).forEach((function(e){return e.onDestroy()})),p.get(s).onDestroy()},e}()),l=function(){function e(){var e=this;this._destroy$=new t.Subject,this._active$=new t.ReplaySubject(1),u.getService(s).receive$.pipe(n.filter((function(e){return"host"===e.channel})),n.takeUntil(this._destroy$)).subscribe((function(t){e.onHostMessage(t)}))}return e.prototype.onHostMessage=function(e){switch(e.message.type){case i.ViewHostMessageTypes.Active:this.handleActiveChange(e);break;case i.ViewHostMessageTypes.BeforeDestroy:this.handleBeforeDestroy(e)}},e.prototype.setProperties=function(e){u.getService(s).postMessage({channel:"host",message:{type:i.ViewHostMessageTypes.PropertiesWrite,payload:e}})},e.prototype.getProperties=function(){return u.getService(s).requestReply({channel:"host",message:{type:i.ViewHostMessageTypes.PropertiesRead}}).then((function(e){return e&&e.message||{}}))},e.prototype.close=function(){u.getService(s).postMessage({channel:"host",message:{type:i.ViewHostMessageTypes.Close}})},e.prototype.setDestroyNotifier=function(e){this._destroyNotifier=e,this.setProperties({useDestroyNotifier:!!e})},Object.defineProperty(e.prototype,"active$",{get:function(){return this._active$.asObservable()},enumerable:!1,configurable:!0}),e.prototype.onDestroy=function(){this._destroy$.next()},e.prototype.handleActiveChange=function(e){this._active$.next(e.message.payload)},e.prototype.handleBeforeDestroy=function(e){var n=this._destroyNotifier;(function(){if(!n)return Promise.resolve(!0);var e=n();return"boolean"==typeof e?Promise.resolve(e):e instanceof t.Observable?e.toPromise():e})().then((function(t){return u.getService(s).postMessage({channel:"reply",replyToUid:e.replyToUid,replyTo:e.sender,message:t})}))},e}(),f=function(){function e(){}return e.prototype.open=function(e,t){var n={type:i.PlatformCapabilityTypes.MessageBox,qualifier:t,payload:e};return u.getService(s).requestReply({channel:"intent",message:n}).then((function(e){return e&&e.message}))},e.prototype.onDestroy=function(){},e}(),y=function(){function e(){}return e.prototype.notify=function(e,t){var n={type:i.PlatformCapabilityTypes.Notification,qualifier:t,payload:"string"==typeof e?{text:e}:e};u.getService(s).postMessage({channel:"intent",message:n})},e.prototype.onDestroy=function(){},e}(),g=function(){function e(){var e=this;this._destroy$=new t.Subject,this._active$=new t.ReplaySubject(1),this._disposables=new Set,u.getService(s).receive$.pipe(n.filter((function(e){return"host"===e.channel})),n.takeUntil(this._destroy$)).subscribe((function(t){e.onHostMessage(t)}))}return e.prototype.onHostMessage=function(e){switch(e.message.type){case i.ActivityHostMessageTypes.Active:this.handleActiveChange(e)}},e.prototype.setProperties=function(e){u.getService(s).postMessage({channel:"host",message:{type:i.ActivityHostMessageTypes.PropertiesWrite,payload:e}})},e.prototype.getProperties=function(){return u.getService(s).requestReply({channel:"host",message:{type:i.ActivityHostMessageTypes.PropertiesRead}}).then((function(e){return e&&e.message||{}}))},e.prototype.addAction=function(e){var t=this,n=o.randomUUID();e.metadata={id:n},u.getService(s).postMessage({channel:"host",message:{type:i.ActivityHostMessageTypes.ActionAdd,payload:e}});var r={dispose:function(){t._disposables.delete(r),u.getService(s).postMessage({channel:"host",message:{type:i.ActivityHostMessageTypes.ActionRemove,payload:n}})}};return this._disposables.add(r),r},Object.defineProperty(e.prototype,"active$",{get:function(){return this._active$.asObservable()},enumerable:!1,configurable:!0}),e.prototype.handleActiveChange=function(e){this._active$.next(e.message.payload)},e.prototype.onDestroy=function(){this._disposables.forEach((function(e){return e.dispose()})),this._disposables.clear(),this._destroy$.next()},e}(),m=function(){function e(){this._destroy$=new t.Subject,this._capabilityChange$=u.getService(s).receive$.pipe(n.filter((function(e){return"host"===e.channel})),n.filter((function(e){return e.message.type===i.ManifestHostMessageTypes.CapabilityChange})),n.mapTo(void 0),n.takeUntil(this._destroy$))}return Object.defineProperty(e.prototype,"manifests$",{get:function(){var e={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindManifests}};return u.getService(s).requestReceive$({channel:"intent",message:e},{once:!0}).pipe(d([]))},enumerable:!1,configurable:!0}),e.prototype.manifest$=function(e){var t={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindManifest,symbolicAppName:e}};return u.getService(s).requestReceive$({channel:"intent",message:t},{once:!0}).pipe(d(null))},e.prototype.capabilityProviders$=function(e){var t={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindCapabilityProviders,intentId:e}};return u.getService(s).requestReceive$({channel:"intent",message:t},{once:!0}).pipe(d([]))},e.prototype.capabilityConsumers$=function(e){var t={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindCapabilityConsumers,capabilityId:e}};return u.getService(s).requestReceive$({channel:"intent",message:t},{once:!0}).pipe(d([]))},e.prototype.capability$=function(e){var t={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindCapability,capabilityId:e}};return u.getService(s).requestReceive$({channel:"intent",message:t},{once:!0}).pipe(d(null))},e.prototype.capabilities$=function(e,t){var r={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.FindCapabilities,type:e,qualifier:t}};return this._capabilityChange$.pipe(n.startWith(void 0),n.switchMap((function(){return u.getService(s).requestReceive$({channel:"intent",message:r},{once:!0})})),d([]))},e.prototype.registerCapability$=function(e){var r={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.RegisterCapability,capability:e}};return u.getService(s).requestReceive$({channel:"intent",message:r},{once:!0}).pipe(d(null),n.mergeMap((function(e){return e&&"ok"===e.status?t.EMPTY:t.throwError(e.message)})))},e.prototype.unregisterCapability$=function(e,r){var o={type:i.PlatformCapabilityTypes.ManifestRegistry,qualifier:i.NilQualifier,payload:{command:i.ManifestCommands.UnregisterCapability,type:e,qualifier:r}};return u.getService(s).requestReceive$({channel:"intent",message:o},{once:!0}).pipe(d(null),n.mergeMap((function(e){return e&&"ok"===e.status?t.EMPTY:t.throwError(e.message)})))},Object.defineProperty(e.prototype,"capabilityChange$",{get:function(){return this._capabilityChange$},enumerable:!1,configurable:!0}),e.prototype.onDestroy=function(){this._destroy$.next()},e}();function d(e){return n.map((function(t){return t?t.message:e}))}var h=function(){function e(){}return e.prototype.navigate=function(e){var t={type:i.PlatformCapabilityTypes.View,qualifier:e.qualifier,payload:{queryParams:e.queryParams,matrixParams:e.matrixParams,activateIfPresent:e.activateIfPresent,closeIfPresent:e.closeIfPresent,target:e.target,blankInsertionIndex:e.blankInsertionIndex}};u.getService(s).postMessage({channel:"intent",message:t})},e.prototype.onDestroy=function(){},e}(),v=function(){function e(){}return e.prototype.open=function(e,t){var n=e.anchor.getBoundingClientRect(),r=n.top,o=n.right,a=n.bottom,c=n.left,p=n.width,l=n.height,f={type:i.PlatformCapabilityTypes.Popup,qualifier:t,payload:{queryParams:e.queryParams,matrixParams:e.matrixParams,anchor:{top:r,right:o,bottom:a,left:c,width:p,height:l},position:e.position,closeStrategy:e.closeStrategy}};return u.getService(s).requestReply({channel:"intent",message:f}).then((function(e){return e&&e.message}))},e.prototype.close=function(e){u.getService(s).postMessage({channel:"host",message:{type:i.PopupHostMessageTypes.Close,payload:e}})},e.prototype.onDestroy=function(){},e}(),b=function(){function e(){this._destroy$=new t.Subject,this._ancestorOrigin=location.ancestorOrigins&&location.ancestorOrigins[0],this.installPlatformEventDispatcher(),this._mouseDispatcher=r.installMouseDispatcher(window.parent,this._ancestorOrigin||"*")}return e.prototype.installPlatformEventDispatcher=function(){var e=this;t.merge(t.fromEvent(document,"focusin"),t.fromEvent(document,"focusout")).pipe(n.debounceTime(15),n.map((function(e){return e.type})),n.distinctUntilChanged(),n.takeUntil(this._destroy$)).subscribe((function(t){window.parent.postMessage({protocol:"sci://workbench/remote-site",event:"sci-"+t},e._ancestorOrigin||"*")})),t.fromEvent(document,"keydown").pipe(n.filter((function(e){return"Escape"===e.key})),n.takeUntil(this._destroy$)).subscribe((function(){window.parent.postMessage({protocol:"sci://workbench/remote-site",event:"sci-escape"},e._ancestorOrigin||"*")}))},e.prototype.onDestroy=function(){this._destroy$.next(),this._mouseDispatcher.dispose()},e}();var w=function(){function e(){}return e.prototype.issueIntent$=function(e,t,i){var r={type:e,qualifier:t,payload:i};return u.getService(s).requestReceive$({channel:"intent",message:r}).pipe(n.map((function(e){return e&&e.message})))},e.prototype.issueIntent=function(e,t,n){var i={type:e,qualifier:t,payload:n};return u.getService(s).postMessage({channel:"intent",message:i})},e.prototype.onDestroy=function(){},e}(),M=function(){function e(){}return e.start=function(e){var t=this;void 0===e&&(e=new a),u.register(e,s),u.register(new b),u.register(new h),u.register(new g),u.register(new l),u.register(new f),u.register(new y),u.register(new v),u.register(new m),u.register(new w),window.addEventListener("beforeunload",(function(){return t.stop()}),{once:!0})},e.stop=function(){u.destroy()},e}();Object.keys(i).forEach((function(t){"default"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return i[t]}})})),e.ActivityService=g,e.DefaultMessageBus=a,e.IntentService=w,e.ManifestRegistryService=m,e.MessageBoxService=f,e.MessageBus=s,e.NotificationService=y,e.Platform=u,e.PlatformActivator=M,e.PopupService=v,e.RouterService=h,e.UUID=o,e.ViewService=l,e.determineAncestorOrigin=c,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=scion-workbench-application.core.umd.min.js.map