@telia-ace/widget-core-flamingo 1.1.24 → 1.1.25

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -267,7 +267,7 @@
267
267
  opacity: 0;
268
268
  animation: slideDown 0.3s linear;
269
269
  }
270
- `;sr([y({attribute:!1})],it.prototype,"application",2);class nr{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const r=a=>{if(Array.isArray(a)){const[c,...h]=a;return{definitionId:c,overrides:h}}return{definitionId:a,overrides:[]}},s=(a,c,h,p)=>{h.forEach(l=>{const f=r(l),u=p[f.definitionId];if(!u){console.error(`No definition found for component type '${f.definitionId}'.`);return}const g=a.createNode(u.type,u.type);g&&(g.name=f.definitionId,g.application=e,u.properties&&g.writeProperties(u.properties),u.context&&g.writeContext(u.context),u.layout&&g.writeLayout(u.layout),c.addChild(g),u.children&&s(a,g,u.children,p))})},{entry:n,components:o}=t;return s(this,this.root,[n],o),this.root}createRoot(){return new it}createNode(t,e){const r=this.resolveComponent(e);if(!r)return console.warn(`Unable to resolve component: ${e}`),new _t;const s=new r;return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const ie=class{constructor(){this.components=new Map}getComponent(i){const t=this.components.get(i);return t||console.warn(`Unable to resolve component: ${i}. You most likely forgot to register the required plugin.`),t}registerComponent(i,t){this.components.set(i,t)}async loadComponents(){const i=[...this.components.entries()].map(([t,e])=>e.then(r=>{this.defineAsWebComponent(t,r.default)}));await Promise.all(i)}defineAsWebComponent(i,t){const e=ie.ResolveWebComponentName(i);customElements.get(e)||customElements.define(e,t)}};let se=ie;se.ResolveWebComponentName=i=>`ace-${i}`;class or{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const r=this.texts.get(t);return r||e||null}}class ne{constructor(t,e,r,s){this.name=t,this.container=e,this.settings=r,this.options=s,this.platform=new nr,this.texts=new or,this.renderStrategy=A.Inline,this.autoActivate=!1,this.plugins=[],this.componentResolver=new se,this.renderStrategy=this.options.renderStrategy||A.Inline,this.triggerIcon=this.options.triggerIcon,typeof s.autoActivate=="boolean"&&(this.autoActivate=s.autoActivate),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(Gt.Ready),this.autoActivate){const t=this.render();t&&document.body.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))}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded"))}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}render(){if(this.renderStrategy===A.Trigger){const t=new b;return t.application=this,t}return this.root}}const oe=class{async getSite(i){const e=await(await fetch(i)).json();return e?{id:e.id,apps:e.widgets.map(r=>{let s=A.Inline;return r.renderStrategy==="Trigger"&&(s=A.Trigger),{id:r.id,widgetId:r.widgetId,renderStrategy:s,autoActivate:r.autoActivate,triggerIcon:{type:"Telia",content:r.triggerIcon}}})}:null}async getWidget(i){const e=await(await fetch(`${oe.endpoint}/widget/${i}`)).json();return e?{name:e.name,config:JSON.parse(e.configuration)}:null}};let X=oe;X.endpoint="https://widgets.ace.teliacompany.net/api";class ae{constructor(){this.applications=[],this.container=new vt("environment",this),setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate()}async activate(){const t=this.applications.filter(e=>e.autoActivate);for await(const e of t)await e.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const r=this.applications.find(s=>s.name===e.name);r&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:r}}))})}registerApp(t,e,r){const s=new vt(t,this),n=new ne(t,s,e,r);this.applications.push(n)}}class ce{constructor(t){this.configurations=[],this.httpClient=new X,this.httpClient=new X,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}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new ae,this.addGlobal(this.environment);for await(const r of this.configurations){const s=await this.httpClient.getWidget(r.widgetId);s&&((e=this.environment)==null||e.registerApp(s.name,s.config,{renderStrategy:r.renderStrategy,triggerIcon:r.triggerIcon,autoActivate:r.autoActivate}))}t(this.environment),await this.environment.bootstrap()}addGlobal(t){globalThis.widgets=t}}var ar=Object.defineProperty,cr=Object.getOwnPropertyDescriptor,$t=(i,t,e,r)=>{for(var s=r>1?void 0:r?cr(t,e):t,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=(r?o(t,e,s):o(s))||s);return r&&s&&ar(t,e,s),s};class U extends w{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 d;if(this.widget.renderStrategy===A.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}}U.styles=[B`
270
+ `;sr([y({attribute:!1})],it.prototype,"application",2);class nr{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const r=a=>{if(Array.isArray(a)){const[c,...h]=a;return{definitionId:c,overrides:h}}return{definitionId:a,overrides:[]}},s=(a,c,h,p)=>{h.forEach(l=>{const f=r(l),u=p[f.definitionId];if(!u){console.error(`No definition found for component type '${f.definitionId}'.`);return}const g=a.createNode(u.type,u.type);g&&(g.name=f.definitionId,g.application=e,u.properties&&g.writeProperties(u.properties),u.context&&g.writeContext(u.context),u.layout&&g.writeLayout(u.layout),c.addChild(g),u.children&&s(a,g,u.children,p))})},{entry:n,components:o}=t;return s(this,this.root,[n],o),this.root}createRoot(){return new it}createNode(t,e){const r=this.resolveComponent(e);if(!r)return console.warn(`Unable to resolve component: ${e}`),new _t;const s=new r;return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const ie=class{constructor(){this.components=new Map}getComponent(i){const t=this.components.get(i);return t||console.warn(`Unable to resolve component: ${i}. You most likely forgot to register the required plugin.`),t}registerComponent(i,t){this.components.set(i,t)}async loadComponents(){const i=[...this.components.entries()].map(([t,e])=>e.then(r=>{this.defineAsWebComponent(t,r.default)}));await Promise.all(i)}defineAsWebComponent(i,t){const e=ie.ResolveWebComponentName(i);customElements.get(e)||customElements.define(e,t)}};let se=ie;se.ResolveWebComponentName=i=>`ace-${i}`;class or{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const r=this.texts.get(t);return r||e||null}}class ne{constructor(t,e,r,s){this.name=t,this.container=e,this.settings=r,this.options=s,this.platform=new nr,this.texts=new or,this.renderStrategy=A.Inline,this.autoActivate=!1,this.plugins=[],this.componentResolver=new se,this.renderStrategy=this.options.renderStrategy||A.Inline,this.triggerIcon=this.options.triggerIcon,typeof s.autoActivate=="boolean"&&(this.autoActivate=s.autoActivate),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(Gt.Ready),this.autoActivate){const t=this.render();t&&document.body.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))}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded"))}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}render(){if(this.renderStrategy===A.Trigger){const t=new b;return t.application=this,t}return this.root}}const oe=class{async getSite(i){const e=await(await fetch(i)).json();return e?{id:e.id,apps:e.widgets.map(r=>{let s=A.Inline;return r.renderStrategy==="Trigger"&&(s=A.Trigger),{id:r.id,widgetId:r.widgetId,renderStrategy:s,autoActivate:r.autoActivate,triggerIcon:{type:"Telia",content:r.triggerIcon}}})}:null}async getWidget(i){const e=await(await fetch(`${oe.endpoint}/widget/${i}`)).json();return e?{name:e.name,config:JSON.parse(e.configuration)}:null}};let X=oe;X.endpoint="https://widgets.ace.teliacompany.net/api";class ae{constructor(){this.applications=[],this.container=new vt("environment",this),setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate()}async activate(){const t=this.applications.filter(e=>e.autoActivate);for await(const e of t)await e.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const r=this.applications.find(s=>s.name===e.name);r&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:r}}))})}registerApp(t,e,r){const s=new vt(t,this),n=new ne(t,s,e,r);this.applications.push(n)}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class ce{constructor(t){this.configurations=[],this.httpClient=new X,this.httpClient=new X,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}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new ae,this.addGlobal(this.environment);for await(const r of this.configurations){const s=await this.httpClient.getWidget(r.widgetId);s&&((e=this.environment)==null||e.registerApp(s.name,s.config,{renderStrategy:r.renderStrategy,triggerIcon:r.triggerIcon,autoActivate:r.autoActivate}))}t(this.environment),await this.environment.bootstrap()}addGlobal(t){globalThis.widgets=t}}var ar=Object.defineProperty,cr=Object.getOwnPropertyDescriptor,$t=(i,t,e,r)=>{for(var s=r>1?void 0:r?cr(t,e):t,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=(r?o(t,e,s):o(s))||s);return r&&s&&ar(t,e,s),s};class U extends w{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 d;if(this.widget.renderStrategy===A.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}}U.styles=[B`
271
271
  :host {
272
272
  display: block;
273
273
  }
