@telia-ace/widget-core 1.1.1-rc.1 → 1.1.1-rc.3
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 +3 -3
- package/index.mjs +246 -1444
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class Vt{constructor(t){const{events:e}=t.get("$widget");this.events=e.createChild(this)}action(t,e,s){this.events.dispatch("data:action",{action:e,value:s,target:t},{bubbles:!0})}subscribe(t,e){return this.events.subscribe("data:action",(s,{action:i,value:r,target:o})=>t===o&&e(t,i,r))}}const B=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},yt=n=>{const t=n.container||n;return{info:(e,...s)=>B(t,"info",e,...s),warn:(e,...s)=>B(t,"warning",e,...s),error:(e,...s)=>B(t,"error",e,...s)}},ht=(n,t)=>{if(!t)return!0;if(typeof t=="string"){const e=t.split(",");for(let s=0,i=e.length;s<i;s++){const r=e[s].trim();if(r===n||r==="*")return!0}}return t instanceof Array?t.indexOf(n)>-1:!1},jt=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?qt(t):t;return!(!ht(n.tenant||"",e.tenant||"")||!ht(n.name,e.implementation||""))},Wt=n=>t=>jt(t,n),Q=n=>n instanceof Array&&n.length===1?n[0]:n,qt=n=>{const t={},e=n.split(":");return e.length===1?t.implementation=Q(e[0].split(",")):(t.tenant=Q(e[0].split(",")),t.implementation=Q(e[1].split(","))),t};var D=(n=>(n.Implementation="implementation",n.Widget="widget",n))(D||{}),P=(n=>(n.Pre="pre",n.Post="post",n))(P||{});const Ft=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let c;return i[r]&&(c=i[r].call(i,o)),Promise.resolve(c)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function lt(n,t){return typeof n>"u"?t:n}let Ht=class{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:D.Widget,stage:P.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:lt(e.scope,D.Widget),stage:lt(e.stage,P.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((c,u)=>{u===o.length-1?r[c]||(r[c]=()=>i):r=this.part[c]=this.part[c]||{}}),this}get(){return this.part}};const wt=n=>{const t=new Ht({});return n(t),t.get()};wt(n=>{n.createCommand("types.register",{scope:D.Implementation,stage:P.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:P.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:P.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:P.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,c=e,u=s;typeof e=="string"&&(o=e,c=s,u=i);const h=a=>{const{transformPluginSettings:l}=t.container.get("$environmentOptions"),p=l?l(u||{},o,t.container,c):s;try{const d=Ft(o,c,r,p);r.get("$plugins").push(d),a&&d.invoke("initialize",null)}catch(d){yt(t).warn("Error when initializing plugin",d)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})});function Bt(n,t,e){return Array.from(n.querySelectorAll(`div[id^="${t}_"], div[id^="${t}:"]`)).map(s=>{if(s.id.substr(0,7)===`${t}_`)return{widgetName:s.id.substr(7),element:s};const{3:i}=s.id.split(":");return{widgetName:i,element:s}})}const Qt=n=>{const t=n.map(e=>e.replace(/\./g,"\\.")).join("|");return new RegExp("^((http[s]?:)?//)?("+t+")/([^\\s]+)")},Yt=n=>n.href;function Ut(n,t){const e=Qt(t),s=i=>{const r=e.exec(Yt(i));return r?{element:i,widget:r[4]}:null};return Array.from(n.querySelectorAll("a")).map(i=>s(i)).filter(i=>!!i).map(i=>({element:i.element,widgetName:i.widget}))}function xt(n){return n.filter((t,e,s)=>s.indexOf(t)===e)}let Gt=class{constructor(t){this.container=t.container,this.events=t.events}watch(t){const e=this.container.get("triggerElements")||[],s=xt(e.concat(t));this.container.register("triggerElements",s),this.events.dispatch("bootstrap:trigger-elements-updated",{triggerElements:s},{bubbles:!0})}};function Ct(n,...t){return n.implementation.events.subscribe("widget:create-instance",(e,s)=>{if(e.target===n){let i=n.container.get("bootstrapping.monitor");i||(i=new Gt(n),n.container.register("bootstrapping.monitor",i)),i.watch(t)}}),n.load()}function $t(n,t=document){var e;const s=n.bindings,i=[].concat(Ut(t,s),Bt(t,((e=n.environment)==null?void 0:e.name)||"")),r=xt(i.map(({widgetName:o})=>o)).reduce((o,c)=>{const u=n.widgets.get(c);if(!u)return process.env.NODE_ENV!=="production"&&yt(n).warn(`A trigger element for "${c}" was found but no widget with that name is available on the implementation ("${n.name}"). Make sure this is not a mistake.`),o;const h=i.filter(a=>a.widgetName===c).map(a=>a.element);return o.push(Ct(u,...h)),o},[]);return Promise.all(r)}function Kt(){return new Promise(n=>{document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>n()):n()})}const Jt=(n,t)=>{const e=n;e.scan=i=>$t(e,i),e.bindings=t,e.attach=(i,...r)=>Ct(i,...r);const{environment:s}=e;return typeof s.configure>"u"&&(s.configure=(i,r)=>{let o,c;r?(o=i,c=r):(o="*",c=i),s.implementations.query(o).forEach(u=>u.configure(c)),s.events.subscribe("implementation:created",(u,h)=>{const{implementation:a}=h;Wt(o)(a)&&a.configure(c)})}),e};function Xt(n,t,e=()=>[],s){const i={ready:!1};n.container.register("bootstrapping",i);const r=Jt(n,t);return Kt().then(()=>{n.configure((...o)=>{e().forEach(c=>c(...o))})}).then(()=>$t(r,s())).then(()=>(i.ready=!0,n.events.dispatch("bootstrap:ready",{}),r))}const Zt=wt(n=>{n.createCommand("ready",{scope:D.Implementation,stage:P.Pre},t=>e=>{const{container:s}=t,i=s.owner;s.get("bootstrapping").ready?e(i):i.events.subscribeOnce("bootstrap:ready",()=>{e(i)})})}),Y=new WeakMap;function A(){return n=>(Y.has(n)||Y.set(n,{}),Y.get(n))}const U=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},g=n=>{const t=n.container||n;return{info:(e,...s)=>U(t,"info",e,...s),warn:(e,...s)=>U(t,"warning",e,...s),error:(e,...s)=>U(t,"error",e,...s)}},m=A(),X=(()=>{let n=0;return()=>++n})(),Z=(n,t,e)=>{const s=m(n).touchQueue.get(t);s&&s.forEach(i=>{i(e,n)})};class te{constructor(t,e,s,i){this.key=t,this.factory=e,this.parent=s,this.container=i,this.id=X(),this.resolved=!1,this.constructed=!1,this.async=!0}resolve(){if(!this.constructed){const t=this.factory(this.parent,this.container);return this.constructed=!0,this.value=Promise.resolve(t).then(e=>(this.resolved=!0,Z(this.container,this.key,e),e))}return this.value}}class ee{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=X(),this.async=!1,this.resolved=!1,this.constructed=!0,this.resolve=()=>(this.resolved=!0,Z(this.container,this.key,this.value),this.value)}}class se{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=X(),this.async=!1,this.resolved=!1,this.constructed=!1,this.resolve=()=>{this.resolved=!0,this.constructed=!0;const r=this.value(this.parent,this.container);return Z(this.container,this.key,this.value),r}}}class tt{constructor(t,e,s){this.owner=t,this.name=e,this.parent=s,m(this).resolvers=new Map,m(this).touchQueue=new Map,m(this).children=[]}delete(t){const e=m(this).resolvers,s=Array.from(e.values()).find(i=>i.id===t);return s?(m(this).touchQueue.delete(s.key),Promise.resolve(e.delete(s.key))):this.parent?this.parent.delete(t):Promise.resolve(!1)}clear(){const t=m(this).resolvers,e=Array.from(t.values());return Promise.all(e.map(s=>{if(s.constructed)return Promise.resolve(s.resolve()).then(i=>{if(i!==null&&typeof i=="object"&&typeof i.dispose=="function")return i.dispose.call(i,this,s)})})).then(()=>{e.forEach(s=>this.delete(s.id)),m(this).children.forEach(s=>s.clear())})}detach(){if(this.parent){const t=m(this.parent).children,e=t.indexOf(this);e>-1&&(t.splice(e,1),delete this.parent)}}touch(t,e){const s=m(this).resolvers.get(t);if(s&&s.constructed)Promise.resolve(s.resolve()).then(i=>{e(i,this)});else{const i=m(this).touchQueue;let r=i.get(t);r||(r=[],i.set(t,r)),r.push(e)}return this.parent&&!s?this.parent.touch(t,e):Promise.resolve()}registerAsync(t,e){const s=m(this).resolvers.get(t);s&&!s.async&&process.env.NODE_ENV!=="production"&&g(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${t}') previously used by a non-async resolver.`);const i=new te(t,e,s,this);return m(this).resolvers.set(t,i),i.id}registerFactory(t,e){const s=m(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&g(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new se(t,e,s,this);return m(this).resolvers.set(t,i),i.id}register(t,e){const s=m(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&g(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new ee(t,e,s,this);return m(this).resolvers.set(t,i),i.id}get(t){const e=m(this).resolvers.get(t);if(e)return e.async&&process.env.NODE_ENV!=="production"&&g(this).warn(`You are retrieving an async value (with key '${t}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`),e.resolve();if(this.parent)return this.parent.get(t)}getAsync(t){const e=m(this).resolvers.get(t);if(e){if(!e.async)throw process.env.NODE_ENV!=="production"&&g(this).warn(`You are retrieving a non-async value (with key '${t}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`),"Mismatching resolver type";return e.resolve()}return this.parent?this.parent.getAsync(t):Promise.resolve(void 0)}getMany(...t){const e={};return t.forEach(s=>e[s]=this.get(s)),e}getManyAsync(...t){const e={};return Promise.all(t.map(s=>this.getAsync(s).then(i=>e[s]=i))).then(()=>e)}createChild(t,e){const s=new tt(t,e,this);return m(this).children.push(s),s}}class ut{constructor(t,e,s=!1,i=!1){this.type=t,this.target=e,this.cancelable=!!s,this.bubbles=!!i,this.defaultPrevented=!1}preventDefault(){this.cancelable&&(this.defaultPrevented=!0)}}const b=A(),pt=(n,t)=>[].concat(b(n).listenerLookup.get(t.toLowerCase())||[],b(n).listenerLookup.get("*")||[]),dt=(n,t,e,s)=>{let i,r;return t instanceof ut?(i=t,r=t.type):(i=new ut(t,n.target,!!e.cancelable,!!e.bubbles),r=t),{event:i,type:r,async:s}};class et{constructor(t,e){this.target=t,this.parent=e,b(this).listenerLookup=new Map,b(this).children=[]}clear(){b(this).listenerLookup.clear(),b(this).children.forEach(t=>t.clear())}detach(){if(this.parent){const t=b(this.parent).children,e=t.indexOf(this);e>-1&&t.splice(e,1)}}subscribe(t,e,s){const i=b(this).listenerLookup,r=t.toLowerCase();return i.has(r)||i.set(r,[]),i.get(r).push(e),()=>this.unsubscribe(t,e)}subscribeOnce(t,e){const s=this.subscribe(t,(i,r)=>(s(),e(i,r)))}unsubscribe(t,e){const s=b(this).listenerLookup.get(t.toLowerCase());if(s){const i=s.indexOf(e);i>-1&&s.splice(i,1)}}dispatchAsync(t,e,s={}){const{event:i,type:r}=dt(this,t,s,!0),o=pt(this,r);let c=0;const u=o.length;let h=Promise.resolve();for(c=0;c<u;c++)(a=>{h=h.then(l=>l?Promise.resolve(!0):Promise.resolve(a(i,e)).then(()=>i.defaultPrevented))})(o[c]);return h.then(a=>!a&&i.bubbles&&this.parent?this.parent.dispatchAsync(i,e):a)}dispatch(t,e,s={}){const{event:i,type:r}=dt(this,t,s,!1),o=pt(this,r);let c=0;const u=o.length;let h=!1;for(c=0;c<u;c++)if(o[c](i,e),i.defaultPrevented){h=!0;break}return!h&&i.bubbles&&this.parent&&(h=this.parent.dispatch(i,e)),h}createChild(t){const e=new et(t,this);return b(this).children.push(e),e}}const I=(n,t,e)=>{const s=n.get("$plugins").map(i=>{try{return i.invoke(t,e)}catch(r){g(n).error("An error occured when invoking a plugin.",i,r)}});return Promise.all(s)};class ne{constructor(t){this.widget=t.get("$widget"),this.events=this.widget.events,this.container=this.widget.container,this.initialized=null,this.activated=null,this.initialize=this.initialize.bind(this),this.activate=this.activate.bind(this),this.deactivate=this.deactivate.bind(this),this.invoke=this.invoke.bind(this),this.createInstance()}createInstance(){if(!this.widget.container.get("$instance")){const t=this.widget.container.get("$types"),e=this.widget.container.get("$type");!e&&g(this).error("Unable to create widget. No type is specified.");const s=t[e];!s&&g(this).error(`Unable to create widget. Type '${e}' is not registered.`),this.widget.events.dispatch("widget:create-instance",{},{bubbles:!0});try{this.widget.container.register("$instance",new s(this.container))}catch(i){g(this).error("Unable to create widget type.",i)}this.widget.events.dispatch("widget:instance-created",{},{bubbles:!0})}}initialize(t){return this.initialized=this.initialized||(()=>{const e=this.container.get("$instance"),s=e.initialize||(()=>{});return this.initialized=Promise.resolve(s.call(e,t)).then(()=>I(this.container,"initialize",t)).then(()=>{})})()}activate(t){return(this.initialized||this.initialize()).then(()=>{this.activated=this.activated||(()=>I(this.container,"activate").then(()=>{const e=this.container.get("$instance");return this.activated=e.activate(t)}))()})}deactivate(){const t=this.container.get("$instance"),e=t.deactivate||(()=>{});return I(this.container,"deactivate").then(()=>Promise.resolve(e.call(t))).then(()=>{this.initialized=null,this.activated=null}).then(()=>{})}invoke(t,...e){return I(this.container,"invoke",{command:t,args:e}).then(()=>{const s=this.container.get("$instance");if(s[t])return s[t].apply(s,e);const i=s.invoke;if(i)return i.call(s,t,...e)})}}const O=(n,t)=>{if(!t)return!0;if(typeof t=="string"){const e=t.split(",");for(let s=0,i=e.length;s<i;s++){const r=e[s].trim();if(r===n||r==="*")return!0}}return t instanceof Array?t.indexOf(n)>-1:!1},ie=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?oe(t):t;return!(!O(n.implementation.tenant||"",e.tenant||"")||!O(n.implementation.name,e.implementation||"")||!O(n.name,e.widget||"")||!O(n.container.get("$type"),e.type||""))},re=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?ce(t):t;return!(!O(n.tenant||"",e.tenant||"")||!O(n.name,e.implementation||""))},kt=n=>t=>ie(t,n),Pt=n=>t=>re(t,n),x=n=>n instanceof Array&&n.length===1?n[0]:n,oe=n=>{const t={},e=n.split(":");return e.length===1?t.widget=x(e[0].split(",")):e.length===2?(t.implementation=x(e[0].split(",")),t.widget=x(e[1].split(","))):(t.tenant=x(e[0].split(",")),t.implementation=x(e[1].split(",")),t.widget=x(e[2].split(","))),t},ce=n=>{const t={},e=n.split(":");return e.length===1?t.implementation=x(e[0].split(",")):(t.tenant=x(e[0].split(",")),t.implementation=x(e[1].split(","))),t},M=A(),mt=(n,t,e)=>n.filter(s=>s.stage===t&&kt(s.selector)(e));function ae(n){const t=n.container.get("$environment");let e=M(t).configurationCache;e&&(e=e.filter(s=>s[0]!==n),M(t).configurationCache=e)}var z=(n=>(n.Implementation="implementation",n.Widget="widget",n))(z||{}),C=(n=>(n.Pre="pre",n.Post="post",n))(C||{});const Et=(n,t,e)=>(Object.keys(t).forEach(s=>{const i=t[s];if(typeof i=="function"){const r=i();typeof r.defaultArgs<"u"&&e(r,...r.defaultArgs),n[s]=(...o)=>{const c=Object.assign({},r,{handlerResolver:r.handlerResolver.bind({})});return e(c,...o),n}}else n[s]=Et({},i,e)}),n),he=(n,t)=>{switch(t){case"implementation":return n.implementation;case"widget":return n}},gt=(n,t,e,s)=>(s.forEach(i=>{Et(n,i,(r,...o)=>{const c={selector:t,stage:r.stage,handler:u=>{const h=he(u,r.scope),a={container:h.container,events:h.events},l=r.handlerResolver,p=l(a);let d=M(e.environment).configurationCache;return d||(d=M(e.environment).configurationCache=[]),d.find($=>$.indexOf(h)>-1&&$.indexOf(l)>-1)?Promise.resolve():(d.push([h,l]),Promise.resolve(p(...o)))}};e.instructions.push(c)})}),n);function le(n,t){function e(s){return gt({},s,n,t)}return gt(e,"*",n,t)}class ue{constructor(t,e){this.container=t,this.settings=e,this.widget=t.get("$widget"),this.events=this.widget.events}}const pe=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let c;return i[r]&&(c=i[r].call(i,o)),Promise.resolve(c)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function ft(n,t){return typeof n>"u"?t:n}class de{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:z.Widget,stage:C.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:ft(e.scope,z.Widget),stage:ft(e.stage,C.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((c,u)=>{u===o.length-1?r[c]||(r[c]=()=>i):r=this.part[c]=this.part[c]||{}}),this}get(){return this.part}}const Ot=n=>{const t=new de({});return n(t),t.get()},me=Ot(n=>{n.createCommand("types.register",{scope:z.Implementation,stage:C.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:C.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:C.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:C.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,c=e,u=s;typeof e=="string"&&(o=e,c=s,u=i);const h=a=>{const{transformPluginSettings:l}=t.container.get("$environmentOptions"),p=l?l(u||{},o,t.container,c):s;try{const d=pe(o,c,r,p);r.get("$plugins").push(d),a&&d.invoke("initialize",null)}catch(d){g(t).warn("Error when initializing plugin",d)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})}),ge=me;function fe(n,t,e=[]){const s=[ge].concat(e),i=le(t,s);n(i,t)}class ve{constructor(){this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(t,e,s,i){this.tasks.push({task:t,resolve:e,reject:s,done:i}),this.next()}next(){this.current=this.current.then(()=>{const t=this.tasks.shift();if(t){const e=Promise.resolve(t.task());return Promise.resolve(e).then(this.next).then(()=>e.then(s=>{t.done(),t.resolve(s)})).catch(s=>(t.done(),t.reject(s),this.next()))}return Promise.resolve()})}}const S=new WeakMap;function be(n){return S.has(n)||S.set(n,new ve),t=>new Promise((e,s)=>{const i=S.get(n);i.add(t,e,s,()=>{i.tasks.length||S.delete(n)})})}const vt=n=>typeof n<"u",_=(n,t)=>{n.events.dispatch("widget:state-change",{state:t},{bubbles:!0}),n.state=t,n.events.dispatch("widget:state-changed",{},{bubbles:!0})},v=A(),ye=n=>{const{container:t,events:e}=n;t.get("$controller")||(t.register("$controller",new ne(t)),e.dispatch("widget:controller-created",{},{bubbles:!0}))};class we{constructor(t,e,s){this.state="deactivated",this.name=t,this.implementation=e,this.container=e.container.createChild(this,t),this.events=e.events.createChild(this),v(this).subscriptions=[],s&&e.configure(i=>{const r=i(t);vt(s.type)&&r.type(s.type),vt(s.settings)&&r.settings(s.settings),s.plugins&&Object.keys(s.plugins).forEach(o=>{var c;const u=(c=s.plugins)==null?void 0:c[o];r.plugin(o,u)})}),this.load=this.load.bind(this),this.activate=this.activate.bind(this),this.invoke=this.invoke.bind(this),this.deactivate=this.deactivate.bind(this)}load(){return be(this)(()=>{v(this).deactivatedPromise=null;const t=this.state==="deactivated";t&&(_(this,"activating"),this.container.register("$widget",this),this.container.register("$controller",null),this.container.register("$plugins",[]),this.container.register("$type",null),this.container.register("$instance",null)),_(this,"loading");const e=this.implementation.instructions,s=mt(e,C.Pre,this);return Promise.all(s.map(i=>i.handler(this))).then(()=>{ye(this);const i=mt(e,C.Post,this);return Promise.all(i.map(r=>r.handler(this))).then(()=>{t&&this.container.get("$controller").initialize()})}).then(()=>(_(this,"activated"),this))})}activate(t){v(this).subscriptions.push(this.implementation.events.subscribe("implementation:configured",()=>{["activated","activating","loading"].indexOf(this.state)>-1&&this.load()}));const e=v(this).activatedPromise;return e?(process.env.NODE_ENV!=="production"&&g(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`,t),e):v(this).activatedPromise=this.load().then(()=>this.container.get("$controller").activate(t))}invoke(t,...e){const s=v(this).activatedPromise,i=(r,...o)=>s.then(this.load).then(()=>this.container.get("$controller").invoke(r,...o));return s?i(t,...e):(process.env.NODE_ENV!=="production"&&g(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.",this),new Promise(r=>{const o=this.events.subscribe("widget:state-changed",()=>{this.state==="activated"&&(o(),r(i(t,...e)))})}))}deactivate(){return v(this).deactivatedPromise||(this.state==="deactivated"?Promise.resolve():(_(this,"deactivating"),v(this).deactivatedPromise=this.container.get("$controller").deactivate().then(()=>(v(this).activatedPromise=null,v(this).subscriptions.forEach(e=>e()),v(this).subscriptions=[],this.container.clear().then(()=>{this.events.clear(),ae(this),_(this,"deactivated")})))))}}class xe{constructor(t){this.container=t,this.widget=t.get("$widget"),this.settings=t.get("$settings"),this.events=this.widget.events,this.widget.events.subscribe("settings:change",(e,s)=>{this.settings=s})}}const bt=A();class At{constructor(t,e,s=[]){this.instructions=[],this.widgets=new Map,this.name=t.name,this.tenant=t.tenant,this.environment=e,this.container=e.container.createChild(this,this.name),this.events=e.events.createChild(this),this.container.register("$types",{}),bt(this).configurationApiExtensions=s}load(){const t=Array.from(this.widgets.values());return Promise.all(t.map(e=>e.load())).then(()=>t)}configure(t){return fe(t,this,bt(this).configurationApiExtensions),this.events.dispatch("implementation:configured",{implementation:this},{bubbles:!0}),this}createWidget(t,e){const s=new we(t,this,e);return this.widgets.set(s.name,s),s}}function Ce(n,t,e){const s=new At(n,t,e);return n.widgets&&Object.keys(n.widgets).forEach(i=>{var r;const o=(r=n.widgets)==null?void 0:r[i];s.createWidget(i,o)}),s}class T{constructor(t,e){this.selectorFactory=e,typeof t=="function"?this.resolver=t:this.resolver=()=>t}append(t){const e=typeof t=="function"?t:()=>t;return new T(()=>this.all().concat(e()),this.selectorFactory)}all(){return this.resolver().concat([])}query(t){return this.all().filter(this.selectorFactory(t))}find(t){const e=this.query(t);if(e.length)return e[0]}}const st="#____version____#",G=A(),$e=n=>n.tenant?`${n.name}:${n.tenant}`:n.name,Nt=class{constructor(n,t=[],e={}){this.widgets=new T(()=>{let s=[];return this.implementations.all().forEach(i=>{s=s.concat(Array.from(i.widgets.values()))}),s},kt),this.implementations=new T([],Pt),this.name=n,this.container=new tt(this,n),this.events=new et(this),this.container.register("$version",st),this.container.register("$environment",this),this.container.register("$environmentOptions",e),G(this).configurationApiExtensions=t}createImplementation(n){const t=$e(n);let e=this.implementations.find(t);if(e)return process.env.NODE_ENV!=="production"&&g(e).warn(`Implementation "${t}" already exist on current environment.`),e;const s=G(this).configurationApiExtensions;return e=Ce(n,this,s),this.implementations=this.implementations.append([e]),this.events.dispatch("implementation:created",{implementation:e}),e}patch(n={}){const{name:t,configurationApiExtensions:e}=n;typeof t<"u"&&t!==null&&(this.name=t),e&&e.forEach(s=>{G(this).configurationApiExtensions.push(s)})}static create(n={}){return new Nt(n.name||"",n.configurationApiExtensions,n.options)}};let _t=Nt;_t.version=st;const ke=(n,t,e={})=>Xt(n,n.bindings,()=>{const s=n.container.get("$runtimecfg").map(i=>{const r=i[0];if(typeof r=="function")return r;if(Pt(r)(n))return i[1]}).filter(i=>!!i);return(t?[t]:[]).concat(s)},e.rootElementResolver||(()=>document.body)),Rt=n=>{const t=[];return[(s,i)=>{t.push(n.subscribe(s,i))},()=>{t.forEach(s=>{s()})}]};class j{constructor(t,e=[]){this.platform=t,this.rules=e}match(t){return this.rules.every(e=>!(e.id&&e.id!==t.id||e.type&&e.type!==t.type))}ofType(t){return this.rules.push({type:t}),this}withId(t){return this.rules.push({id:t}),this}select(){return new Pe(this.platform,this)}}class nt{constructor(t,e,s){this.platform=t,this.node=e,this.actions=new W(t,new j(t).withId(e.id),s);const[i,r]=Rt(this.platform.events);this.subscribe=i,this.unsubscribe=r}properties(t){return t&&this.node.touchProperties(e=>t(e)),this.node.attributes.properties}context(t){return t&&this.subscribe("components:context-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.context)}),this.node.attributes.context}layout(t){return t&&this.subscribe("components:layout-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(t,e){this.node.writeProperties(t,e)}writeContext(t,e){this.node.writeProperties(t,e)}writeLayout(t,e){this.node.writeLayout(t,e)}dispose(){this.unsubscribe(),this.actions.dispose()}}class Pe{constructor(t,e,s=!0){this.platform=t,this.target=e,this.clearOnDispose=s,this.removes=[],this.actions=new W(this.platform,this.target)}writeProperties(t,e){this.removes.push(this.platform.write({options:e,attributes:{properties:t},target:this.target,removable:this.clearOnDispose}))}writeContext(t,e){this.removes.push(this.platform.write({options:e,attributes:{context:t},target:this.target,removable:this.clearOnDispose}))}writeLayout(t,e){this.removes.push(this.platform.write({options:e,attributes:{layout:t},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(t=>{t()}),this.actions.dispose()}}const Ee=(n,t,e)=>{const s=n.concat(),i=(r,o,c)=>{let u=!0;if(s.length){const h=s.shift(),a=(l,p)=>(u=!1,i(l,Object.assign({},o,p),c));return Promise.resolve(h(r,a,c)).then(l=>({...l,cancelled:u}))}return Promise.resolve({data:r,cancelled:!1,options:o})};return i(t,{},e)};class W{constructor(t,e,s){this.platform=t,this.target=e,this.ns=s,this.subscriptions=[],this.create=this.create.bind(this)}create(t,e=()=>{}){const s={key:t,fn:e,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(s);const i=()=>{const r=this.platform.actionsState.handlers.indexOf(s);r>-1&&this.platform.actionsState.handlers.splice(r,1)};return this.subscriptions.push(i),i}dispatch(t,e){const s=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},r=this.platform.actionsState.handlers.filter(o=>o.key===t&&(!o.ns||!this.ns||o.ns===this.ns));return Promise.all(r.map(o=>{const c=s.filter(h=>o.target.match(h)&&this.target.match(h)),u=this.platform.actionsState.watchers.filter(h=>h.key===t&&(!h.ns||!this.ns||h.ns===this.ns)&&c.some(a=>h.target.match(a))).map(h=>h.fn);return Promise.all(c.map(h=>{const a=new nt(this.platform,h,this.ns);return Ee(u,e,a).then(l=>{const{data:p={},options:d,cancelled:$}=l;return Promise.resolve($?{}:o.fn(p,d,a)).then(N=>{i[h.id]=N})})}))})).then(()=>i)}watch(t,e){let s=t,i=this.ns;const r=t.split(".");r.length>1&&(i=r[0],s=r.splice(1).join("."));const o={fn:e,target:this.target,key:s,ns:i};this.platform.actionsState.watchers.push(o);const c=()=>{const u=this.platform.actionsState.watchers.indexOf(o);u>-1&&this.platform.actionsState.watchers.splice(u,1)};return this.subscriptions.push(c),c}dispose(){this.subscriptions.forEach(t=>t())}}const Oe=Ot(n=>{n.createCommand("components",t=>e=>{t.events.subscribeOnce("components:platform-created",(s,{platform:i})=>{e.handlers&&e.handlers.forEach(([r,o])=>{i.addComponentHandler(r,o)})})})}),q=(n,t,...e)=>typeof t=="string"?n(`[humany] ${t}`,...e):n(t,...e),R=class{constructor(){this.keys=[],this.log=(n,...t)=>this.lookup(n,()=>R.log(...t)),this.warn=(n,...t)=>this.lookup(n,()=>R.warn(...t)),this.error=(n,...t)=>this.lookup(n,()=>R.error(...t)),this.info=(n,...t)=>this.lookup(n,()=>R.info(...t))}lookup(n,t){this.keys.indexOf(n)===-1&&(this.keys.push(n),t())}};let E=R;E.log=(...n)=>q(console.log,...n);E.warn=(...n)=>q(console.warn,...n);E.error=(...n)=>q(console.error,...n);E.info=(...n)=>q(console.info,...n);const k=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);function it(){return k()+k()+"-"+k()+"-"+k()+"-"+k()+"-"+k()+k()+k()}class J{constructor(t,e){this.events=t,this.tags=[],this.children={},this.changesets=[],this.mountCount=0,this.id=it(),this.type=e,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(t,e){let s=t.get("mounted-nodes");return s||(s=new Map,t.register("mounted-nodes",s)),s.has(this)?(process.env.NODE_ENV!=="production"&&E.error("Trying to mount an already mounted component node.",this),()=>{}):(this.events.dispatch("components:node-mounted",{node:this}),this.mountCount===0&&(this.mountCount=this.mountCount+1,this.events.dispatch("components:node-enter",{node:this})),()=>{s.delete(this),this.events.dispatch("components:node-unmounted",{node:this}),this.mountCount=this.mountCount-1,this.mountCount===0&&this.events.dispatch("components:node-exit",{node:this})})}appendChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].push(t),this.events.dispatch("components:node-appended",{node:t})}prependChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].unshift(t),this.events.dispatch("components:node-appended",{node:t})}touchProperties(t,e={},s){const r=[{properties:t},e];return this.changesets.push(r),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const o=this.changesets.indexOf(r);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(t,e={},s){const r=[{properties:t},e];return this.changesets.push(r),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const o=this.changesets.indexOf(r);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(t,e={},s){const r=[{layout:t},e];return this.changesets.push(r),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!s)return;const o=this.changesets.indexOf(r);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(t,e={},s){const r=[{context:t},e];return this.changesets.push(r),this.events.dispatch("components:set-context",{node:this}),()=>{if(!s)return;const o=this.changesets.indexOf(r);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(t="default"){const e=this.children[t]||[];return e.reduce((s,i,r)=>{const{order:o=r}=i.attributes.layout;return s[o]?s.splice(o,0,i):s[o]=i,s},Array(e.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(t){Object.keys(this.children).forEach(e=>{const s=this.children[e],i=s.indexOf(t);i>-1&&(s.splice(i,1),this.events.dispatch("components:node-removed",{node:t,parentNode:this}))}),delete t.parent}}const Dt=(n,t,e)=>{for(let s=0,i=n.length;s<i&&e(n[s])!==!0;s++){const r=t[n[s].id]||"default",o=n[s].getChildren(r);Dt(o,t,e)}},F=(n,t,e)=>{if(e(n)!==!0){const s=t[n.id]||"default",i=n.children[s];Dt(i,t,e)}},L=(n,t)=>{const e=[];return F(n,t,s=>{e.push(s)}),e},It=(n,t,e)=>{let s;return F(n,t,i=>{if(e(i))return s=i,!0}),s};class Ae{constructor(t,e,s){this.root=t,this.switches=e,this.all=[],this.visible=[],this.detached=[],s.subscribe("components:node-appended",(i,r)=>{this.all.push(r.node),this.visible=L(t,e)}),s.subscribe("components:node-removed",(i,r)=>{let o=this.all.indexOf(r.node);o>-1&&this.all.splice(o,1),o=this.visible.indexOf(r.node),o>-1&&this.visible.splice(o,1),this.visible=L(t,e)}),s.subscribe("components:node-switched",(i,r)=>{this.visible=L(t,e)})}query(t={}){const e=[];return F(this.root,this.switches,s=>{Object.keys(t).every(r=>t[r]===s[r])&&e.push(s)}),e}get(t){return It(this.root,this.switches,e=>e.id===t)||this.detached.find(e=>e.id===t)}}class Ne{constructor(){this.handlers=new Map}add(t,e){this.handlers.set(t,e)}get(t){return this.handlers.get(t)}}const _e=n=>{let t=n,e=0;for(;t.parent;)e=e+1,t=t.parent;return e},Re=n=>n.map(([e,s])=>[_e(e),e,s]).sort(([e],[s])=>e-s).map(([,e,s])=>[e,s]),K=n=>n instanceof Date?!1:n&&typeof n=="object"&&!Array.isArray(n),w=(n,...t)=>{if(!t.length)return n;const e=t.shift();if(K(n)&&K(e))for(const s in e)K(e[s])?(n[s]||Object.assign(n,{[s]:{}}),w(n[s],e[s])):Object.assign(n,{[s]:e[s]});return w(n,...t)},De=(n,t)=>!n||n==="all"?!0:n.some(e=>t.indexOf(e)>-1),Ie=(n,t)=>{let e=[],s=[],i;const r=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const c=new Map,u=Re(e.map((a,l)=>[a,s[l]])),h=(a,l)=>{var at;const p=c.get(a)||{},d=l.context&&!p.context,$=l.properties&&!p.properties,N=l.layout&&!p.layout;c.set(a,{context:p.context||d,properties:p.properties||$,layout:p.layout||N}),$&&(a.attributes.properties={}),N&&(a.attributes.layout={}),d&&(a.attributes.context=w({},(at=a.parent)==null?void 0:at.attributes.context));const rt=[],ot=[],ct=[];if(a.changesets.forEach(y=>{const[f,H]=y;De(H.breakpoints,n.breakpoints)&&($&&(typeof f.properties=="function"?rt.push(f.properties):w(a.attributes.properties,f.properties)),N&&(typeof f.layout=="function"?ot.push(f.layout):w(a.attributes.layout,f.layout)),d&&(typeof f.context=="function"?ct.push(f.context):w(a.attributes.context,f.context)))}),rt.forEach(y=>{w(a.attributes.properties,y(a.attributes.properties))}),ot.forEach(y=>{w(a.attributes.layout,y(a.attributes.layout))}),ct.forEach(y=>{w(a.attributes.context,y(a.attributes.context))}),d||l.recursive){const y=n.getBranch(a),f=l.recursive?l:{context:!!d};a.getChildren(y).forEach(H=>{h(H,f)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),u.forEach(([a,l])=>{h(a,l)}),e=[],s=[],t(c)},o=()=>{clearTimeout(i),i=setTimeout(r,0)};return(c,u)=>{const h=e.indexOf(c);if(h>-1){const a=s[h];return u.context&&(a.context=!0),u.properties&&(a.properties=!0),u.layout&&(a.layout=!0),u.recursive&&(a.recursive=!0),o()}return e.push(c),s.push(u),o()}};class St{constructor(t,e={}){this.providers=e,this.breakpoints=[],this.actionsState={handlers:[],watchers:[]},this.switches={},this.changesets=[],this.subscriptions=[],this.customComponentHandler=new Ne,this.events=t.events.createChild(this);const s=new J(this.events,"root");s.name=`root-${t.name}`,this.nodes=new Ae(s,this.switches,this.events);const i=this.processNode=Ie(this,r=>{const o=Array.from(r.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
|
|
2
|
-
${
|
|
3
|
-
`)}`),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("@webprovisions/bootstrapping"),b=require("@webprovisions/platform"),g=require("@telia-ace/widget-utilities");class Q{constructor(t){const{events:e}=t.get("$widget");this.events=e.createChild(this)}action(t,e,s){this.events.dispatch("data:action",{action:e,value:s,target:t},{bubbles:!0})}subscribe(t,e){return this.events.subscribe("data:action",(s,{action:i,value:r,target:c})=>t===c&&e(t,i,r))}}const z=(n,t,e={})=>$.bootstrapImplementation(n,n.bindings,()=>{const s=n.container.get("$runtimecfg").map(i=>{const r=i[0];if(typeof r=="function")return r;if(b.selectImplementations(r)(n))return i[1]}).filter(i=>!!i);return(t?[t]:[]).concat(s)},e.rootElementResolver||(()=>document.body)),L=n=>{const t=[];return[(s,i)=>{t.push(n.subscribe(s,i))},()=>{t.forEach(s=>{s()})}]};class E{constructor(t,e=[]){this.platform=t,this.rules=e}match(t){return this.rules.every(e=>!(e.id&&e.id!==t.id||e.type&&e.type!==t.type))}ofType(t){return this.rules.push({type:t}),this}withId(t){return this.rules.push({id:t}),this}select(){return new U(this.platform,this)}}class A{constructor(t,e,s){this.platform=t,this.node=e,this.actions=new O(t,new E(t).withId(e.id),s);const[i,r]=L(this.platform.events);this.subscribe=i,this.unsubscribe=r}properties(t){return t&&this.node.touchProperties(e=>t(e)),this.node.attributes.properties}context(t){return t&&this.subscribe("components:context-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.context)}),this.node.attributes.context}layout(t){return t&&this.subscribe("components:layout-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(t,e){this.node.writeProperties(t,e)}writeContext(t,e){this.node.writeProperties(t,e)}writeLayout(t,e){this.node.writeLayout(t,e)}dispose(){this.unsubscribe(),this.actions.dispose()}}class U{constructor(t,e,s=!0){this.platform=t,this.target=e,this.clearOnDispose=s,this.removes=[],this.actions=new O(this.platform,this.target)}writeProperties(t,e){this.removes.push(this.platform.write({options:e,attributes:{properties:t},target:this.target,removable:this.clearOnDispose}))}writeContext(t,e){this.removes.push(this.platform.write({options:e,attributes:{context:t},target:this.target,removable:this.clearOnDispose}))}writeLayout(t,e){this.removes.push(this.platform.write({options:e,attributes:{layout:t},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(t=>{t()}),this.actions.dispose()}}const W=(n,t,e)=>{const s=n.concat(),i=(r,c,a)=>{let u=!0;if(s.length){const h=s.shift(),o=(p,l)=>(u=!1,i(p,Object.assign({},c,l),a));return Promise.resolve(h(r,o,a)).then(p=>({...p,cancelled:u}))}return Promise.resolve({data:r,cancelled:!1,options:c})};return i(t,{},e)};class O{constructor(t,e,s){this.platform=t,this.target=e,this.ns=s,this.subscriptions=[],this.create=this.create.bind(this)}create(t,e=()=>{}){const s={key:t,fn:e,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(s);const i=()=>{const r=this.platform.actionsState.handlers.indexOf(s);r>-1&&this.platform.actionsState.handlers.splice(r,1)};return this.subscriptions.push(i),i}dispatch(t,e){const s=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},r=this.platform.actionsState.handlers.filter(c=>c.key===t&&(!c.ns||!this.ns||c.ns===this.ns));return Promise.all(r.map(c=>{const a=s.filter(h=>c.target.match(h)&&this.target.match(h)),u=this.platform.actionsState.watchers.filter(h=>h.key===t&&(!h.ns||!this.ns||h.ns===this.ns)&&a.some(o=>h.target.match(o))).map(h=>h.fn);return Promise.all(a.map(h=>{const o=new A(this.platform,h,this.ns);return W(u,e,o).then(p=>{const{data:l={},options:d,cancelled:y}=p;return Promise.resolve(y?{}:c.fn(l,d,o)).then(x=>{i[h.id]=x})})}))})).then(()=>i)}watch(t,e){let s=t,i=this.ns;const r=t.split(".");r.length>1&&(i=r[0],s=r.splice(1).join("."));const c={fn:e,target:this.target,key:s,ns:i};this.platform.actionsState.watchers.push(c);const a=()=>{const u=this.platform.actionsState.watchers.indexOf(c);u>-1&&this.platform.actionsState.watchers.splice(u,1)};return this.subscriptions.push(a),a}dispose(){this.subscriptions.forEach(t=>t())}}const F=b.createConfigurationApi(n=>{n.createCommand("components",t=>e=>{t.events.subscribeOnce("components:platform-created",(s,{platform:i})=>{e.handlers&&e.handlers.forEach(([r,c])=>{i.addComponentHandler(r,c)})})})});class R{constructor(t,e){this.events=t,this.tags=[],this.children={},this.changesets=[],this.mountCount=0,this.id=g.uuid(),this.type=e,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(t,e){let s=t.get("mounted-nodes");return s||(s=new Map,t.register("mounted-nodes",s)),s.has(this)?(process.env.NODE_ENV!=="production"&&g.Logger.error("Trying to mount an already mounted component node.",this),()=>{}):(this.events.dispatch("components:node-mounted",{node:this}),this.mountCount===0&&(this.mountCount=this.mountCount+1,this.events.dispatch("components:node-enter",{node:this})),()=>{s.delete(this),this.events.dispatch("components:node-unmounted",{node:this}),this.mountCount=this.mountCount-1,this.mountCount===0&&this.events.dispatch("components:node-exit",{node:this})})}appendChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].push(t),this.events.dispatch("components:node-appended",{node:t})}prependChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].unshift(t),this.events.dispatch("components:node-appended",{node:t})}touchProperties(t,e={},s){const r=[{properties:t},e];return this.changesets.push(r),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const c=this.changesets.indexOf(r);c>-1&&(this.changesets.splice(c,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(t,e={},s){const r=[{properties:t},e];return this.changesets.push(r),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const c=this.changesets.indexOf(r);c>-1&&(this.changesets.splice(c,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(t,e={},s){const r=[{layout:t},e];return this.changesets.push(r),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!s)return;const c=this.changesets.indexOf(r);c>-1&&(this.changesets.splice(c,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(t,e={},s){const r=[{context:t},e];return this.changesets.push(r),this.events.dispatch("components:set-context",{node:this}),()=>{if(!s)return;const c=this.changesets.indexOf(r);c>-1&&(this.changesets.splice(c,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(t="default"){const e=this.children[t]||[];return e.reduce((s,i,r)=>{const{order:c=r}=i.attributes.layout;return s[c]?s.splice(c,0,i):s[c]=i,s},Array(e.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(t){Object.keys(this.children).forEach(e=>{const s=this.children[e],i=s.indexOf(t);i>-1&&(s.splice(i,1),this.events.dispatch("components:node-removed",{node:t,parentNode:this}))}),delete t.parent}}const _=(n,t,e)=>{for(let s=0,i=n.length;s<i&&e(n[s])!==!0;s++){const r=t[n[s].id]||"default",c=n[s].getChildren(r);_(c,t,e)}},N=(n,t,e)=>{if(e(n)!==!0){const s=t[n.id]||"default",i=n.children[s];_(i,t,e)}},C=(n,t)=>{const e=[];return N(n,t,s=>{e.push(s)}),e},H=(n,t,e)=>{let s;return N(n,t,i=>{if(e(i))return s=i,!0}),s};class G{constructor(t,e,s){this.root=t,this.switches=e,this.all=[],this.visible=[],this.detached=[],s.subscribe("components:node-appended",(i,r)=>{this.all.push(r.node),this.visible=C(t,e)}),s.subscribe("components:node-removed",(i,r)=>{let c=this.all.indexOf(r.node);c>-1&&this.all.splice(c,1),c=this.visible.indexOf(r.node),c>-1&&this.visible.splice(c,1),this.visible=C(t,e)}),s.subscribe("components:node-switched",(i,r)=>{this.visible=C(t,e)})}query(t={}){const e=[];return N(this.root,this.switches,s=>{Object.keys(t).every(r=>t[r]===s[r])&&e.push(s)}),e}get(t){return H(this.root,this.switches,e=>e.id===t)||this.detached.find(e=>e.id===t)}}class K{constructor(){this.handlers=new Map}add(t,e){this.handlers.set(t,e)}get(t){return this.handlers.get(t)}}const Y=n=>{let t=n,e=0;for(;t.parent;)e=e+1,t=t.parent;return e},J=n=>n.map(([e,s])=>[Y(e),e,s]).sort(([e],[s])=>e-s).map(([,e,s])=>[e,s]),k=n=>n instanceof Date?!1:n&&typeof n=="object"&&!Array.isArray(n),v=(n,...t)=>{if(!t.length)return n;const e=t.shift();if(k(n)&&k(e))for(const s in e)k(e[s])?(n[s]||Object.assign(n,{[s]:{}}),v(n[s],e[s])):Object.assign(n,{[s]:e[s]});return v(n,...t)},X=(n,t)=>!n||n==="all"?!0:n.some(e=>t.indexOf(e)>-1),Z=(n,t)=>{let e=[],s=[],i;const r=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const a=new Map,u=J(e.map((o,p)=>[o,s[p]])),h=(o,p)=>{var I;const l=a.get(o)||{},d=p.context&&!l.context,y=p.properties&&!l.properties,x=p.layout&&!l.layout;a.set(o,{context:l.context||d,properties:l.properties||y,layout:l.layout||x}),y&&(o.attributes.properties={}),x&&(o.attributes.layout={}),d&&(o.attributes.context=v({},(I=o.parent)==null?void 0:I.attributes.context));const S=[],T=[],D=[];if(o.changesets.forEach(f=>{const[m,P]=f;X(P.breakpoints,n.breakpoints)&&(y&&(typeof m.properties=="function"?S.push(m.properties):v(o.attributes.properties,m.properties)),x&&(typeof m.layout=="function"?T.push(m.layout):v(o.attributes.layout,m.layout)),d&&(typeof m.context=="function"?D.push(m.context):v(o.attributes.context,m.context)))}),S.forEach(f=>{v(o.attributes.properties,f(o.attributes.properties))}),T.forEach(f=>{v(o.attributes.layout,f(o.attributes.layout))}),D.forEach(f=>{v(o.attributes.context,f(o.attributes.context))}),d||p.recursive){const f=n.getBranch(o),m=p.recursive?p:{context:!!d};o.getChildren(f).forEach(P=>{h(P,m)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),u.forEach(([o,p])=>{h(o,p)}),e=[],s=[],t(a)},c=()=>{clearTimeout(i),i=setTimeout(r,0)};return(a,u)=>{const h=e.indexOf(a);if(h>-1){const o=s[h];return u.context&&(o.context=!0),u.properties&&(o.properties=!0),u.layout&&(o.layout=!0),u.recursive&&(o.recursive=!0),c()}return e.push(a),s.push(u),c()}};class M{constructor(t,e={}){this.providers=e,this.breakpoints=[],this.actionsState={handlers:[],watchers:[]},this.switches={},this.changesets=[],this.subscriptions=[],this.customComponentHandler=new K,this.events=t.events.createChild(this);const s=new R(this.events,"root");s.name=`root-${t.name}`,this.nodes=new G(s,this.switches,this.events);const i=this.processNode=Z(this,r=>{const c=Array.from(r.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${c.length} node(s) processed:
|
|
2
|
+
${c.map(a=>`${a.name||"<no name>"} (${a.id})
|
|
3
|
+
`)}`),c.forEach(a=>{const u=r.get(a);a.parent&&a.parent.type==="root"&&this.events.dispatch("components:root-children-changed",{node:a}),u!=null&&u.context&&this.events.dispatch("components:context-changed",{node:a}),u!=null&&u.properties&&this.events.dispatch("components:properties-changed",{node:a}),u!=null&&u.layout&&this.events.dispatch("components:layout-changed",{node:a})}),this.events.dispatch("components:component-model-initialized",{},{bubbles:!0})});Promise.all(Object.keys(e).map(r=>e[r].load(this))),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,c)=>{const{node:a}=c;this.changesets.forEach(u=>{const{changeset:h,target:o,removes:p}=u,[l,d]=h;o.match(c.node)&&(l.properties&&p.push(a.writeProperties(l.properties,d)),l.context&&p.push(a.writeContext(l.context,d)),l.layout&&p.push(a.writeLayout(l.layout,d)))})})),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,c)=>{i(c.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-properties",(r,c)=>{i(c.node,{properties:!0})})),this.subscriptions.push(this.events.subscribe("components:set-context",(r,c)=>{i(c.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-indent",(r,c)=>{i(c.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:set-layout",(r,c)=>{i(c.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:node-switched",(r,{node:c,branch:a})=>{i(c,{layout:!0,recursive:!0,properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:node-removed",(r,{parentNode:c})=>{i(c,{properties:!0})})),this.events.parent&&this.events.parent.dispatch("components:platform-created",{platform:this})}static getInstance(t){return t.getAsync("components")}addBreakpoint(t){this.breakpoints.indexOf(t)===-1&&(this.breakpoints.push(t),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}removeBreakpoint(t){const e=this.breakpoints.indexOf(t);e>-1&&(this.breakpoints.splice(e,1),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}setSwitch(t,e){this.switches[t.id]=e,this.events.dispatch("components:node-switched",{node:t,branch:e})}getBranch(t){return this.switches[t.id]}createNode(t,e={}){const s=new R(this.events,t);return e.detached&&this.nodes.detached.push(s),s}components(){return new E(this)}actions(t,e){return new O(this,t,e)}write(t){const{provider:e,target:s,attributes:i,options:r={},removable:c}=t,a=t.key||g.uuid(),h={changeset:[i,r],target:s,removes:[]};if(e){const o=this.providers[e];o.write(a,s,i,r),h.removes.push(()=>{o.remove(a)})}return this.changesets.push(h),this.nodes.all.forEach(o=>{if(s.match(o)){let p=()=>{};i.properties&&(p=o.writeProperties(i.properties,r,c)),i.context&&(p=o.writeContext(i.context,r,c)),i.layout&&(p=o.writeContext(i.layout,r,c)),h.removes.push(p)}}),()=>{if(c){h.removes.forEach(p=>p());const o=this.changesets.indexOf(h);o>-1&&this.changesets.splice(o,1)}}}addComponentHandler(t,e){this.customComponentHandler.add(t,e)}getComponentHandler(t){return this.customComponentHandler.get(t)}dispose(){this.subscriptions.forEach(t=>t())}}const tt=n=>{if(Array.isArray(n)){const[t,...e]=n;return{definitionId:t,overrides:e}}return{definitionId:n,overrides:[]}},w=(n,t,e,s,i,r)=>{e.forEach(c=>{const a=tt(c),u=s[a.definitionId];if(a.definitionId==="view"){const h=n.createNode("view");h.name="view",Object.keys(i).forEach(o=>{const p=i[o];w(n,h,[p.entry],s,i,o)}),t.appendChild(h),a.overrides.forEach(o=>{o.properties&&h.writeProperties(o.properties,{breakpoints:o.breakpoints}),o.context&&h.writeContext(o.context,{breakpoints:o.breakpoints}),o.layout&&h.writeLayout(o.layout,{breakpoints:o.breakpoints})})}else if(n.getComponentHandler(u.type)){const h=n.getComponentHandler(u.type);h&&h(a,{platform:n,node:t,references:e,definitions:s,views:i,branch:r})}else{const h=s[a.definitionId];if(process.env.NODE_ENV!=="production"&&!h){g.Logger.error(`No definition found for component type '${a.definitionId}'.`);return}const o=n.createNode(h.type);o.name=a.definitionId,o.tags=h.tags||[],h.properties&&o.writeProperties(h.properties),h.context&&o.writeContext(h.context),h.layout&&o.writeLayout(h.layout),t.appendChild(o,r),a.overrides.forEach(p=>{const l={breakpoints:p.breakpoints};p.properties&&o.writeProperties(p.properties,l),p.context&&o.writeContext(p.context,l),p.layout&&o.writeLayout(p.layout,l)}),h.children&&w(n,o,h.children,s,i)}})},et=(n,t)=>{const{entry:e,components:s,breakpoints:i,views:r}=t,c=[];return Object.keys(i).forEach(a=>{const u=i[a],h=window.matchMedia(u);h.matches&&n.breakpoints.push(a);const o=p=>{p.matches?n.addBreakpoint(a):n.removeBreakpoint(a)};h.addListener(o),c.push(()=>h.removeListener(o))}),w(n,n.nodes.root,[e],s,r),()=>c.forEach(a=>{a()})},st=(n,t)=>({id:n.id,type:n.type,name:n.name,branch:t||"default"}),nt=(n,t,e,s=g.uuid(),i={})=>n.getAsync("components").then(r=>{let c;if(typeof t=="string"){const h=new E(r);h.ofType(t),c=h}else c=t;const a={},u=h=>{const o=a[h.id];return o?Promise.resolve(o.controller):M.getInstance(n).then(p=>new A(p,h,s))};r.events.subscribe("components:node-enter",(h,{node:o})=>{c.match(o)&&u(o).then(p=>{Promise.resolve(e(p)).then(l=>{a[o.id]={dispose:l,controller:p}})})}),r.events.subscribe("components:node-exit",(h,{node:o})=>{const p=a[o.id];p&&(p.dispose&&p.dispose(),i.reuseController||(p.controller.dispose(),delete a[o.id]))})});class it{constructor(t){this.aliases=new Map,this.components=new Map,this.logger=new g.Logger;const{events:e}=t.get("$widget");this.events=e}getComponent(t){const e=this.aliases.get(t),s=this.components.get(e||t)||null;return process.env.NODE_ENV!=="production"&&(s||this.logger.warn(e||t,`Unable to resolve component: "${e||t}". You most likely forgot to register the required plugin for: ${e||t}.`)),s}registerComponent(t,e){return this.components.set(t,e),this.events.dispatch("component-resolver:resolve",t),()=>{this.components.delete(t)}}registerResolver(t,e){return this.events.subscribe("component-resolver:resolve",(s,i)=>{if(i===t){const r=this.getComponent(t);e(r)}})}registerAlias(t,e){return this.aliases.set(t,e),this.events.dispatch("component-resolver:resolve",t),()=>{this.aliases.delete(t)}}}const V="#____version____#",B=class extends b.Environment{constructor(n,t=[]){super(n,t,{transformPluginSettings:(e,s,i)=>{const r=i.get("$settings");return{...r.plugins&&s?r.plugins[s]||{}:{},...e}}})}createImplementation(n){const t=super.createImplementation(n);return t.bindings=n.bindings,t}navigate(n,t,e){this.widgets.query(n).forEach(s=>s.invoke("navigate",{route:t,params:e}))}static create(n={}){const t=[$.ConfigurationApi].concat(n.configurationApiExtensions||[]);return new B("humany",t)}static createFromGlobal(n,t={}){if(this.isRuntime(n))return n.patch(t),n;const e=[],s=n&&n._c;s&&s.forEach(r=>e.push(r));const i=this.create(t);return i.container.register("$runtimecfg",e),i}static isRuntime(n){return!!(n&&typeof n=="object"&&n.container&&typeof n.container.get=="function"&&n.container.get("$environment")===n&&n.container.owner===n)}};let j=B;j.version=`${V} (${b.version})`;class ot extends b.Implementation{constructor(){super(...arguments),this.bindings=[]}}class rt extends b.Plugin{constructor(t,e){super(t,e)}}var q=(n=>(n.open="open",n.closed="closed",n.hidden="hidden",n))(q||{});class ct extends b.WidgetType{constructor(t){super(t)}}exports.ActionResolver=Q;exports.ActionsController=O;exports.ComponentNode=R;exports.ComponentNodeController=A;exports.ComponentPlatform=M;exports.ComponentQuery=E;exports.ComponentResolver=it;exports.Environment=j;exports.Implementation=ot;exports.Plugin=rt;exports.WidgetRenderState=q;exports.WidgetType=ct;exports.asDescriptor=st;exports.bootstrap=z;exports.componentConfigurationApi=F;exports.createChildren=w;exports.createComponentModel=et;exports.createEventSubscriber=L;exports.extendComponent=nt;exports.findComponent=H;exports.findVisibleComponents=C;exports.traverseComponents=N;exports.version=V;
|