@claspo/renderer 18.7.7 → 18.7.8-rc1

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.
@@ -18,8 +18,11 @@ export default class BaseRequestAction {
18
18
  context: any;
19
19
  getServices: GetServicesT;
20
20
  category: any;
21
+ initiatorComponentId: any;
21
22
  constructor(eventEmitter: any, form: any, config: any, httpClient: any, configService: any, tracking: any, state: any, context: any, getServices: any);
22
23
  skipHttpRequest: boolean;
24
+ setInitiatorComponentId(componentId: any): void;
25
+ emitSubmitLifecycleEvent(eventName: any, payload?: any): void;
23
26
  getTrackingMessageBeforeSentData(): string;
24
27
  getTrackingMessageByStatus(_: any): string;
25
28
  execute(_state: any, _event: any, force: any, overrideParams: any): Promise<unknown>;
@@ -1 +1 @@
1
- import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import systemResultStateNames from"../../document-model/systemResultStateNames";import getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import isDictionary from"@claspo/common/object/isDictionary";function componentModelHasSubmitAction(t){var e,s;try{return!!(null===(s=null===(e=t.props)||void 0===e?void 0:e.handlers)||void 0===s?void 0:s.find(t=>{var e;return null===(e=null==t?void 0:t.actions)||void 0===e?void 0:e.find(t=>[SysActionTypes.REQUEST,SysActionTypes.SUBSCRIBE_CONTACT].includes(t.type))}))}catch(t){return!1}}function viewHasControls(t){if(!t)return!1;let e=0;return DocumentUtils.iterateDepthFirst(t,t=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(t.type)||componentModelHasSubmitAction(t))&&e++}),e>0}function isResultView(t,e){return!!t&&(systemResultStateNames.includes(t.label)||e.includes(t.id))}export const RequestStatus={SUCCESS:"SUCCESS",ALREADY_SUBSCRIBED:"ALREADY_SUBSCRIBED",ERROR:"ERROR",TOO_MANY_REQUESTS:"TOO_MANY_REQUESTS"};export default class BaseRequestAction{constructor(t,e,s,i,n,o,r,a,c){this.skipHttpRequest=!0,this.id=s.id,this.params=s.params,this.form=e,this.eventEmitter=t,this.httpClient=i,this.configService=n,this.formEventsListener=null,this.tracking=o,this.stateService=r,this.context=a,this.getServices=c,this.category=ActionCategory.SUBMIT}getTrackingMessageBeforeSentData(){return""}getTrackingMessageByStatus(t){return""}async execute(t,e,s,i){var n;if(this.formEventsListener&&this.formEventsListener.off(),this.form.submitQueuedAfterPending)return;if(this.form.preventSubmit)return void(this.form.submitQueuedAfterPending=!1);if(this.form.isPending()&&(this.form.submitQueuedAfterPending=!0,await this.form.waitForPendingValidationAndCheckIfValid()),this.form.submitQueuedAfterPending=!1,this.form.preventSubmit)return;const o=new Promise(t=>{this.submit(t,s,i)});return null===(n=this.getServices().submitState)||void 0===n||n.trackSubmission(o),o}submit(t,e,s){var i;const n=this.getServices().viewRouter.getCurrentViewIndex(),o=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),r=this.getServices().documentModel.getViews()[n+1],a=r&&!isResultView(r,o),c=Object.assign(Object.assign({},this.params),s);if(this.form.markAsTouched(),this.stateService.getState().emitActionOnSubmit&&this.eventEmitter.emit(this.stateService.getState().emitActionOnSubmit.eventName),this.stateService.getState().interceptSubmitActions&&!e)return;if(!this.form.isValid()&&!c.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const u=this.stateService,S=u.getState().conditionalRedirectViewId,m=c.conditionalRedirectViewId||S;S&&(c.conditionalRedirectViewId=S,u.setState({conditionalRedirectViewId:null}));let d=this.getServices().documentModel.getViews()[n+1];const l=this.getServices().documentModel.getViews()[n];if(!c.skipNavigation&&m&&getComponentCountOnView(l,"SysNetPromoterScoreComponent")+getComponentCountOnView(l,"SysFeedbackComponent")===1&&(d=this.getServices().documentModel.getViews().find(t=>t.id===c.conditionalRedirectViewId),viewHasControls(d)||isResultView(d,o)))return this.goToView(d.path[0],c),void t(!0);const E=null!==(i=c.formValue)&&void 0!==i?i:this.form.getControlsMap(),h=this.getContextValue(c);if(!c.skipNavigation&&a&&(viewHasControls(d)||!Object.keys(E).length&&!Object.keys(h).length))return this.goToView(n+1,c),void t(!0);if(!Object.keys(E).length&&!Object.keys(h).length)return void t(!0);const g=UTMParamsExtractor.extractTrackingParams(this.context),R=this.constructRequestPayload({contextValue:h,formValue:E,utmParams:g});this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_STARTED,R),this.eventEmitter.emit("CONTACT_DATA_SUBMIT",R);if(this.getTrackingMessageBeforeSentData()&&this.tracking.send("FormFinish_[Name]"),this.configService.getConfig("isBot"))return this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.SUCCESS,success:!0,skipped:!0}),void t();this.sendRequest(R).then(t=>t.json().then(e=>t.status===HttpStatus.TOO_MANY_REQUESTS?{state:RequestStatus.TOO_MANY_REQUESTS}:{contactId:e.contactId,state:e&&e.next&&e.next.type}),()=>({state:RequestStatus.ERROR})).then(e=>{const s=this.getTrackingMessageByStatus(e.state);if(s&&this.tracking.send(s),c.skipNavigation)return e.state===RequestStatus.TOO_MANY_REQUESTS&&this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS),e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),void t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED);switch(e.state){case RequestStatus.SUCCESS:a&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:m&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:m&&d?this.goToView(d.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(m&&d?d.path[0]:this.getErrorViewIndex()),this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS)}e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED)}).catch(()=>{this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.ERROR,success:!1}),c.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){var e,s;if(!t.excludeFormContext)return this.context.getKVMap();const i=(null===(s=(e=this.context).getRecordsMap)||void 0===s?void 0:s.call(e))||{};return Object.values(i).reduce((t,e)=>{var s;const i=null===(s=null==e?void 0:e.getValue)||void 0===s?void 0:s.call(e);return i&&"FORM"!==i.sourceId?(t[i.id]=i.value,t):t},{})}constructDataToSent({contextValue:t,formValue:e,utmParams:s}){const i=Object.assign({},t);return i.tracking=s,Object.keys(e).forEach(t=>{if(t.startsWith("clConsentId")){if(t.endsWith("_label"))return;const s={value:e[t]};e[`${t}_label`]&&(s.text=e[`${t}_label`]),i.consents?i.consents[t]=s:i.consents={[t]:s}}else{const s=e[t];i[t]=isDictionary(s)||Array.isArray(s)?JSON.stringify(s):s}}),i}constructRequestPayload({contextValue:t,formValue:e,utmParams:s}){let i={data:this.constructDataToSent({contextValue:t,formValue:e,utmParams:s}),referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy")};return this.configService.getConfig("widgetDebugMode")&&(i.ignoreTracking=!0),i}constructRequestHeaders(){const t={},e=this.configService.getConfig("clCustomerId");return e&&Object.assign(t,{"cl-customer-id":e}),t}goToView(t,e){this.eventEmitter.emit(SysActionTypes.GO_TO_VIEW,t,e)}sendRequest(t){return this.skipHttpRequest?Promise.resolve({status:200,json:()=>Promise.resolve({next:{type:RequestStatus.SUCCESS}})}):this.httpClient.execute(this.configService.getConfig("subscribeContactUrl"),"POST",t,this.constructRequestHeaders())}getSuccessViewIndex(){return this.resolveResultViewIndex("successViewId",["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"])}getErrorViewIndex(){return this.resolveResultViewIndex("errorViewId",["DOCUMENT_VIEW_TYPE_ERROR"])}getAlreadySubscribedViewIndex(){const t=this.getActiveSubmitActionParams();return t&&!t.alreadySubscribedViewId?this.getSuccessViewIndex():this.resolveResultViewIndex("alreadySubscribedViewId",["DOCUMENT_VIEW_TYPE_SUBSCRIBED"])}resolveResultViewIndex(t,e){var s;const i=this.getServices().documentModel.getViews(),n=null===(s=this.getActiveSubmitActionParams())||void 0===s?void 0:s[t];if(n){const t=i.findIndex(t=>t.id===n);if(-1!==t)return t}return i.findIndex(t=>e.includes(t.label))}hasFormControls(){return this.form.getControlsAsArray().length>0}getActiveSubmitActionParams(){if(this.hasFormControls())return this.getServices().documentModel.getShared().submitActionParams}runPostSubmitActionOrGoToView(t){var e;const s=null===(e=this.getActiveSubmitActionParams())||void 0===e?void 0:e.runAction;s?setTimeout(()=>{this.getServices().actionFactory.get(s).execute(this.stateService.getState())},1500):this.goToView(t())}handleErrorResponse(){const t=this.getErrorViewIndex();-1!==t?this.goToView(t):this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW)}}
1
+ import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import systemResultStateNames from"../../document-model/systemResultStateNames";import getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import isDictionary from"@claspo/common/object/isDictionary";function componentModelHasSubmitAction(t){var e,i;try{return!!(null===(i=null===(e=t.props)||void 0===e?void 0:e.handlers)||void 0===i?void 0:i.find(t=>{var e;return null===(e=null==t?void 0:t.actions)||void 0===e?void 0:e.find(t=>[SysActionTypes.REQUEST,SysActionTypes.SUBSCRIBE_CONTACT].includes(t.type))}))}catch(t){return!1}}function viewHasControls(t){if(!t)return!1;let e=0;return DocumentUtils.iterateDepthFirst(t,t=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(t.type)||componentModelHasSubmitAction(t))&&e++}),e>0}function isResultView(t,e){return!!t&&(systemResultStateNames.includes(t.label)||e.includes(t.id))}export const RequestStatus={SUCCESS:"SUCCESS",ALREADY_SUBSCRIBED:"ALREADY_SUBSCRIBED",ERROR:"ERROR",TOO_MANY_REQUESTS:"TOO_MANY_REQUESTS"};export default class BaseRequestAction{constructor(t,e,i,s,n,o,r,a,c){this.skipHttpRequest=!0,this.id=i.id,this.params=i.params,this.form=e,this.eventEmitter=t,this.httpClient=s,this.configService=n,this.formEventsListener=null,this.tracking=o,this.stateService=r,this.context=a,this.getServices=c,this.category=ActionCategory.SUBMIT}setInitiatorComponentId(t){this.initiatorComponentId=t}emitSubmitLifecycleEvent(t,e=void 0){this.eventEmitter.emit(t,e,{initiatorComponentId:this.initiatorComponentId})}getTrackingMessageBeforeSentData(){return""}getTrackingMessageByStatus(t){return""}async execute(t,e,i,s){var n;if(this.formEventsListener&&this.formEventsListener.off(),this.form.submitQueuedAfterPending)return;if(this.form.preventSubmit)return void(this.form.submitQueuedAfterPending=!1);if(this.form.isPending()&&(this.form.submitQueuedAfterPending=!0,await this.form.waitForPendingValidationAndCheckIfValid()),this.form.submitQueuedAfterPending=!1,this.form.preventSubmit)return;const o=new Promise(t=>{this.submit(t,i,s)});return null===(n=this.getServices().submitState)||void 0===n||n.trackSubmission(o),o}submit(t,e,i){var s;const n=this.getServices().viewRouter.getCurrentViewIndex(),o=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),r=this.getServices().documentModel.getViews()[n+1],a=r&&!isResultView(r,o),c=Object.assign(Object.assign({},this.params),i);if(this.form.markAsTouched(),this.stateService.getState().emitActionOnSubmit&&this.eventEmitter.emit(this.stateService.getState().emitActionOnSubmit.eventName),this.stateService.getState().interceptSubmitActions&&!e)return;if(!this.form.isValid()&&!c.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const u=this.stateService,S=u.getState().conditionalRedirectViewId,m=c.conditionalRedirectViewId||S;S&&(c.conditionalRedirectViewId=S,u.setState({conditionalRedirectViewId:null}));let d=this.getServices().documentModel.getViews()[n+1];const l=this.getServices().documentModel.getViews()[n];if(!c.skipNavigation&&m&&getComponentCountOnView(l,"SysNetPromoterScoreComponent")+getComponentCountOnView(l,"SysFeedbackComponent")===1&&(d=this.getServices().documentModel.getViews().find(t=>t.id===c.conditionalRedirectViewId),viewHasControls(d)||isResultView(d,o)))return this.goToView(d.path[0],c),void t(!0);const h=null!==(s=c.formValue)&&void 0!==s?s:this.form.getControlsMap(),E=this.getContextValue(c);if(!c.skipNavigation&&a&&(viewHasControls(d)||!Object.keys(h).length&&!Object.keys(E).length))return this.goToView(n+1,c),void t(!0);if(!Object.keys(h).length&&!Object.keys(E).length)return void t(!0);const g=UTMParamsExtractor.extractTrackingParams(this.context),v=this.constructRequestPayload({contextValue:E,formValue:h,utmParams:g});this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_STARTED,v),this.eventEmitter.emit("CONTACT_DATA_SUBMIT",v);if(this.getTrackingMessageBeforeSentData()&&this.tracking.send("FormFinish_[Name]"),this.configService.getConfig("isBot"))return this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.SUCCESS,success:!0,skipped:!0}),void t();this.sendRequest(v).then(t=>t.json().then(e=>t.status===HttpStatus.TOO_MANY_REQUESTS?{state:RequestStatus.TOO_MANY_REQUESTS}:{contactId:e.contactId,state:e&&e.next&&e.next.type}),()=>({state:RequestStatus.ERROR})).then(e=>{const i=this.getTrackingMessageByStatus(e.state);if(i&&this.tracking.send(i),c.skipNavigation)return e.state===RequestStatus.TOO_MANY_REQUESTS&&this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS),e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),void t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED);switch(e.state){case RequestStatus.SUCCESS:a&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:m&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:m&&d?this.goToView(d.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(m&&d?d.path[0]:this.getErrorViewIndex()),this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS)}e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED)}).catch(()=>{this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.ERROR,success:!1}),c.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){var e,i;if(!t.excludeFormContext)return this.context.getKVMap();const s=(null===(i=(e=this.context).getRecordsMap)||void 0===i?void 0:i.call(e))||{};return Object.values(s).reduce((t,e)=>{var i;const s=null===(i=null==e?void 0:e.getValue)||void 0===i?void 0:i.call(e);return s&&"FORM"!==s.sourceId?(t[s.id]=s.value,t):t},{})}constructDataToSent({contextValue:t,formValue:e,utmParams:i}){const s=Object.assign({},t);return s.tracking=i,Object.keys(e).forEach(t=>{if(t.startsWith("clConsentId")){if(t.endsWith("_label"))return;const i={value:e[t]};e[`${t}_label`]&&(i.text=e[`${t}_label`]),s.consents?s.consents[t]=i:s.consents={[t]:i}}else{const i=e[t];s[t]=isDictionary(i)||Array.isArray(i)?JSON.stringify(i):i}}),s}constructRequestPayload({contextValue:t,formValue:e,utmParams:i}){let s={data:this.constructDataToSent({contextValue:t,formValue:e,utmParams:i}),referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy")};return this.configService.getConfig("widgetDebugMode")&&(s.ignoreTracking=!0),s}constructRequestHeaders(){const t={},e=this.configService.getConfig("clCustomerId");return e&&Object.assign(t,{"cl-customer-id":e}),t}goToView(t,e){this.eventEmitter.emit(SysActionTypes.GO_TO_VIEW,t,e)}sendRequest(t){return this.skipHttpRequest?Promise.resolve({status:200,json:()=>Promise.resolve({next:{type:RequestStatus.SUCCESS}})}):this.httpClient.execute(this.configService.getConfig("subscribeContactUrl"),"POST",t,this.constructRequestHeaders())}getSuccessViewIndex(){return this.resolveResultViewIndex("successViewId",["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"])}getErrorViewIndex(){return this.resolveResultViewIndex("errorViewId",["DOCUMENT_VIEW_TYPE_ERROR"])}getAlreadySubscribedViewIndex(){const t=this.getActiveSubmitActionParams();return t&&!t.alreadySubscribedViewId?this.getSuccessViewIndex():this.resolveResultViewIndex("alreadySubscribedViewId",["DOCUMENT_VIEW_TYPE_SUBSCRIBED"])}resolveResultViewIndex(t,e){var i;const s=this.getServices().documentModel.getViews(),n=null===(i=this.getActiveSubmitActionParams())||void 0===i?void 0:i[t];if(n){const t=s.findIndex(t=>t.id===n);if(-1!==t)return t}return s.findIndex(t=>e.includes(t.label))}hasFormControls(){return this.form.getControlsAsArray().length>0}getActiveSubmitActionParams(){if(this.hasFormControls())return this.getServices().documentModel.getShared().submitActionParams}runPostSubmitActionOrGoToView(t){var e;const i=null===(e=this.getActiveSubmitActionParams())||void 0===e?void 0:e.runAction;i?setTimeout(()=>{this.getServices().actionFactory.get(i).execute(this.stateService.getState())},1500):this.goToView(t())}handleErrorResponse(){const t=this.getErrorViewIndex();-1!==t?this.goToView(t):this.emitSubmitLifecycleEvent(SysEventTypes.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW)}}
@@ -1 +1 @@
1
- var __asyncValues=this&&this.__asyncValues||function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,s=t[Symbol.asyncIterator];return s?s.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(s){e[s]=t[s]&&function(e){return new Promise(function(r,n){(function(t,e,s,r){Promise.resolve(r).then(function(e){t({value:e,done:s})},e)})(r,n,(e=t[s](e)).done,e.value)})}}};import{applySysAttrPrefix}from"../renderer/RenderConstants";import ViewEntryType from"../document-model/ViewEntryType";import SysActionTypes from"../action/SysActionTypes";export class ClickHandler{static sortActions(t){const e={[SysActionTypes.CLOSE_WIDGET]:-1,[SysActionTypes.OPEN_LINK]:-2,[SysActionTypes.SHOW_WIDGET]:1,[SysActionTypes.SUBSCRIBE_CONTACT]:2,[SysActionTypes.REQUEST]:3},s=t=>void 0!==e[t.type]?e[t.type]:0;return[...t].sort((t,e)=>s(t)>s(e)?-1:s(t)<s(e)?1:0)}constructor(t,e){this.config=t,this.actions=ClickHandler.sortActions(e),this.listener=null,this.targetElements=[],this.eventsQueue=[],this.state=null,this.postponed=!1}activate(t,e,s){this.state=t;const r=s(),n=r.getAttribute(applySysAttrPrefix("id"));this.listener=t=>{const e=t.composedPath().filter(t=>t instanceof HTMLElement&&t.getAttribute(applySysAttrPrefix("type")));let s=0;for(;e[s]&&e[s].getAttribute(applySysAttrPrefix("id"))!==n;){let t=e[s].getAttribute(applySysAttrPrefix("type"));if(ClickHandler.IGNORING_VIEW_ENTRY_TYPES.includes(t))return;s++}this.eventsQueue.push({event:t}),this.postponed||this.execute()},this.targetElements=this.config.relativeSelector?Array.from((r.shadowRoot||r).querySelectorAll(this.config.relativeSelector)):[r],this.targetElements.forEach(t=>{t.addEventListener("click",this.listener)})}async execute(){var t,e,s,r;try{for(var n,i=!0,o=__asyncValues(this.eventsQueue);!(t=(n=await o.next()).done);i=!0){r=n.value,i=!1;const{event:t}=r;for(const e of this.actions){if(!await e.execute(this.state.getState(),t))break}}}catch(t){e={error:t}}finally{try{i||t||!(s=o.return)||await s.call(o)}finally{if(e)throw e.error}}this.eventsQueue=[]}postpone(){this.postponed=!0}release(){this.postponed=!1,this.execute()}destroy(){this.listener&&this.targetElements.length&&(this.targetElements.forEach(t=>{t.removeEventListener("click",this.listener)}),this.targetElements=[])}}ClickHandler.IGNORING_VIEW_ENTRY_TYPES=[ViewEntryType.BUTTON,ViewEntryType.CONSENT,ViewEntryType.INPUT];
1
+ var __asyncValues=this&&this.__asyncValues||function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(r){e[r]=t[r]&&function(e){return new Promise(function(s,n){(function(t,e,r,s){Promise.resolve(s).then(function(e){t({value:e,done:r})},e)})(s,n,(e=t[r](e)).done,e.value)})}}};import{applySysAttrPrefix}from"../renderer/RenderConstants";import ViewEntryType from"../document-model/ViewEntryType";import SysActionTypes from"../action/SysActionTypes";export class ClickHandler{static sortActions(t){const e={[SysActionTypes.CLOSE_WIDGET]:-1,[SysActionTypes.OPEN_LINK]:-2,[SysActionTypes.SHOW_WIDGET]:1,[SysActionTypes.SUBSCRIBE_CONTACT]:2,[SysActionTypes.REQUEST]:3},r=t=>void 0!==e[t.type]?e[t.type]:0;return[...t].sort((t,e)=>r(t)>r(e)?-1:r(t)<r(e)?1:0)}constructor(t,e){this.config=t,this.actions=ClickHandler.sortActions(e),this.listener=null,this.targetElements=[],this.eventsQueue=[],this.state=null,this.postponed=!1}activate(t,e,r){this.state=t;const s=r(),n=s.getAttribute(applySysAttrPrefix("id"));this.actions.forEach(t=>{var e;return null===(e=t.setInitiatorComponentId)||void 0===e?void 0:e.call(t,n)}),this.listener=t=>{const e=t.composedPath().filter(t=>t instanceof HTMLElement&&t.getAttribute(applySysAttrPrefix("type")));let r=0;for(;e[r]&&e[r].getAttribute(applySysAttrPrefix("id"))!==n;){let t=e[r].getAttribute(applySysAttrPrefix("type"));if(ClickHandler.IGNORING_VIEW_ENTRY_TYPES.includes(t))return;r++}this.eventsQueue.push({event:t}),this.postponed||this.execute()},this.targetElements=this.config.relativeSelector?Array.from((s.shadowRoot||s).querySelectorAll(this.config.relativeSelector)):[s],this.targetElements.forEach(t=>{t.addEventListener("click",this.listener)})}async execute(){var t,e,r,s;try{for(var n,i=!0,o=__asyncValues(this.eventsQueue);!(t=(n=await o.next()).done);i=!0){s=n.value,i=!1;const{event:t}=s;for(const e of this.actions){if(!await e.execute(this.state.getState(),t))break}}}catch(t){e={error:t}}finally{try{i||t||!(r=o.return)||await r.call(o)}finally{if(e)throw e.error}}this.eventsQueue=[]}postpone(){this.postponed=!0}release(){this.postponed=!1,this.execute()}destroy(){this.listener&&this.targetElements.length&&(this.targetElements.forEach(t=>{t.removeEventListener("click",this.listener)}),this.targetElements=[])}}ClickHandler.IGNORING_VIEW_ENTRY_TYPES=[ViewEntryType.BUTTON,ViewEntryType.CONSENT,ViewEntryType.INPUT];
@@ -1 +1 @@
1
- export default class ComponentEventHandler{constructor(t,e){this.config=t,this.actions=e,this.componentEmitterListener=null}activate(t,e,n){this.componentEmitterListener=e.on(this.config.eventName,()=>{this.actions.forEach(e=>e.execute(t.getState(),this.config.params))})}destroy(){this.componentEmitterListener&&this.componentEmitterListener.off()}}
1
+ import{applySysAttrPrefix}from"../renderer/RenderConstants";export default class ComponentEventHandler{constructor(t,e){this.config=t,this.actions=e,this.componentEmitterListener=null}activate(t,e,n){var i;const o=null===(i=n())||void 0===i?void 0:i.getAttribute(applySysAttrPrefix("id"));this.actions.forEach(t=>{var e;return null===(e=t.setInitiatorComponentId)||void 0===e?void 0:e.call(t,o)}),this.componentEmitterListener=e.on(this.config.eventName,()=>{this.actions.forEach(e=>e.execute(t.getState(),this.config.params))})}destroy(){this.componentEmitterListener&&this.componentEmitterListener.off()}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.7.7",
3
+ "version": "18.7.8-rc1",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",