@telia-ace/widget-conversation-flamingo 1.1.72-rc.1 → 1.1.72-rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/index.mjs +2 -2
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -376,11 +376,11 @@
376
376
  animation: slideDown 0.3s linear;
377
377
  pointer-events: none;
378
378
  }
379
- `;Sa([w({attribute:!1}),wa({context:Ca})],cn.prototype,"application",2);var ui=(s=>(s.Mandatory="mandatory",s.Preferences="preferences",s.Analytics="analytics",s))(ui||{}),Aa=Object.defineProperty,Ea=Object.getOwnPropertyDescriptor,hn=(s,e,t,n)=>{for(var i=n>1?void 0:n?Ea(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Aa(e,t,i),i};class Ue extends k{constructor(){super(),this.status="deactivated",this.addEventListener("environment-created",this.onEnvironmentCreated)}async connectedCallback(){super.connectedCallback(),await this.getGlobalEnvironment()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("environment-created",this.onEnvironmentCreated)}async onEnvironmentCreated(e){this.widget=e.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const e=globalThis.widgets;e&&(this.widget=e.applications.find(t=>t.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return g;if(this.widget.renderStrategy===ln.Trigger){const e=new G;return e.application=this.widget,e}return this.widget.render()}}Ue.styles=[E`
379
+ `;Sa([w({attribute:!1}),wa({context:Ca})],cn.prototype,"application",2);var ui=(s=>(s.Necessary="necessary",s.Functional="functional",s.Analytics="analytics",s))(ui||{}),Aa=Object.defineProperty,Ea=Object.getOwnPropertyDescriptor,hn=(s,e,t,n)=>{for(var i=n>1?void 0:n?Ea(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Aa(e,t,i),i};class Ue extends k{constructor(){super(),this.status="deactivated",this.addEventListener("environment-created",this.onEnvironmentCreated)}async connectedCallback(){super.connectedCallback(),await this.getGlobalEnvironment()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("environment-created",this.onEnvironmentCreated)}async onEnvironmentCreated(e){this.widget=e.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const e=globalThis.widgets;e&&(this.widget=e.applications.find(t=>t.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return g;if(this.widget.renderStrategy===ln.Trigger){const e=new G;return e.application=this.widget,e}return this.widget.render()}}Ue.styles=[E`
380
380
  :host {
381
381
  display: block;
382
382
  }
