@telia-ace/widget-site 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/index.mjs +3 -4
- package/index.umd.js +1 -1
- package/package.json +1 -1
- package/site.component.d.ts +1 -1
package/index.js
CHANGED
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
* @license
|
|
25
25
|
* Copyright 2017 Google LLC
|
|
26
26
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
|
-
*/function P(n){return v({...n,state:!0,attribute:!1})}var Mt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,C=(n,t,e,i)=>{for(var s=i>1?void 0:i?Rt(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&Mt(t,e,s),s};const rt="https://widgets.ace.teliacompany.net",ot="https://embed.webprovisions.io",It=()=>{if(typeof window<"u"){const n=history.pushState,t=history.replaceState;history.pushState=function(...e){n.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class g extends E{constructor(){super(...arguments),this.apiUrl=rt,this.embedUrl=ot,this._site=null,this._widgets={},this._path=""}async connectedCallback(){super.connectedCallback(),It(),await this.loadSite(),window.addEventListener("locationchange",this.routeChangeListener)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("locationchange",this.routeChangeListener)}
|
|
27
|
+
*/function P(n){return v({...n,state:!0,attribute:!1})}var Mt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,C=(n,t,e,i)=>{for(var s=i>1?void 0:i?Rt(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&Mt(t,e,s),s};const rt="https://widgets.ace.teliacompany.net",ot="https://embed.webprovisions.io",It=()=>{if(typeof window<"u"){const n=history.pushState,t=history.replaceState;history.pushState=function(...e){n.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class g extends E{constructor(){super(...arguments),this.apiUrl=rt,this.embedUrl=ot,this._site=null,this._widgets={},this._path="",this.routeChangeListener=()=>{this._path=window.location.pathname,this.requestUpdate()}}async connectedCallback(){super.connectedCallback(),It(),await this.loadSite(),window.addEventListener("locationchange",this.routeChangeListener)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("locationchange",this.routeChangeListener)}async loadSite(){var i;const e=await(await fetch(`${this.apiUrl}/api/site/${this.siteId}`)).json();this._site=e,(((i=this._site)==null?void 0:i.widgets)||[]).forEach(async s=>{this.addWidgetEl(s.widgetId)})}addWidgetEl(t){const e=`ace-widget_${t}`;let i=document.getElementById(e);i||(i=document.createElement("ace-widget-wrapper"),i.setAttribute("id",e),i.setAttribute("widgetId",t),this.apiUrl!==rt&&i.setAttribute("apiUrl",this.apiUrl),this.embedUrl!==ot&&i.setAttribute("embedUrl",this.embedUrl),document.body.appendChild(i)),this._widgets={...this._widgets,[t]:i},window.ace=window.ace||{_c:[],_w:[],widget:function(s,r){window.ace._w.push([s,r])},configure:function(s){window.ace._c.push(s)}}}render(){if(console.log("path = ",this._path),!this._site)return l;const t=jt(this._site);for(const[e,i]of Object.entries(this._widgets))t.find(r=>r.widgetId===e)?i.isActivated()||i.activate():i.isActivated()&&i.deactivate();return l}}C([v({attribute:!0})],g.prototype,"siteId",2);C([v()],g.prototype,"apiUrl",2);C([v()],g.prototype,"embedUrl",2);C([P()],g.prototype,"_site",2);C([P()],g.prototype,"_widgets",2);C([P()],g.prototype,"_path",2);const jt=n=>{const t=[];return(n.triggers||[]).filter(e=>e.triggerType==="visit").forEach(e=>{const i=window.location.pathname,s=e.condition.outputs||[];e.condition.type==="url"&&s.forEach(r=>{const o=r.action.type==="render_widget";if((r.value===i||r.value==="*")&&o){let a={widgetId:""};try{a=JSON.parse(r.action.data)}catch{a={widgetId:""}}const d=t.findIndex(h=>h.widgetId===a.widgetId)>-1,p=((n==null?void 0:n.widgets)||[]).find(h=>h.widgetId===a.widgetId);p&&!d&&t.push(p)}})}),t};window.customElements.get("ace-site")||window.customElements.define("ace-site",g);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,O=(n,t,e,i)=>{for(var s=i>1?void 0:i?Bt(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&Lt(t,e,s),s};const Wt="https://widgets.ace.teliacompany.net",kt="https://embed.webprovisions.io";class m extends E{constructor(){super(...arguments),this.apiUrl=Wt,this.embedUrl=kt,this.widget=null,this.scriptEl=null,this.activated=!1}async connectedCallback(){super.connectedCallback(),this.widget=await this._loadWidget(this.widgetId)}async _loadWidget(t){return await(await fetch(`${this.apiUrl}/api/widget/${t}`)).json()}_createEmbedScript(){var e;if(!((e=this.widget)!=null&&e.distributionName))return;let t=document.createElement("script");t.setAttribute("type","module"),t.setAttribute("async","true"),t.setAttribute("src",`${this.embedUrl}/d/${this.widget.organization}/${this.widget.distributionName}@latest/index.js`),this.scriptEl=t}isActivated(){return this.activated}async activate(){this.widget||(this.widget=await this._loadWidget(this.widgetId)),this._createEmbedScript(),console.log("activating"),this.activated=!0}async deactivate(){console.log("deactivating"),this.activated=!1}render(){return this.scriptEl?this.scriptEl:l}}O([v({attribute:!0})],m.prototype,"widgetId",2);O([v()],m.prototype,"apiUrl",2);O([v()],m.prototype,"embedUrl",2);O([P()],m.prototype,"widget",2);O([P()],m.prototype,"scriptEl",2);O([P()],m.prototype,"activated",2);customElements.get("ace-widget-wrapper")||customElements.define("ace-widget-wrapper",m);exports.SiteComponent=g;exports.WidgetComponent=m;
|
package/index.mjs
CHANGED
|
@@ -628,7 +628,9 @@ const rt = "https://widgets.ace.teliacompany.net", ot = "https://embed.webprovis
|
|
|
628
628
|
};
|
|
629
629
|
class w extends E {
|
|
630
630
|
constructor() {
|
|
631
|
-
super(...arguments), this.apiUrl = rt, this.embedUrl = ot, this._site = null, this._widgets = {}, this._path = ""
|
|
631
|
+
super(...arguments), this.apiUrl = rt, this.embedUrl = ot, this._site = null, this._widgets = {}, this._path = "", this.routeChangeListener = () => {
|
|
632
|
+
this._path = window.location.pathname, this.requestUpdate();
|
|
633
|
+
};
|
|
632
634
|
}
|
|
633
635
|
async connectedCallback() {
|
|
634
636
|
super.connectedCallback(), It(), await this.loadSite(), window.addEventListener("locationchange", this.routeChangeListener);
|
|
@@ -636,9 +638,6 @@ class w extends E {
|
|
|
636
638
|
disconnectedCallback() {
|
|
637
639
|
super.disconnectedCallback(), window.removeEventListener("locationchange", this.routeChangeListener);
|
|
638
640
|
}
|
|
639
|
-
routeChangeListener() {
|
|
640
|
-
this._path = window.location.pathname, this.requestUpdate();
|
|
641
|
-
}
|
|
642
641
|
async loadSite() {
|
|
643
642
|
var i;
|
|
644
643
|
const e = await (await fetch(`${this.apiUrl}/api/site/${this.siteId}`)).json();
|
package/index.umd.js
CHANGED
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
* @license
|
|
25
25
|
* Copyright 2017 Google LLC
|
|
26
26
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
|
-
*/function O(n){return E({...n,state:!0,attribute:!1})}var Rt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,x=(n,t,e,i)=>{for(var s=i>1?void 0:i?jt(t,e):t,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(t,e,s):r(s))||s);return i&&s&&Rt(t,e,s),s};const dt="https://widgets.ace.teliacompany.net",pt="https://embed.webprovisions.io",It=()=>{if(typeof window<"u"){const n=history.pushState,t=history.replaceState;history.pushState=function(...e){n.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class g extends C{constructor(){super(...arguments),this.apiUrl=dt,this.embedUrl=pt,this._site=null,this._widgets={},this._path=""}async connectedCallback(){super.connectedCallback(),It(),await this.loadSite(),window.addEventListener("locationchange",this.routeChangeListener)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("locationchange",this.routeChangeListener)}
|
|
27
|
+
*/function O(n){return E({...n,state:!0,attribute:!1})}var Rt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,x=(n,t,e,i)=>{for(var s=i>1?void 0:i?jt(t,e):t,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(t,e,s):r(s))||s);return i&&s&&Rt(t,e,s),s};const dt="https://widgets.ace.teliacompany.net",pt="https://embed.webprovisions.io",It=()=>{if(typeof window<"u"){const n=history.pushState,t=history.replaceState;history.pushState=function(...e){n.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class g extends C{constructor(){super(...arguments),this.apiUrl=dt,this.embedUrl=pt,this._site=null,this._widgets={},this._path="",this.routeChangeListener=()=>{this._path=window.location.pathname,this.requestUpdate()}}async connectedCallback(){super.connectedCallback(),It(),await this.loadSite(),window.addEventListener("locationchange",this.routeChangeListener)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("locationchange",this.routeChangeListener)}async loadSite(){var i;const e=await(await fetch(`${this.apiUrl}/api/site/${this.siteId}`)).json();this._site=e,(((i=this._site)==null?void 0:i.widgets)||[]).forEach(async s=>{this.addWidgetEl(s.widgetId)})}addWidgetEl(t){const e=`ace-widget_${t}`;let i=document.getElementById(e);i||(i=document.createElement("ace-widget-wrapper"),i.setAttribute("id",e),i.setAttribute("widgetId",t),this.apiUrl!==dt&&i.setAttribute("apiUrl",this.apiUrl),this.embedUrl!==pt&&i.setAttribute("embedUrl",this.embedUrl),document.body.appendChild(i)),this._widgets={...this._widgets,[t]:i},window.ace=window.ace||{_c:[],_w:[],widget:function(s,o){window.ace._w.push([s,o])},configure:function(s){window.ace._c.push(s)}}}render(){if(console.log("path = ",this._path),!this._site)return l;const t=Lt(this._site);for(const[e,i]of Object.entries(this._widgets))t.find(o=>o.widgetId===e)?i.isActivated()||i.activate():i.isActivated()&&i.deactivate();return l}}x([E({attribute:!0})],g.prototype,"siteId",2),x([E()],g.prototype,"apiUrl",2),x([E()],g.prototype,"embedUrl",2),x([O()],g.prototype,"_site",2),x([O()],g.prototype,"_widgets",2),x([O()],g.prototype,"_path",2);const Lt=n=>{const t=[];return(n.triggers||[]).filter(e=>e.triggerType==="visit").forEach(e=>{const i=window.location.pathname,s=e.condition.outputs||[];e.condition.type==="url"&&s.forEach(o=>{const r=o.action.type==="render_widget";if((o.value===i||o.value==="*")&&r){let a={widgetId:""};try{a=JSON.parse(o.action.data)}catch{a={widgetId:""}}const d=t.findIndex(h=>h.widgetId===a.widgetId)>-1,p=((n==null?void 0:n.widgets)||[]).find(h=>h.widgetId===a.widgetId);p&&!d&&t.push(p)}})}),t};window.customElements.get("ace-site")||window.customElements.define("ace-site",g);var Bt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,T=(n,t,e,i)=>{for(var s=i>1?void 0:i?Wt(t,e):t,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(t,e,s):r(s))||s);return i&&s&&Bt(t,e,s),s};const kt="https://widgets.ace.teliacompany.net",zt="https://embed.webprovisions.io";class m extends C{constructor(){super(...arguments),this.apiUrl=kt,this.embedUrl=zt,this.widget=null,this.scriptEl=null,this.activated=!1}async connectedCallback(){super.connectedCallback(),this.widget=await this._loadWidget(this.widgetId)}async _loadWidget(t){return await(await fetch(`${this.apiUrl}/api/widget/${t}`)).json()}_createEmbedScript(){var e;if(!((e=this.widget)!=null&&e.distributionName))return;let t=document.createElement("script");t.setAttribute("type","module"),t.setAttribute("async","true"),t.setAttribute("src",`${this.embedUrl}/d/${this.widget.organization}/${this.widget.distributionName}@latest/index.js`),this.scriptEl=t}isActivated(){return this.activated}async activate(){this.widget||(this.widget=await this._loadWidget(this.widgetId)),this._createEmbedScript(),console.log("activating"),this.activated=!0}async deactivate(){console.log("deactivating"),this.activated=!1}render(){return this.scriptEl?this.scriptEl:l}}T([E({attribute:!0})],m.prototype,"widgetId",2),T([E()],m.prototype,"apiUrl",2),T([E()],m.prototype,"embedUrl",2),T([O()],m.prototype,"widget",2),T([O()],m.prototype,"scriptEl",2),T([O()],m.prototype,"activated",2),customElements.get("ace-widget-wrapper")||customElements.define("ace-widget-wrapper",m),A.SiteComponent=g,A.WidgetComponent=m,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/site.component.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class SiteComponent extends LitElement {
|
|
|
31
31
|
_path: string;
|
|
32
32
|
connectedCallback(): Promise<void>;
|
|
33
33
|
disconnectedCallback(): void;
|
|
34
|
-
|
|
34
|
+
routeChangeListener: () => void;
|
|
35
35
|
loadSite(): Promise<void>;
|
|
36
36
|
addWidgetEl(widgetId: string): void;
|
|
37
37
|
protected render(): symbol;
|