@claspo/renderer 18.6.0-ctx.0 → 18.6.1-hotfix

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.
@@ -1 +1 @@
1
- import DefaultState from"./common/DefaultState";import FormGroup from"./form/FormGroup";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentModelService from"./document-model/DocumentModelService";import ConfigService from"./common/ConfigService";import ClDocumentResizeListener from"./renderer/style/ClDocumentResizeListener";import MobileDeviceOrientationListener from"./renderer/style/MobileDeviceOrientationListener";import DefaultMediaQueryListener from"./renderer/style/DefaultMediaQueryListener";import DocumentService from"./document-model/DocumentService";import CommonStylesService from"./renderer/style/CommonStylesService";import WcFactory from"./wc-renderer/WcFactory";import WcViewRenderer from"./wc-renderer/WcViewRenderer";import ActionFactory from"./action/ActionFactory";import PrizePoolFactory from"./prize-pool/PrizePoolFactory";import httpClient from"@claspo/common/network/HttpClient";import{ActionRegister}from"./action/ActionRegister";import ContextSDK from"./sdk/context/ContextSDK";import{MergeTagsProcessorFactory}from"./sdk/merge-tags/MergeTagsProcessorFactory";import SourceRegistry from"./sdk/source/SourceRegistry";import ContextData from"./sdk/context/ContextData";import SubmitStateService from"./submit-state/SubmitStateService";import HiddenFieldsContextHydrator from"./sdk/hidden-fields/HiddenFieldsContextHydrator";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,s,m,a){var l;const d=new DocumentModelService(e),y=!o,f=y?new DefaultMediaQueryListener(d,t):new ClDocumentResizeListener(d,o),u=new DefaultState,S=new ConfigService(t),v=new MobileDeviceOrientationListener(d,S),p=new CommonStylesService;p.setStyles(i);const D=new DefaultEventEmitter,g=new FormGroup(r),w=new SubmitStateService(g,D,a,d),F=new SourceRegistry(g,t),C=new ContextData,R=new ContextSDK(F,C,y);new HiddenFieldsContextHydrator(R,d.getShared().hiddenFields).hydrate();const h=new(null!==(l=t.actionFactoryClass)&&void 0!==l?l:ActionFactory)(D,g,S,r,u,R,()=>this.services),x=new ActionRegister(D,()=>this.services),M=new PrizePoolFactory(httpClient,S),L=new MergeTagsProcessorFactory(y,R,S),P=new WcFactory({state:u,eventEmitter:D,form:g,documentModel:d,resizeListener:f,config:S,commonStylesService:p,trackingService:r,layoutType:n,actionFactory:h,actionRegister:x,prizePoolFactory:M,context:R,mergeTagsProcessorFactory:L,mobileDeviceOrientationListener:v,componentRegister:s,htmlDocumentObject:m}),b=new WcViewRenderer(d,f,t,P,D),z=new DocumentService(d,b,c);this.services={documentService:z,documentModel:d,state:u,form:g,eventEmitter:D,config:S,resizeListener:f,mobileDeviceOrientationListener:v,componentFactory:P,viewRenderer:b,commonStylesService:p,tracking:r,actionFactory:h,actionRegister:x,submitState:w,prizePoolFactory:M,context:R,mergeTagsProcessorFactory:L}}destroy(){Object.keys(this.services).filter(e=>"viewRenderer"!==e).forEach(e=>this.services[e]&&this.services[e].destroy&&this.services[e].destroy())}}
1
+ import DefaultState from"./common/DefaultState";import FormGroup from"./form/FormGroup";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentModelService from"./document-model/DocumentModelService";import ConfigService from"./common/ConfigService";import ClDocumentResizeListener from"./renderer/style/ClDocumentResizeListener";import MobileDeviceOrientationListener from"./renderer/style/MobileDeviceOrientationListener";import DefaultMediaQueryListener from"./renderer/style/DefaultMediaQueryListener";import DocumentService from"./document-model/DocumentService";import CommonStylesService from"./renderer/style/CommonStylesService";import WcFactory from"./wc-renderer/WcFactory";import WcViewRenderer from"./wc-renderer/WcViewRenderer";import ActionFactory from"./action/ActionFactory";import PrizePoolFactory from"./prize-pool/PrizePoolFactory";import httpClient from"@claspo/common/network/HttpClient";import{ActionRegister}from"./action/ActionRegister";import ContextSDK from"./sdk/context/ContextSDK";import{MergeTagsProcessorFactory}from"./sdk/merge-tags/MergeTagsProcessorFactory";import SourceRegistry from"./sdk/source/SourceRegistry";import ContextData from"./sdk/context/ContextData";import SubmitStateService from"./submit-state/SubmitStateService";import HiddenFieldsContextHydrator from"./sdk/hidden-fields/HiddenFieldsContextHydrator";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,s,m,a){var l;const d=new DocumentModelService(e),y=!o,f=y?new DefaultMediaQueryListener(d,t):new ClDocumentResizeListener(d,o),u=new DefaultState,S=new ConfigService(t),v=new MobileDeviceOrientationListener(d,S),p=new CommonStylesService;p.setStyles(i);const D=new DefaultEventEmitter,g=new FormGroup(r),w=new SubmitStateService(g,D,d),F=new SourceRegistry(g,t),C=new ContextData,R=new ContextSDK(F,C,y);new HiddenFieldsContextHydrator(R,d.getShared().hiddenFields).hydrate();const h=new(null!==(l=t.actionFactoryClass)&&void 0!==l?l:ActionFactory)(D,g,S,r,u,R,()=>this.services),x=new ActionRegister(D,()=>this.services),M=new PrizePoolFactory(httpClient,S),L=new MergeTagsProcessorFactory(y,R,S),P=new WcFactory({state:u,eventEmitter:D,form:g,documentModel:d,resizeListener:f,config:S,commonStylesService:p,trackingService:r,layoutType:n,actionFactory:h,actionRegister:x,prizePoolFactory:M,context:R,mergeTagsProcessorFactory:L,mobileDeviceOrientationListener:v,componentRegister:s,htmlDocumentObject:m}),b=new WcViewRenderer(d,f,t,P,D),z=new DocumentService(d,b,c);this.services={documentService:z,documentModel:d,state:u,form:g,eventEmitter:D,config:S,resizeListener:f,mobileDeviceOrientationListener:v,componentFactory:P,viewRenderer:b,commonStylesService:p,tracking:r,actionFactory:h,actionRegister:x,submitState:w,prizePoolFactory:M,context:R,mergeTagsProcessorFactory:L}}destroy(){Object.keys(this.services).filter(e=>"viewRenderer"!==e).forEach(e=>this.services[e]&&this.services[e].destroy&&this.services[e].destroy())}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.6.0-ctx.0",
3
+ "version": "18.6.1-hotfix",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
@@ -3,7 +3,6 @@ import { UrlQueryParamsConfigI } from "./sources/UrlQueryParamsSource";
3
3
  import { JSApiVariablesConfigI } from "./sources/JSApiVariablesSource";