383
- `];hn([w({attribute:!0})],Ue.prototype,"name",2);hn([C()],Ue.prototype,"widget",2);hn([C()],Ue.prototype,"status",2);customElements.get("ace-trigger-slot")||customElements.define("ace-trigger-slot",an);customElements.get("ace-trigger")||customElements.define("ace-trigger",G);customElements.get("ace-unresolved-component")||customElements.define("ace-unresolved-component",hi);customElements.get("ace-wrapper")||customElements.define("ace-wrapper",cn);customElements.get("ace-widget")||customElements.define("ace-widget",Ue);class Ta{constructor(e){this._message=null,this._host=e,e.addController(this)}hostConnected(){}set message(e){this._message=e,this._host.requestUpdate()}get message(){return this._message}hasMessage(){return!!this.message}}class as{constructor(e,t,n,i,r){this.id=e,this.providerKey=t,this.providerOptions=n,this.component=r,this.provider$=new U(null),this.entries$=new U([]),this.removeEntryAction$=new _,this.kill$=new _,this.isTyping$=new U(!1),this.data$=new U({}),this.complete$=this.provider$.pipe(pe(l=>l?l.onComplete():Pe));const o=this._getProviderFactory(t);if(!o)throw new Error(`No provider with key "${t}" was found.`);this.data$.next(i);const a=o(this.component);this.provider$.next(a),a.actions().pipe(zt(this.kill$)).subscribe(l=>{this.write(l)}),a.isTyping().pipe(zt(this.kill$)).subscribe(l=>{this.isTyping$.next(l)})}start(){const e=this.provider$.value;if(!e)throw new Error("No provider bound to session.");e.saveToCurrentSession$.subscribe(t=>{this.data$.next(t)}),e.connect(this.providerOptions)}entries(){return this.entries$.asObservable()}rehydrate(){var e;(e=this.provider$.value)==null||e.rehydrate(this.data$.value)}toStore(){return{id:this.id,providerKey:this.providerKey,providerOptions:this.providerOptions,data:this.data$.value}}write(e){this._addEntryRemoveHandler(e),this.entries$.pipe(Mt(1)).subscribe(t=>{this.entries$.next([...t,e])})}_addEntryRemoveHandler(e){e.remove$.pipe(pe(()=>this.entries$),Mt(1)).subscribe(t=>{this.removeEntryAction$.next(e),this.entries$.next(t.filter(n=>n!==e))})}_getProviderFactory(e){return this.component.platform.registeredProviders.get(e)}}class La{constructor(e){this.component=e,this.currentSession$=new U(null),this.sessions=[],this.storage=null,Ge(e,"handover").subscribe(t=>{const n=this._createNewSession(t.detail.providerKey,t.detail.providerOptions);this._setSession(n),t.detail.complete=n.complete$,n.start()})}loadFromStorage(){const e=this._getStoredSessions();this.sessions=e.sessions,this.sessions.forEach(t=>{this._setSession(t),t.rehydrate()}),this.save(e)}startSession(){const e=this._getStoredSessions();let t=null;if(e.sessions.length)t=e.sessions[e.sessions.length-1];else{const n=this._getInitialProviderKey(),i={};t=this._createNewSession(n,i)}this._setSession(t),t.start()}setStorageService(e){this.storage=e}currentSession(){return this.currentSession$.asObservable()}_getStoredSessions(){if(!this.storage)throw new Error("Could not locate StorageService in SessionService.");if(this.sessions.length)return{sessions:this.sessions};const e=this.storage.get("conversation");return e?{sessions:e.sessions.map(t=>new as(t.id,t.providerKey,t.providerOptions,t.data,this.component))}:{sessions:[]}}_setSession(e){this.currentSession$.next(e),e.data$.subscribe(()=>{this._saveSession(e)})}_saveSession(e){let t=this._getStoredSessions();const n=t.sessions.findIndex(i=>i.id===e.id);n>-1?t={sessions:[...t.sessions.slice(0,n),e,...t.sessions.slice(n+1)]}:t.sessions.push(e),this.save(t)}save(e){if(!this.storage)throw new Error("Could not locate StorageService in SessionService.");const t={sessions:e.sessions.map(n=>n.toStore())};this.storage.set("conversation",t,ui.Mandatory)}_createNewSession(e,t={}){const n=this._getStoredSessions(),i=new as(Is(),e,t,{},this.component);return n.sessions.push(i),this.save(n),i}_getInitialProviderKey(){var e;if(!((e=this.component.properties.providers)!=null&&e.length))throw new Error("No providers registered on conversation component.");return this.component.properties.providers[0]}}class Oa{constructor(e,t){this.state$=e,this.component=t,this.entries$=new U([]),this.session=()=>this.session$,this.isTyping=()=>this.isTyping$,this.entries=()=>this.entries$.asObservable(),this.sessionService=new La(this.component),this.session$=this.sessionService.currentSession(),this.isTyping$=this.session$.pipe(pe(n=>n?n.provider$.pipe(pe(i=>i?i.isTyping():It(!1))):It(!1))),e.subscribe(n=>{switch(n){case"init":this.initialize();break;case"rehydrating":this.rehydrate();break;case"connected":this.connected();break}})}setStorage(e){var t;(t=this.sessionService)==null||t.setStorageService(e)}initialize(){this.state$.next("rehydrating")}rehydrate(){this.session$.pipe(pe(e=>{if(!e)return Pe;const t=e.removeEntryAction$.pipe(Ut(this.entries$)).pipe(Ke(([i,r])=>r.filter(o=>o.id!==i.id))),n=e.entries().pipe(Ke(i=>{const r=this.entries$.value,o=i.filter(a=>r.findIndex(l=>l.id===a.id)===-1);return[...r,...o]}));return _r(t,n)})).subscribe(e=>{this.entries$.next(e)}),this.sessionService.loadFromStorage(),this.state$.next("connected")}connected(){var e;(e=this.sessionService)==null||e.startSession()}}var Pa=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,Ia=(s,e,t,n)=>{for(var i=n>1?void 0:n?Ra(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Pa(e,t,i),i};class un extends k{connectedCallback(){var e;super.connectedCallback(),(e=this.entry.didUpdate)==null||e.subscribe(()=>{this.requestUpdate()})}_getTimestamp(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hourCycle:"h23"})}_renderTimestamp(e,t){if(!e&&!t)return g;let n="";return e?t?n=`${e}: ${this._getTimestamp(t)}`:n=e:t&&(n=this._getTimestamp(t)),m`<p class="conversation-timestamp">${n}</p>`}_renderDeliveryStatus(e){return e==="delivered"?m`<telia-icon
383
+ `];hn([w({attribute:!0})],Ue.prototype,"name",2);hn([C()],Ue.prototype,"widget",2);hn([C()],Ue.prototype,"status",2);customElements.get("ace-trigger-slot")||customElements.define("ace-trigger-slot",an);customElements.get("ace-trigger")||customElements.define("ace-trigger",G);customElements.get("ace-unresolved-component")||customElements.define("ace-unresolved-component",hi);customElements.get("ace-wrapper")||customElements.define("ace-wrapper",cn);customElements.get("ace-widget")||customElements.define("ace-widget",Ue);class Ta{constructor(e){this._message=null,this._host=e,e.addController(this)}hostConnected(){}set message(e){this._message=e,this._host.requestUpdate()}get message(){return this._message}hasMessage(){return!!this.message}}class as{constructor(e,t,n,i,r){this.id=e,this.providerKey=t,this.providerOptions=n,this.component=r,this.provider$=new U(null),this.entries$=new U([]),this.removeEntryAction$=new _,this.kill$=new _,this.isTyping$=new U(!1),this.data$=new U({}),this.complete$=this.provider$.pipe(pe(l=>l?l.onComplete():Pe));const o=this._getProviderFactory(t);if(!o)throw new Error(`No provider with key "${t}" was found.`);this.data$.next(i);const a=o(this.component);this.provider$.next(a),a.actions().pipe(zt(this.kill$)).subscribe(l=>{this.write(l)}),a.isTyping().pipe(zt(this.kill$)).subscribe(l=>{this.isTyping$.next(l)})}start(){const e=this.provider$.value;if(!e)throw new Error("No provider bound to session.");e.saveToCurrentSession$.subscribe(t=>{this.data$.next(t)}),e.connect(this.providerOptions)}entries(){return this.entries$.asObservable()}rehydrate(){var e;(e=this.provider$.value)==null||e.rehydrate(this.data$.value)}toStore(){return{id:this.id,providerKey:this.providerKey,providerOptions:this.providerOptions,data:this.data$.value}}write(e){this._addEntryRemoveHandler(e),this.entries$.pipe(Mt(1)).subscribe(t=>{this.entries$.next([...t,e])})}_addEntryRemoveHandler(e){e.remove$.pipe(pe(()=>this.entries$),Mt(1)).subscribe(t=>{this.removeEntryAction$.next(e),this.entries$.next(t.filter(n=>n!==e))})}_getProviderFactory(e){return this.component.platform.registeredProviders.get(e)}}class La{constructor(e){this.component=e,this.currentSession$=new U(null),this.sessions=[],this.storage=null,Ge(e,"handover").subscribe(t=>{const n=this._createNewSession(t.detail.providerKey,t.detail.providerOptions);this._setSession(n),t.detail.complete=n.complete$,n.start()})}loadFromStorage(){const e=this._getStoredSessions();this.sessions=e.sessions,this.sessions.forEach(t=>{this._setSession(t),t.rehydrate()}),this.save(e)}startSession(){const e=this._getStoredSessions();let t=null;if(e.sessions.length)t=e.sessions[e.sessions.length-1];else{const n=this._getInitialProviderKey(),i={};t=this._createNewSession(n,i)}this._setSession(t),t.start()}setStorageService(e){this.storage=e}currentSession(){return this.currentSession$.asObservable()}_getStoredSessions(){if(!this.storage)throw new Error("Could not locate StorageService in SessionService.");if(this.sessions.length)return{sessions:this.sessions};const e=this.storage.get("conversation");return e?{sessions:e.sessions.map(t=>new as(t.id,t.providerKey,t.providerOptions,t.data,this.component))}:{sessions:[]}}_setSession(e){this.currentSession$.next(e),e.data$.subscribe(()=>{this._saveSession(e)})}_saveSession(e){let t=this._getStoredSessions();const n=t.sessions.findIndex(i=>i.id===e.id);n>-1?t={sessions:[...t.sessions.slice(0,n),e,...t.sessions.slice(n+1)]}:t.sessions.push(e),this.save(t)}save(e){if(!this.storage)throw new Error("Could not locate StorageService in SessionService.");const t={sessions:e.sessions.map(n=>n.toStore())};this.storage.set("conversation",t,ui.Necessary)}_createNewSession(e,t={}){const n=this._getStoredSessions(),i=new as(Is(),e,t,{},this.component);return n.sessions.push(i),this.save(n),i}_getInitialProviderKey(){var e;if(!((e=this.component.properties.providers)!=null&&e.length))throw new Error("No providers registered on conversation component.");return this.component.properties.providers[0]}}class Oa{constructor(e,t){this.state$=e,this.component=t,this.entries$=new U([]),this.session=()=>this.session$,this.isTyping=()=>this.isTyping$,this.entries=()=>this.entries$.asObservable(),this.sessionService=new La(this.component),this.session$=this.sessionService.currentSession(),this.isTyping$=this.session$.pipe(pe(n=>n?n.provider$.pipe(pe(i=>i?i.isTyping():It(!1))):It(!1))),e.subscribe(n=>{switch(n){case"init":this.initialize();break;case"rehydrating":this.rehydrate();break;case"connected":this.connected();break}})}setStorage(e){var t;(t=this.sessionService)==null||t.setStorageService(e)}initialize(){this.state$.next("rehydrating")}rehydrate(){this.session$.pipe(pe(e=>{if(!e)return Pe;const t=e.removeEntryAction$.pipe(Ut(this.entries$)).pipe(Ke(([i,r])=>r.filter(o=>o.id!==i.id))),n=e.entries().pipe(Ke(i=>{const r=this.entries$.value,o=i.filter(a=>r.findIndex(l=>l.id===a.id)===-1);return[...r,...o]}));return _r(t,n)})).subscribe(e=>{this.entries$.next(e)}),this.sessionService.loadFromStorage(),this.state$.next("connected")}connected(){var e;(e=this.sessionService)==null||e.startSession()}}var Pa=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,Ia=(s,e,t,n)=>{for(var i=n>1?void 0:n?Ra(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Pa(e,t,i),i};class un extends k{connectedCallback(){var e;super.connectedCallback(),(e=this.entry.didUpdate)==null||e.subscribe(()=>{this.requestUpdate()})}_getTimestamp(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hourCycle:"h23"})}_renderTimestamp(e,t){if(!e&&!t)return g;let n="";return e?t?n=`${e}: ${this._getTimestamp(t)}`:n=e:t&&(n=this._getTimestamp(t)),m`<p class="conversation-timestamp">${n}</p>`}_renderDeliveryStatus(e){return e==="delivered"?m`<telia-icon
384
384
  svg=${Yr.svg}
