@telia-ace/widget-core 1.1.4-rc.0 → 1.1.4-rc.2
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 +2 -2
- package/index.mjs +2 -2
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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;
|
|
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;
|
package/index.mjs
CHANGED
|
@@ -488,9 +488,9 @@ class et {
|
|
|
488
488
|
(r) => {
|
|
489
489
|
const c = Array.from(r.keys());
|
|
490
490
|
process.env.NODE_ENV !== "production" && console.info(`STATE PROCESSOR: ${c.length} node(s) processed:
|
|
491
|
-
${c.map(
|
|
491
|
+
${c.map(
|
|
492
492
|
(a) => `${a.name || "<no name>"} (${a.id})
|
|
493
|
-
`
|
|
493
|
+
`
|
|
494
494
|
)}`), c.forEach((a) => {
|
|
495
495
|
const u = r.get(a);
|
|
496
496
|
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 });
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-core",
|
|
3
|
-
"version": "1.1.4-rc.
|
|
3
|
+
"version": "1.1.4-rc.2",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@webprovisions/platform": "^1.1.4",
|
|
6
6
|
"@webprovisions/bootstrapping": "^1.0.14",
|
|
7
|
-
"@telia-ace/widget-utilities": "^1.1.4-rc.
|
|
7
|
+
"@telia-ace/widget-utilities": "^1.1.4-rc.2"
|
|
8
8
|
},
|
|
9
9
|
"main": "./index.js",
|
|
10
10
|
"module": "./index.mjs",
|