4
4
  import FormGroup from '../../form/FormGroup';
5
5
  export interface SourceRegistryConfigI extends UrlQueryParamsConfigI, JSApiVariablesConfigI {
6
- jsSource?: Source;
7
6
  [key: string]: any;
8
7
  }
9
8
  export default class SourceRegistry {
@@ -11,7 +10,7 @@ export default class SourceRegistry {
11
10
  [key: string]: Source;
12
11
  };
13
12
  sources: Source[];
14
- constructor(form: FormGroup, config?: SourceRegistryConfigI);
13
+ constructor(form: FormGroup, config: SourceRegistryConfigI);
15
14
  registerSource(source: Source): Source;
16
15
  getSource(id: string): Source | undefined;
17
16
  getSources(): Source[];
@@ -1 +1 @@
1
- import Source from"./Source";import FormSource from"./sources/FormSource";import UrlQueryParamsSource from"./sources/UrlQueryParamsSource";import DataLayerSource from"./sources/DataLayerSource";import CookieSource from"./sources/CookieSource";import LocalStorageSource from"./sources/LocalStorageSource";export default class SourceRegistry{constructor(r,e={}){this.registeredSourcesMap={},this.sources=[new Source("FORM",new FormSource(r)),new Source("DATA_LAYER",new DataLayerSource),new Source("URL_QUERY_PARAMS",new UrlQueryParamsSource(e)),new Source("COOKIE",new CookieSource),new Source("LOCAL_STORAGE",new LocalStorageSource)],e.jsSource&&this.sources.push(e.jsSource)}registerSource(r){if(this.registeredSourcesMap[r.id])throw new Error(`Source with id ${r.id} already registered`);return this.registeredSourcesMap[r.id]=r}getSource(r){return this.registeredSourcesMap[r]}getSources(){return Object.values(this.registeredSourcesMap)}registerInitialSources(){return this.sources.map(r=>this.registerSource(r))}}
1
+ import Source from"./Source";import FormSource from"./sources/FormSource";import UrlQueryParamsSource from"./sources/UrlQueryParamsSource";import DataLayerSource from"./sources/DataLayerSource";import JSApiVariablesSource from"./sources/JSApiVariablesSource";import CookieSource from"./sources/CookieSource";import LocalStorageSource from"./sources/LocalStorageSource";export default class SourceRegistry{constructor(r,e){this.registeredSourcesMap={},this.sources=[new Source("FORM",new FormSource(r)),new Source("DATA_LAYER",new DataLayerSource),new Source("URL_QUERY_PARAMS",new UrlQueryParamsSource(e)),new Source("JS_API_VARIABLE",new JSApiVariablesSource(e)),new Source("COOKIE",new CookieSource),new Source("LOCAL_STORAGE",new LocalStorageSource)]}registerSource(r){if(this.registeredSourcesMap[r.id])throw new Error(`Source with id ${r.id} already registered`);return this.registeredSourcesMap[r.id]=r}getSource(r){return this.registeredSourcesMap[r]}getSources(){return Object.values(this.registeredSourcesMap)}registerInitialSources(){return this.sources.map(r=>this.registerSource(r))}}
@@ -1,6 +1,5 @@
1
1
  import DefaultEventEmitter from "@claspo/common/DefaultEventEmitter";
2
2
  import { SourceUpdateDataI } from '../../context/ContextSDK';
3
- import { SourceType } from "@claspo/common/document/hidden-fields.interface";
4
3
  declare global {
5
4
  interface Window {
6
5
  [key: string]: any;
@@ -22,18 +21,10 @@ export interface JSApiVariablesProcessorResultI {
22
21
  processor: (ctx: any, model: JSApiVariablesModelI) => string;
23
22
  }
24
23
  export default class JSApiVariablesSource extends DefaultEventEmitter {
25
- static sourceId: SourceType;
24
+ static sourceId: string;
26
25
  instanceName: string | undefined;
27
- private subscribers;
28
26
  constructor(config?: JSApiVariablesConfigI);
29
- get appInstance(): any;
30
- get variables(): any;
31
27
  subscribe(cb: (data: SourceUpdateDataI) => void): void;
32
- getValue(key?: string): JSApiVariablesProcessorResultI | {
33
- [k: string]: any;
34
- };
35
- addValues<T extends {
36
- [key: string]: any;
37
- }>(values: T): void;
28
+ getValue(key?: string): JSApiVariablesProcessorResultI | Record<string, never>;
38
29
  static processModel(model: JSApiVariablesModelI, instanceName?: string): string;
39
30
  }
@@ -1 +1 @@
1
- import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{SourceType}from"@claspo/common/document/hidden-fields.interface";class JSApiVariablesSource extends DefaultEventEmitter{constructor(e={}){super(),this.subscribers=new Set,this.instanceName=e.instanceName}get appInstance(){return window[this.instanceName]}get variables(){var e;return(null===(e=this.appInstance)||void 0===e?void 0:e.variables)||{}}subscribe(e){e&&this.subscribers.add(e)}getValue(e){if(!e){const e=this.variables;return Object.keys(e).reduce((r,t)=>{const s=e[t];return r[t]={id:t,value:null==s?"":String(s),sourceId:JSApiVariablesSource.sourceId},r},{})}return{processor:(e,r)=>JSApiVariablesSource.processModel(r,this.instanceName)}}addValues(e){if(!this.appInstance)throw new Error("Instatiate first");if(!e||"object"!=typeof e)throw new Error("Values should be object");const r=Object.keys(e);r.length&&(this.appInstance.variables=Object.assign(Object.assign({},this.variables),e),this.subscribers.size&&r.forEach(r=>{const t=e[r],s={key:r,value:null==t?"":String(t),componentId:r};this.subscribers.forEach(e=>{try{e(s)}catch(e){}})}),this.emit("CHANGED",r))}static processModel(e,r){var t;if(!e.arguments)return"";const s=e.arguments.find(e=>"JavaScriptVariable"===e.name);if(!(null==s?void 0:s.value)||!r||!(null===(t=window[r])||void 0===t?void 0:t.variables))return"";try{return window[r].variables[s.value]||""}catch(r){return console.error("JSApiVariablesSource: error while getting variable. Model: ",e,"Error: ",r),""}}}JSApiVariablesSource.sourceId=SourceType.JS_API_VARIABLE;export default JSApiVariablesSource;
1
+ import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";class JSApiVariablesSource extends DefaultEventEmitter{constructor(e={}){super(),this.instanceName=e.instanceName}subscribe(e){}getValue(e){return e?{processor:(e,r)=>JSApiVariablesSource.processModel(r,this.instanceName)}:{}}static processModel(e,r){var a;if(!e.arguments)return"";const t=e.arguments.find(e=>"JavaScriptVariable"===e.name);if(!(null==t?void 0:t.value)||!r||!(null===(a=window[r])||void 0===a?void 0:a.variables))return"";try{return window[r].variables[t.value]||""}catch(r){return console.error("JSApiVariablesSource: error while getting variable. Model: ",e,"Error: ",r),""}}}JSApiVariablesSource.sourceId="JS_API_VARIABLE";export default JSApiVariablesSource;
@@ -1,6 +1,5 @@
1
1
  import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
2
2
  import FormGroup from '../form/FormGroup';
3
- import WcResolver from "../wc-renderer/WcResolver";
4
3
  import DocumentModelService from '../document-model/DocumentModelService';
5
4
  export declare const SubmitState: {
6
5
  readonly IDLE: "idle";
@@ -13,20 +12,21 @@ export type SubmitStateValue = typeof SubmitState[keyof typeof SubmitState];
13
12
  export default class SubmitStateService {
14
13
  form: FormGroup;
15
14
  eventEmitter: DefaultEventEmitter;
16
- componentResolver: WcResolver;
17
15
  documentModel?: DocumentModelService;
18
16
  state: SubmitStateValue;
19
17
  currentSubmission: Promise<boolean> | null;
20
18
  subscriptions: Array<{
21
19
  off: () => void;
22
20
  }>;
23
- constructor(form: FormGroup, eventEmitter: DefaultEventEmitter, componentResolver: WcResolver, documentModel?: DocumentModelService);
21
+ constructor(form: FormGroup, eventEmitter: DefaultEventEmitter, documentModel?: DocumentModelService);
24
22
  getState(): SubmitStateValue;
25
23
  hasDirtyFormData(): boolean;
26
24
  hasSubmitAttemptSinceLastChange(): boolean;
27
25
  trackSubmission(promise: Promise<boolean>): void;
28
26
  waitForCurrentSubmission(): Promise<boolean>;
29
27
  getRequiredControlNames(): string[];
28
+ hasComponentWithName(componentNames: string[]): boolean;
29
+ hasNpsOrFeedbackComponent(): boolean;
30
30
  allRequiredControlsAreValid(): Promise<boolean>;
31
31
  prepareAutoSubmitFormValue(): Promise<Record<string, any>>;
32
32
  destroy(): void;
@@ -1 +1 @@
1
- import FormGroupEvents from"../form/FormGroupEvents";import SysEventTypes from"../common/SysEventTypes";import DocumentUtils from"@claspo/common/document/DocumentUtils";function hasMeaningfulValue(t){return null!=t&&("string"==typeof t?""!==t.trim():Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0)}export const SubmitState={IDLE:"idle",DIRTY:"dirty",SUBMITTING:"submitting",SUBMITTED:"submitted",FAILED:"failed"};export default class SubmitStateService{constructor(t,e,i,s){this.form=t,this.eventEmitter=e,this.componentResolver=i,this.documentModel=s,this.state=SubmitState.IDLE,this.currentSubmission=null,this.subscriptions=[this.form.on(FormGroupEvents.valueChanged,()=>{this.state=SubmitState.DIRTY}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.state=SubmitState.SUBMITTING}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{this.currentSubmission=null,this.state=(null==t?void 0:t.success)?SubmitState.SUBMITTED:SubmitState.FAILED})]}getState(){return this.state}hasDirtyFormData(){return this.form.getControlsAsArray().some(t=>t.isTouched())}hasSubmitAttemptSinceLastChange(){return[SubmitState.SUBMITTING,SubmitState.SUBMITTED,SubmitState.FAILED].includes(this.state)}trackSubmission(t){this.currentSubmission=t}waitForCurrentSubmission(){return this.currentSubmission||Promise.resolve(!1)}getRequiredControlNames(){var t;const e=new Set;return null===(t=this.documentModel)||void 0===t||t.getViews().forEach(t=>{DocumentUtils.iterateDepthFirst(t,t=>{var i,s,n,o,r;const a=null===(s=null===(i=t.props)||void 0===i?void 0:i.control)||void 0===s?void 0:s.name;a&&(null===(r=null===(o=null===(n=t.props)||void 0===n?void 0:n.control)||void 0===o?void 0:o.validation)||void 0===r?void 0:r.required)&&e.add(a)})}),[...e]}async allRequiredControlsAreValid(){const t=this.getRequiredControlNames();if(!t.length)return!0;const e=this.form.getControlsMap(),i=t.map(t=>this.form.getControl(t));if(t.some(t=>!hasMeaningfulValue(e[t])))return!1;return(await Promise.all(i.map(t=>t.validate({silent:!0})))).every(Boolean)}async prepareAutoSubmitFormValue(){const t=this.form.getControlsAsArray(),e=t.find(t=>t.getName().includes("clConsentId")&&!t.getName().includes("label"));if(e){if(!e.isValid())return{}}else if(this.componentResolver.presentComponentManifests.find(t=>"SysConsentComponent"===t.name))return{};if(!await this.allRequiredControlsAreValid())return{};const i=t.filter(t=>hasMeaningfulValue(t.getValue()));return(await Promise.all(i.map(async t=>({control:t,isValid:await t.validate({silent:!0})})))).reduce((t,{control:e,isValid:i})=>{const s=e.getValue();return i&&hasMeaningfulValue(s)?(t[e.getName()]=s,t):(t[e.getName()]=void 0,t)},{})}destroy(){this.subscriptions.forEach(t=>t.off()),this.subscriptions=[],this.currentSubmission=null}}
1
+ import FormGroupEvents from"../form/FormGroupEvents";import SysEventTypes from"../common/SysEventTypes";import DocumentUtils from"@claspo/common/document/DocumentUtils";function hasMeaningfulValue(t){return null!=t&&("string"==typeof t?""!==t.trim():Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0)}export const SubmitState={IDLE:"idle",DIRTY:"dirty",SUBMITTING:"submitting",SUBMITTED:"submitted",FAILED:"failed"};export default class SubmitStateService{constructor(t,e,i){this.form=t,this.eventEmitter=e,this.documentModel=i,this.state=SubmitState.IDLE,this.currentSubmission=null,this.subscriptions=[this.form.on(FormGroupEvents.valueChanged,()=>{this.state=SubmitState.DIRTY}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.state=SubmitState.SUBMITTING}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{this.currentSubmission=null,this.state=(null==t?void 0:t.success)?SubmitState.SUBMITTED:SubmitState.FAILED})]}getState(){return this.state}hasDirtyFormData(){return this.form.getControlsAsArray().some(t=>t.isTouched())}hasSubmitAttemptSinceLastChange(){return[SubmitState.SUBMITTING,SubmitState.SUBMITTED,SubmitState.FAILED].includes(this.state)}trackSubmission(t){this.currentSubmission=t}waitForCurrentSubmission(){return this.currentSubmission||Promise.resolve(!1)}getRequiredControlNames(){var t;const e=new Set;return null===(t=this.documentModel)||void 0===t||t.getViews().forEach(t=>{DocumentUtils.iterateDepthFirst(t,t=>{var i,s,o,n,r;const a=null===(s=null===(i=t.props)||void 0===i?void 0:i.control)||void 0===s?void 0:s.name;a&&(null===(r=null===(n=null===(o=t.props)||void 0===o?void 0:o.control)||void 0===n?void 0:n.validation)||void 0===r?void 0:r.required)&&e.add(a)})}),[...e]}hasComponentWithName(t){var e;let i=!1;return null===(e=this.documentModel)||void 0===e||e.getViews().forEach(e=>{DocumentUtils.iterateDepthFirst(e,e=>{t.includes(e.name)&&(i=!0)})}),i}hasNpsOrFeedbackComponent(){return this.hasComponentWithName(["SysNetPromoterScoreComponent","SysFeedbackComponent"])}async allRequiredControlsAreValid(){if(this.hasNpsOrFeedbackComponent())return!0;const t=this.getRequiredControlNames();if(!t.length)return!0;const e=this.form.getControlsMap(),i=t.map(t=>this.form.getControl(t));if(t.some(t=>!hasMeaningfulValue(e[t])))return!1;return(await Promise.all(i.map(t=>t.validate({silent:!0})))).every(Boolean)}async prepareAutoSubmitFormValue(){const t=this.form.getControlsAsArray(),e=t.find(t=>t.getName().includes("clConsentId")&&!t.getName().includes("label"));if(e){if(!e.isValid())return{}}else if(this.hasComponentWithName(["SysConsentComponent"]))return{};if(!await this.allRequiredControlsAreValid())return{};const i=t.filter(t=>hasMeaningfulValue(t.getValue()));return(await Promise.all(i.map(async t=>({control:t,isValid:await t.validate({silent:!0})})))).reduce((t,{control:e,isValid:i})=>{const s=e.getValue();return i&&hasMeaningfulValue(s)?(t[e.getName()]=s,t):(t[e.getName()]=void 0,t)},{})}destroy(){this.subscriptions.forEach(t=>t.off()),this.subscriptions=[],this.currentSubmission=null}}
@@ -15,7 +15,6 @@ export default class WcResolver {
15
15
  private productKeyPrefix;
16
16
  renderMode: RenderMode;
17
17
  wcRegister: WcRegister;
18
- presentComponentManifests: ComponentManifestI[];
19
18
  constructor(renderMode: RenderMode, wcRegister: WcRegister, productKeyPrefix?: string);
20
19
  getComponentManifests(): ComponentManifestI[];
21
20
  getAllComponents(): (CustomElementConstructor | undefined)[];
@@ -1 +1 @@
1
- import DocumentUtils from"@claspo/common/document/DocumentUtils";import{RenderMode}from"@claspo/common/RenderMode";export default class WcResolver{constructor(e=RenderMode.STATIC,t,o="cl"){this.productKeyPrefix=o,this.renderMode=e,this.wcRegister=t,this.presentComponentManifests=[]}getComponentManifests(){return this.getAllComponents().map(e=>{var t;return null===(t=e.define)||void 0===t?void 0:t.manifest}).filter(e=>!!e)}getAllComponents(){return Object.values(this.wcRegister.modelNameToTagMap).map(e=>this.wcRegister.getComponentTagName(e,this.renderMode)).map(e=>customElements.get(e)).filter(e=>!!e)}async loadComponentsIfNecessary(e,t){const o=new Set;e.views.forEach(e=>{DocumentUtils.iterateDepthFirst(e,e=>{o.add(e.name)})});const n=this.getComponentManifests(),s=n.map(e=>e.name),i=[...o].filter(e=>!s.includes(e));return i.length?(await this.loadComponents(i,t),this.presentComponentManifests=this.getComponentManifests(),{manifests:this.presentComponentManifests}):{manifests:n}}async loadComponents(e,t){const o=this.getComponentNamesToLoad(e),n=this.buildComponentFilePaths(o,t);await this.loadComponentClasses(n,o)}getComponentNamesToLoad(e){return e||[]}buildComponentFilePaths(e,t){return e.map(e=>`${t.replace(/\/$/,"")}/${e}/${e}.js`)}loadComponentClasses(e,t){return Promise.all(e.map((e,o)=>new Promise((n,s)=>{const i=t[o],r=`${this.productKeyPrefix}_${this.getWindowKeyForComponentClass(i)}`;if(window[r])this.wcRegister.registerComponent(window[r],this.renderMode),n(window[r]);else{const t=document.createElement("script");t.type="module",t.onload=()=>{const e=window[this.getWindowKeyForComponentClass(i)];window[r]=e,this.wcRegister.registerComponent(e,this.renderMode),n(e)},t.onerror=s,t.src=e,document.body.appendChild(t)}})))}getWindowKeyForComponentClass(e){return`clComponentClass_${e}`}}
1
+ import DocumentUtils from"@claspo/common/document/DocumentUtils";import{RenderMode}from"@claspo/common/RenderMode";export default class WcResolver{constructor(e=RenderMode.STATIC,t,o="cl"){this.productKeyPrefix=o,this.renderMode=e,this.wcRegister=t}getComponentManifests(){return this.getAllComponents().map(e=>{var t;return null===(t=e.define)||void 0===t?void 0:t.manifest}).filter(e=>!!e)}getAllComponents(){return Object.values(this.wcRegister.modelNameToTagMap).map(e=>this.wcRegister.getComponentTagName(e,this.renderMode)).map(e=>customElements.get(e)).filter(e=>!!e)}async loadComponentsIfNecessary(e,t){const o=new Set;e.views.forEach(e=>{DocumentUtils.iterateDepthFirst(e,e=>{o.add(e.name)})});const n=this.getComponentManifests(),s=n.map(e=>e.name),i=[...o].filter(e=>!s.includes(e));return i.length?(await this.loadComponents(i,t),{manifests:this.getComponentManifests()}):{manifests:n}}async loadComponents(e,t){const o=this.getComponentNamesToLoad(e),n=this.buildComponentFilePaths(o,t);await this.loadComponentClasses(n,o)}getComponentNamesToLoad(e){return e||[]}buildComponentFilePaths(e,t){return e.map(e=>`${t.replace(/\/$/,"")}/${e}/${e}.js`)}loadComponentClasses(e,t){return Promise.all(e.map((e,o)=>new Promise((n,s)=>{const i=t[o],r=`${this.productKeyPrefix}_${this.getWindowKeyForComponentClass(i)}`;if(window[r])this.wcRegister.registerComponent(window[r],this.renderMode),n(window[r]);else{const t=document.createElement("script");t.type="module",t.onload=()=>{const e=window[this.getWindowKeyForComponentClass(i)];window[r]=e,this.wcRegister.registerComponent(e,this.renderMode),n(e)},t.onerror=s,t.src=e,document.body.appendChild(t)}})))}getWindowKeyForComponentClass(e){return`clComponentClass_${e}`}}