@telia-ace/widget-core-flamingo 1.1.82-rc.8 → 1.1.82-rc.9

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 +1 -1
  2. package/index.mjs +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -433,7 +433,7 @@
433
433
  animation: slideDown 0.3s linear;
434
434
  pointer-events: none;
435
435
  }
436
- `;let N=Nt;Ee([m({attribute:!0})],N.prototype,"mobile");Ee([m({attribute:!1}),ki({context:Pe})],N.prototype,"application");class Mi{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...l]=a;return{definitionId:c,overrides:l}}return{definitionId:a,overrides:[]}},s=(a,c,l,h)=>{l.forEach(d=>{const p=i(d),f=h[p.definitionId];if(!f){console.error(`No definition found for component type '${p.definitionId}'.`);return}const g=a.createNode(f.type,f.type);g&&(g.name=p.definitionId,g.application=e,f.properties&&g.writeProperties(f.properties),f.context&&g.writeContext(f.context),f.layout&&g.writeLayout(f.layout),c.addChild(g),f.children&&s(a,g,f.children,h))})},{entry:o,components:n}=t;return s(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",N)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new et;const s=document.createElement(`ace-${e}`);return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const it=class it{constructor(){this.components=new Map}getComponent(t){const e=this.components.get(t);return e||console.warn(`Unable to resolve component: ${t}. You most likely forgot to register the required plugin.`),e}registerComponent(t,e){this.components.set(t,e)}async loadComponents(){const t=[...this.components.entries()].map(([e,i])=>i.then(s=>{this.defineAsWebComponent(e,s.default)}));await Promise.all(t)}defineAsWebComponent(t,e){const i=it.ResolveWebComponentName(t);customElements.get(i)||customElements.define(i,e)}};it.ResolveWebComponentName=t=>`ace-${t}`;let At=it;var y=(r=>(r.Necessary="necessary",r.Functional="functional",r.Analytics="analytics",r))(y||{});class Oe{constructor(t,e,i,s){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i,this.storageEntries=s}set(t,e){if(this.disallowedKeys.includes(t))return;const i=this.storageEntries[t];if(!i){console.warn(`Storage key '${t}' is not defined.`);return}const s=i.category;if(this.policy[s]){const o={value:e,category:s};this.storage.setItem(this._prefixKey(t),JSON.stringify(o))}else console.warn(`Storage policy does not allow storing items in category: ${s}`)}get(t){const e=this.storage.getItem(this._prefixKey(t));if(!e)return null;try{const i=JSON.parse(e);return this.policy[i.category]?i.value:(console.warn(`Storage policy does not allow retrieving items from category: ${i.category}`),null)}catch{return null}}removeItem(t){this.storage.removeItem(this._prefixKey(t))}enforcePolicy(){var t;for(const[e,i]of Object.entries(this.storage)){const s=(t=JSON.parse(i))==null?void 0:t.category;this.policy[s]||this.storage.removeItem(e)}}updatePolicy(t){this.policy=t,this.enforcePolicy()}disallowKey(t){this.disallowedKeys.includes(t)||this.disallowedKeys.push(t),this.removeItem(t)}_prefixKey(t){return`ace_${this.widgetId.substring(0,7)}-${t}`}}class Ni{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const i=this.texts.get(t);return i||e||null}getOrFallback(t,e){return this.texts.get(t)||e}}const Ui="1.1.82-rc.8";class Li{constructor(t){this.widget=t,this.name=t.name}open(){this.widget.appendToDOM()}close(){this.widget.hide()}setMobileMode(t){this.widget.setMobileMode(t)}setZIndex(t){this.widget.setZIndex(t)}version(){return{version:Ui}}}class Ie{constructor(t,e,i,s,o){this.id=t,this.name=e,this.container=i,this.settings=s,this.options=o,this.platform=new Mi,this.texts=new Ni,this.renderStrategy=$.Inline,this.mobile=!1,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new At,this.components=[],this.trigger=null,this.api=new Li(this),this.onMessageReceived=async a=>{var l;const c=a.data;switch(c.type){case"set-storage-policies":{const{policies:h}=c.data||[],d={[y.Analytics]:h.includes("analytics"),[y.Necessary]:h.includes("necessary"),[y.Functional]:h.includes("functional")};this.storage.updatePolicy(d);return}case"disallow-storage-key":{const{storageKey:h}=c.data||null;h&&this.storage.disallowKey(h);return}case"set-mobile-mode":{const{value:h}=c.data;typeof h=="boolean"&&this.setMobileMode(h);return}case"open":{this.appendToDOM();return}case"close":{this.hide();return}case"set-z-index":{const{zIndex:h}=c.data||null;h&&this.setZIndex(h);return}case"deactivate-widget":{const h=this.storage.get("open");this.hide(),(l=this.trigger)==null||l.hideTrigger(),h&&this.storage.set("open",!0);return}default:return}},this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[y.Necessary]:!0,[y.Functional]:!0,[y.Analytics]:!0};this.storage=new Oe(this.id,"sessionStorage",n,this.settings.storage),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",s),this.texts.loadTexts(s.texts||{}),window.addEventListener("message",this.onMessageReceived)}async activate(){if(await this.loadPlugins(),await this.componentResolver.loadComponents(),this.root=this.platform.createComponentModel(this.settings,this),this.container.setState(ue.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(t)}if(window!=null&&window.parent){const{version:t}=this.api.version();window.parent.postMessage({type:"widget-activated",data:{widgetId:this.id,version:t}},"*")}}async loadPlugins(){for await(const t of this.plugins)await t(this)}styles(){return this.settings.styles||{}}branding(){return this.settings.branding||{}}plugin(t){return this.plugins.push(t),this}appendToDOM(){this.root&&(this.root.classList.add("expanded"),this.root.classList.remove("hidden"),document.body.appendChild(this.root)),this.storage.set("open",!0)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0)}unmute(){this.storage.set("muteAudioNotifications",!1)}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}mountComponent(t){this.components.push(t)}getComponent(t){const e=this.components.find(i=>i.type===t);return e||null}_getTargetElement(){let t="bottom-right";if(this.anchor==="BottomRight"?t="bottom-right":this.anchor==="BottomLeft"&&(t="bottom-left"),this.renderStrategy===$.Trigger){let e=document.querySelector(`ace-trigger-slot.${t}`);return e||(e=new W,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}_isEmbeddedInIFrame(){return window.self!==window.top}setMobileMode(t){this.mobile=t,this.root&&(this.root.mobile=!0)}render(){if(this._isEmbeddedInIFrame())return this.root;if(this.renderStrategy===$.Trigger){const t=new b;return t.application=this,this.trigger=t,this.storage.get("open")&&this.trigger.toggleActive(),t}return this.root}}const ji=r=>new U(r),st=class st{constructor(t=st.endpoint){this._endpoint=t}async getSite(t){const i=await(await fetch(t)).json();return i?{id:i.id,triggers:i.triggers||[],apps:(i.widgets||[]).map(s=>{let o=$.Trigger;s.renderStrategy.toLowerCase()==="inline"&&(o=$.Inline);const n=s.widgetId?s.widgetId:s.id,a=typeof s.autoActivate=="boolean"?s.autoActivate:!1,c=typeof s.anchor=="string"?s.anchor:"BottomRight",l=typeof s.triggerIcon=="string"?s.triggerIcon:"question";return{id:n,widgetId:n,renderStrategy:o,autoActivate:a,anchor:c,triggerIcon:{type:"Telia",content:l}}})}:null}async getWidget(t){const i=await(await fetch(`${this._endpoint}/widget/${t}`)).json();return i?{name:i.name,config:JSON.parse(i.configuration)}:null}};st.endpoint="https://widgets.ace.teliacompany.net/api";let U=st;class Hi{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(s=>{if(s.storage){const o={[y.Analytics]:t.includes("analytics"),[y.Necessary]:t.includes("necessary"),[y.Functional]:t.includes("functional")};s.storage.updatePolicy(o)}})}disallowStorageKey(t){var e;(((e=this.site.environment)==null?void 0:e.applications)||[]).forEach(i=>{i.storage&&i.storage.disallowKey(t)})}}class Te{constructor(){this.applications=[],this.container=new $t("environment",this),this.bootstrapped=!1,this.site=null,this.widgetAPIHandlers=new Map,this.siteConfigurationHandlers=[],setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate(),this.siteConfigurationHandlers.forEach(t=>{this.site&&t(this.site.api)});for(const[t,e]of this.widgetAPIHandlers)e.forEach(i=>{i()});this.bootstrapped=!0}async activate(){var e;const t=this.applications.filter(i=>i.autoActivate);(((e=this.site)==null?void 0:e.triggers)||[]).filter(i=>i.triggerType==="visit").forEach(i=>{const s=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===s||n.value==="*")&&a){let l={widgetId:""};try{l=JSON.parse(n.action.data)}catch{l={widgetId:""}}const h=t.findIndex(p=>p.id===l.widgetId)>-1,d=this.applications.find(p=>p.id===l.widgetId);d&&!h&&(d.autoActivate=!0,t.push(d))}})});for await(const i of t)await i.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const i=this.applications.find(s=>s.name===e.name);i&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:i}}))})}configure(t){if(!this.site||!this.bootstrapped){this.siteConfigurationHandlers.push(t);return}t(this.site.api)}widget(t,e){const i=this.applications.find(s=>s.name===t);if(!i){const s=this.widgetAPIHandlers.get(t)||[];s.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,s);return}e(i==null?void 0:i.api)}registerApp(t,e,i,s){const o=new $t(e,this),n=new Ie(t,e,o,i,s);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class ke{constructor(t){this.configurations=[],this.httpClient=new U,this.api=new Hi(this),this.triggers=[],this.httpClient=new U,typeof t=="string"?this.url=t:(t.httpClient&&(this.httpClient=t.httpClient),this.loadFromConfig(t))}async load(t){const e=await this.httpClient.getSite(t);if(!e){console.warn(`Unable to load site from the url provided: ${t}`);return}this.configurations=e.apps,this.triggers=e.triggers||[]}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,anchor:e.anchor,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}setHttpClient(t){this.httpClient=t}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new Te,this.addGlobal(this.environment);for await(const i of this.configurations){const s=await this.httpClient.getWidget(i.widgetId);s&&((e=this.environment)==null||e.registerApp(i.widgetId,s.name,s.config,{renderStrategy:i.renderStrategy,triggerIcon:i.triggerIcon,autoActivate:i.autoActivate,anchor:i.anchor}))}t(this.environment),this.environment.registerSite(this),await this.environment.bootstrap()}addGlobal(t){const e=globalThis.ace;((e==null?void 0:e._w)||[]).forEach(([i,s])=>{t.widget(i,s)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var Bi=Object.defineProperty,Tt=(r,t,e,i)=>{for(var s=void 0,o=r.length-1,n;o>=0;o--)(n=r[o])&&(s=n(t,e,s)||s);return s&&Bi(t,e,s),s};const Ut=class Ut extends A{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(t){this.widget=t.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const t=globalThis.widgets;t&&(this.widget=t.applications.find(e=>e.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return u;if(this.widget.renderStrategy===$.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}};Ut.styles=[L`
436
+ `;let N=Nt;Ee([m({attribute:!0})],N.prototype,"mobile");Ee([m({attribute:!1}),ki({context:Pe})],N.prototype,"application");class Mi{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...l]=a;return{definitionId:c,overrides:l}}return{definitionId:a,overrides:[]}},s=(a,c,l,h)=>{l.forEach(d=>{const p=i(d),f=h[p.definitionId];if(!f){console.error(`No definition found for component type '${p.definitionId}'.`);return}const g=a.createNode(f.type,f.type);g&&(g.name=p.definitionId,g.application=e,f.properties&&g.writeProperties(f.properties),f.context&&g.writeContext(f.context),f.layout&&g.writeLayout(f.layout),c.addChild(g),f.children&&s(a,g,f.children,h))})},{entry:o,components:n}=t;return s(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",N)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new et;const s=document.createElement(`ace-${e}`);return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const it=class it{constructor(){this.components=new Map}getComponent(t){const e=this.components.get(t);return e||console.warn(`Unable to resolve component: ${t}. You most likely forgot to register the required plugin.`),e}registerComponent(t,e){this.components.set(t,e)}async loadComponents(){const t=[...this.components.entries()].map(([e,i])=>i.then(s=>{this.defineAsWebComponent(e,s.default)}));await Promise.all(t)}defineAsWebComponent(t,e){const i=it.ResolveWebComponentName(t);customElements.get(i)||customElements.define(i,e)}};it.ResolveWebComponentName=t=>`ace-${t}`;let At=it;var y=(r=>(r.Necessary="necessary",r.Functional="functional",r.Analytics="analytics",r))(y||{});class Oe{constructor(t,e,i,s){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i,this.storageEntries=s}set(t,e){if(this.disallowedKeys.includes(t))return;const i=this.storageEntries[t];if(!i){console.warn(`Storage key '${t}' is not defined.`);return}const s=i.category;if(this.policy[s]){const o={value:e,category:s};this.storage.setItem(this._prefixKey(t),JSON.stringify(o))}else console.warn(`Storage policy does not allow storing items in category: ${s}`)}get(t){const e=this.storage.getItem(this._prefixKey(t));if(!e)return null;try{const i=JSON.parse(e);return this.policy[i.category]?i.value:(console.warn(`Storage policy does not allow retrieving items from category: ${i.category}`),null)}catch{return null}}removeItem(t){this.storage.removeItem(this._prefixKey(t))}enforcePolicy(){var t;for(const[e,i]of Object.entries(this.storage)){const s=(t=JSON.parse(i))==null?void 0:t.category;this.policy[s]||this.storage.removeItem(e)}}updatePolicy(t){this.policy=t,this.enforcePolicy()}disallowKey(t){this.disallowedKeys.includes(t)||this.disallowedKeys.push(t),this.removeItem(t)}_prefixKey(t){return`ace_${this.widgetId.substring(0,7)}-${t}`}}class Ni{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const i=this.texts.get(t);return i||e||null}getOrFallback(t,e){return this.texts.get(t)||e}}const Ui="1.1.82-rc.9";class Li{constructor(t){this.widget=t,this.name=t.name}open(){this.widget.appendToDOM()}close(){this.widget.hide()}setMobileMode(t){this.widget.setMobileMode(t)}setZIndex(t){this.widget.setZIndex(t)}version(){return{version:Ui}}}class Ie{constructor(t,e,i,s,o){this.id=t,this.name=e,this.container=i,this.settings=s,this.options=o,this.platform=new Mi,this.texts=new Ni,this.renderStrategy=$.Inline,this.mobile=!1,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new At,this.components=[],this.trigger=null,this.api=new Li(this),this.onMessageReceived=async a=>{var l;const c=a.data;switch(c.type){case"set-storage-policies":{const{policies:h}=c.data||[],d={[y.Analytics]:h.includes("analytics"),[y.Necessary]:h.includes("necessary"),[y.Functional]:h.includes("functional")};this.storage.updatePolicy(d);return}case"disallow-storage-key":{const{storageKey:h}=c.data||null;h&&this.storage.disallowKey(h);return}case"set-mobile-mode":{const{value:h}=c.data;typeof h=="boolean"&&this.setMobileMode(h);return}case"open":{this.appendToDOM();return}case"close":{this.hide();return}case"set-z-index":{const{zIndex:h}=c.data||null;h&&this.setZIndex(h);return}case"deactivate-widget":{const h=this.storage.get("open");this.hide(),(l=this.trigger)==null||l.hideTrigger(),h&&this.storage.set("open",!0);return}default:return}},this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[y.Necessary]:!0,[y.Functional]:!0,[y.Analytics]:!0};this.storage=new Oe(this.id,"sessionStorage",n,this.settings.storage),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",s),this.texts.loadTexts(s.texts||{}),window.addEventListener("message",this.onMessageReceived)}async activate(){if(await this.loadPlugins(),await this.componentResolver.loadComponents(),this.root=this.platform.createComponentModel(this.settings,this),this.container.setState(ue.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(t)}if(window!=null&&window.parent){const{version:t}=this.api.version();window.parent.postMessage({type:"widget-activated",data:{widgetId:this.id,version:t}},"*")}}async loadPlugins(){for await(const t of this.plugins)await t(this)}styles(){return this.settings.styles||{}}branding(){return this.settings.branding||{}}plugin(t){return this.plugins.push(t),this}appendToDOM(){this.root&&(this.root.classList.add("expanded"),this.root.classList.remove("hidden"),document.body.appendChild(this.root)),this.storage.set("open",!0)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0)}unmute(){this.storage.set("muteAudioNotifications",!1)}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}mountComponent(t){this.components.push(t)}getComponent(t){const e=this.components.find(i=>i.type===t);return e||null}_getTargetElement(){let t="bottom-right";if(this.anchor==="BottomRight"?t="bottom-right":this.anchor==="BottomLeft"&&(t="bottom-left"),this.renderStrategy===$.Trigger){let e=document.querySelector(`ace-trigger-slot.${t}`);return e||(e=new W,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}_isEmbeddedInIFrame(){return window.self!==window.top}setMobileMode(t){this.mobile=t,this.root&&(this.root.mobile=!0)}render(){if(this._isEmbeddedInIFrame())return this.root;if(this.renderStrategy===$.Trigger){const t=new b;return t.application=this,this.trigger=t,this.storage.get("open")&&this.trigger.toggleActive(),t}return this.root}}const ji=r=>new U(r),st=class st{constructor(t=st.endpoint){this._endpoint=t}async getSite(t){const i=await(await fetch(t)).json();return i?{id:i.id,triggers:i.triggers||[],apps:(i.widgets||[]).map(s=>{let o=$.Trigger;s.renderStrategy.toLowerCase()==="inline"&&(o=$.Inline);const n=s.widgetId?s.widgetId:s.id,a=typeof s.autoActivate=="boolean"?s.autoActivate:!1,c=typeof s.anchor=="string"?s.anchor:"BottomRight",l=typeof s.triggerIcon=="string"?s.triggerIcon:"question";return{id:n,widgetId:n,renderStrategy:o,autoActivate:a,anchor:c,triggerIcon:{type:"Telia",content:l}}})}:null}async getWidget(t){const i=await(await fetch(`${this._endpoint}/widget/${t}`)).json();return i?{name:i.name,config:JSON.parse(i.configuration)}:null}};st.endpoint="https://widgets.ace.teliacompany.net/api";let U=st;class Hi{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(s=>{if(s.storage){const o={[y.Analytics]:t.includes("analytics"),[y.Necessary]:t.includes("necessary"),[y.Functional]:t.includes("functional")};s.storage.updatePolicy(o)}})}disallowStorageKey(t){var e;(((e=this.site.environment)==null?void 0:e.applications)||[]).forEach(i=>{i.storage&&i.storage.disallowKey(t)})}}class Te{constructor(){this.applications=[],this.container=new $t("environment",this),this.bootstrapped=!1,this.site=null,this.widgetAPIHandlers=new Map,this.siteConfigurationHandlers=[],setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate(),this.siteConfigurationHandlers.forEach(t=>{this.site&&t(this.site.api)});for(const[t,e]of this.widgetAPIHandlers)e.forEach(i=>{i()});this.bootstrapped=!0}async activate(){var e;const t=this.applications.filter(i=>i.autoActivate);(((e=this.site)==null?void 0:e.triggers)||[]).filter(i=>i.triggerType==="visit").forEach(i=>{const s=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===s||n.value==="*")&&a){let l={widgetId:""};try{l=JSON.parse(n.action.data)}catch{l={widgetId:""}}const h=t.findIndex(p=>p.id===l.widgetId)>-1,d=this.applications.find(p=>p.id===l.widgetId);d&&!h&&(d.autoActivate=!0,t.push(d))}})});for await(const i of t)await i.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const i=this.applications.find(s=>s.name===e.name);i&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:i}}))})}configure(t){if(!this.site||!this.bootstrapped){this.siteConfigurationHandlers.push(t);return}t(this.site.api)}widget(t,e){const i=this.applications.find(s=>s.name===t);if(!i){const s=this.widgetAPIHandlers.get(t)||[];s.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,s);return}e(i==null?void 0:i.api)}registerApp(t,e,i,s){const o=new $t(e,this),n=new Ie(t,e,o,i,s);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class ke{constructor(t){this.configurations=[],this.httpClient=new U,this.api=new Hi(this),this.triggers=[],this.httpClient=new U,typeof t=="string"?this.url=t:(t.httpClient&&(this.httpClient=t.httpClient),this.loadFromConfig(t))}async load(t){const e=await this.httpClient.getSite(t);if(!e){console.warn(`Unable to load site from the url provided: ${t}`);return}this.configurations=e.apps,this.triggers=e.triggers||[]}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,anchor:e.anchor,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}setHttpClient(t){this.httpClient=t}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new Te,this.addGlobal(this.environment);for await(const i of this.configurations){const s=await this.httpClient.getWidget(i.widgetId);s&&((e=this.environment)==null||e.registerApp(i.widgetId,s.name,s.config,{renderStrategy:i.renderStrategy,triggerIcon:i.triggerIcon,autoActivate:i.autoActivate,anchor:i.anchor}))}t(this.environment),this.environment.registerSite(this),await this.environment.bootstrap()}addGlobal(t){const e=globalThis.ace;((e==null?void 0:e._w)||[]).forEach(([i,s])=>{t.widget(i,s)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var Bi=Object.defineProperty,Tt=(r,t,e,i)=>{for(var s=void 0,o=r.length-1,n;o>=0;o--)(n=r[o])&&(s=n(t,e,s)||s);return s&&Bi(t,e,s),s};const Ut=class Ut extends A{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(t){this.widget=t.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const t=globalThis.widgets;t&&(this.widget=t.applications.find(e=>e.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return u;if(this.widget.renderStrategy===$.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}};Ut.styles=[L`
437
437
  :host {
438
438
  display: block;
439
439
  }
package/index.mjs CHANGED
@@ -2370,7 +2370,7 @@ class ki {
2370
2370
  return this.texts.get(t) || e;
2371
2371
  }
2372
2372
  }
2373
- const Ri = "1.1.82-rc.8";
2373
+ const Ri = "1.1.82-rc.9";
2374
2374
  class Mi {
2375
2375
  constructor(t) {
2376
2376
  this.widget = t, this.name = t.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-core-flamingo",
3
- "version": "1.1.82-rc.8",
3
+ "version": "1.1.82-rc.9",
4
4
  "dependencies": {
5
5
  "lit": "^3.0.2",
6
6
  "@teliads/icons": "^8.4.0",