package/index.mjs CHANGED
@@ -1931,6 +1931,11 @@ class nr {
1931
1931
  const s = new xt(t, this), n = new sr(t, s, e, r);
1932
1932
  this.applications.push(n);
1933
1933
  }
1934
+ plugin(t) {
1935
+ return this.applications.forEach((e) => {
1936
+ e.plugin(t);
1937
+ }), this;
1938
+ }
1934
1939
  }
1935
1940
  class or {
1936
1941
  constructor(t) {
@@ -1,6 +1,6 @@
1
1
  import { Application } from './application';
2
2
  import { Container } from './container';
3
- import { ApplicationOptions, WidgetConfig } from '../types';
3
+ import { ApplicationOptions, PluginType, WidgetConfig } from '../types';
4
4
  export declare class Environment {
5
5
  applications: Application[];
6
6
  container: Container;
@@ -9,4 +9,5 @@ export declare class Environment {
9
9
  private activate;
10
10
  private notifyWidgetsOfCreation;
11
11
  registerApp(name: string, config: WidgetConfig, options: ApplicationOptions): void;
12
+ plugin(plugin: PluginType): this;
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-core-flamingo",
3
- "version": "1.1.24",
3
+ "version": "1.1.25",
4
4
  "dependencies": {
5
5
  "lit": "^3.0.2",
6
6
  "@teliads/icons": "^8.4.0",