@telia-ace/widget-core-flamingo 1.1.76-rc.8 → 1.1.76-rc.9
Sign up to get free protection for your applications and to get access to all the features.
- package/components/ace-widget.component.d.ts +0 -1
- package/index.js +1 -1
- package/index.mjs +57 -56
- package/models/application.d.ts +1 -0
- package/package.json +1 -1
@@ -13,7 +13,6 @@ export declare class AceWidget extends LitElement {
|
|
13
13
|
constructor();
|
14
14
|
connectedCallback(): Promise<void>;
|
15
15
|
disconnectedCallback(): void;
|
16
|
-
onMessageReceived: (event: any) => Promise<void>;
|
17
16
|
onEnvironmentCreated(event: any): Promise<void>;
|
18
17
|
activate(): Promise<void>;
|
19
18
|
getGlobalEnvironment(): Promise<void>;
|
package/index.js
CHANGED
@@ -421,7 +421,7 @@
|
|
421
421
|
animation: slideDown 0.3s linear;
|
422
422
|
pointer-events: none;
|
423
423
|
}
|
424
|
-
`;Ii([v({attribute:!1}),Pi({context:be})],ot.prototype,"application",2);class Ri{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...h]=a;return{definitionId:c,overrides:h}}return{definitionId:a,overrides:[]}},r=(a,c,h,l)=>{h.forEach(d=>{const p=i(d),f=l[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&&r(a,g,f.children,l))})},{entry:o,components:n}=t;return r(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",ot)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new Et;const r=document.createElement(`ace-${e}`);return r.type=e,r.name=t,r}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const we=class{constructor(){this.components=new Map}getComponent(s){const t=this.components.get(s);return t||console.warn(`Unable to resolve component: ${s}. You most likely forgot to register the required plugin.`),t}registerComponent(s,t){this.components.set(s,t)}async loadComponents(){const s=[...this.components.entries()].map(([t,e])=>e.then(i=>{this.defineAsWebComponent(t,i.default)}));await Promise.all(s)}defineAsWebComponent(s,t){const e=we.ResolveWebComponentName(s);customElements.get(e)||customElements.define(e,t)}};let $e=we;$e.ResolveWebComponentName=s=>`ace-${s}`;var m=(s=>(s.Necessary="necessary",s.Functional="functional",s.Analytics="analytics",s))(m||{});class _e{constructor(t,e,i){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i}set(t,e,i){if(!this.disallowedKeys.includes(t))if(this.policy[i]){const r={value:e,category:i};this.storage.setItem(this._prefixKey(t),JSON.stringify(r))}else console.warn(`Storage policy does not allow storing items in category: ${i}`)}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 r=(t=JSON.parse(i))==null?void 0:t.category;this.policy[r]||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 ki{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}}class Ni{constructor(t){this.widget=t,this.name=t.name}open(){this.widget.appendToDOM()}close(){this.widget.hide()}setZIndex(t){this.widget.setZIndex(t)}}class Ae{constructor(t,e,i,r,o){this.id=t,this.name=e,this.container=i,this.settings=r,this.options=o,this.platform=new Ri,this.texts=new ki,this.renderStrategy=$.Inline,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new $e,this.components=[],this.trigger=null,this.api=new Ni(this),this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[m.Necessary]:!0,[m.Functional]:!0,[m.Analytics]:!0};this.storage=new _e(this.id,"sessionStorage",n),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",r),this.texts.loadTexts(r.texts||{})}async activate(){if(await this.loadPlugins(),await this.componentResolver.loadComponents(),this.root=this.platform.createComponentModel(this.settings,this),this.container.setState(oe.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(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,m.Necessary)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1,m.Necessary)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0,m.Necessary)}unmute(){this.storage.set("muteAudioNotifications",!1,m.Necessary)}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 rt,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}render(){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 Ui=s=>new F(s),xe=class{constructor(s=xe.endpoint){this._endpoint=s}async getSite(s){const e=await(await fetch(s)).json();return e?{id:e.id,triggers:e.triggers||[],apps:e.widgets.map(i=>{let r=$.Inline;return i.renderStrategy==="Trigger"&&(r=$.Trigger),{id:i.id,widgetId:i.widgetId,renderStrategy:r,autoActivate:i.autoActivate,anchor:i.anchor,triggerIcon:{type:"Telia",content:i.triggerIcon}}})}:null}async getWidget(s){const e=await(await fetch(`${this._endpoint}/widget/${s}`)).json();return e?{name:e.name,config:JSON.parse(e.configuration)}:null}};let F=xe;F.endpoint="https://widgets.ace.teliacompany.net/api";class Mi{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(r=>{if(r.storage){const o={[m.Analytics]:t.includes("analytics"),[m.Necessary]:t.includes("necessary"),[m.Functional]:t.includes("functional")};r.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 Ce{constructor(){this.applications=[],this.container=new wt("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 r=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===r||n.value==="*")&&a){let h={widgetId:""};try{h=JSON.parse(n.action.data)}catch{h={widgetId:""}}const l=t.findIndex(p=>p.id===h.widgetId)>-1,d=this.applications.find(p=>p.id===h.widgetId);d&&!l&&(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(r=>r.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(r=>r.name===t);if(!i){const r=this.widgetAPIHandlers.get(t)||[];r.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,r);return}e(i==null?void 0:i.api)}registerApp(t,e,i,r){const o=new wt(e,this),n=new Ae(t,e,o,i,r);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class Se{constructor(t){this.configurations=[],this.httpClient=new F,this.api=new Mi(this),this.triggers=[],this.httpClient=new F,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 Ce,this.addGlobal(this.environment);for await(const i of this.configurations){const r=await this.httpClient.getWidget(i.widgetId);r&&((e=this.environment)==null||e.registerApp(i.widgetId,r.name,r.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,r])=>{t.widget(i,r)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var ji=Object.defineProperty,Hi=Object.getOwnPropertyDescriptor,Pt=(s,t,e,i)=>{for(var r=i>1?void 0:i?Hi(t,e):t,o=s.length-1,n;o>=0;o--)(n=s[o])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&ji(t,e,r),r};class M extends A{constructor(){super(),this.status="deactivated",this.onMessageReceived=async t=>{var i;const e=t.data;switch(console.log("postmessage received",t,t.data),e.type){case"deactivate-widget":if(this.widget){console.log("deactivating widget");const r=this.widget.storage.get("open");this.widget.hide(),(i=this.widget.trigger)==null||i.hideTrigger(),r&&this.widget.storage.set("open",!0,m.Necessary)}break}},this.addEventListener("environment-created",this.onEnvironmentCreated),window.addEventListener("message",this.onMessageReceived)}async connectedCallback(){super.connectedCallback(),await this.getGlobalEnvironment()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("environment-created",this.onEnvironmentCreated),window.removeEventListener("message",this.onMessageReceived)}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()}}M.styles=[N`
|
424
|
+
`;Ii([v({attribute:!1}),Pi({context:be})],ot.prototype,"application",2);class Ri{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...h]=a;return{definitionId:c,overrides:h}}return{definitionId:a,overrides:[]}},r=(a,c,h,l)=>{h.forEach(d=>{const p=i(d),f=l[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&&r(a,g,f.children,l))})},{entry:o,components:n}=t;return r(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",ot)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new Et;const r=document.createElement(`ace-${e}`);return r.type=e,r.name=t,r}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const we=class{constructor(){this.components=new Map}getComponent(s){const t=this.components.get(s);return t||console.warn(`Unable to resolve component: ${s}. You most likely forgot to register the required plugin.`),t}registerComponent(s,t){this.components.set(s,t)}async loadComponents(){const s=[...this.components.entries()].map(([t,e])=>e.then(i=>{this.defineAsWebComponent(t,i.default)}));await Promise.all(s)}defineAsWebComponent(s,t){const e=we.ResolveWebComponentName(s);customElements.get(e)||customElements.define(e,t)}};let $e=we;$e.ResolveWebComponentName=s=>`ace-${s}`;var m=(s=>(s.Necessary="necessary",s.Functional="functional",s.Analytics="analytics",s))(m||{});class _e{constructor(t,e,i){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i}set(t,e,i){if(!this.disallowedKeys.includes(t))if(this.policy[i]){const r={value:e,category:i};this.storage.setItem(this._prefixKey(t),JSON.stringify(r))}else console.warn(`Storage policy does not allow storing items in category: ${i}`)}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 r=(t=JSON.parse(i))==null?void 0:t.category;this.policy[r]||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 ki{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}}class Ni{constructor(t){this.widget=t,this.name=t.name}open(){this.widget.appendToDOM()}close(){this.widget.hide()}setZIndex(t){this.widget.setZIndex(t)}}class Ae{constructor(t,e,i,r,o){this.id=t,this.name=e,this.container=i,this.settings=r,this.options=o,this.platform=new Ri,this.texts=new ki,this.renderStrategy=$.Inline,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new $e,this.components=[],this.trigger=null,this.api=new Ni(this),this.onMessageReceived=async a=>{var h;const c=a.data;switch(console.log("postmessage received",a,a.data),c.type){case"deactivate-widget":{console.log("deactivating widget");const l=this.storage.get("open");this.hide(),(h=this.trigger)==null||h.hideTrigger(),l&&this.storage.set("open",!0,m.Necessary);return}default:return}},this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[m.Necessary]:!0,[m.Functional]:!0,[m.Analytics]:!0};this.storage=new _e(this.id,"sessionStorage",n),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",r),this.texts.loadTexts(r.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(oe.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(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,m.Necessary)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1,m.Necessary)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0,m.Necessary)}unmute(){this.storage.set("muteAudioNotifications",!1,m.Necessary)}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 rt,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}render(){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 Ui=s=>new F(s),xe=class{constructor(s=xe.endpoint){this._endpoint=s}async getSite(s){const e=await(await fetch(s)).json();return e?{id:e.id,triggers:e.triggers||[],apps:e.widgets.map(i=>{let r=$.Inline;return i.renderStrategy==="Trigger"&&(r=$.Trigger),{id:i.id,widgetId:i.widgetId,renderStrategy:r,autoActivate:i.autoActivate,anchor:i.anchor,triggerIcon:{type:"Telia",content:i.triggerIcon}}})}:null}async getWidget(s){const e=await(await fetch(`${this._endpoint}/widget/${s}`)).json();return e?{name:e.name,config:JSON.parse(e.configuration)}:null}};let F=xe;F.endpoint="https://widgets.ace.teliacompany.net/api";class Mi{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(r=>{if(r.storage){const o={[m.Analytics]:t.includes("analytics"),[m.Necessary]:t.includes("necessary"),[m.Functional]:t.includes("functional")};r.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 Ce{constructor(){this.applications=[],this.container=new wt("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 r=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===r||n.value==="*")&&a){let h={widgetId:""};try{h=JSON.parse(n.action.data)}catch{h={widgetId:""}}const l=t.findIndex(p=>p.id===h.widgetId)>-1,d=this.applications.find(p=>p.id===h.widgetId);d&&!l&&(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(r=>r.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(r=>r.name===t);if(!i){const r=this.widgetAPIHandlers.get(t)||[];r.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,r);return}e(i==null?void 0:i.api)}registerApp(t,e,i,r){const o=new wt(e,this),n=new Ae(t,e,o,i,r);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class Se{constructor(t){this.configurations=[],this.httpClient=new F,this.api=new Mi(this),this.triggers=[],this.httpClient=new F,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 Ce,this.addGlobal(this.environment);for await(const i of this.configurations){const r=await this.httpClient.getWidget(i.widgetId);r&&((e=this.environment)==null||e.registerApp(i.widgetId,r.name,r.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,r])=>{t.widget(i,r)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var ji=Object.defineProperty,Hi=Object.getOwnPropertyDescriptor,Pt=(s,t,e,i)=>{for(var r=i>1?void 0:i?Hi(t,e):t,o=s.length-1,n;o>=0;o--)(n=s[o])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&ji(t,e,r),r};class M 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()}}M.styles=[N`
|
425
425
|
:host {
|
426
426
|
display: block;
|
427
427
|
}
|
package/index.mjs
CHANGED
@@ -587,7 +587,7 @@ const Re = (s) => new ne(typeof s == "string" ? s : s + "", void 0, _t), N = (s,
|
|
587
587
|
* Copyright 2017 Google LLC
|
588
588
|
* SPDX-License-Identifier: BSD-3-Clause
|
589
589
|
*/
|
590
|
-
const { is: Ne, defineProperty: Ue, getOwnPropertyDescriptor: Me, getOwnPropertyNames: je, getOwnPropertySymbols:
|
590
|
+
const { is: Ne, defineProperty: Ue, getOwnPropertyDescriptor: Me, getOwnPropertyNames: je, getOwnPropertySymbols: He, getPrototypeOf: Le } = Object, C = globalThis, Mt = C.trustedTypes, De = Mt ? Mt.emptyScript : "", ct = C.reactiveElementPolyfillSupport, j = (s, t) => s, X = { toAttribute(s, t) {
|
591
591
|
switch (t) {
|
592
592
|
case Boolean:
|
593
593
|
s = s ? De : null;
|
@@ -649,14 +649,14 @@ let I = class extends HTMLElement {
|
|
649
649
|
static _$Ei() {
|
650
650
|
if (this.hasOwnProperty(j("elementProperties")))
|
651
651
|
return;
|
652
|
-
const t =
|
652
|
+
const t = Le(this);
|
653
653
|
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
|
654
654
|
}
|
655
655
|
static finalize() {
|
656
656
|
if (this.hasOwnProperty(j("finalized")))
|
657
657
|
return;
|
658
658
|
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(j("properties"))) {
|
659
|
-
const e = this.properties, i = [...je(e), ...
|
659
|
+
const e = this.properties, i = [...je(e), ...He(e)];
|
660
660
|
for (const r of i)
|
661
661
|
this.createProperty(r, e[r]);
|
662
662
|
}
|
@@ -834,13 +834,13 @@ I.elementStyles = [], I.shadowRootOptions = { mode: "open" }, I[j("elementProper
|
|
834
834
|
* Copyright 2017 Google LLC
|
835
835
|
* SPDX-License-Identifier: BSD-3-Clause
|
836
836
|
*/
|
837
|
-
const
|
838
|
-
\f\r]`, M = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,
|
837
|
+
const H = globalThis, Q = H.trustedTypes, Ht = Q ? Q.createPolicy("lit-html", { createHTML: (s) => s }) : void 0, ae = "$lit$", x = `lit$${(Math.random() + "").slice(9)}$`, ce = "?" + x, Be = `<${ce}>`, O = document, D = () => O.createComment(""), B = (s) => s === null || typeof s != "object" && typeof s != "function", he = Array.isArray, ze = (s) => he(s) || typeof (s == null ? void 0 : s[Symbol.iterator]) == "function", ht = `[
|
838
|
+
\f\r]`, M = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, Lt = /-->/g, Dt = />/g, S = RegExp(`>|${ht}(?:([^\\s"'>=/]+)(${ht}*=${ht}*(?:[^
|
839
839
|
\f\r"'\`<>=]|("|')|))|$)`, "g"), Bt = /'/g, zt = /"/g, le = /^(?:script|style|textarea|title)$/i, We = (s) => (t, ...e) => ({ _$litType$: s, strings: t, values: e }), R = We(1), T = Symbol.for("lit-noChange"), u = Symbol.for("lit-nothing"), Wt = /* @__PURE__ */ new WeakMap(), P = O.createTreeWalker(O, 129);
|
840
840
|
function de(s, t) {
|
841
841
|
if (!Array.isArray(s) || !s.hasOwnProperty("raw"))
|
842
842
|
throw Error("invalid template strings array");
|
843
|
-
return
|
843
|
+
return Ht !== void 0 ? Ht.createHTML(t) : t;
|
844
844
|
}
|
845
845
|
const Fe = (s, t) => {
|
846
846
|
const e = s.length - 1, i = [];
|
@@ -849,7 +849,7 @@ const Fe = (s, t) => {
|
|
849
849
|
const c = s[a];
|
850
850
|
let h, l, d = -1, p = 0;
|
851
851
|
for (; p < c.length && (n.lastIndex = p, l = n.exec(c), l !== null); )
|
852
|
-
p = n.lastIndex, n === M ? l[1] === "!--" ? n =
|
852
|
+
p = n.lastIndex, n === M ? l[1] === "!--" ? n = Lt : l[1] !== void 0 ? n = Dt : l[2] !== void 0 ? (le.test(l[2]) && (r = RegExp("</" + l[2], "g")), n = S) : l[3] !== void 0 && (n = S) : n === S ? l[0] === ">" ? (n = r ?? M, d = -1) : l[1] === void 0 ? d = -2 : (d = n.lastIndex - l[2].length, h = l[1], n = l[3] === void 0 ? S : l[3] === '"' ? zt : Bt) : n === zt || n === Bt ? n = S : n === Lt || n === Dt ? n = M : (n = S, r = void 0);
|
853
853
|
const f = n === S && s[a + 1].startsWith("/>") ? " " : "";
|
854
854
|
o += n === M ? c + Be : d >= 0 ? (i.push(h), c.slice(0, d) + ae + c.slice(d) + x + f) : c + x + (d === -2 ? a : f);
|
855
855
|
}
|
@@ -1070,8 +1070,8 @@ class Ze {
|
|
1070
1070
|
k(this, t);
|
1071
1071
|
}
|
1072
1072
|
}
|
1073
|
-
const lt =
|
1074
|
-
lt == null || lt(z, F), (
|
1073
|
+
const lt = H.litHtmlPolyfillSupport;
|
1074
|
+
lt == null || lt(z, F), (H.litHtmlVersions ?? (H.litHtmlVersions = [])).push("3.1.2");
|
1075
1075
|
const Je = (s, t, e) => {
|
1076
1076
|
const i = (e == null ? void 0 : e.renderBefore) ?? t;
|
1077
1077
|
let r = i._$litPart$;
|
@@ -1142,7 +1142,7 @@ const Ge = { attribute: !0, type: String, converter: X, reflect: !1, hasChanged:
|
|
1142
1142
|
}
|
1143
1143
|
throw Error("Unsupported decorator location: " + i);
|
1144
1144
|
};
|
1145
|
-
function
|
1145
|
+
function v(s) {
|
1146
1146
|
return (t, e) => typeof e == "object" ? Xe(s, t, e) : ((i, r, o) => {
|
1147
1147
|
const n = r.hasOwnProperty(o);
|
1148
1148
|
return r.constructor.createProperty(o, n ? { ...i, wrapped: !0 } : i), n ? Object.getOwnPropertyDescriptor(r, o) : void 0;
|
@@ -1154,7 +1154,7 @@ function m(s) {
|
|
1154
1154
|
* SPDX-License-Identifier: BSD-3-Clause
|
1155
1155
|
*/
|
1156
1156
|
function U(s) {
|
1157
|
-
return
|
1157
|
+
return v({ ...s, state: !0, attribute: !1 });
|
1158
1158
|
}
|
1159
1159
|
var Qe = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, ei = (s, t, e, i) => {
|
1160
1160
|
for (var r = i > 1 ? void 0 : i ? ti(t, e) : t, o = s.length - 1, n; o >= 0; o--)
|
@@ -1193,7 +1193,7 @@ rt.styles = [
|
|
1193
1193
|
`
|
1194
1194
|
];
|
1195
1195
|
ei([
|
1196
|
-
|
1196
|
+
v({ attribute: !0 })
|
1197
1197
|
], rt.prototype, "anchor", 2);
|
1198
1198
|
/**
|
1199
1199
|
* @license
|
@@ -1228,13 +1228,13 @@ const ii = (s) => s.strings === void 0;
|
|
1228
1228
|
* Copyright 2017 Google LLC
|
1229
1229
|
* SPDX-License-Identifier: BSD-3-Clause
|
1230
1230
|
*/
|
1231
|
-
const
|
1231
|
+
const L = (s, t) => {
|
1232
1232
|
var i;
|
1233
1233
|
const e = s._$AN;
|
1234
1234
|
if (e === void 0)
|
1235
1235
|
return !1;
|
1236
1236
|
for (const r of e)
|
1237
|
-
(i = r._$AO) == null || i.call(r, t, !1),
|
1237
|
+
(i = r._$AO) == null || i.call(r, t, !1), L(r, t);
|
1238
1238
|
return !0;
|
1239
1239
|
}, tt = (s) => {
|
1240
1240
|
let t, e;
|
@@ -1262,11 +1262,11 @@ function ri(s, t = !1, e = 0) {
|
|
1262
1262
|
if (t)
|
1263
1263
|
if (Array.isArray(i))
|
1264
1264
|
for (let o = e; o < i.length; o++)
|
1265
|
-
|
1265
|
+
L(i[o], !1), tt(i[o]);
|
1266
1266
|
else
|
1267
|
-
i != null && (
|
1267
|
+
i != null && (L(i, !1), tt(i));
|
1268
1268
|
else
|
1269
|
-
|
1269
|
+
L(this, s);
|
1270
1270
|
}
|
1271
1271
|
const oi = (s) => {
|
1272
1272
|
s.type == xt.CHILD && (s._$AP ?? (s._$AP = ri), s._$AQ ?? (s._$AQ = si));
|
@@ -1280,7 +1280,7 @@ class fe extends pe {
|
|
1280
1280
|
}
|
1281
1281
|
_$AO(t, e = !0) {
|
1282
1282
|
var i, r;
|
1283
|
-
t !== this.isConnected && (this.isConnected = t, t ? (i = this.reconnected) == null || i.call(this) : (r = this.disconnected) == null || r.call(this)), e && (
|
1283
|
+
t !== this.isConnected && (this.isConnected = t, t ? (i = this.reconnected) == null || i.call(this) : (r = this.disconnected) == null || r.call(this)), e && (L(this, t), tt(this));
|
1284
1284
|
}
|
1285
1285
|
setValue(t) {
|
1286
1286
|
if (ii(this._$Ct))
|
@@ -1857,7 +1857,7 @@ A.styles = [
|
|
1857
1857
|
`
|
1858
1858
|
];
|
1859
1859
|
V([
|
1860
|
-
|
1860
|
+
v({ attribute: !1 })
|
1861
1861
|
], A.prototype, "application", 2);
|
1862
1862
|
V([
|
1863
1863
|
U()
|
@@ -1916,19 +1916,19 @@ const yi = (s) => {
|
|
1916
1916
|
}
|
1917
1917
|
`
|
1918
1918
|
], E([
|
1919
|
-
|
1919
|
+
v()
|
1920
1920
|
], t.prototype, "properties", 2), E([
|
1921
|
-
|
1921
|
+
v()
|
1922
1922
|
], t.prototype, "context", 2), E([
|
1923
|
-
|
1923
|
+
v()
|
1924
1924
|
], t.prototype, "layout", 2), E([
|
1925
|
-
|
1925
|
+
v()
|
1926
1926
|
], t.prototype, "name", 2), E([
|
1927
|
-
|
1927
|
+
v()
|
1928
1928
|
], t.prototype, "type", 2), E([
|
1929
|
-
|
1929
|
+
v({ attribute: !1 })
|
1930
1930
|
], t.prototype, "application", 2), E([
|
1931
|
-
|
1931
|
+
v({ attribute: !1 })
|
1932
1932
|
], t.prototype, "parent", 2), t;
|
1933
1933
|
};
|
1934
1934
|
class St extends yi(_) {
|
@@ -2257,7 +2257,7 @@ ot.styles = N`
|
|
2257
2257
|
}
|
2258
2258
|
`;
|
2259
2259
|
Si([
|
2260
|
-
|
2260
|
+
v({ attribute: !1 }),
|
2261
2261
|
Ai({ context: Ei })
|
2262
2262
|
], ot.prototype, "application", 2);
|
2263
2263
|
class Pi {
|
@@ -2343,7 +2343,7 @@ const ye = class {
|
|
2343
2343
|
};
|
2344
2344
|
let be = ye;
|
2345
2345
|
be.ResolveWebComponentName = (s) => `ace-${s}`;
|
2346
|
-
var
|
2346
|
+
var m = /* @__PURE__ */ ((s) => (s.Necessary = "necessary", s.Functional = "functional", s.Analytics = "analytics", s))(m || {});
|
2347
2347
|
class Oi {
|
2348
2348
|
constructor(t, e, i) {
|
2349
2349
|
this.disallowedKeys = [], this.widgetId = t, this.storage = e === "localStorage" ? window.localStorage : window.sessionStorage, this.policy = i;
|
@@ -2422,13 +2422,26 @@ class Ii {
|
|
2422
2422
|
}
|
2423
2423
|
class Ri {
|
2424
2424
|
constructor(t, e, i, r, o) {
|
2425
|
-
this.id = t, this.name = e, this.container = i, this.settings = r, this.options = o, this.platform = new Pi(), this.texts = new Ti(), this.renderStrategy = w.Inline, this.anchor = "BottomRight", this.autoActivate = !1, this.plugins = [], this.componentResolver = new be(), this.components = [], this.trigger = null, this.api = new Ii(this), this.
|
2425
|
+
this.id = t, this.name = e, this.container = i, this.settings = r, this.options = o, this.platform = new Pi(), this.texts = new Ti(), this.renderStrategy = w.Inline, this.anchor = "BottomRight", this.autoActivate = !1, this.plugins = [], this.componentResolver = new be(), this.components = [], this.trigger = null, this.api = new Ii(this), this.onMessageReceived = async (a) => {
|
2426
|
+
var h;
|
2427
|
+
const c = a.data;
|
2428
|
+
switch (console.log("postmessage received", a, a.data), c.type) {
|
2429
|
+
case "deactivate-widget": {
|
2430
|
+
console.log("deactivating widget");
|
2431
|
+
const l = this.storage.get("open");
|
2432
|
+
this.hide(), (h = this.trigger) == null || h.hideTrigger(), l && this.storage.set("open", !0, m.Necessary);
|
2433
|
+
return;
|
2434
|
+
}
|
2435
|
+
default:
|
2436
|
+
return;
|
2437
|
+
}
|
2438
|
+
}, this.renderStrategy = this.options.renderStrategy || w.Inline, this.triggerIcon = this.options.triggerIcon;
|
2426
2439
|
const n = {
|
2427
|
-
[
|
2428
|
-
[
|
2429
|
-
[
|
2440
|
+
[m.Necessary]: !0,
|
2441
|
+
[m.Functional]: !0,
|
2442
|
+
[m.Analytics]: !0
|
2430
2443
|
};
|
2431
|
-
this.storage = new Oi(this.id, "sessionStorage", n), typeof o.autoActivate == "boolean" && (this.autoActivate = o.autoActivate), o.anchor && (this.anchor = o.anchor), this.container.register("$settings", r), this.texts.loadTexts(r.texts || {});
|
2444
|
+
this.storage = new Oi(this.id, "sessionStorage", n), typeof o.autoActivate == "boolean" && (this.autoActivate = o.autoActivate), o.anchor && (this.anchor = o.anchor), this.container.register("$settings", r), this.texts.loadTexts(r.texts || {}), window.addEventListener("message", this.onMessageReceived);
|
2432
2445
|
}
|
2433
2446
|
async activate() {
|
2434
2447
|
if (await this.loadPlugins(), await this.componentResolver.loadComponents(), this.root = this.platform.createComponentModel(this.settings, this), this.container.setState(oe.Ready), this.autoActivate) {
|
@@ -2450,22 +2463,22 @@ class Ri {
|
|
2450
2463
|
return this.plugins.push(t), this;
|
2451
2464
|
}
|
2452
2465
|
appendToDOM() {
|
2453
|
-
this.root && (this.root.classList.add("expanded"), this.root.classList.remove("hidden"), document.body.appendChild(this.root)), this.storage.set("open", !0,
|
2466
|
+
this.root && (this.root.classList.add("expanded"), this.root.classList.remove("hidden"), document.body.appendChild(this.root)), this.storage.set("open", !0, m.Necessary);
|
2454
2467
|
}
|
2455
2468
|
hide() {
|
2456
|
-
this.root && (this.root.classList.add("hidden"), this.root.classList.remove("expanded")), this.storage.set("open", !1,
|
2469
|
+
this.root && (this.root.classList.add("hidden"), this.root.classList.remove("expanded")), this.storage.set("open", !1, m.Necessary);
|
2457
2470
|
}
|
2458
2471
|
setZIndex(t) {
|
2459
2472
|
this.root && (this.root.style.zIndex = t.toString());
|
2460
2473
|
}
|
2461
2474
|
mute() {
|
2462
|
-
this.storage.set("muteAudioNotifications", !0,
|
2475
|
+
this.storage.set("muteAudioNotifications", !0, m.Necessary);
|
2463
2476
|
}
|
2464
2477
|
unmute() {
|
2465
2478
|
this.storage.set(
|
2466
2479
|
"muteAudioNotifications",
|
2467
2480
|
!1,
|
2468
|
-
|
2481
|
+
m.Necessary
|
2469
2482
|
);
|
2470
2483
|
}
|
2471
2484
|
registerComponent(t, e) {
|
@@ -2545,9 +2558,9 @@ class ki {
|
|
2545
2558
|
(((i = this.site.environment) == null ? void 0 : i.applications) || []).forEach((r) => {
|
2546
2559
|
if (r.storage) {
|
2547
2560
|
const o = {
|
2548
|
-
[
|
2549
|
-
[
|
2550
|
-
[
|
2561
|
+
[m.Analytics]: t.includes("analytics"),
|
2562
|
+
[m.Necessary]: t.includes("necessary"),
|
2563
|
+
[m.Functional]: t.includes("functional")
|
2551
2564
|
};
|
2552
2565
|
r.storage.updatePolicy(o);
|
2553
2566
|
}
|
@@ -2711,25 +2724,13 @@ var Mi = Object.defineProperty, ji = Object.getOwnPropertyDescriptor, Et = (s, t
|
|
2711
2724
|
};
|
2712
2725
|
class Y extends _ {
|
2713
2726
|
constructor() {
|
2714
|
-
super(), this.status = "deactivated", this.
|
2715
|
-
var i;
|
2716
|
-
const e = t.data;
|
2717
|
-
switch (console.log("postmessage received", t, t.data), e.type) {
|
2718
|
-
case "deactivate-widget":
|
2719
|
-
if (this.widget) {
|
2720
|
-
console.log("deactivating widget");
|
2721
|
-
const r = this.widget.storage.get("open");
|
2722
|
-
this.widget.hide(), (i = this.widget.trigger) == null || i.hideTrigger(), r && this.widget.storage.set("open", !0, v.Necessary);
|
2723
|
-
}
|
2724
|
-
break;
|
2725
|
-
}
|
2726
|
-
}, this.addEventListener("environment-created", this.onEnvironmentCreated), window.addEventListener("message", this.onMessageReceived);
|
2727
|
+
super(), this.status = "deactivated", this.addEventListener("environment-created", this.onEnvironmentCreated);
|
2727
2728
|
}
|
2728
2729
|
async connectedCallback() {
|
2729
2730
|
super.connectedCallback(), await this.getGlobalEnvironment();
|
2730
2731
|
}
|
2731
2732
|
disconnectedCallback() {
|
2732
|
-
super.disconnectedCallback(), this.removeEventListener("environment-created", this.onEnvironmentCreated)
|
2733
|
+
super.disconnectedCallback(), this.removeEventListener("environment-created", this.onEnvironmentCreated);
|
2733
2734
|
}
|
2734
2735
|
async onEnvironmentCreated(t) {
|
2735
2736
|
this.widget = t.detail.widget, await this.activate(), this.requestUpdate();
|
@@ -2761,7 +2762,7 @@ Y.styles = [
|
|
2761
2762
|
`
|
2762
2763
|
];
|
2763
2764
|
Et([
|
2764
|
-
|
2765
|
+
v({ attribute: !0 })
|
2765
2766
|
], Y.prototype, "name", 2);
|
2766
2767
|
Et([
|
2767
2768
|
U()
|
@@ -2785,7 +2786,7 @@ export {
|
|
2785
2786
|
Ni as Environment,
|
2786
2787
|
et as HttpClient,
|
2787
2788
|
Ui as Site,
|
2788
|
-
|
2789
|
+
m as StorageCategory,
|
2789
2790
|
Oi as StorageService,
|
2790
2791
|
A as Trigger,
|
2791
2792
|
yi as WidgetComponent,
|
package/models/application.d.ts
CHANGED
@@ -29,6 +29,7 @@ export declare class Application {
|
|
29
29
|
constructor(id: string, name: string, container: Container, settings: WidgetConfig, options: ApplicationOptions);
|
30
30
|
activate(): Promise<void>;
|
31
31
|
private loadPlugins;
|
32
|
+
onMessageReceived: (event: any) => Promise<void>;
|
32
33
|
styles(): Record<string, any>;
|
33
34
|
branding(): Record<string, any>;
|
34
35
|
plugin(plugin: PluginType): this;
|