@telia-ace/widget-core-flamingo 1.1.76-rc.4 → 1.1.76-rc.40
Sign up to get free protection for your applications and to get access to all the features.
- package/components/trigger.component.d.ts +1 -0
- package/index.js +9 -9
- package/index.mjs +83 -52
- package/models/application.d.ts +2 -0
- package/package.json +1 -1
@@ -15,6 +15,7 @@ export declare class Trigger extends LitElement {
|
|
15
15
|
connectedCallback(): Promise<void>;
|
16
16
|
disconnectedCallback(): void;
|
17
17
|
toggleActive(): void;
|
18
|
+
notify(type: string, data?: Record<string, any>): void;
|
18
19
|
_applyBranding(): void;
|
19
20
|
_renderSymbol(): Promise<typeof nothing | import("lit-html").TemplateResult<1>>;
|
20
21
|
hideTrigger(): void;
|
package/index.js
CHANGED
@@ -22,11 +22,11 @@
|
|
22
22
|
* @license
|
23
23
|
* Copyright 2017 Google LLC
|
24
24
|
* SPDX-License-Identifier: BSD-3-Clause
|
25
|
-
*/const si={attribute:!0,type:String,converter:Q,reflect:!1,hasChanged:xt},ri=(s=si,t,e)=>{const{kind:i,metadata:r}=e;let n=globalThis.litPropertyMetadata.get(r);if(n===void 0&&globalThis.litPropertyMetadata.set(r,n=new Map),n.set(e.name,s),i==="accessor"){const{name:o}=e;return{set(a){const c=t.get.call(this);t.set.call(this,a),this.requestUpdate(o,c,s)},init(a){return a!==void 0&&this.P(o,void 0,s),a}}}if(i==="setter"){const{name:o}=e;return function(a){const c=this[o];t.call(this,a),this.requestUpdate(o,c,s)}}throw Error("Unsupported decorator location: "+i)};function
|
25
|
+
*/const si={attribute:!0,type:String,converter:Q,reflect:!1,hasChanged:xt},ri=(s=si,t,e)=>{const{kind:i,metadata:r}=e;let n=globalThis.litPropertyMetadata.get(r);if(n===void 0&&globalThis.litPropertyMetadata.set(r,n=new Map),n.set(e.name,s),i==="accessor"){const{name:o}=e;return{set(a){const c=t.get.call(this);t.set.call(this,a),this.requestUpdate(o,c,s)},init(a){return a!==void 0&&this.P(o,void 0,s),a}}}if(i==="setter"){const{name:o}=e;return function(a){const c=this[o];t.call(this,a),this.requestUpdate(o,c,s)}}throw Error("Unsupported decorator location: "+i)};function v(s){return(t,e)=>typeof e=="object"?ri(s,t,e):((i,r,n)=>{const o=r.hasOwnProperty(n);return r.constructor.createProperty(n,o?{...i,wrapped:!0}:i),o?Object.getOwnPropertyDescriptor(r,n):void 0})(s,t,e)}/**
|
26
26
|
* @license
|
27
27
|
* Copyright 2017 Google LLC
|
28
28
|
* SPDX-License-Identifier: BSD-3-Clause
|
29
|
-
*/function U(s){return
|
29
|
+
*/function U(s){return v({...s,state:!0,attribute:!1})}var ni=Object.defineProperty,oi=Object.getOwnPropertyDescriptor,ai=(s,t,e,i)=>{for(var r=i>1?void 0:i?oi(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&ni(t,e,r),r};class rt extends A{constructor(){super(...arguments),this.anchor="BottomRight"}appendChild(t){var e;return(e=this.shadowRoot)==null||e.appendChild(t),t}render(){return this.anchor==="BottomLeft"?this.renderRoot.host.classList.add("bottom-left"):this.anchor==="BottomRight"&&this.renderRoot.host.classList.add("bottom-right"),u}}rt.styles=[N`
|
30
30
|
:host {
|
31
31
|
position: fixed;
|
32
32
|
display: flex;
|
@@ -42,7 +42,7 @@
|
|
42
42
|
bottom: 20px;
|
43
43
|
left: 20px;
|
44
44
|
}
|
45
|
-
`];ai([
|
45
|
+
`];ai([v({attribute:!0})],rt.prototype,"anchor",2);/**
|
46
46
|
* @license
|
47
47
|
* Copyright 2017 Google LLC
|
48
48
|
* SPDX-License-Identifier: BSD-3-Clause
|
@@ -62,7 +62,7 @@
|
|
62
62
|
* @license
|
63
63
|
* Copyright 2020 Google LLC
|
64
64
|
* SPDX-License-Identifier: BSD-3-Clause
|
65
|
-
*/const me=()=>new bi;class bi{}const ft=new WeakMap,ve=St(class extends fe{render(s){return u}update(s,[t]){var i;const e=t!==this.Y;return e&&this.Y!==void 0&&this.rt(void 0),(e||this.lt!==this.ct)&&(this.Y=t,this.ht=(i=s.options)==null?void 0:i.host,this.rt(this.ct=s.element)),u}rt(s){if(typeof this.Y=="function"){const t=this.ht??globalThis;let e=ft.get(t);e===void 0&&(e=new WeakMap,ft.set(t,e)),e.get(this.Y)!==void 0&&this.Y.call(this.ht,void 0),e.set(this.Y,s),s!==void 0&&this.Y.call(this.ht,s)}else this.Y.value=s}get lt(){var s,t;return typeof this.Y=="function"?(s=ft.get(this.ht??globalThis))==null?void 0:s.get(this.Y):(t=this.Y)==null?void 0:t.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});var wi=Object.defineProperty,$i=Object.getOwnPropertyDescriptor,q=(s,t,e,i)=>{for(var r=i>1?void 0:i?$i(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&wi(t,e,r),r};class b extends A{constructor(){super(...arguments),this.active=!1,this.triggerVisible=!0,this.loaded=!1,this.containerRef=me(),this.widgetActive$=new re(!1),this.componentIsDestroyed$=new $t}async connectedCallback(){super.connectedCallback(),this.icon=await this._renderSymbol(),this.loaded=!0,this._applyBranding()}disconnectedCallback(){super.disconnectedCallback(),this.componentIsDestroyed$.next(),this.componentIsDestroyed$.complete()}toggleActive(){var t;if(!((t=this.application)!=null&&t.root)){console.warn("Could not activate widget. No root element assigned to widget.");return}this.active=!this.active,this.active?(this.application.appendToDOM(),this.widgetActive$.next(!0),this.hideTrigger()):(this.application.hide(),this.widgetActive$.next(!1),this.showTrigger())}_applyBranding(){var t;(t=this.application)!=null&&t.settings&&ge(this.application.settings.branding,this)}async _renderSymbol(){var a,c,h;const t=(a=this.application)==null?void 0:a.branding(),e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e)return R` <img src=${e} class="trigger-icon" alt="" /> `;const i=(h=this.application)==null?void 0:h.triggerIcon;if(!i)return u;const r=async l=>yi,{type:n,content:o}=i;switch(n){case"Telia":{const l=await r();return l?R`<telia-icon
|
65
|
+
*/const me=()=>new bi;class bi{}const ft=new WeakMap,ve=St(class extends fe{render(s){return u}update(s,[t]){var i;const e=t!==this.Y;return e&&this.Y!==void 0&&this.rt(void 0),(e||this.lt!==this.ct)&&(this.Y=t,this.ht=(i=s.options)==null?void 0:i.host,this.rt(this.ct=s.element)),u}rt(s){if(typeof this.Y=="function"){const t=this.ht??globalThis;let e=ft.get(t);e===void 0&&(e=new WeakMap,ft.set(t,e)),e.get(this.Y)!==void 0&&this.Y.call(this.ht,void 0),e.set(this.Y,s),s!==void 0&&this.Y.call(this.ht,s)}else this.Y.value=s}get lt(){var s,t;return typeof this.Y=="function"?(s=ft.get(this.ht??globalThis))==null?void 0:s.get(this.Y):(t=this.Y)==null?void 0:t.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});var wi=Object.defineProperty,$i=Object.getOwnPropertyDescriptor,q=(s,t,e,i)=>{for(var r=i>1?void 0:i?$i(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&wi(t,e,r),r};class b extends A{constructor(){super(...arguments),this.active=!1,this.triggerVisible=!0,this.loaded=!1,this.containerRef=me(),this.widgetActive$=new re(!1),this.componentIsDestroyed$=new $t}async connectedCallback(){super.connectedCallback(),this.icon=await this._renderSymbol(),this.loaded=!0,this._applyBranding()}disconnectedCallback(){super.disconnectedCallback(),this.componentIsDestroyed$.next(),this.componentIsDestroyed$.complete()}toggleActive(){var t;if(!((t=this.application)!=null&&t.root)){console.warn("Could not activate widget. No root element assigned to widget.");return}this.active=!this.active,this.active?(this.application.appendToDOM(),this.notify("widget-set-active",{widgetId:this.application.id,active:!0}),this.widgetActive$.next(!0),this.hideTrigger()):(this.application.hide(),this.notify("widget-set-active",{widgetId:this.application.id,active:!1}),this.widgetActive$.next(!1),this.showTrigger())}notify(t,e={}){window!=null&&window.parent&&window.parent.postMessage({type:t,data:e},"*")}_applyBranding(){var t;(t=this.application)!=null&&t.settings&&ge(this.application.settings.branding,this)}async _renderSymbol(){var a,c,h;const t=(a=this.application)==null?void 0:a.branding(),e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e)return R` <img src=${e} class="trigger-icon" alt="" /> `;const i=(h=this.application)==null?void 0:h.triggerIcon;if(!i)return u;const r=async l=>yi,{type:n,content:o}=i;switch(n){case"Telia":{const l=await r();return l?R`<telia-icon
|
66
66
|
class="trigger-icon"
|
67
67
|
svg=${l.svg}
|
68
68
|
size="lg"
|
@@ -244,7 +244,7 @@
|
|
244
244
|
.trigger-label:hover {
|
245
245
|
opacity: 0.8;
|
246
246
|
}
|
247
|
-
`];q([
|
247
|
+
`];q([v({attribute:!1})],b.prototype,"application",2);q([U()],b.prototype,"active",2);q([U()],b.prototype,"triggerVisible",2);q([U()],b.prototype,"loaded",2);q([U()],b.prototype,"icon",2);var _i=Object.defineProperty,Ai=Object.getOwnPropertyDescriptor,E=(s,t,e,i)=>{for(var r=i>1?void 0:i?Ai(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&_i(t,e,r),r};const ye=s=>{class t extends s{constructor(){super(...arguments),this.properties={},this.context={},this.layout={},this.nodes=[]}writeProperties(i){this.properties=i}writeLayout(i){this.layout=i}writeContext(i){this.context=i}addChild(i){i.parent=this,this.nodes.push(i)}connectedCallback(){super.connectedCallback(),this.renderRoot.host.style.setProperty("--width",this.layout.size==="full"?"var(--columns, 1)":`min(${this.layout.size||"var(--columns)"}, var(--columns))`),this.application.mountComponent(this)}}return t.styles=[N`
|
248
248
|
:host {
|
249
249
|
font-family: var(--font-family);
|
250
250
|
grid-column: span var(--width);
|
@@ -256,7 +256,7 @@
|
|
256
256
|
* {
|
257
257
|
box-sizing: border-box;
|
258
258
|
}
|
259
|
-
`],E([
|
259
|
+
`],E([v()],t.prototype,"properties",2),E([v()],t.prototype,"context",2),E([v()],t.prototype,"layout",2),E([v()],t.prototype,"name",2),E([v()],t.prototype,"type",2),E([v({attribute:!1})],t.prototype,"application",2),E([v({attribute:!1})],t.prototype,"parent",2),t};class Et extends ye(A){render(){return R`Non resolved component`}}Et.styles=[N`
|
260
260
|
:host {
|
261
261
|
display: block;
|
262
262
|
}
|
@@ -284,7 +284,7 @@
|
|
284
284
|
* @license
|
285
285
|
* Copyright 2017 Google LLC
|
286
286
|
* SPDX-License-Identifier: BSD-3-Clause
|
287
|
-
*/function Pi({context:s}){return(t,e)=>{const i=new WeakMap;if(typeof e=="object")return e.addInitializer(function(){i.set(this,new Gt(this,{context:s}))}),{get(){return t.get.call(this)},set(r){var n;return(n=i.get(this))==null||n.setValue(r),t.set.call(this,r)},init(r){var n;return(n=i.get(this))==null||n.setValue(r),r}};{t.constructor.addInitializer(o=>{i.set(o,new Gt(o,{context:s}))});const r=Object.getOwnPropertyDescriptor(t,e);let n;if(r===void 0){const o=new WeakMap;n={get:function(){return o.get(this)},set:function(a){i.get(this).setValue(a),o.set(this,a)},configurable:!0,enumerable:!0}}else{const o=r.set;n={...r,set:function(a){i.get(this).setValue(a),o==null||o.call(this,a)}}}return void Object.defineProperty(t,e,n)}}}var Oi=Object.defineProperty,Ti=Object.getOwnPropertyDescriptor,Ii=(s,t,e,i)=>{for(var r=i>1?void 0:i?Ti(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&Oi(t,e,r),r};const be="application";class nt extends A{constructor(){super(...arguments),this.nodes=[],this.wrapperRef=me()}addChild(t){t.parent=this,this.nodes.push(t)}applyBranding(){if(!this.wrapperRef.value)return;const t=this.application.settings;t!=null&&t.branding&&ge(t.branding,this.wrapperRef.value)}applyStyles(){if(!this.wrapperRef.value)return;const t=this.application.styles(),e=this.wrapperRef.value;Object.entries(t).forEach(([i,r])=>{e.style.setProperty(`--${i}`,r)})}firstUpdated(t){this.applyBranding(),this.applyStyles()}render(){var i,r;const t=this.application.settings.components.conversation;return((r=(i=t==null?void 0:t.properties)==null?void 0:i.chat)==null?void 0:r.isThirdPartyWidget)?this.renderRoot.host.classList.add("third-party"):this.application.renderStrategy===$.Trigger&&(this.renderRoot.host.classList.add("floating"),this.application.anchor==="BottomLeft"?this.renderRoot.host.classList.add("bottom-left"):this.application.anchor==="BottomRight"&&this.renderRoot.host.classList.add("bottom-right")),R`<div class="widget-container" ${ve(this.wrapperRef)}>
|
287
|
+
*/function Pi({context:s}){return(t,e)=>{const i=new WeakMap;if(typeof e=="object")return e.addInitializer(function(){i.set(this,new Gt(this,{context:s}))}),{get(){return t.get.call(this)},set(r){var n;return(n=i.get(this))==null||n.setValue(r),t.set.call(this,r)},init(r){var n;return(n=i.get(this))==null||n.setValue(r),r}};{t.constructor.addInitializer(o=>{i.set(o,new Gt(o,{context:s}))});const r=Object.getOwnPropertyDescriptor(t,e);let n;if(r===void 0){const o=new WeakMap;n={get:function(){return o.get(this)},set:function(a){i.get(this).setValue(a),o.set(this,a)},configurable:!0,enumerable:!0}}else{const o=r.set;n={...r,set:function(a){i.get(this).setValue(a),o==null||o.call(this,a)}}}return void Object.defineProperty(t,e,n)}}}var Oi=Object.defineProperty,Ti=Object.getOwnPropertyDescriptor,Ii=(s,t,e,i)=>{for(var r=i>1?void 0:i?Ti(t,e):t,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(r))||r);return i&&r&&Oi(t,e,r),r};const be="application";class nt extends A{constructor(){super(...arguments),this.nodes=[],this.wrapperRef=me()}addChild(t){t.parent=this,this.nodes.push(t)}applyBranding(){if(!this.wrapperRef.value)return;const t=this.application.settings;t!=null&&t.branding&&ge(t.branding,this.wrapperRef.value)}applyStyles(){if(!this.wrapperRef.value)return;const t=this.application.styles(),e=this.wrapperRef.value;Object.entries(t).forEach(([i,r])=>{e.style.setProperty(`--${i}`,r)})}firstUpdated(t){this.applyBranding(),this.applyStyles()}render(){var i,r;const t=this.application.settings.components.conversation;return((r=(i=t==null?void 0:t.properties)==null?void 0:i.chat)==null?void 0:r.isThirdPartyWidget)?this.renderRoot.host.classList.add("third-party"):this.application.renderStrategy===$.Trigger&&(this.renderRoot.host.classList.add("floating"),this.application.anchor==="BottomLeft"?this.renderRoot.host.classList.add("bottom-left"):this.application.anchor==="BottomRight"&&this.renderRoot.host.classList.add("bottom-right")),window.self!==window.top&&this.renderRoot.host.classList.add("embedded"),R`<div class="widget-container" ${ve(this.wrapperRef)}>
|
288
288
|
${xi(this.nodes,n=>n)}
|
289
289
|
</div>`}}nt.styles=N`
|
290
290
|
:host {
|
@@ -421,8 +421,8 @@
|
|
421
421
|
animation: slideDown 0.3s linear;
|
422
422
|
pointer-events: none;
|
423
423
|
}
|
424
|
-
`;Ii([m({attribute:!1}),Pi({context:be})],nt.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:n,components:o}=t;return r(this,this.root,[n],o),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",nt)),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 v=(s=>(s.Necessary="necessary",s.Functional="functional",s.Analytics="analytics",s))(v||{});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,n){this.id=t,this.name=e,this.container=i,this.settings=r,this.options=n,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 o={[v.Necessary]:!0,[v.Functional]:!0,[v.Analytics]:!0};this.storage=new _e(this.id,"sessionStorage",o),typeof n.autoActivate=="boolean"&&(this.autoActivate=n.autoActivate),n.anchor&&(this.anchor=n.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(ne.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,v.Necessary)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1,v.Necessary)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0,v.Necessary)}unmute(){this.storage.set("muteAudioNotifications",!1,v.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 n={[v.Analytics]:t.includes("analytics"),[v.Necessary]:t.includes("necessary"),[v.Functional]:t.includes("functional")};r.storage.updatePolicy(n)}})}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,n=i.condition.outputs||[];i.condition.type==="url"&&n.forEach(o=>{const a=o.action.type==="render_widget";if((o.value===r||o.value==="*")&&a){let h={widgetId:""};try{h=JSON.parse(o.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 n=this.applications.find(o=>o.name===t);e(n==null?void 0:n.api)}),this.widgetAPIHandlers.set(t,r);return}e(i==null?void 0:i.api)}registerApp(t,e,i,r){const n=new wt(e,this),o=new Ae(t,e,n,i,r);this.applications.push(o)}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,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(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`
|
424
|
+
`;Ii([v({attribute:!1}),Pi({context:be})],nt.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:n,components:o}=t;return r(this,this.root,[n],o),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",nt)),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,n){this.id=t,this.name=e,this.container=i,this.settings=r,this.options=n,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;switch(a.data.type){case"deactivate-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 o={[m.Necessary]:!0,[m.Functional]:!0,[m.Analytics]:!0};this.storage=new _e(this.id,"sessionStorage",o),typeof n.autoActivate=="boolean"&&(this.autoActivate=n.autoActivate),n.anchor&&(this.anchor=n.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(ne.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}_isEmbeddedInIFrame(){return window.self!==window.top}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 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 n={[m.Analytics]:t.includes("analytics"),[m.Necessary]:t.includes("necessary"),[m.Functional]:t.includes("functional")};r.storage.updatePolicy(n)}})}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,n=i.condition.outputs||[];i.condition.type==="url"&&n.forEach(o=>{const a=o.action.type==="render_widget";if((o.value===r||o.value==="*")&&a){let h={widgetId:""};try{h=JSON.parse(o.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 n=this.applications.find(o=>o.name===t);e(n==null?void 0:n.api)}),this.widgetAPIHandlers.set(t,r);return}e(i==null?void 0:i.api)}registerApp(t,e,i,r){const n=new wt(e,this),o=new Ae(t,e,n,i,r);this.applications.push(o)}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,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(t,e,r):o(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
|
}
|
428
|
-
`];Pt([
|
428
|
+
`];Pt([v({attribute:!0})],M.prototype,"name",2);Pt([U()],M.prototype,"widget",2);Pt([U()],M.prototype,"status",2);customElements.get("ace-trigger-slot")||customElements.define("ace-trigger-slot",rt);customElements.get("ace-trigger")||customElements.define("ace-trigger",b);customElements.get("ace-unresolved-component")||customElements.define("ace-unresolved-component",Et);customElements.get("ace-wrapper")||customElements.define("ace-wrapper",nt);customElements.get("ace-widget")||customElements.define("ace-widget",M);const Li=async(s,t,e={})=>{const i=new Se(s);e.httpClient&&i.setHttpClient(e.httpClient),await i.bootstrap(t)};exports.AceWidget=M;exports.Application=Ae;exports.Container=wt;exports.Environment=Ce;exports.HttpClient=F;exports.Site=Se;exports.StorageCategory=m;exports.StorageService=_e;exports.Trigger=b;exports.WidgetComponent=ye;exports.applicationContext=be;exports.bootstrap=Li;exports.createHttpClient=Ui;
|
package/index.mjs
CHANGED
@@ -93,8 +93,8 @@ var it = function() {
|
|
93
93
|
var h = c.value;
|
94
94
|
h.remove(this);
|
95
95
|
}
|
96
|
-
} catch (
|
97
|
-
t = { error:
|
96
|
+
} catch (y) {
|
97
|
+
t = { error: y };
|
98
98
|
} finally {
|
99
99
|
try {
|
100
100
|
c && !c.done && (e = a.return) && e.call(a);
|
@@ -109,8 +109,8 @@ var it = function() {
|
|
109
109
|
if ($(l))
|
110
110
|
try {
|
111
111
|
l();
|
112
|
-
} catch (
|
113
|
-
n =
|
112
|
+
} catch (y) {
|
113
|
+
n = y instanceof ot ? y.errors : [y];
|
114
114
|
}
|
115
115
|
var d = this._finalizers;
|
116
116
|
if (d) {
|
@@ -120,12 +120,12 @@ var it = function() {
|
|
120
120
|
var g = f.value;
|
121
121
|
try {
|
122
122
|
Pt(g);
|
123
|
-
} catch (
|
124
|
-
n = n ?? [],
|
123
|
+
} catch (y) {
|
124
|
+
n = n ?? [], y instanceof ot ? n = G(G([], J(n)), J(y.errors)) : n.push(y);
|
125
125
|
}
|
126
126
|
}
|
127
|
-
} catch (
|
128
|
-
i = { error:
|
127
|
+
} catch (y) {
|
128
|
+
i = { error: y };
|
129
129
|
} finally {
|
130
130
|
try {
|
131
131
|
f && !f.done && (r = p.return) && r.call(p);
|
@@ -587,7 +587,7 @@ const Re = (s) => new oe(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: Le, getPrototypeOf: He } = 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 = He(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), ...Le(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 L = globalThis, Q = L.trustedTypes, Lt = 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, Ht = /-->/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 Lt !== void 0 ? Lt.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 && (o.lastIndex = p, l = o.exec(c), l !== null); )
|
852
|
-
p = o.lastIndex, o === M ? l[1] === "!--" ? o =
|
852
|
+
p = o.lastIndex, o === M ? l[1] === "!--" ? o = Ht : l[1] !== void 0 ? o = Dt : l[2] !== void 0 ? (le.test(l[2]) && (r = RegExp("</" + l[2], "g")), o = S) : l[3] !== void 0 && (o = S) : o === S ? l[0] === ">" ? (o = r ?? M, d = -1) : l[1] === void 0 ? d = -2 : (d = o.lastIndex - l[2].length, h = l[1], o = l[3] === void 0 ? S : l[3] === '"' ? zt : Bt) : o === zt || o === Bt ? o = S : o === Ht || o === Dt ? o = M : (o = S, r = void 0);
|
853
853
|
const f = o === S && s[a + 1].startsWith("/>") ? " " : "";
|
854
854
|
n += o === 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 = L.litHtmlPolyfillSupport;
|
1074
|
+
lt == null || lt(z, F), (L.litHtmlVersions ?? (L.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, n) => {
|
1147
1147
|
const o = r.hasOwnProperty(n);
|
1148
1148
|
return r.constructor.createProperty(n, o ? { ...i, wrapped: !0 } : i), o ? Object.getOwnPropertyDescriptor(r, n) : 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, n = s.length - 1, o; n >= 0; n--)
|
@@ -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 H = (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), H(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 n = e; n < i.length; n++)
|
1265
|
-
|
1265
|
+
H(i[n], !1), tt(i[n]);
|
1266
1266
|
else
|
1267
|
-
i != null && (
|
1267
|
+
i != null && (H(i, !1), tt(i));
|
1268
1268
|
else
|
1269
|
-
|
1269
|
+
H(this, s);
|
1270
1270
|
}
|
1271
1271
|
const ni = (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 && (H(this, t), tt(this));
|
1284
1284
|
}
|
1285
1285
|
setValue(t) {
|
1286
1286
|
if (ii(this._$Ct))
|
@@ -1624,7 +1624,22 @@ class A extends _ {
|
|
1624
1624
|
);
|
1625
1625
|
return;
|
1626
1626
|
}
|
1627
|
-
this.active = !this.active, this.active ? (this.application.appendToDOM(), this.
|
1627
|
+
this.active = !this.active, this.active ? (this.application.appendToDOM(), this.notify("widget-set-active", {
|
1628
|
+
widgetId: this.application.id,
|
1629
|
+
active: !0
|
1630
|
+
}), this.widgetActive$.next(!0), this.hideTrigger()) : (this.application.hide(), this.notify("widget-set-active", {
|
1631
|
+
widgetId: this.application.id,
|
1632
|
+
active: !1
|
1633
|
+
}), this.widgetActive$.next(!1), this.showTrigger());
|
1634
|
+
}
|
1635
|
+
notify(t, e = {}) {
|
1636
|
+
window != null && window.parent && window.parent.postMessage(
|
1637
|
+
{
|
1638
|
+
type: t,
|
1639
|
+
data: e
|
1640
|
+
},
|
1641
|
+
"*"
|
1642
|
+
);
|
1628
1643
|
}
|
1629
1644
|
_applyBranding() {
|
1630
1645
|
var t;
|
@@ -1857,7 +1872,7 @@ A.styles = [
|
|
1857
1872
|
`
|
1858
1873
|
];
|
1859
1874
|
V([
|
1860
|
-
|
1875
|
+
v({ attribute: !1 })
|
1861
1876
|
], A.prototype, "application", 2);
|
1862
1877
|
V([
|
1863
1878
|
U()
|
@@ -1916,19 +1931,19 @@ const yi = (s) => {
|
|
1916
1931
|
}
|
1917
1932
|
`
|
1918
1933
|
], E([
|
1919
|
-
|
1934
|
+
v()
|
1920
1935
|
], t.prototype, "properties", 2), E([
|
1921
|
-
|
1936
|
+
v()
|
1922
1937
|
], t.prototype, "context", 2), E([
|
1923
|
-
|
1938
|
+
v()
|
1924
1939
|
], t.prototype, "layout", 2), E([
|
1925
|
-
|
1940
|
+
v()
|
1926
1941
|
], t.prototype, "name", 2), E([
|
1927
|
-
|
1942
|
+
v()
|
1928
1943
|
], t.prototype, "type", 2), E([
|
1929
|
-
|
1944
|
+
v({ attribute: !1 })
|
1930
1945
|
], t.prototype, "application", 2), E([
|
1931
|
-
|
1946
|
+
v({ attribute: !1 })
|
1932
1947
|
], t.prototype, "parent", 2), t;
|
1933
1948
|
};
|
1934
1949
|
class St extends yi(_) {
|
@@ -2115,7 +2130,7 @@ class nt extends _ {
|
|
2115
2130
|
render() {
|
2116
2131
|
var i, r;
|
2117
2132
|
const t = this.application.settings.components.conversation;
|
2118
|
-
return ((r = (i = t == null ? void 0 : t.properties) == null ? void 0 : i.chat) == null ? void 0 : r.isThirdPartyWidget) ? this.renderRoot.host.classList.add("third-party") : this.application.renderStrategy === w.Trigger && (this.renderRoot.host.classList.add("floating"), this.application.anchor === "BottomLeft" ? this.renderRoot.host.classList.add("bottom-left") : this.application.anchor === "BottomRight" && this.renderRoot.host.classList.add("bottom-right")), R`<div class="widget-container" ${ve(this.wrapperRef)}>
|
2133
|
+
return ((r = (i = t == null ? void 0 : t.properties) == null ? void 0 : i.chat) == null ? void 0 : r.isThirdPartyWidget) ? this.renderRoot.host.classList.add("third-party") : this.application.renderStrategy === w.Trigger && (this.renderRoot.host.classList.add("floating"), this.application.anchor === "BottomLeft" ? this.renderRoot.host.classList.add("bottom-left") : this.application.anchor === "BottomRight" && this.renderRoot.host.classList.add("bottom-right")), window.self !== window.top && this.renderRoot.host.classList.add("embedded"), R`<div class="widget-container" ${ve(this.wrapperRef)}>
|
2119
2134
|
${bi(this.nodes, (n) => n)}
|
2120
2135
|
</div>`;
|
2121
2136
|
}
|
@@ -2257,7 +2272,7 @@ nt.styles = N`
|
|
2257
2272
|
}
|
2258
2273
|
`;
|
2259
2274
|
Si([
|
2260
|
-
|
2275
|
+
v({ attribute: !1 }),
|
2261
2276
|
Ai({ context: Ei })
|
2262
2277
|
], nt.prototype, "application", 2);
|
2263
2278
|
class Pi {
|
@@ -2343,7 +2358,7 @@ const ye = class {
|
|
2343
2358
|
};
|
2344
2359
|
let be = ye;
|
2345
2360
|
be.ResolveWebComponentName = (s) => `ace-${s}`;
|
2346
|
-
var
|
2361
|
+
var m = /* @__PURE__ */ ((s) => (s.Necessary = "necessary", s.Functional = "functional", s.Analytics = "analytics", s))(m || {});
|
2347
2362
|
class Oi {
|
2348
2363
|
constructor(t, e, i) {
|
2349
2364
|
this.disallowedKeys = [], this.widgetId = t, this.storage = e === "localStorage" ? window.localStorage : window.sessionStorage, this.policy = i;
|
@@ -2422,13 +2437,24 @@ class Ii {
|
|
2422
2437
|
}
|
2423
2438
|
class Ri {
|
2424
2439
|
constructor(t, e, i, r, n) {
|
2425
|
-
this.id = t, this.name = e, this.container = i, this.settings = r, this.options = n, 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.
|
2440
|
+
this.id = t, this.name = e, this.container = i, this.settings = r, this.options = n, 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) => {
|
2441
|
+
var h;
|
2442
|
+
switch (a.data.type) {
|
2443
|
+
case "deactivate-widget": {
|
2444
|
+
const l = this.storage.get("open");
|
2445
|
+
this.hide(), (h = this.trigger) == null || h.hideTrigger(), l && this.storage.set("open", !0, m.Necessary);
|
2446
|
+
return;
|
2447
|
+
}
|
2448
|
+
default:
|
2449
|
+
return;
|
2450
|
+
}
|
2451
|
+
}, this.renderStrategy = this.options.renderStrategy || w.Inline, this.triggerIcon = this.options.triggerIcon;
|
2426
2452
|
const o = {
|
2427
|
-
[
|
2428
|
-
[
|
2429
|
-
[
|
2453
|
+
[m.Necessary]: !0,
|
2454
|
+
[m.Functional]: !0,
|
2455
|
+
[m.Analytics]: !0
|
2430
2456
|
};
|
2431
|
-
this.storage = new Oi(this.id, "sessionStorage", o), typeof n.autoActivate == "boolean" && (this.autoActivate = n.autoActivate), n.anchor && (this.anchor = n.anchor), this.container.register("$settings", r), this.texts.loadTexts(r.texts || {});
|
2457
|
+
this.storage = new Oi(this.id, "sessionStorage", o), typeof n.autoActivate == "boolean" && (this.autoActivate = n.autoActivate), n.anchor && (this.anchor = n.anchor), this.container.register("$settings", r), this.texts.loadTexts(r.texts || {}), window.addEventListener("message", this.onMessageReceived);
|
2432
2458
|
}
|
2433
2459
|
async activate() {
|
2434
2460
|
if (await this.loadPlugins(), await this.componentResolver.loadComponents(), this.root = this.platform.createComponentModel(this.settings, this), this.container.setState(ne.Ready), this.autoActivate) {
|
@@ -2450,22 +2476,22 @@ class Ri {
|
|
2450
2476
|
return this.plugins.push(t), this;
|
2451
2477
|
}
|
2452
2478
|
appendToDOM() {
|
2453
|
-
this.root && (this.root.classList.add("expanded"), this.root.classList.remove("hidden"), document.body.appendChild(this.root)), this.storage.set("open", !0,
|
2479
|
+
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
2480
|
}
|
2455
2481
|
hide() {
|
2456
|
-
this.root && (this.root.classList.add("hidden"), this.root.classList.remove("expanded")), this.storage.set("open", !1,
|
2482
|
+
this.root && (this.root.classList.add("hidden"), this.root.classList.remove("expanded")), this.storage.set("open", !1, m.Necessary);
|
2457
2483
|
}
|
2458
2484
|
setZIndex(t) {
|
2459
2485
|
this.root && (this.root.style.zIndex = t.toString());
|
2460
2486
|
}
|
2461
2487
|
mute() {
|
2462
|
-
this.storage.set("muteAudioNotifications", !0,
|
2488
|
+
this.storage.set("muteAudioNotifications", !0, m.Necessary);
|
2463
2489
|
}
|
2464
2490
|
unmute() {
|
2465
2491
|
this.storage.set(
|
2466
2492
|
"muteAudioNotifications",
|
2467
2493
|
!1,
|
2468
|
-
|
2494
|
+
m.Necessary
|
2469
2495
|
);
|
2470
2496
|
}
|
2471
2497
|
registerComponent(t, e) {
|
@@ -2491,7 +2517,12 @@ class Ri {
|
|
2491
2517
|
}
|
2492
2518
|
return document.body;
|
2493
2519
|
}
|
2520
|
+
_isEmbeddedInIFrame() {
|
2521
|
+
return window.self !== window.top;
|
2522
|
+
}
|
2494
2523
|
render() {
|
2524
|
+
if (this._isEmbeddedInIFrame())
|
2525
|
+
return this.root;
|
2495
2526
|
if (this.renderStrategy === w.Trigger) {
|
2496
2527
|
const t = new A();
|
2497
2528
|
return t.application = this, this.trigger = t, this.storage.get("open") && this.trigger.toggleActive(), t;
|
@@ -2545,9 +2576,9 @@ class ki {
|
|
2545
2576
|
(((i = this.site.environment) == null ? void 0 : i.applications) || []).forEach((r) => {
|
2546
2577
|
if (r.storage) {
|
2547
2578
|
const n = {
|
2548
|
-
[
|
2549
|
-
[
|
2550
|
-
[
|
2579
|
+
[m.Analytics]: t.includes("analytics"),
|
2580
|
+
[m.Necessary]: t.includes("necessary"),
|
2581
|
+
[m.Functional]: t.includes("functional")
|
2551
2582
|
};
|
2552
2583
|
r.storage.updatePolicy(n);
|
2553
2584
|
}
|
@@ -2749,7 +2780,7 @@ Y.styles = [
|
|
2749
2780
|
`
|
2750
2781
|
];
|
2751
2782
|
Et([
|
2752
|
-
|
2783
|
+
v({ attribute: !0 })
|
2753
2784
|
], Y.prototype, "name", 2);
|
2754
2785
|
Et([
|
2755
2786
|
U()
|
@@ -2773,7 +2804,7 @@ export {
|
|
2773
2804
|
Ni as Environment,
|
2774
2805
|
et as HttpClient,
|
2775
2806
|
Ui as Site,
|
2776
|
-
|
2807
|
+
m as StorageCategory,
|
2777
2808
|
Oi as StorageService,
|
2778
2809
|
A as Trigger,
|
2779
2810
|
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;
|
@@ -42,5 +43,6 @@ export declare class Application {
|
|
42
43
|
mountComponent(component: WidgetComponentType): void;
|
43
44
|
getComponent<T extends WidgetComponentType>(type: string): T | null;
|
44
45
|
private _getTargetElement;
|
46
|
+
private _isEmbeddedInIFrame;
|
45
47
|
render(): Trigger | Wrapper | undefined;
|
46
48
|
}
|