@claspo/renderer 18.8.0-nonlinear2 → 18.8.0-nonlinear4
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/CompositionRoot.js +1 -1
- package/action/actions/BaseRequestAction.d.ts +1 -2
- package/action/actions/BaseRequestAction.js +1 -1
- package/action/actions/GoToPreviousViewAction.js +1 -1
- package/form/FormControl.d.ts +1 -0
- package/form/FormControl.js +1 -1
- package/form/FormGroup.js +1 -1
- package/lead-capture/FinishCoordinator.js +1 -1
- package/lead-capture/NavigationLeadCollector.d.ts +2 -1
- package/lead-capture/NavigationLeadCollector.js +1 -1
- package/package.json +1 -1
package/CompositionRoot.js
CHANGED
|
@@ -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";import ActivePathTracker from"./lead-capture/ActivePathTracker";import NavigationLeadCollector from"./lead-capture/NavigationLeadCollector";import FinishCoordinator from"./lead-capture/FinishCoordinator";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,s,a,m){var l;const d=new DocumentModelService(e),v=!o,f=v?new DefaultMediaQueryListener(d,t):new ClDocumentResizeListener(d,o),
|
|
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";import ActivePathTracker from"./lead-capture/ActivePathTracker";import NavigationLeadCollector from"./lead-capture/NavigationLeadCollector";import FinishCoordinator from"./lead-capture/FinishCoordinator";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,s,a,m){var l;const d=new DocumentModelService(e),v=!o,f=v?new DefaultMediaQueryListener(d,t):new ClDocumentResizeListener(d,o),y=new DefaultState,u=new ConfigService(t),p=new MobileDeviceOrientationListener(d,u),S=new CommonStylesService;S.setStyles(i);const g=new DefaultEventEmitter,w=new FormGroup(r),C=new SourceRegistry(w,t),D=new ContextData,F=new ContextSDK(C,D,v);new HiddenFieldsContextHydrator(F,d.getShared().hiddenFields).hydrate();const h=new ActivePathTracker(g,w,F,y),R=new SubmitStateService(w,g,d,h),L=new NavigationLeadCollector(g,d,w,F,u.getConfig("triggeredBy")),P=new FinishCoordinator(g,d,()=>this.services),x=new(null!==(l=t.actionFactoryClass)&&void 0!==l?l:ActionFactory)(g,w,u,r,y,F,()=>this.services),M=new ActionRegister(g,()=>this.services),k=new PrizePoolFactory(httpClient,u),b=new MergeTagsProcessorFactory(v,F,u),z=new WcFactory({state:y,eventEmitter:g,form:w,documentModel:d,resizeListener:f,config:u,commonStylesService:S,trackingService:r,layoutType:n,actionFactory:x,actionRegister:M,prizePoolFactory:k,context:F,mergeTagsProcessorFactory:b,mobileDeviceOrientationListener:p,componentRegister:s,htmlDocumentObject:a}),T=new WcViewRenderer(d,f,t,z,g),A=new DocumentService(d,T,c);this.services={documentService:A,documentModel:d,state:y,form:w,eventEmitter:g,config:u,resizeListener:f,mobileDeviceOrientationListener:p,componentFactory:z,viewRenderer:T,commonStylesService:S,tracking:r,actionFactory:x,actionRegister:M,submitState:R,prizePoolFactory:k,context:F,mergeTagsProcessorFactory:b,activePathTracker:h,navigationLeadCollector:L,finishCoordinator:P}}destroy(){Object.keys(this.services).filter(e=>"viewRenderer"!==e).forEach(e=>this.services[e]&&this.services[e].destroy&&this.services[e].destroy())}}
|
|
@@ -33,11 +33,10 @@ export default class BaseRequestAction {
|
|
|
33
33
|
formValue: any;
|
|
34
34
|
utmParams: any;
|
|
35
35
|
}): Record<string, any>;
|
|
36
|
-
constructRequestPayload({ contextValue, formValue, utmParams
|
|
36
|
+
constructRequestPayload({ contextValue, formValue, utmParams }: {
|
|
37
37
|
contextValue: any;
|
|
38
38
|
formValue: any;
|
|
39
39
|
utmParams: any;
|
|
40
|
-
triggeredBy: any;
|
|
41
40
|
}): import("../RequestPayloadBuilder").RequestPayloadI;
|
|
42
41
|
constructRequestHeaders(): Record<string, string>;
|
|
43
42
|
goToView(viewIndex: any, params: any): void;
|
|
@@ -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
|
|
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 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";export default class GoToPreviousViewAction{constructor(t,i,
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";export default class GoToPreviousViewAction{constructor(t,e,i,s){this.type=SysActionTypes.GO_TO_PREVIOUS_VIEW,this.eventEmitter=t,this.config=e,this.tracking=i,this.activePathTracker=s}execute(){var t,e;const i=null!==(e=null===(t=this.activePathTracker)||void 0===t?void 0:t.getActivePath())&&void 0!==e?e:[],s=i[i.length-2];return this.eventEmitter.emit(this.type,s),Promise.resolve(!0)}}
|
package/form/FormControl.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class FormControl extends DefaultEventEmitter {
|
|
|
31
31
|
isValid(): boolean;
|
|
32
32
|
isPending(): boolean;
|
|
33
33
|
validate(options?: SetValueOptionsI): Promise<boolean>;
|
|
34
|
+
adoptValidationState(previous: FormControl): void;
|
|
34
35
|
markAsTouched(): void;
|
|
35
36
|
isTouched(): boolean;
|
|
36
37
|
getErrorKeys(): string[];
|
package/form/FormControl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import FormControlValidator from"./FormControlValidator";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import FormControlEvents from"./FormControlEvents";import debounce from"@claspo/common/async/debounce";export class FormControl extends DefaultEventEmitter{constructor(e,t,i,n
|
|
1
|
+
import FormControlValidator from"./FormControlValidator";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import FormControlEvents from"./FormControlEvents";import debounce from"@claspo/common/async/debounce";export class FormControl extends DefaultEventEmitter{constructor(e,t,i,s,n){super(),this.componentId=e.componentId,this.viewIdx=Number.isInteger(e.viewIdx)?e.viewIdx:null,this.name=e.name,this.defaultValue=e.defaultValue,this.value=e.defaultValue?e.defaultValue:void 0,this.validator=new FormControlValidator(this,e.validation,i,s),this.errorKeys=this.validator.getSyncErrorKeys(this.getValue()),this.valid=!this.errorKeys.length,this.disabled=!1,this.pending=!1,this.debounceValue=e.hasOwnProperty("debounceValue")?e.debounceValue:300,this.tracking=n,this.touched=!1,this.valueChanged=!1,this.elementRef=null,this.debouncedValidate=()=>{},this._init(e,t)}inputElementValueChanged(e){this.tracking.send("FormStartFilling_[Name]"),this.setValue(e)}setDisabled(){this.disabled=!0,this.elementRef&&this.elementRef.setAttribute("disabled","disabled")}setEnabled(){this.disabled=!1,this.elementRef&&this.elementRef.removeAttribute("disabled")}setPending(e){this.pending=e}getName(){return this.name}getValue(){return this.value}getComponentId(){return this.componentId}setValue(e="",t={silent:!1,skipValidation:!1,skipElementUpdate:!1}){t.skipElementUpdate||(this.valueChanged=this.value!==e),this.value=e,this.elementRef&&!t.skipElementUpdate&&("checkbox"===this.elementRef.getAttribute("type")?this.elementRef.checked=!!e:this.elementRef.value=e),t.skipValidation?!t.silent&&this.valueChanged&&this.emit(FormControlEvents.valueChanged,e):(this.pending=!0,this.emit(FormControlEvents.validationStatusChanged,"pending"),this.debouncedValidate(t)),t.silent||t.skipValidation||this.elementRef||this.markAsTouched()}isValid(){return this.valid}isPending(){return this.pending}async validate(e={silent:!1}){this.pending=!0;const t=await this.validator.getErrorKeys(this.getValue());return this.valid=!t.length,this.errorKeys=t,this.pending=!1,e.silent||(this.emit(FormControlEvents.validationStatusChanged,this.valid?"valid":"invalid"),this.valueChanged&&(this.emit(FormControlEvents.valueChanged,this.getValue()),this.valueChanged=!1)),this.valid}adoptValidationState(e){e&&(this.touched=e.isTouched(),e.isPending()?this.validate():this.valid&&!e.isValid()&&(this.valid=!1,this.errorKeys=e.getErrorKeys()))}markAsTouched(){this.touched=!0,this.emit(FormControlEvents.touchedStatusChanged,null)}isTouched(){return this.touched}getErrorKeys(){return this.errorKeys}destroy(){super.destroy()}_init(e,t){const i=t?t.getAttribute("type"):null;if(t&&e.defaultValue&&("checkbox"===i?t.checked=e.defaultValue:t.value=e.defaultValue),t){const s=e.triggerEvent?e.triggerEvent:"input",n="checkbox"===i;t.addEventListener(s,e=>{const t=e.target;this.inputElementValueChanged(n?t.checked:t.value)}),t.addEventListener("blur",()=>{this.markAsTouched()}),this.elementRef=t}this.debouncedValidate=this.debounceValue?debounce(e=>this.validate(e),this.debounceValue):this.validate.bind(this)}}
|
package/form/FormGroup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FormControl}from"./FormControl";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import FormGroupEvents from"./FormGroupEvents";import FormControlEvents from"./FormControlEvents";export default class FormGroup extends DefaultEventEmitter{constructor(t){super(),this.controls={},this.tracking=t,this.submitQueuedAfterPending=!1,this.preventSubmit=!1}registerControl(t,e,o,r){const s=new FormControl(t,e,o,r,this.tracking);return this.controls[t.name]=s,s.on("*",(t,e)=>{if(e===FormControlEvents.valueChanged)this.emit(FormGroupEvents.valueChanged,s);else this.emit(e,t),e===FormControlEvents.validationStatusChanged&&this.emit(FormGroupEvents.validationChecked,this.isValid())}),this.emit(FormGroupEvents.controlRegistered,s),this.getControl(t.name)}updateControl(t,e,o,r){const s=this.getControl(t.name)
|
|
1
|
+
import{FormControl}from"./FormControl";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import FormGroupEvents from"./FormGroupEvents";import FormControlEvents from"./FormControlEvents";export default class FormGroup extends DefaultEventEmitter{constructor(t){super(),this.controls={},this.tracking=t,this.submitQueuedAfterPending=!1,this.preventSubmit=!1}registerControl(t,e,o,r){const s=new FormControl(t,e,o,r,this.tracking);return this.controls[t.name]=s,s.on("*",(t,e)=>{if(e===FormControlEvents.valueChanged)this.emit(FormGroupEvents.valueChanged,s);else this.emit(e,t),e===FormControlEvents.validationStatusChanged&&this.emit(FormGroupEvents.validationChecked,this.isValid())}),this.emit(FormGroupEvents.controlRegistered,s),this.getControl(t.name)}updateControl(t,e,o,r){const s=this.getControl(t.name),n=this.registerControl(Object.assign(Object.assign({},t),{defaultValue:s.getValue()||""}),e,o,r);return n.adoptValidationState(s),n}getControl(t){return this.controls[t]}hasControl(t){return!!this.getControl(t)}removeControl(t){const e=this.getControl(t);e&&(e.destroy(),delete this.controls[t])}setControlValue(t,e){this.controls[t].setValue(e)}setPreventSubmit(t){this.preventSubmit=t}destroy(){super.destroy()}isValid(){return Object.values(this.controls).every(t=>t.isValid())}waitForPendingValidationAndCheckIfValid(){return this.isPending()?new Promise(t=>{const e=this.on(FormGroupEvents.validationChecked,o=>{e.off(),t(o)})}):Promise.resolve(this.isValid())}isPending(){return!!Object.values(this.controls).filter(t=>t.isPending()).length}getControlsMap(){return Object.values(this.controls).reduce((t,e)=>Object.assign(Object.assign({},t),{[e.getName()]:e.getValue()}),{})}getControlsAsArray(){return Object.values(this.controls)}setDisabledAll(){this.getControlsAsArray().forEach(t=>t.setDisabled())}setEnabledAll(){this.getControlsAsArray().forEach(t=>t.setEnabled())}markAsTouched(){Object.values(this.controls).forEach(t=>t.markAsTouched())}isTouched(){return Object.values(this.controls).every(t=>t.isTouched())}}
|
|
@@ -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";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 s=this.getServices(),n=null==s?void 0:s.submitState;if(!n||this.finished||this.inFlight)return!1;if(n.hasSubmitAttemptSinceLastChange())return!1;if(t===FinishTrigger.CLOSE&&(n.getState()!==SubmitState.DIRTY||!n.hasDirtyFormData()))return!1;this.inFlight=!0;try{const t=await n.prepareAutoSubmitFormValue();if(this.finished||n.hasSubmitAttemptSinceLastChange())return!1;if(!t||!Object.values(t).length)return!1;this.finished=!0,null===(e=null==i?void 0:i.beforeExecute)||void 0===e||e.call(i,t);const r=(null===(o=s.actionRegister)||void 0===o?void 0:o.getRegisteredActions().find(t=>t.category===ActionCategory.SUBMIT))||s.actionFactory.get({type:SysActionTypes.REQUEST});return!1!==await r.execute(void 0,void 0,!0,{skipValidation:!0,skipNavigation:!0,excludeFormContext:!0,formValue:t})}catch(t){return console.error(t),!1}finally{this.inFlight=!1}}onNavigationEnd(t){isMultiViewFlow(this.graph)&&isAutoCommitTerminal(this.graph,t)&&this.attemptCommit(FinishTrigger.TERMINAL)}}
|
|
@@ -9,11 +9,12 @@ export default class NavigationLeadCollector {
|
|
|
9
9
|
private context;
|
|
10
10
|
private views;
|
|
11
11
|
private graph;
|
|
12
|
+
private triggeredBy;
|
|
12
13
|
private previousViewIndex;
|
|
13
14
|
private lastSentSignature;
|
|
14
15
|
private latestForwardNavigationData;
|
|
15
16
|
private subscriptions;
|
|
16
|
-
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, form: FormGroup, context: ContextSDK);
|
|
17
|
+
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, form: FormGroup, context: ContextSDK, triggeredBy: string);
|
|
17
18
|
destroy(): void;
|
|
18
19
|
getLatestNavigationData(): RequestNavigationDataI | null;
|
|
19
20
|
private onNavigationEnd;
|
|
@@ -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){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.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 i,e;const r=this.previousViewIndex;if(this.previousViewIndex=t,!isMultiViewFlow(this.graph))return;if(null===r||t<=r)return;if(this.latestForwardNavigationData={previousViewId:null===(i=this.views[r])||void 0===i?void 0:i.id,currentViewId:null===(e=this.views[t])||void 0===e?void 0:e.id},isAutoCommitTerminal(this.graph,t))return;const a=this.buildFormValue(),o=extractContextValue(this.context,!0);if(!Object.keys(a).length&&!Object.keys(o).length)return;const n=stableStringify({contextValue:o,formValue:a});if(n===this.lastSentSignature)return;const s=constructRequestPayload({contextValue:o,formValue:a,utmParams:UTMParamsExtractor.extractTrackingParams(this.context),referrer:window.location.href,triggeredBy:
|
|
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 i,e;const r=this.previousViewIndex;if(this.previousViewIndex=t,!isMultiViewFlow(this.graph))return;if(null===r||t<=r)return;if(this.latestForwardNavigationData={previousViewId:null===(i=this.views[r])||void 0===i?void 0:i.id,currentViewId:null===(e=this.views[t])||void 0===e?void 0:e.id},isAutoCommitTerminal(this.graph,t))return;const a=this.buildFormValue(),o=extractContextValue(this.context,!0);if(!Object.keys(a).length&&!Object.keys(o).length)return;const n=stableStringify({contextValue:o,formValue:a});if(n===this.lastSentSignature)return;const s=constructRequestPayload({contextValue:o,formValue:a,utmParams:UTMParamsExtractor.extractTrackingParams(this.context),referrer:window.location.href,triggeredBy:this.triggeredBy});s.ignoreTracking=!0,s.navigationData=this.latestForwardNavigationData,this.lastSentSignature=n,this.eventEmitter.emit(SysEventTypes.LEAD_PROGRESS,s)}buildFormValue(){return this.form.getControlsAsArray().reduce((t,i)=>{const e=i.getValue();return hasMeaningfulValue(e)&&i.isValid()&&(t[i.getName()]=e),t},{})}}
|