385
385
  size="sm"
386
386
  ></telia-icon>`:e==="failed"?m`<telia-icon
package/index.mjs CHANGED
@@ -3729,7 +3729,7 @@ ka([
3729
3729
  w({ attribute: !1 }),
3730
3730
  $a({ context: _a })
3731
3731
  ], ln.prototype, "application", 2);
3732
- var ci = /* @__PURE__ */ ((s) => (s.Mandatory = "mandatory", s.Preferences = "preferences", s.Analytics = "analytics", s))(ci || {}), Sa = Object.defineProperty, Ca = Object.getOwnPropertyDescriptor, cn = (s, e, t, n) => {
3732
+ var ci = /* @__PURE__ */ ((s) => (s.Necessary = "necessary", s.Functional = "functional", s.Analytics = "analytics", s))(ci || {}), Sa = Object.defineProperty, Ca = Object.getOwnPropertyDescriptor, cn = (s, e, t, n) => {
3733
3733
  for (var i = n > 1 ? void 0 : n ? Ca(e, t) : e, r = s.length - 1, o; r >= 0; r--)
3734
3734
  (o = s[r]) && (i = (n ? o(e, t, i) : o(i)) || i);
3735
3735
  return n && i && Sa(e, t, i), i;
@@ -3938,7 +3938,7 @@ class Ea {
3938
3938
  const t = {
3939
3939
  sessions: e.sessions.map((n) => n.toStore())
3940
3940
  };
3941
- this.storage.set("conversation", t, ci.Mandatory);
3941
+ this.storage.set("conversation", t, ci.Necessary);
3942
3942
  }
3943
3943
  _createNewSession(e, t = {}) {
3944
3944
  const n = this._getStoredSessions(), i = new os(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversation-flamingo",
3
- "version": "1.1.72-rc.1",
3
+ "version": "1.1.72-rc.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -9,7 +9,7 @@
9
9
  "@lit-labs/motion": "^1.0.4",
10
10
  "@teliads/icons": "^8.4.0",
11
11
  "@teliads/components": "^22.1.1",
12
- "@telia-ace/widget-core-flamingo": "1.1.72-rc.1",
12
+ "@telia-ace/widget-core-flamingo": "1.1.72-rc.3",
13
13
  "lit-html": "^3.0.2",
14
14
  "rxjs": "^7.8.1",
15
15
  "marked": "^12.0.2"