@claspo/renderer 18.8.0-nonlinear5 → 18.8.1-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.
- package/ViewRouter.d.ts +3 -1
- package/ViewRouter.js +1 -1
- package/action/ActionFactory.js +1 -1
- package/action/actions/BaseRequestAction.js +1 -1
- package/action/actions/GoToViewAction.d.ts +4 -1
- package/action/actions/GoToViewAction.js +1 -1
- package/document-model/DocumentModelService.js +1 -1
- package/lead-capture/ActivePathTracker.js +1 -1
- package/lead-capture/FinishCoordinator.d.ts +2 -0
- package/lead-capture/FinishCoordinator.js +1 -1
- package/lead-capture/NavigationLeadCollector.d.ts +3 -0
- package/lead-capture/NavigationLeadCollector.js +1 -1
- package/package.json +2 -2
package/ViewRouter.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export default class ViewRouter extends DefaultEventEmitter {
|
|
|
13
13
|
getCurrentViewIndex(): any;
|
|
14
14
|
start(viewIndex: any): any;
|
|
15
15
|
destroy(): void;
|
|
16
|
-
navigate(index: any, routeState?: {
|
|
16
|
+
navigate(index: any, routeState?: {
|
|
17
|
+
isForward?: boolean;
|
|
18
|
+
} | null): void;
|
|
17
19
|
viewDestroy(): void;
|
|
18
20
|
getDocumentContainer(): any;
|
|
19
21
|
getLastTransition(): any;
|
package/ViewRouter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"./action/SysActionTypes";import SysEventTypes from"./common/SysEventTypes";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import SysRouterEvent from"./RouterEvent";export default class ViewRouter extends DefaultEventEmitter{constructor(t,e,n,i,
|
|
1
|
+
import SysActionTypes from"./action/SysActionTypes";import SysEventTypes from"./common/SysEventTypes";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import SysRouterEvent from"./RouterEvent";export default class ViewRouter extends DefaultEventEmitter{constructor(t,e,n,i,r){super(),this.eventEmitter=t,this.documentModel=e,this.viewRenderer=n,this.optionalDocumentStyles=i,this.services=r,this.currentViewIndex=null,this.currentViewComponentRef=null,this.eventEmitter.on(SysEventTypes.TOO_MANY_REQUESTS,()=>{this.viewDestroy(),this.documentContainer.innerText="Too many requests"}),this.transitions=[]}getCurrentViewIndex(){return this.currentViewIndex}start(t){this.documentContainer=window.document.createElement("div"),this.documentContainer.setAttribute("cl-document",""),this.optionalDocumentStyles&&Object.keys(this.optionalDocumentStyles).forEach(t=>{this.documentContainer.style[t]=this.optionalDocumentStyles[t]}),this.navigate(t||0);return this.eventEmitter.on(SysActionTypes.GO_TO_VIEW,(t,e,n)=>{const i="number"==typeof t?t:this.documentModel.getModel().views.findIndex(e=>e.id===t);-1===i?this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{viewPointer:t}):this.navigate(i,n)}),this.eventEmitter.on(SysActionTypes.GO_TO_PREVIOUS_VIEW,t=>{"number"!=typeof t?this.getCurrentViewIndex()<=0||this.navigate(this.getCurrentViewIndex()-1,{isForward:!1}):this.navigate(t,{isForward:!1})}),this.eventEmitter.on(SysActionTypes.GO_TO_NEXT_VIEW,()=>{this.documentModel.getModel().views[this.getCurrentViewIndex()+1]&&this.navigate(this.getCurrentViewIndex()+1,{isForward:!0})}),this.documentContainer}destroy(){this.viewDestroy(),this.documentContainer&&this.documentContainer.remove()}navigate(t,e={}){var n;let i=this.documentModel.getView(t);const r=this.currentViewIndex;if(this.currentViewIndex===t)return;if(!i)throw this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{navigateTo:t}),new Error("View was not found by index: "+t);const o=this.viewRenderer.render(i,t);this.viewDestroy(),this.documentContainer.appendChild(o),this.currentViewComponentRef=o,this.currentViewIndex=t,this.transitions.push({prevViewIndex:r,currentViewIndex:t,currentViewComponentRef:o,contactDataSubmitted:null===(n=this.services.submitState)||void 0===n?void 0:n.hasSubmitAttemptSinceLastChange(),routeState:e});const s="boolean"==typeof(null==e?void 0:e.isForward)?e.isForward:null!==r&&t>r;this.eventEmitter.emit(SysRouterEvent.NAVIGATION_END,t,{isForward:s})}viewDestroy(){this.currentViewComponentRef&&this.viewRenderer.destroy(this.currentViewComponentRef)}getDocumentContainer(){return this.documentContainer}getLastTransition(){return this.transitions[this.transitions.length-1]}}
|
package/action/ActionFactory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,n,s
|
|
1
|
+
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,n,c,s){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=c,this.getServices=s}get(t){switch(t.type){case SysActionTypes.SUBSCRIBE_CONTACT:return new SubscribeContactAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.REQUEST:return new RequestAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t);case SysActionTypes.GO_TO_VIEW:return new GoToViewAction(this.eventEmitter,t,this.configService,this.form,this.getServices().viewRouter,this.getServices().documentModel,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_PREVIOUS_VIEW:return new GoToPreviousViewAction(this.eventEmitter,t,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_NEXT_VIEW:return new GoToNextViewAction(this.eventEmitter,this.form,t,this.tracking);case SysActionTypes.SHOW_WIDGET:return new ShowWidgetAction(this.eventEmitter,t,this.tracking);case SysActionTypes.OPEN_LINK:return new OpenLinkAction(t,this.configService,this.tracking);case SysActionTypes.CLOSE_WIDGET:return new CloseWidgetAction(this.eventEmitter,t,this.configService,this.tracking);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import{SYSTEM_RESULT_STATE_LABELS,submitAdvancesToNextStep}from"@claspo/common/document/ViewNavigationGraph";import getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import{constructDataToSent,constructRequestHeaders,constructRequestPayload,extractContextValue}from"../RequestPayloadBuilder";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&&(SYSTEM_RESULT_STATE_LABELS.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,o,n,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=o,this.formEventsListener=null,this.tracking=n,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 o;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 n=new Promise(t=>{this.submit(t,i,s)});return null===(o=this.getServices().submitState)||void 0===o||o.trackSubmission(n),n}submit(t,e,i){var s,o,n;const r=this.getServices().viewRouter.getCurrentViewIndex(),a=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),c=submitAdvancesToNextStep(this.getServices().documentModel.getNavigationGraph(),this.getServices().documentModel.getViews(),r,a),u=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()&&!u.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const S=this.stateService,d=S.getState().conditionalRedirectViewId,m=u.conditionalRedirectViewId||d;d&&(u.conditionalRedirectViewId=d,S.setState({conditionalRedirectViewId:null}));let E=this.getServices().documentModel.getViews()[r+1];const h=this.getServices().documentModel.getViews()[r];if(!u.skipNavigation&&m&&getComponentCountOnView(h,"SysNetPromoterScoreComponent")+getComponentCountOnView(h,"SysFeedbackComponent")===1&&(E=this.getServices().documentModel.getViews().find(t=>t.id===u.conditionalRedirectViewId),viewHasControls(E)||isResultView(E,a)))return this.goToView(E.path[0],u),void t(!0);const l=null!==(s=u.formValue)&&void 0!==s?s:this.form.getControlsMap(),g=this.getContextValue(u);if(!u.skipNavigation&&c&&(viewHasControls(E)||!Object.keys(l).length&&!Object.keys(g).length))return this.goToView(r+1,u),void t(!0);if(!Object.keys(l).length&&!Object.keys(g).length)return void t(!0);const T=UTMParamsExtractor.extractTrackingParams(this.context),v=this.constructRequestPayload({contextValue:g,formValue:l,utmParams:T}),R=null===(n=null===(o=this.getServices().navigationLeadCollector)||void 0===o?void 0:o.getLatestNavigationData)||void 0===n?void 0:n.call(o);R&&(v.navigationData=R),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),u.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:c&&E?this.goToView(E.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:m&&E?this.goToView(E.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:m&&E?this.goToView(E.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(m&&E?E.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}),u.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){return extractContextValue(this.context,t.excludeFormContext)}constructDataToSent({contextValue:t,formValue:e,utmParams:i}){return constructDataToSent({contextValue:t,formValue:e,utmParams:i})}constructRequestPayload({contextValue:t,formValue:e,utmParams:i}){return constructRequestPayload({contextValue:t,formValue:e,utmParams:i,referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy"),widgetDebugMode:this.configService.getConfig("widgetDebugMode")})}constructRequestHeaders(){return constructRequestHeaders({clCustomerId:this.configService.getConfig("clCustomerId")})}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(),o=null===(i=this.getActiveSubmitActionParams())||void 0===i?void 0:i[t];if(o){const t=s.findIndex(t=>t.id===o);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
|
+
import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import{SYSTEM_RESULT_STATE_LABELS,submitAdvancesToNextStep}from"@claspo/common/document/ViewNavigationGraph";import getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import{constructDataToSent,constructRequestHeaders,constructRequestPayload,extractContextValue}from"../RequestPayloadBuilder";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&&(SYSTEM_RESULT_STATE_LABELS.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,o,n,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=o,this.formEventsListener=null,this.tracking=n,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 o;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 n=new Promise(t=>{this.submit(t,i,s)});return null===(o=this.getServices().submitState)||void 0===o||o.trackSubmission(n),n}submit(t,e,i){var s,o,n;const r=this.getServices().viewRouter.getCurrentViewIndex(),a=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),c=submitAdvancesToNextStep(this.getServices().documentModel.getNavigationGraph(),this.getServices().documentModel.getViews(),r,a),u=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()&&!u.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const S=this.stateService,d=S.getState().conditionalRedirectViewId,m=u.conditionalRedirectViewId||d;d&&(u.conditionalRedirectViewId=d,S.setState({conditionalRedirectViewId:null}));let E=this.getServices().documentModel.getViews()[r+1];const h=this.getServices().documentModel.getViews()[r];if(!u.skipNavigation&&m&&getComponentCountOnView(h,"SysNetPromoterScoreComponent")+getComponentCountOnView(h,"SysFeedbackComponent")===1&&(E=this.getServices().documentModel.getViews().find(t=>t.id===u.conditionalRedirectViewId),viewHasControls(E)||isResultView(E,a)))return this.goToView(E.path[0],u),void t(!0);const l=null!==(s=u.formValue)&&void 0!==s?s:this.form.getControlsMap(),g=this.getContextValue(u);if(!u.skipNavigation&&c&&(viewHasControls(E)||!Object.keys(l).length&&!Object.keys(g).length))return this.goToView(r+1,u),void t(!0);if(!Object.keys(l).length&&!Object.keys(g).length)return void t(!0);const T=UTMParamsExtractor.extractTrackingParams(this.context),v=this.constructRequestPayload({contextValue:g,formValue:l,utmParams:T}),R=null===(n=null===(o=this.getServices().navigationLeadCollector)||void 0===o?void 0:o.getLatestNavigationData)||void 0===n?void 0:n.call(o);R&&(v.navigationData=R),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),u.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:c&&E?this.goToView(E.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:m&&E?this.goToView(E.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:m&&E?this.goToView(E.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(m&&E?E.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}),u.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){return extractContextValue(this.context,t.excludeFormContext)}constructDataToSent({contextValue:t,formValue:e,utmParams:i}){return constructDataToSent({contextValue:t,formValue:e,utmParams:i})}constructRequestPayload({contextValue:t,formValue:e,utmParams:i}){return constructRequestPayload({contextValue:t,formValue:e,utmParams:i,referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy"),widgetDebugMode:this.configService.getConfig("widgetDebugMode")})}constructRequestHeaders(){return constructRequestHeaders({clCustomerId:this.configService.getConfig("clCustomerId")})}goToView(t,e){this.eventEmitter.emit(SysActionTypes.GO_TO_VIEW,t,Object.assign(Object.assign({},e),{isForward:!0}))}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(),o=null===(i=this.getActiveSubmitActionParams())||void 0===i?void 0:i[t];if(o){const t=s.findIndex(t=>t.id===o);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)}}
|
|
@@ -6,7 +6,10 @@ export default class GoToViewAction {
|
|
|
6
6
|
viewRouter: any;
|
|
7
7
|
documentModel: any;
|
|
8
8
|
tracking: any;
|
|
9
|
+
activePathTracker: any;
|
|
9
10
|
type: SysActionTypes;
|
|
10
|
-
constructor(eventEmitter: any, actionConfig: any, configService: any, form: any, viewRouter: any, documentModel: any, tracking: any);
|
|
11
|
+
constructor(eventEmitter: any, actionConfig: any, configService: any, form: any, viewRouter: any, documentModel: any, tracking: any, activePathTracker: any);
|
|
11
12
|
execute(): Promise<boolean>;
|
|
13
|
+
private getTargetViewIndex;
|
|
14
|
+
private isForwardNavigation;
|
|
12
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";export default class GoToViewAction{constructor(i,
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";import ErrorLogger from"../../error/ErrorLogger";export default class GoToViewAction{constructor(t,i,e,r,o,a,s,n){this.type=SysActionTypes.GO_TO_VIEW,this.eventEmitter=t,this.config=i,this.form=r,this.viewRouter=o,this.documentModel=a,this.tracking=s,this.activePathTracker=n}async execute(){var t;try{this.form.markAsTouched();const i=this.isForwardNavigation(this.getTargetViewIndex());if(i&&(null===(t=this.config.params.validateForm)||void 0===t||t)){if(!await this.form.waitForPendingValidationAndCheckIfValid())return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),!1}return this.eventEmitter.emit(this.type,this.config.params.viewId||this.config.params.viewIndex,{isForward:i}),this.config.params.trackClick&&this.tracking.trackClick({params:this.config.params.trackClickParams,countAsTargetAction:this.config.params.countAsTargetAction}),!0}catch(t){return ErrorLogger.log(`GoToViewAction.execute failed: ${(null==t?void 0:t.stack)||t}`),!1}}getTargetViewIndex(){return this.config.params.viewId?this.documentModel.getViews().findIndex(t=>t.id===this.config.params.viewId):this.config.params.viewIndex}isForwardNavigation(t){var i,e,r;if("number"!=typeof t||t<0)return!1;const o=null!==(r=null===(e=null===(i=this.activePathTracker)||void 0===i?void 0:i.getActivePath)||void 0===e?void 0:e.call(i))&&void 0!==r?r:[];return o.length?!o.includes(t):this.viewRouter.getCurrentViewIndex()<t}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import ModulesComponentExtractor from"./ModulesComponentExtractor";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentUtils from"@claspo/common/document/DocumentUtils";import{buildViewNavigationGraph}from"@claspo/common/document/ViewNavigationGraph";export const EditorToWidgetEventType={COMPONENT_INSERT:"COMPONENT_INSERT",COMPONENT_REMOVE:"COMPONENT_REMOVE",COMPONENT_MOVE:"COMPONENT_MOVE",COMPONENT_UPDATE:"COMPONENT_UPDATE",COMPONENT_PROPS_UPDATE:"COMPONENT_PROPS_UPDATE",REMOVE_FOCUS:"REMOVE_FOCUS",SET_FOCUS:"SET_FOCUS",SHARED_UPDATE:"SHARED_UPDATE",MOBILE_BREAKPOINT_UPDATE:"MOBILE_BREAKPOINT_UPDATE",ENVIRONMENT_UPDATE:"ENVIRONMENT_UPDATE",TEXT_CLASS_ADDED:"TEXT_CLASS_ADDED",TEXT_CLASS_UPDATED:"TEXT_CLASS_UPDATED",TEXT_CLASS_REMOVED:"TEXT_CLASS_REMOVED",HEADER_FONT_FAMILY_UPDATE:"HEADER_FONT_FAMILY_UPDATE",TEXT_FONT_FAMILY_UPDATE:"TEXT_FONT_FAMILY_UPDATE",SHARED_UPDATE_ALL:"SHARED_UPDATE_ALL",COLOR_SCHEMA_UPDATE:"COLOR_SCHEMA_UPDATE",THEME_UPDATE:"THEME_UPDATE"};export default class DocumentModelService extends DefaultEventEmitter{constructor(t){super(),this.navigationGraph=null,this.json=t,this.flatJson=ModulesComponentExtractor.extract(this.json)}setComponentRef(t,e){DocumentUtils.getNodeById(this.getViews(),t).componentRef=e}getModel(){return this.flatJson}getView(t){return this.flatJson.views[t]}getViews(){return this.flatJson.views}getShared(){return this.flatJson.shared}getNavigationGraph(){
|
|
1
|
+
import ModulesComponentExtractor from"./ModulesComponentExtractor";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentUtils from"@claspo/common/document/DocumentUtils";import{buildViewNavigationGraph}from"@claspo/common/document/ViewNavigationGraph";import ErrorLogger from"../error/ErrorLogger";export const EditorToWidgetEventType={COMPONENT_INSERT:"COMPONENT_INSERT",COMPONENT_REMOVE:"COMPONENT_REMOVE",COMPONENT_MOVE:"COMPONENT_MOVE",COMPONENT_UPDATE:"COMPONENT_UPDATE",COMPONENT_PROPS_UPDATE:"COMPONENT_PROPS_UPDATE",REMOVE_FOCUS:"REMOVE_FOCUS",SET_FOCUS:"SET_FOCUS",SHARED_UPDATE:"SHARED_UPDATE",MOBILE_BREAKPOINT_UPDATE:"MOBILE_BREAKPOINT_UPDATE",ENVIRONMENT_UPDATE:"ENVIRONMENT_UPDATE",TEXT_CLASS_ADDED:"TEXT_CLASS_ADDED",TEXT_CLASS_UPDATED:"TEXT_CLASS_UPDATED",TEXT_CLASS_REMOVED:"TEXT_CLASS_REMOVED",HEADER_FONT_FAMILY_UPDATE:"HEADER_FONT_FAMILY_UPDATE",TEXT_FONT_FAMILY_UPDATE:"TEXT_FONT_FAMILY_UPDATE",SHARED_UPDATE_ALL:"SHARED_UPDATE_ALL",COLOR_SCHEMA_UPDATE:"COLOR_SCHEMA_UPDATE",THEME_UPDATE:"THEME_UPDATE"};export default class DocumentModelService extends DefaultEventEmitter{constructor(t){super(),this.navigationGraph=null,this.json=t,this.flatJson=ModulesComponentExtractor.extract(this.json)}setComponentRef(t,e){DocumentUtils.getNodeById(this.getViews(),t).componentRef=e}getModel(){return this.flatJson}getView(t){return this.flatJson.views[t]}getViews(){return this.flatJson.views}getShared(){return this.flatJson.shared}getNavigationGraph(){if(!this.navigationGraph)try{this.navigationGraph=buildViewNavigationGraph(this.getViews(),this.getShared())}catch(t){ErrorLogger.log(`buildViewNavigationGraph failed: ${(null==t?void 0:t.stack)||t}`),this.navigationGraph={nodes:[],edges:[]}}return this.navigationGraph}iterateViewModelAndExecute(t,e){const o=this.getView(t);DocumentUtils.iterateDepthFirst(o,e)}destroy(){}destroyView(t){console.warn("destroyView now should do nothing"),this.iterateViewModelAndExecute(t,t=>{t.componentRef&&(t.componentRef.remove(),t.componentRef=null)})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysRouterEvent from"../RouterEvent";import FormGroupEvents from"../form/FormGroupEvents";import FormSource from"../sdk/source/sources/FormSource";export default class ActivePathTracker{constructor(e,t,i,s){this.activePath=[],this.pendingTail=[],this.stashedValues=new Map,this.form=t,this.context=i,this.state=s,this.subscriptions=[e.on(SysRouterEvent.NAVIGATION_END,e=>this.onNavigationEnd(e)),t.on(FormGroupEvents.controlRegistered,e=>this.reseedStashedValue(e))]}getActivePath(){return[...this.activePath]}destroy(){this.subscriptions.forEach(e=>{var t;return null===(t=null==e?void 0:e.off)||void 0===t?void 0:t.call(e)}),this.subscriptions=[]}onNavigationEnd(e){if(!this.activePath.length)return void this.activePath.push(e);if(this.activePath[this.activePath.length-1]===e)return;const t=this.activePath.indexOf(e);if(-1!==t){const e=this.activePath.splice(t+1);return this.stashTailControls(e),void(this.pendingTail=[...e,...this.pendingTail])}if(this.pendingTail.length){const t=this.pendingTail.indexOf(e);if(-1===t)this.pruneAbandonedTail(this.pendingTail),this.pendingTail=[];else{const e=this.pendingTail.slice(0,t);e.length&&this.pruneAbandonedTail(e),this.pendingTail=this.pendingTail.slice(t+1)}}this.activePath.push(e)}stashTailControls(e){this.form.getControlsAsArray().forEach(t=>{if(null===t.viewIdx||!e.includes(t.viewIdx))return;const i=t.getValue();void 0!==i&&""!==i&&this.stashedValues.set(t.getName(),{value:i,viewIdx:t.viewIdx}),this.form.removeControl(t.getName())})}reseedStashedValue(e){const t=this.stashedValues.get(e.getName());t
|
|
1
|
+
import SysRouterEvent from"../RouterEvent";import FormGroupEvents from"../form/FormGroupEvents";import FormSource from"../sdk/source/sources/FormSource";import ErrorLogger from"../error/ErrorLogger";export default class ActivePathTracker{constructor(e,t,i,s){this.activePath=[],this.pendingTail=[],this.stashedValues=new Map,this.form=t,this.context=i,this.state=s,this.subscriptions=[e.on(SysRouterEvent.NAVIGATION_END,e=>this.onNavigationEnd(e)),t.on(FormGroupEvents.controlRegistered,e=>this.reseedStashedValue(e))]}getActivePath(){return[...this.activePath]}destroy(){this.subscriptions.forEach(e=>{var t;return null===(t=null==e?void 0:e.off)||void 0===t?void 0:t.call(e)}),this.subscriptions=[]}onNavigationEnd(e){try{if(!this.activePath.length)return void this.activePath.push(e);if(this.activePath[this.activePath.length-1]===e)return;const t=this.activePath.indexOf(e);if(-1!==t){const e=this.activePath.splice(t+1);return this.stashTailControls(e),void(this.pendingTail=[...e,...this.pendingTail])}if(this.pendingTail.length){const t=this.pendingTail.indexOf(e);if(-1===t)this.pruneAbandonedTail(this.pendingTail),this.pendingTail=[];else{const e=this.pendingTail.slice(0,t);e.length&&this.pruneAbandonedTail(e),this.pendingTail=this.pendingTail.slice(t+1)}}this.activePath.push(e)}catch(e){ErrorLogger.log(`ActivePathTracker.onNavigationEnd failed: ${(null==e?void 0:e.stack)||e}`)}}stashTailControls(e){this.form.getControlsAsArray().forEach(t=>{if(null===t.viewIdx||!e.includes(t.viewIdx))return;const i=t.getValue();void 0!==i&&""!==i&&this.stashedValues.set(t.getName(),{value:i,viewIdx:t.viewIdx}),this.form.removeControl(t.getName())})}reseedStashedValue(e){try{const t=this.stashedValues.get(e.getName());if(!t||t.viewIdx!==e.viewIdx)return;this.stashedValues.delete(e.getName()),e.setValue(t.value)}catch(e){ErrorLogger.log(`ActivePathTracker.reseedStashedValue failed: ${(null==e?void 0:e.stack)||e}`)}}pruneAbandonedTail(e){Array.from(this.stashedValues.entries()).forEach(([t,i])=>{e.includes(i.viewIdx)&&this.stashedValues.delete(t)}),this.form.getControlsAsArray().forEach(t=>{null!==t.viewIdx&&e.includes(t.viewIdx)&&this.form.removeControl(t.getName())});const t=this.context.getRecordsMap();Object.keys(t).forEach(i=>{var s;const r=null===(s=t[i])||void 0===s?void 0:s.getValue();r&&r.sourceId===FormSource.sourceId&&void 0!==r.viewIndex&&e.includes(r.viewIndex)&&this.context.deleteRecord(i,!0)}),this.state.setState({conditionalRedirectViewId:null})}}
|
|
@@ -12,6 +12,8 @@ export default class FinishCoordinator {
|
|
|
12
12
|
private graph;
|
|
13
13
|
private finished;
|
|
14
14
|
private inFlight;
|
|
15
|
+
private executingCommit;
|
|
16
|
+
private lastSubmitAttemptWasOwnFailedCommit;
|
|
15
17
|
private subscriptions;
|
|
16
18
|
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, getServices: () => any);
|
|
17
19
|
destroy(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysRouterEvent from"../RouterEvent";import SysEventTypes from"../common/SysEventTypes";import SysActionTypes from"../action/SysActionTypes";import ActionCategory from"../action/actions/ActionCategory";import{SubmitState}from"../submit-state/SubmitStateService";import{isAutoCommitTerminal,isMultiViewFlow}from"@claspo/common/document/ViewNavigationGraph";export var FinishTrigger;!function(t){t.TERMINAL="terminal",t.CLOSE="close"}(FinishTrigger||(FinishTrigger={}));export default class FinishCoordinator{constructor(t,i,e){this.finished=!1,this.inFlight=!1,this.getServices=e,this.graph=i.getNavigationGraph(),this.subscriptions=[t.on(SysRouterEvent.NAVIGATION_END,t=>this.onNavigationEnd(t)),t.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{(null==t?void 0:t.success)&&(this.finished=!0)})]}destroy(){this.subscriptions.forEach(t=>{var i;return null===(i=null==t?void 0:t.off)||void 0===i?void 0:i.call(t)}),this.subscriptions=[]}async attemptCommit(t,i){var e,o;const
|
|
1
|
+
import SysRouterEvent from"../RouterEvent";import SysEventTypes from"../common/SysEventTypes";import SysActionTypes from"../action/SysActionTypes";import ActionCategory from"../action/actions/ActionCategory";import{SubmitState}from"../submit-state/SubmitStateService";import{isAutoCommitTerminal,isMultiViewFlow}from"@claspo/common/document/ViewNavigationGraph";import ErrorLogger from"../error/ErrorLogger";export var FinishTrigger;!function(t){t.TERMINAL="terminal",t.CLOSE="close"}(FinishTrigger||(FinishTrigger={}));export default class FinishCoordinator{constructor(t,i,e){this.finished=!1,this.inFlight=!1,this.executingCommit=!1,this.lastSubmitAttemptWasOwnFailedCommit=!1,this.getServices=e,this.graph=i.getNavigationGraph(),this.subscriptions=[t.on(SysRouterEvent.NAVIGATION_END,t=>this.onNavigationEnd(t)),t.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.executingCommit||(this.lastSubmitAttemptWasOwnFailedCommit=!1)}),t.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{(null==t?void 0:t.success)&&(this.finished=!0,this.lastSubmitAttemptWasOwnFailedCommit=!1)})]}destroy(){this.subscriptions.forEach(t=>{var i;return null===(i=null==t?void 0:t.off)||void 0===i?void 0:i.call(t)}),this.subscriptions=[]}async attemptCommit(t,i){var e,o;const r=this.getServices(),s=null==r?void 0:r.submitState;if(!s||this.finished||this.inFlight)return!1;if(s.hasSubmitAttemptSinceLastChange()&&!this.lastSubmitAttemptWasOwnFailedCommit)return!1;if(t===FinishTrigger.CLOSE&&(!s.hasDirtyFormData()||s.getState()!==SubmitState.DIRTY&&!this.lastSubmitAttemptWasOwnFailedCommit))return!1;this.inFlight=!0;try{const t=await s.prepareAutoSubmitFormValue();if(this.finished||s.hasSubmitAttemptSinceLastChange()&&!this.lastSubmitAttemptWasOwnFailedCommit)return!1;if(!t||!Object.values(t).length)return!1;this.lastSubmitAttemptWasOwnFailedCommit=!1,null===(e=null==i?void 0:i.beforeExecute)||void 0===e||e.call(i,t);const n=(null===(o=r.actionRegister)||void 0===o?void 0:o.getRegisteredActions().find(t=>t.category===ActionCategory.SUBMIT))||r.actionFactory.get({type:SysActionTypes.REQUEST});let a;this.executingCommit=!0;try{a=await n.execute(void 0,void 0,!0,{skipValidation:!0,skipNavigation:!0,excludeFormContext:!0,formValue:t})}catch(t){ErrorLogger.log(`FinishCoordinator commit execute failed: ${(null==t?void 0:t.stack)||t}`),a=!1}finally{this.executingCommit=!1}return!1===a?(this.lastSubmitAttemptWasOwnFailedCommit=!0,!1):(this.finished=!0,!0)}catch(t){return ErrorLogger.log(`FinishCoordinator.attemptCommit failed: ${(null==t?void 0:t.stack)||t}`),!1}finally{this.inFlight=!1}}onNavigationEnd(t){try{if(!isMultiViewFlow(this.graph))return;if(!isAutoCommitTerminal(this.graph,t))return;this.attemptCommit(FinishTrigger.TERMINAL).catch(t=>{ErrorLogger.log(`FinishCoordinator terminal commit rejected: ${(null==t?void 0:t.stack)||t}`)})}catch(t){ErrorLogger.log(`FinishCoordinator.onNavigationEnd failed: ${(null==t?void 0:t.stack)||t}`)}}}
|
|
@@ -12,11 +12,14 @@ export default class NavigationLeadCollector {
|
|
|
12
12
|
private triggeredBy;
|
|
13
13
|
private previousViewIndex;
|
|
14
14
|
private lastSentSignature;
|
|
15
|
+
private lastCompletedSubscribeSignature;
|
|
15
16
|
private latestForwardNavigationData;
|
|
16
17
|
private subscriptions;
|
|
17
18
|
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, form: FormGroup, context: ContextSDK, triggeredBy: string);
|
|
18
19
|
destroy(): void;
|
|
19
20
|
getLatestNavigationData(): RequestNavigationDataI | null;
|
|
20
21
|
private onNavigationEnd;
|
|
22
|
+
private onSubmitRequestFinished;
|
|
23
|
+
private dataSignature;
|
|
21
24
|
private buildFormValue;
|
|
22
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysRouterEvent from"../RouterEvent";import SysEventTypes from"../common/SysEventTypes";import UTMParamsExtractor from"../action/UTMParamsExtractor";import{constructRequestPayload,extractContextValue}from"../action/RequestPayloadBuilder";import{hasMeaningfulValue}from"../submit-state/SubmitStateService";import{isAutoCommitTerminal,isMultiViewFlow}from"@claspo/common/document/ViewNavigationGraph";function stableStringify(t){var i;if(Array.isArray(t))return`[${t.map(stableStringify).join(",")}]`;if(t&&"object"==typeof t){return`{${Object.keys(t).sort().map(i=>`${JSON.stringify(i)}:${stableStringify(t[i])}`).join(",")}}`}return null!==(i=JSON.stringify(t))&&void 0!==i?i:"undefined"}export default class NavigationLeadCollector{constructor(t,i,e,r,a){this.previousViewIndex=null,this.lastSentSignature=null,this.latestForwardNavigationData=null,this.eventEmitter=t,this.form=e,this.context=r,this.views=i.getViews(),this.graph=i.getNavigationGraph(),this.triggeredBy=a,this.subscriptions=[t.on(SysRouterEvent.NAVIGATION_END,t=>this.onNavigationEnd(t))]}destroy(){this.subscriptions.forEach(t=>{var i;return null===(i=null==t?void 0:t.off)||void 0===i?void 0:i.call(t)}),this.subscriptions=[]}getLatestNavigationData(){return this.latestForwardNavigationData}onNavigationEnd(t){var
|
|
1
|
+
import SysRouterEvent from"../RouterEvent";import SysEventTypes from"../common/SysEventTypes";import UTMParamsExtractor from"../action/UTMParamsExtractor";import{constructRequestPayload,extractContextValue}from"../action/RequestPayloadBuilder";import{hasMeaningfulValue}from"../submit-state/SubmitStateService";import{isAutoCommitTerminal,isMultiViewFlow}from"@claspo/common/document/ViewNavigationGraph";import ErrorLogger from"../error/ErrorLogger";function stableStringify(t){var i;if(Array.isArray(t))return`[${t.map(stableStringify).join(",")}]`;if(t&&"object"==typeof t){return`{${Object.keys(t).sort().map(i=>`${JSON.stringify(i)}:${stableStringify(t[i])}`).join(",")}}`}return null!==(i=JSON.stringify(t))&&void 0!==i?i:"undefined"}export default class NavigationLeadCollector{constructor(t,i,e,r,a){this.previousViewIndex=null,this.lastSentSignature=null,this.lastCompletedSubscribeSignature=null,this.latestForwardNavigationData=null,this.eventEmitter=t,this.form=e,this.context=r,this.views=i.getViews(),this.graph=i.getNavigationGraph(),this.triggeredBy=a,this.subscriptions=[t.on(SysRouterEvent.NAVIGATION_END,(t,i,e)=>this.onNavigationEnd(t,e)),t.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>this.onSubmitRequestFinished(t))]}destroy(){this.subscriptions.forEach(t=>{var i;return null===(i=null==t?void 0:t.off)||void 0===i?void 0:i.call(t)}),this.subscriptions=[]}getLatestNavigationData(){return this.latestForwardNavigationData}onNavigationEnd(t,i){var e,r;try{const a=this.previousViewIndex;if(this.previousViewIndex=t,!isMultiViewFlow(this.graph))return;const o="boolean"==typeof(null==i?void 0:i.isForward)?i.isForward:null!==a&&t>a;if(null===a||!o)return;if(this.latestForwardNavigationData={previousViewId:null===(e=this.views[a])||void 0===e?void 0:e.id,currentViewId:null===(r=this.views[t])||void 0===r?void 0:r.id},isAutoCommitTerminal(this.graph,t))return;const n=this.buildFormValue(),s=extractContextValue(this.context,!0);if(!Object.keys(n).length&&!Object.keys(s).length)return;const l=this.dataSignature(n,s);if(l===this.lastSentSignature||l===this.lastCompletedSubscribeSignature)return;const u=constructRequestPayload({contextValue:s,formValue:n,utmParams:UTMParamsExtractor.extractTrackingParams(this.context),referrer:window.location.href,triggeredBy:this.triggeredBy});u.ignoreTracking=!0,u.navigationData=this.latestForwardNavigationData,this.lastSentSignature=l,this.eventEmitter.emit(SysEventTypes.LEAD_PROGRESS,u)}catch(t){ErrorLogger.log(`NavigationLeadCollector.onNavigationEnd failed: ${(null==t?void 0:t.stack)||t}`)}}onSubmitRequestFinished(t){try{if(!(null==t?void 0:t.success))return;this.lastCompletedSubscribeSignature=this.dataSignature(this.buildFormValue(),extractContextValue(this.context,!0))}catch(t){ErrorLogger.log(`NavigationLeadCollector.onSubmitRequestFinished failed: ${(null==t?void 0:t.stack)||t}`)}}dataSignature(t,i){return stableStringify({contextValue:i,formValue:t})}buildFormValue(){return this.form.getControlsAsArray().reduce((t,i)=>{const e=i.getValue();return hasMeaningfulValue(e)&&i.isValid()&&(t[i.getName()]=e),t},{})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/renderer",
|
|
3
|
-
"version": "18.8.
|
|
3
|
+
"version": "18.8.1-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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"node": ">=18.16.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@claspo/common": "7.4.0
|
|
18
|
+
"@claspo/common": "7.4.0",
|
|
19
19
|
"@testing-library/dom": "^10.4.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|