@claspo/renderer 18.7.9 → 18.8.0-nonlinear2
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/ViewRouter.d.ts +1 -2
- package/ViewRouter.js +1 -1
- package/action/ActionFactory.js +1 -1
- package/action/RequestPayloadBuilder.d.ts +39 -0
- package/action/RequestPayloadBuilder.js +1 -0
- package/action/actions/BaseRequestAction.d.ts +5 -8
- package/action/actions/BaseRequestAction.js +1 -1
- package/action/actions/GoToPreviousViewAction.d.ts +2 -1
- package/action/actions/GoToPreviousViewAction.js +1 -1
- package/action/actions/GoToViewAction.js +1 -1
- package/common/SysEventTypes.d.ts +2 -1
- package/common/SysEventTypes.js +1 -1
- package/document-model/DocumentModelService.d.ts +3 -0
- package/document-model/DocumentModelService.js +1 -1
- package/form/FormControl.js +1 -1
- package/lead-capture/ActivePathTracker.d.ts +20 -0
- package/lead-capture/ActivePathTracker.js +1 -0
- package/lead-capture/FinishCoordinator.d.ts +20 -0
- package/lead-capture/FinishCoordinator.js +1 -0
- package/lead-capture/NavigationLeadCollector.d.ts +21 -0
- package/lead-capture/NavigationLeadCollector.js +1 -0
- package/package.json +2 -2
- package/sdk/context/ContextSDK.d.ts +1 -1
- package/sdk/context/ContextSDK.js +1 -1
- package/sdk/source/sources/FormSource.d.ts +1 -0
- package/sdk/source/sources/FormSource.js +1 -1
- package/submit-state/SubmitStateService.d.ts +4 -2
- package/submit-state/SubmitStateService.js +1 -1
- package/document-model/systemResultStateNames.d.ts +0 -2
- package/document-model/systemResultStateNames.js +0 -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";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,s,m
|
|
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),u=new DefaultState,y=new ConfigService(t),p=new MobileDeviceOrientationListener(d,y),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,u),R=new SubmitStateService(w,g,d,h),L=new NavigationLeadCollector(g,d,w,F),P=new FinishCoordinator(g,d,()=>this.services),x=new(null!==(l=t.actionFactoryClass)&&void 0!==l?l:ActionFactory)(g,w,y,r,u,F,()=>this.services),M=new ActionRegister(g,()=>this.services),k=new PrizePoolFactory(httpClient,y),b=new MergeTagsProcessorFactory(v,F,y),z=new WcFactory({state:u,eventEmitter:g,form:w,documentModel:d,resizeListener:f,config:y,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:u,form:w,eventEmitter:g,config:y,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())}}
|
package/ViewRouter.d.ts
CHANGED
|
@@ -13,9 +13,8 @@ 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?: {}): void;
|
|
17
17
|
viewDestroy(): void;
|
|
18
18
|
getDocumentContainer(): any;
|
|
19
19
|
getLastTransition(): any;
|
|
20
|
-
_previousViewDestroyedCb(): void;
|
|
21
20
|
}
|
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";
|
|
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,s){super(),this.eventEmitter=t,this.documentModel=e,this.viewRenderer=n,this.optionalDocumentStyles=i,this.services=s,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):this.navigate(t)}),this.eventEmitter.on(SysActionTypes.GO_TO_NEXT_VIEW,()=>{this.documentModel.getModel().views[this.getCurrentViewIndex()+1]&&this.navigate(this.getCurrentViewIndex()+1)}),this.documentContainer}destroy(){this.viewDestroy(),this.documentContainer&&this.documentContainer.remove()}navigate(t,e={}){var n;let i=this.documentModel.getView(t);const s=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 r=this.viewRenderer.render(i,t);this.viewDestroy(),this.documentContainer.appendChild(r),this.currentViewComponentRef=r,this.currentViewIndex=t,this.transitions.push({prevViewIndex:s,currentViewIndex:t,currentViewComponentRef:r,contactDataSubmitted:null===(n=this.services.submitState)||void 0===n?void 0:n.hasSubmitAttemptSinceLastChange(),routeState:e}),this.eventEmitter.emit(SysRouterEvent.NAVIGATION_END,t)}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,c){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=s,this.getServices=c}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);case SysActionTypes.GO_TO_PREVIOUS_VIEW:return new GoToPreviousViewAction(this.eventEmitter,t,this.tracking);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
|
+
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,c){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=s,this.getServices=c}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);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}`)}}}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface RequestNavigationDataI {
|
|
2
|
+
previousViewId: string;
|
|
3
|
+
currentViewId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RequestPayloadPartsI {
|
|
6
|
+
contextValue: Record<string, any>;
|
|
7
|
+
formValue: Record<string, any>;
|
|
8
|
+
utmParams: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export interface RequestPayloadEnvI {
|
|
11
|
+
referrer: string;
|
|
12
|
+
triggeredBy: string;
|
|
13
|
+
widgetDebugMode?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RequestPayloadI {
|
|
16
|
+
data: Record<string, any>;
|
|
17
|
+
referrer: string;
|
|
18
|
+
triggeredBy: string;
|
|
19
|
+
ignoreTracking?: boolean;
|
|
20
|
+
navigationData?: RequestNavigationDataI;
|
|
21
|
+
}
|
|
22
|
+
export declare function constructDataToSent({ contextValue, formValue, utmParams }: RequestPayloadPartsI): Record<string, any>;
|
|
23
|
+
export declare function constructRequestPayload({ contextValue, formValue, utmParams, referrer, triggeredBy, widgetDebugMode }: RequestPayloadPartsI & RequestPayloadEnvI): RequestPayloadI;
|
|
24
|
+
export declare function constructRequestHeaders({ clCustomerId }: {
|
|
25
|
+
clCustomerId?: string;
|
|
26
|
+
}): Record<string, string>;
|
|
27
|
+
interface ContextRecordValueLikeI {
|
|
28
|
+
id: string;
|
|
29
|
+
value: any;
|
|
30
|
+
sourceId?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ContextValueReaderI {
|
|
33
|
+
getKVMap(): Record<string, any>;
|
|
34
|
+
getRecordsMap(): Record<string, {
|
|
35
|
+
getValue(): ContextRecordValueLikeI | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export declare function extractContextValue(context: ContextValueReaderI, excludeFormContext?: boolean): Record<string, any>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import isDictionary from"@claspo/common/object/isDictionary";import FormSource from"../sdk/source/sources/FormSource";export function constructDataToSent({contextValue:e,formValue:t,utmParams:r}){const o=Object.assign({},e);return o.tracking=r,Object.keys(t).forEach(e=>{if(e.startsWith("clConsentId")){if(e.endsWith("_label"))return;const r={value:t[e]};t[`${e}_label`]&&(r.text=t[`${e}_label`]),o.consents?o.consents[e]=r:o.consents={[e]:r}}else{const r=t[e];o[e]=isDictionary(r)||Array.isArray(r)?JSON.stringify(r):r}}),o}export function constructRequestPayload({contextValue:e,formValue:t,utmParams:r,referrer:o,triggeredBy:c,widgetDebugMode:n}){const s={data:constructDataToSent({contextValue:e,formValue:t,utmParams:r}),referrer:o,triggeredBy:c};return n&&(s.ignoreTracking=!0),s}export function constructRequestHeaders({clCustomerId:e}){const t={};return e&&Object.assign(t,{"cl-customer-id":e}),t}export function extractContextValue(e,t){if(!t)return e.getKVMap();const r=e.getRecordsMap();return Object.values(r).reduce((e,t)=>{var r;const o=null===(r=null==t?void 0:t.getValue)||void 0===r?void 0:r.call(t);return o&&o.sourceId!==FormSource.sourceId?(e[o.id]=o.value,e):e},{})}
|
|
@@ -27,22 +27,19 @@ export default class BaseRequestAction {
|
|
|
27
27
|
getTrackingMessageByStatus(_: any): string;
|
|
28
28
|
execute(_state: any, _event: any, force: any, overrideParams: any): Promise<unknown>;
|
|
29
29
|
submit(resolve: any, force: any, overrideParams: any): void;
|
|
30
|
-
getContextValue(nextParams: any): any
|
|
30
|
+
getContextValue(nextParams: any): Record<string, any>;
|
|
31
31
|
constructDataToSent({ contextValue, formValue, utmParams }: {
|
|
32
32
|
contextValue: any;
|
|
33
33
|
formValue: any;
|
|
34
34
|
utmParams: any;
|
|
35
|
-
}): any
|
|
36
|
-
constructRequestPayload({ contextValue, formValue, utmParams }: {
|
|
35
|
+
}): Record<string, any>;
|
|
36
|
+
constructRequestPayload({ contextValue, formValue, utmParams, triggeredBy }: {
|
|
37
37
|
contextValue: any;
|
|
38
38
|
formValue: any;
|
|
39
39
|
utmParams: any;
|
|
40
|
-
}): {
|
|
41
|
-
data: any;
|
|
42
|
-
referrer: string;
|
|
43
40
|
triggeredBy: any;
|
|
44
|
-
};
|
|
45
|
-
constructRequestHeaders():
|
|
41
|
+
}): import("../RequestPayloadBuilder").RequestPayloadI;
|
|
42
|
+
constructRequestHeaders(): Record<string, string>;
|
|
46
43
|
goToView(viewIndex: any, params: any): void;
|
|
47
44
|
sendRequest(requestPayload: any): any;
|
|
48
45
|
private getSuccessViewIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import
|
|
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 g=this.getServices().documentModel.getViews()[r];if(!u.skipNavigation&&m&&getComponentCountOnView(g,"SysNetPromoterScoreComponent")+getComponentCountOnView(g,"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(),h=this.getContextValue(u);if(!u.skipNavigation&&c&&(viewHasControls(E)||!Object.keys(l).length&&!Object.keys(h).length))return this.goToView(r+1,u),void t(!0);if(!Object.keys(l).length&&!Object.keys(h).length)return void t(!0);const T=UTMParamsExtractor.extractTrackingParams(this.context),v=this.constructRequestPayload({contextValue:h,formValue:l,utmParams:T,triggeredBy:u.triggeredBy}),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,triggeredBy:s}){return constructRequestPayload({contextValue:t,formValue:e,utmParams:i,referrer:window.location.href,triggeredBy:null!=s?s: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)}}
|
|
@@ -3,7 +3,8 @@ export default class GoToPreviousViewAction {
|
|
|
3
3
|
eventEmitter: any;
|
|
4
4
|
config: any;
|
|
5
5
|
tracking: any;
|
|
6
|
+
activePathTracker: any;
|
|
6
7
|
type: SysActionTypes;
|
|
7
|
-
constructor(eventEmitter: any, config: any, tracking: any);
|
|
8
|
+
constructor(eventEmitter: any, config: any, tracking: any, activePathTracker: any);
|
|
8
9
|
execute(): Promise<boolean>;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";export default class GoToPreviousViewAction{constructor(t,e,
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";export default class GoToPreviousViewAction{constructor(t,i,e,o){this.type=SysActionTypes.GO_TO_PREVIOUS_VIEW,this.eventEmitter=t,this.config=i,this.tracking=e,this.activePathTracker=o}execute(){var t,i,e,o;let s;if(null===(i=null===(t=this.config)||void 0===t?void 0:t.params)||void 0===i?void 0:i.useNavigationHistory){const t=null!==(o=null===(e=this.activePathTracker)||void 0===e?void 0:e.getActivePath())&&void 0!==o?o:[];s=t[t.length-2]}return this.eventEmitter.emit(this.type,s),Promise.resolve(!0)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";export default class GoToViewAction{constructor(t,
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";export default class GoToViewAction{constructor(i,t,e,s,a,n,r){this.type=SysActionTypes.GO_TO_VIEW,this.eventEmitter=i,this.config=t,this.form=s,this.viewRouter=a,this.documentModel=n,this.tracking=r}async execute(){var i;this.form.markAsTouched();let t=!1;const e=this.viewRouter.getCurrentViewIndex();if(this.config.params.viewId){t=e<this.documentModel.getViews().findIndex(i=>i.id===this.config.params.viewId)}else t=e<this.config.params.viewIndex;if(t&&(null===(i=this.config.params.validateForm)||void 0===i||i)){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),this.config.params.trackClick&&this.tracking.trackClick({params:this.config.params.trackClickParams,countAsTargetAction:this.config.params.countAsTargetAction}),!0}}
|
|
@@ -5,6 +5,7 @@ declare enum SysEventTypes {
|
|
|
5
5
|
SUBMIT_REQUEST_STARTED = "SUBMIT_REQUEST_STARTED",
|
|
6
6
|
SUBMIT_REQUEST_FINISHED = "SUBMIT_REQUEST_FINISHED",
|
|
7
7
|
SUBMIT_REQUEST_ERROR_WITHOUT_VIEW = "SUBMIT_REQUEST_ERROR_WITHOUT_VIEW",
|
|
8
|
-
PROMO_CODE_SHOWN = "PROMO_CODE_SHOWN"
|
|
8
|
+
PROMO_CODE_SHOWN = "PROMO_CODE_SHOWN",
|
|
9
|
+
LEAD_PROGRESS = "LEAD_PROGRESS"
|
|
9
10
|
}
|
|
10
11
|
export default SysEventTypes;
|
package/common/SysEventTypes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var SysEventTypes;!function(E){E.TOO_MANY_REQUESTS="TOO_MANY_REQUESTS",E.COMPONENT_RESOURCES_LOADED="COMPONENT_RESOURCES_LOADED",E.FAILED_TO_LOAD_COMPONENT_RESOURCE="FAILED_TO_LOAD_COMPONENT_RESOURCE",E.SUBMIT_REQUEST_STARTED="SUBMIT_REQUEST_STARTED",E.SUBMIT_REQUEST_FINISHED="SUBMIT_REQUEST_FINISHED",E.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW="SUBMIT_REQUEST_ERROR_WITHOUT_VIEW",E.PROMO_CODE_SHOWN="PROMO_CODE_SHOWN"}(SysEventTypes||(SysEventTypes={}));export default SysEventTypes;
|
|
1
|
+
var SysEventTypes;!function(E){E.TOO_MANY_REQUESTS="TOO_MANY_REQUESTS",E.COMPONENT_RESOURCES_LOADED="COMPONENT_RESOURCES_LOADED",E.FAILED_TO_LOAD_COMPONENT_RESOURCE="FAILED_TO_LOAD_COMPONENT_RESOURCE",E.SUBMIT_REQUEST_STARTED="SUBMIT_REQUEST_STARTED",E.SUBMIT_REQUEST_FINISHED="SUBMIT_REQUEST_FINISHED",E.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW="SUBMIT_REQUEST_ERROR_WITHOUT_VIEW",E.PROMO_CODE_SHOWN="PROMO_CODE_SHOWN",E.LEAD_PROGRESS="LEAD_PROGRESS"}(SysEventTypes||(SysEventTypes={}));export default SysEventTypes;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import DefaultEventEmitter from "@claspo/common/DefaultEventEmitter";
|
|
2
2
|
import { ClBaseComponentI, ClDocumentI, ClDocumentSharedI } from '@claspo/common/document/Document.interface';
|
|
3
|
+
import { ViewNavGraphI } from '@claspo/common/document/ViewNavigationGraph';
|
|
3
4
|
export declare const EditorToWidgetEventType: {
|
|
4
5
|
COMPONENT_INSERT: string;
|
|
5
6
|
COMPONENT_REMOVE: string;
|
|
@@ -23,12 +24,14 @@ export declare const EditorToWidgetEventType: {
|
|
|
23
24
|
export default class DocumentModelService extends DefaultEventEmitter {
|
|
24
25
|
json: ClDocumentI;
|
|
25
26
|
flatJson: ClDocumentI;
|
|
27
|
+
private navigationGraph;
|
|
26
28
|
constructor(json: any);
|
|
27
29
|
setComponentRef(targetComponentId: string, componentRef: any): void;
|
|
28
30
|
getModel(): ClDocumentI;
|
|
29
31
|
getView(index: number): ClBaseComponentI;
|
|
30
32
|
getViews(): ClBaseComponentI[];
|
|
31
33
|
getShared(): ClDocumentSharedI;
|
|
34
|
+
getNavigationGraph(): ViewNavGraphI;
|
|
32
35
|
iterateViewModelAndExecute(viewIndex: number, callback: (node: ClBaseComponentI) => void): void;
|
|
33
36
|
destroy(): void;
|
|
34
37
|
destroyView(viewIndex: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import ModulesComponentExtractor from"./ModulesComponentExtractor";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentUtils from"@claspo/common/document/DocumentUtils";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(
|
|
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(){return this.navigationGraph||(this.navigationGraph=buildViewNavigationGraph(this.getViews(),this.getShared())),this.navigationGraph}iterateViewModelAndExecute(t,e){const E=this.getView(t);DocumentUtils.iterateDepthFirst(E,e)}destroy(){}destroyView(t){console.warn("destroyView now should do nothing"),this.iterateViewModelAndExecute(t,t=>{t.componentRef&&(t.componentRef.remove(),t.componentRef=null)})}}
|
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,s){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,n),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=s,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&&(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}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 n=e.triggerEvent?e.triggerEvent:"input",s="checkbox"===i;t.addEventListener(n,e=>{const t=e.target;this.inputElementValueChanged(s?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)}}
|
|
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,s){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,n),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=s,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}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 n=e.triggerEvent?e.triggerEvent:"input",s="checkbox"===i;t.addEventListener(n,e=>{const t=e.target;this.inputElementValueChanged(s?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)}}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
|
|
2
|
+
import FormGroup from '../form/FormGroup';
|
|
3
|
+
import ContextSDK from '../sdk/context/ContextSDK';
|
|
4
|
+
import DefaultState from '../common/DefaultState';
|
|
5
|
+
export default class ActivePathTracker {
|
|
6
|
+
private form;
|
|
7
|
+
private context;
|
|
8
|
+
private state;
|
|
9
|
+
private activePath;
|
|
10
|
+
private pendingTail;
|
|
11
|
+
private stashedValues;
|
|
12
|
+
private subscriptions;
|
|
13
|
+
constructor(eventEmitter: DefaultEventEmitter, form: FormGroup, context: ContextSDK, state: DefaultState);
|
|
14
|
+
getActivePath(): number[];
|
|
15
|
+
destroy(): void;
|
|
16
|
+
private onNavigationEnd;
|
|
17
|
+
private stashTailControls;
|
|
18
|
+
private reseedStashedValue;
|
|
19
|
+
private pruneAbandonedTail;
|
|
20
|
+
}
|
|
@@ -0,0 +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&&t.viewIdx===e.viewIdx&&(this.stashedValues.delete(e.getName()),e.setValue(t.value))}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 o=null===(s=t[i])||void 0===s?void 0:s.getValue();o&&o.sourceId===FormSource.sourceId&&void 0!==o.viewIndex&&e.includes(o.viewIndex)&&this.context.deleteRecord(i,!0)}),this.state.setState({conditionalRedirectViewId:null})}}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
|
|
2
|
+
import DocumentModelService from '../document-model/DocumentModelService';
|
|
3
|
+
export declare enum FinishTrigger {
|
|
4
|
+
TERMINAL = "terminal",
|
|
5
|
+
CLOSE = "close"
|
|
6
|
+
}
|
|
7
|
+
export interface FinishCommitOptionsI {
|
|
8
|
+
beforeExecute?(formValue: Record<string, any>): void;
|
|
9
|
+
}
|
|
10
|
+
export default class FinishCoordinator {
|
|
11
|
+
private getServices;
|
|
12
|
+
private graph;
|
|
13
|
+
private finished;
|
|
14
|
+
private inFlight;
|
|
15
|
+
private subscriptions;
|
|
16
|
+
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, getServices: () => any);
|
|
17
|
+
destroy(): void;
|
|
18
|
+
attemptCommit(trigger: FinishTrigger, options?: FinishCommitOptionsI): Promise<boolean>;
|
|
19
|
+
private onNavigationEnd;
|
|
20
|
+
}
|
|
@@ -0,0 +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 r=this.getServices(),s=null==r?void 0:r.submitState;if(!s||this.finished||this.inFlight)return!1;if(s.hasSubmitAttemptSinceLastChange())return!1;if(t===FinishTrigger.CLOSE&&(s.getState()!==SubmitState.DIRTY||!s.hasDirtyFormData()))return!1;this.inFlight=!0;try{const n=await s.prepareAutoSubmitFormValue();if(this.finished||s.hasSubmitAttemptSinceLastChange())return!1;if(!n||!Object.values(n).length)return!1;this.finished=!0,null===(e=null==i?void 0:i.beforeExecute)||void 0===e||e.call(i,n);const a=(null===(o=r.actionRegister)||void 0===o?void 0:o.getRegisteredActions().find(t=>t.category===ActionCategory.SUBMIT))||r.actionFactory.get({type:SysActionTypes.REQUEST});return!1!==await a.execute(void 0,void 0,!0,{skipValidation:!0,skipNavigation:!0,excludeFormContext:!0,formValue:n,triggeredBy:t===FinishTrigger.CLOSE?"autosubmit":"terminal"})}catch(t){return console.error(t),!1}finally{this.inFlight=!1}}onNavigationEnd(t){isMultiViewFlow(this.graph)&&isAutoCommitTerminal(this.graph,t)&&this.attemptCommit(FinishTrigger.TERMINAL)}}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RequestNavigationDataI } from '../action/RequestPayloadBuilder';
|
|
2
|
+
import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
|
|
3
|
+
import FormGroup from '../form/FormGroup';
|
|
4
|
+
import ContextSDK from '../sdk/context/ContextSDK';
|
|
5
|
+
import DocumentModelService from '../document-model/DocumentModelService';
|
|
6
|
+
export default class NavigationLeadCollector {
|
|
7
|
+
private eventEmitter;
|
|
8
|
+
private form;
|
|
9
|
+
private context;
|
|
10
|
+
private views;
|
|
11
|
+
private graph;
|
|
12
|
+
private previousViewIndex;
|
|
13
|
+
private lastSentSignature;
|
|
14
|
+
private latestForwardNavigationData;
|
|
15
|
+
private subscriptions;
|
|
16
|
+
constructor(eventEmitter: DefaultEventEmitter, documentModel: DocumentModelService, form: FormGroup, context: ContextSDK);
|
|
17
|
+
destroy(): void;
|
|
18
|
+
getLatestNavigationData(): RequestNavigationDataI | null;
|
|
19
|
+
private onNavigationEnd;
|
|
20
|
+
private buildFormValue;
|
|
21
|
+
}
|
|
@@ -0,0 +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:"progress"});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},{})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/renderer",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.8.0-nonlinear2",
|
|
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.
|
|
18
|
+
"@claspo/common": "7.4.0-nonlinear2",
|
|
19
19
|
"@testing-library/dom": "^10.4.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -19,7 +19,7 @@ export default class ContextSDK extends DefaultEventEmitter {
|
|
|
19
19
|
getRegistry(): SourceRegistry;
|
|
20
20
|
addRecord: (key: string, params: ContextRecordValueI) => void;
|
|
21
21
|
updateRecord: (key: string, params: Partial<ContextRecordValueI>, eventParams?: ContextRecordUpdatedParamsI | null) => void;
|
|
22
|
-
deleteRecord(key: string): void;
|
|
22
|
+
deleteRecord(key: string, force?: boolean): void;
|
|
23
23
|
getRecord: (key: string) => Record | undefined;
|
|
24
24
|
getRecordsMap(): {
|
|
25
25
|
[key: string]: Record;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(e,t,s){super(),this.subscribedSourceIds=new Set,this.addRecord=(e,t)=>{const s=this.data.addRecord(e,t);this.subscribeToSource(t),this.emit(ContextEvents.RECORD_ADDED,s)},this.updateRecord=(e,t,s=null)=>{const r=this.data.getRecord(e);(null==r?void 0:r.update(t))&&this.emit(ContextEvents.RECORD_UPDATED,r.getValue(),s)},this.getRecord=e=>this.data.getRecord(e),this.sourceRegistry=e,this.data=t,this.isStaticMode=s,this.initSources()}getRegistry(){return this.sourceRegistry}deleteRecord(e){const
|
|
1
|
+
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(e,t,s){super(),this.subscribedSourceIds=new Set,this.addRecord=(e,t)=>{const s=this.data.addRecord(e,t);this.subscribeToSource(t),this.emit(ContextEvents.RECORD_ADDED,s)},this.updateRecord=(e,t,s=null)=>{const r=this.data.getRecord(e);(null==r?void 0:r.update(t))&&this.emit(ContextEvents.RECORD_UPDATED,r.getValue(),s)},this.getRecord=e=>this.data.getRecord(e),this.sourceRegistry=e,this.data=t,this.isStaticMode=s,this.initSources()}getRegistry(){return this.sourceRegistry}deleteRecord(e,t=!1){const s=this.data.getRecord(e);!s||this.isStaticMode&&!t||(this.data.deleteRecord(e),this.emit(ContextEvents.RECORD_DELETED,s))}getRecordsMap(){return this.data.getRecordsMap()}getKVMap(){return this.data.getKVMap()}initSources(){this.sourceRegistry.registerInitialSources(),this.sourceRegistry.getSources().forEach(e=>{const t=e.getValue();!this.isStaticMode&&t&&Object.keys(t).length&&Object.entries(t).forEach(([e,t])=>{this.addRecord(e,t)})})}subscribeToSource(e){const t=this.sourceRegistry.getSource(e.sourceId);t&&!this.subscribedSourceIds.has(t.id)&&(this.subscribedSourceIds.add(t.id),t.subscribe(({key:e,value:s,componentId:r})=>{const o={sourceId:t.id,key:e,value:s,componentId:r};this.getAffectedRecordKeys(t.id,e,r).forEach(e=>{const r=this.data.getRecord(e);if(!r)return;const c=this.resolveRecordValueFromSource(r.getValue(),t,s);this.updateRecord(e,{value:c},o)})}))}getAffectedRecordKeys(e,t,s){const r=s||t,o=new Set;return this.data.getRecord(r)&&o.add(r),Object.entries(this.data.getRecordsMap()).forEach(([s,r])=>{const c=r.getValue();c.sourceId===e&&c.sourceDependencyKey&&this.arePathsOverlapping(c.sourceDependencyKey,t)&&o.add(s)}),Array.from(o)}resolveRecordValueFromSource(e,t,s){var r;if(!e.sourceModel)return s;const o=t.getValue(e.sourceDependencyKey||e.id);return o&&"function"==typeof o.processor?o.processor(t,e.sourceModel):null!==(r=null==o?void 0:o.value)&&void 0!==r?r:e.value}arePathsOverlapping(e,t){return e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`)}}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SourceUpdateDataI } from '../../context/ContextSDK';
|
|
2
2
|
import FormGroup from '../../../form/FormGroup';
|
|
3
3
|
export default class FormSource {
|
|
4
|
+
static sourceId: string;
|
|
4
5
|
formService: FormGroup;
|
|
5
6
|
constructor(formService: FormGroup);
|
|
6
7
|
subscribe(cb: (data: SourceUpdateDataI) => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import FormGroupEvents from"../../../form/FormGroupEvents";
|
|
1
|
+
import FormGroupEvents from"../../../form/FormGroupEvents";class FormSource{constructor(e){this.formService=e}subscribe(e){this.formService.on(FormGroupEvents.valueChanged,o=>{e({key:o.getName(),value:o.getValue(),componentId:o.getComponentId()})}),this.formService.on(FormGroupEvents.controlRegistered,o=>{e({key:o.getName(),value:o.getValue()})})}getValue(e){var o;return e?null===(o=this.formService.getControl(e))||void 0===o?void 0:o.getValue():this.formService.getControlsMap()}}FormSource.sourceId="FORM";export default FormSource;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
|
|
2
2
|
import FormGroup from '../form/FormGroup';
|
|
3
3
|
import DocumentModelService from '../document-model/DocumentModelService';
|
|
4
|
+
import type ActivePathTracker from '../lead-capture/ActivePathTracker';
|
|
5
|
+
export declare function hasMeaningfulValue(value: any): boolean;
|
|
4
6
|
export declare const SubmitState: {
|
|
5
7
|
readonly IDLE: "idle";
|
|
6
8
|
readonly DIRTY: "dirty";
|
|
@@ -13,12 +15,13 @@ export default class SubmitStateService {
|
|
|
13
15
|
form: FormGroup;
|
|
14
16
|
eventEmitter: DefaultEventEmitter;
|
|
15
17
|
documentModel?: DocumentModelService;
|
|
18
|
+
activePathTracker?: ActivePathTracker;
|
|
16
19
|
state: SubmitStateValue;
|
|
17
20
|
currentSubmission: Promise<boolean> | null;
|
|
18
21
|
subscriptions: Array<{
|
|
19
22
|
off: () => void;
|
|
20
23
|
}>;
|
|
21
|
-
constructor(form: FormGroup, eventEmitter: DefaultEventEmitter, documentModel?: DocumentModelService);
|
|
24
|
+
constructor(form: FormGroup, eventEmitter: DefaultEventEmitter, documentModel?: DocumentModelService, activePathTracker?: ActivePathTracker);
|
|
22
25
|
getState(): SubmitStateValue;
|
|
23
26
|
hasDirtyFormData(): boolean;
|
|
24
27
|
hasSubmitAttemptSinceLastChange(): boolean;
|
|
@@ -26,7 +29,6 @@ export default class SubmitStateService {
|
|
|
26
29
|
waitForCurrentSubmission(): Promise<boolean>;
|
|
27
30
|
getRequiredControlNames(): string[];
|
|
28
31
|
hasComponentWithName(componentNames: string[]): boolean;
|
|
29
|
-
hasNpsOrFeedbackComponent(): boolean;
|
|
30
32
|
allRequiredControlsAreValid(): Promise<boolean>;
|
|
31
33
|
prepareAutoSubmitFormValue(): Promise<Record<string, any>>;
|
|
32
34
|
destroy(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import FormGroupEvents from"../form/FormGroupEvents";import SysEventTypes from"../common/SysEventTypes";import DocumentUtils from"@claspo/common/document/DocumentUtils";function hasMeaningfulValue(t){return null!=t&&("string"==typeof t?""!==t.trim():Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0)}export const SubmitState={IDLE:"idle",DIRTY:"dirty",SUBMITTING:"submitting",SUBMITTED:"submitted",FAILED:"failed"};export default class SubmitStateService{constructor(t,e,i){this.form=t,this.eventEmitter=e,this.documentModel=i,this.state=SubmitState.IDLE,this.currentSubmission=null,this.subscriptions=[this.form.on(FormGroupEvents.valueChanged,()=>{this.state=SubmitState.DIRTY}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.state=SubmitState.SUBMITTING}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{this.currentSubmission=null,this.state=(null==t?void 0:t.success)?SubmitState.SUBMITTED:SubmitState.FAILED})]}getState(){return this.state}hasDirtyFormData(){return this.form.getControlsAsArray().some(t=>t.isTouched())}hasSubmitAttemptSinceLastChange(){return[SubmitState.SUBMITTING,SubmitState.SUBMITTED,SubmitState.FAILED].includes(this.state)}trackSubmission(t){this.currentSubmission=t}waitForCurrentSubmission(){return this.currentSubmission||Promise.resolve(!1)}getRequiredControlNames(){var t;const
|
|
1
|
+
import FormGroupEvents from"../form/FormGroupEvents";import SysEventTypes from"../common/SysEventTypes";import DocumentUtils from"@claspo/common/document/DocumentUtils";export function hasMeaningfulValue(t){return null!=t&&("string"==typeof t?""!==t.trim():Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0)}export const SubmitState={IDLE:"idle",DIRTY:"dirty",SUBMITTING:"submitting",SUBMITTED:"submitted",FAILED:"failed"};export default class SubmitStateService{constructor(t,e,i,s){this.form=t,this.eventEmitter=e,this.documentModel=i,this.activePathTracker=s,this.state=SubmitState.IDLE,this.currentSubmission=null,this.subscriptions=[this.form.on(FormGroupEvents.valueChanged,()=>{this.state=SubmitState.DIRTY}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.state=SubmitState.SUBMITTING}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{this.currentSubmission=null,this.state=(null==t?void 0:t.success)?SubmitState.SUBMITTED:SubmitState.FAILED})]}getState(){return this.state}hasDirtyFormData(){return this.form.getControlsAsArray().some(t=>t.isTouched())}hasSubmitAttemptSinceLastChange(){return[SubmitState.SUBMITTING,SubmitState.SUBMITTED,SubmitState.FAILED].includes(this.state)}trackSubmission(t){this.currentSubmission=t}waitForCurrentSubmission(){return this.currentSubmission||Promise.resolve(!1)}getRequiredControlNames(){var t,e,i;const s=new Set,r=null!==(e=null===(t=this.activePathTracker)||void 0===t?void 0:t.getActivePath())&&void 0!==e?e:[];return null===(i=this.documentModel)||void 0===i||i.getViews().forEach((t,e)=>{r.length&&!r.includes(e)||DocumentUtils.iterateDepthFirst(t,t=>{var e,i,r,n,o;const a=null===(i=null===(e=t.props)||void 0===e?void 0:e.control)||void 0===i?void 0:i.name;a&&(null===(o=null===(n=null===(r=t.props)||void 0===r?void 0:r.control)||void 0===n?void 0:n.validation)||void 0===o?void 0:o.required)&&s.add(a)})}),[...s]}hasComponentWithName(t){var e;let i=!1;return null===(e=this.documentModel)||void 0===e||e.getViews().forEach(e=>{DocumentUtils.iterateDepthFirst(e,e=>{t.includes(e.name)&&(i=!0)})}),i}async allRequiredControlsAreValid(){const t=this.getRequiredControlNames();if(!t.length)return!0;const e=this.form.getControlsMap(),i=t.map(t=>this.form.getControl(t));if(t.some(t=>!hasMeaningfulValue(e[t])))return!1;return(await Promise.all(i.map(t=>t.validate({silent:!0})))).every(Boolean)}async prepareAutoSubmitFormValue(){const t=this.form.getControlsAsArray(),e=t.find(t=>t.getName().includes("clConsentId")&&!t.getName().includes("label"));if(e){if(!e.isValid())return{}}else if(this.hasComponentWithName(["SysConsentComponent"]))return{};if(!await this.allRequiredControlsAreValid())return{};const i=t.filter(t=>hasMeaningfulValue(t.getValue()));return(await Promise.all(i.map(async t=>({control:t,isValid:await t.validate({silent:!0})})))).reduce((t,{control:e,isValid:i})=>{const s=e.getValue();return i&&hasMeaningfulValue(s)?(t[e.getName()]=s,t):t},{})}destroy(){this.subscriptions.forEach(t=>t.off()),this.subscriptions=[],this.currentSubmission=null}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const systemResultStateNames=["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUBSCRIBED","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","DOCUMENT_VIEW_TYPE_ERROR","REQUEST_FORM_VIEW_TYPE_SUCCESS"];export default systemResultStateNames;
|