@claspo/common 7.3.1-dev.3 → 7.4.0-nonlinear
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.
|
@@ -108,6 +108,7 @@ export interface ClDocumentGoToViewActionParamsI {
|
|
|
108
108
|
[key: string]: string;
|
|
109
109
|
};
|
|
110
110
|
countAsTargetAction?: boolean;
|
|
111
|
+
validateForm?: boolean;
|
|
111
112
|
}
|
|
112
113
|
export interface ClDocumentGoToNextViewActionParamsI {
|
|
113
114
|
trackClick?: boolean;
|
|
@@ -121,6 +122,7 @@ export interface ClDocumentGoToPreviousViewActionParamsI {
|
|
|
121
122
|
[key: string]: string;
|
|
122
123
|
};
|
|
123
124
|
countAsTargetAction?: boolean;
|
|
125
|
+
useNavigationHistory?: boolean;
|
|
124
126
|
}
|
|
125
127
|
export interface ClDocumentCloseWidgetActionParamsI {
|
|
126
128
|
trackClickParams?: {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ClBaseComponentI, ClDocumentSharedI, ClSubmitActionParamsI } from './Document.interface';
|
|
2
|
+
export declare enum ViewNavEdgeKind {
|
|
3
|
+
GO_TO_VIEW = "GO_TO_VIEW",
|
|
4
|
+
GO_TO_NEXT_VIEW = "GO_TO_NEXT_VIEW",
|
|
5
|
+
GO_TO_PREVIOUS_VIEW = "GO_TO_PREVIOUS_VIEW",
|
|
6
|
+
SUBMIT = "SUBMIT",
|
|
7
|
+
NPS_CONDITIONAL = "NPS_CONDITIONAL"
|
|
8
|
+
}
|
|
9
|
+
export declare enum ViewTerminalKind {
|
|
10
|
+
TRUE_TERMINAL = "TRUE_TERMINAL",
|
|
11
|
+
INTERMEDIATE = "INTERMEDIATE"
|
|
12
|
+
}
|
|
13
|
+
export interface ViewNavNodeI {
|
|
14
|
+
index: number;
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
hasSubmitAction: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ViewNavEdgeI {
|
|
20
|
+
fromIndex: number;
|
|
21
|
+
toIndex: number;
|
|
22
|
+
kind: ViewNavEdgeKind;
|
|
23
|
+
isForward: boolean;
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ViewNavGraphI {
|
|
27
|
+
nodes: ViewNavNodeI[];
|
|
28
|
+
edges: ViewNavEdgeI[];
|
|
29
|
+
}
|
|
30
|
+
export declare const SUCCESS_LEGACY_LABELS: string[];
|
|
31
|
+
export declare const ERROR_LEGACY_LABELS: string[];
|
|
32
|
+
export declare const ALREADY_SUBSCRIBED_LEGACY_LABELS: string[];
|
|
33
|
+
export declare const SYSTEM_RESULT_STATE_LABELS: string[];
|
|
34
|
+
export declare function viewHasControls(viewModel: ClBaseComponentI | undefined | null): boolean;
|
|
35
|
+
export declare function isResultView(viewModel: ClBaseComponentI | undefined | null, resultViewIds: string[]): boolean;
|
|
36
|
+
export declare function getConfiguredResultViewIds(submitActionParams: ClSubmitActionParamsI | undefined | null, hasFormControls: boolean): string[];
|
|
37
|
+
export declare function buildViewNavigationGraph(views: ClBaseComponentI[], shared?: Pick<ClDocumentSharedI, 'submitActionParams'> | null): ViewNavGraphI;
|
|
38
|
+
export declare function classifyView(graph: ViewNavGraphI, viewIndex: number): ViewTerminalKind;
|
|
39
|
+
export declare function classifyViews(graph: ViewNavGraphI): ViewTerminalKind[];
|
|
40
|
+
export declare function isAutoCommitTerminal(graph: ViewNavGraphI, viewIndex: number): boolean;
|
|
41
|
+
export declare function isMultiViewFlow(graph: ViewNavGraphI): boolean;
|
|
42
|
+
export declare function isNonLinearFlow(graph: ViewNavGraphI): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ClDocumentActionType}from"./Document.interface";import{iterateDepthFirst}from"./DocumentUtils";export var ViewNavEdgeKind;!function(e){e.GO_TO_VIEW="GO_TO_VIEW",e.GO_TO_NEXT_VIEW="GO_TO_NEXT_VIEW",e.GO_TO_PREVIOUS_VIEW="GO_TO_PREVIOUS_VIEW",e.SUBMIT="SUBMIT",e.NPS_CONDITIONAL="NPS_CONDITIONAL"}(ViewNavEdgeKind||(ViewNavEdgeKind={}));export var ViewTerminalKind;!function(e){e.TRUE_TERMINAL="TRUE_TERMINAL",e.INTERMEDIATE="INTERMEDIATE"}(ViewTerminalKind||(ViewTerminalKind={}));const SUBMIT_ACTION_TYPES=[ClDocumentActionType.REQUEST,ClDocumentActionType.SUBSCRIBE_CONTACT],NPS_BAND_KEYS=["detractor","passive","promoter"];export const SUCCESS_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"];export const ERROR_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_ERROR"];export const ALREADY_SUBSCRIBED_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUBSCRIBED"];export const SYSTEM_RESULT_STATE_LABELS=[...SUCCESS_LEGACY_LABELS,...ERROR_LEGACY_LABELS,...ALREADY_SUBSCRIBED_LEGACY_LABELS];function componentModelHasSubmitAction(e){var n,i;try{return!!(null===(i=null===(n=e.props)||void 0===n?void 0:n.handlers)||void 0===i?void 0:i.find(e=>{var n;return null===(n=null==e?void 0:e.actions)||void 0===n?void 0:n.find(e=>SUBMIT_ACTION_TYPES.includes(e.type))}))}catch(e){return!1}}export function viewHasControls(e){if(!e)return!1;let n=0;return iterateDepthFirst(e,e=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(e.type)||componentModelHasSubmitAction(e))&&n++}),n>0}export function isResultView(e,n){return!!e&&(SYSTEM_RESULT_STATE_LABELS.includes(e.label)||n.includes(e.id))}export function getConfiguredResultViewIds(e,n){return n?!e||e.runAction?[]:[e.successViewId,e.errorViewId,e.alreadySubscribedViewId].filter(Boolean):[]}function resolveResultViewIndex(e,n,i,o){const t=null==n?void 0:n[i];if(t){const n=e.findIndex(e=>e.id===t);if(-1!==n)return n}return e.findIndex(e=>o.includes(e.label))}export function buildViewNavigationGraph(e,n){var i;const o=new Map;e.forEach((e,n)=>o.set(e.id,n));const t=null!==(i=null==n?void 0:n.submitActionParams)&&void 0!==i?i:void 0,d=e.some(e=>viewHasControls(e)),r=getConfiguredResultViewIds(t,d),l=d?t:void 0,E=[],s=[],u=(e,n,i)=>i===ViewNavEdgeKind.GO_TO_NEXT_VIEW||n>e,a=(n,i,o,t)=>{void 0===i||i<0||i>=e.length||E.push({fromIndex:n,toIndex:i,kind:o,isForward:u(n,i,o),label:t})},c=(n,i)=>{var t,d;switch(i.type){case ClDocumentActionType.GO_TO_VIEW:return(null===(t=i.params)||void 0===t?void 0:t.viewId)?o.get(i.params.viewId):"number"==typeof(null===(d=i.params)||void 0===d?void 0:d.viewIndex)?i.params.viewIndex:void 0;case ClDocumentActionType.GO_TO_NEXT_VIEW:return n+1<e.length?n+1:void 0;case ClDocumentActionType.GO_TO_PREVIOUS_VIEW:return n-1>=0?n-1:void 0;default:return}};e.forEach((n,i)=>{const t=new Set;let E;const u=new Set,_=(e,n,o)=>{if(void 0===e||-1===e||e===i)return;const t=`${e}:${n}`;u.has(t)||(u.add(t),a(i,e,n,o))};if(iterateDepthFirst(n,e=>{var n,o,d,r,l,s,u;const _=null===(n=e.props)||void 0===n?void 0:n.content,I=[];for(const n of null!==(d=null===(o=e.props)||void 0===o?void 0:o.handlers)&&void 0!==d?d:[])for(const e of null!==(r=n.actions)&&void 0!==r?r:[])I.push({action:e,label:null!==(l=null==_?void 0:_.text)&&void 0!==l?l:""});if(Array.isArray(null==_?void 0:_.options))for(const e of _.options)(null==e?void 0:e.action)&&I.push({action:e.action,label:null!==(u=null!==(s=null==e?void 0:e.label)&&void 0!==s?s:null==e?void 0:e.value)&&void 0!==u?u:""});for(const{action:e,label:n}of I)SUBMIT_ACTION_TYPES.includes(e.type)?E=null!=E?E:n:e.type!==ClDocumentActionType.GO_TO_VIEW&&e.type!==ClDocumentActionType.GO_TO_NEXT_VIEW&&e.type!==ClDocumentActionType.GO_TO_PREVIOUS_VIEW||a(i,c(i,e),e.type,n);NPS_BAND_KEYS.map(e=>(_||{})[e]||null).filter(e=>e).forEach(e=>t.add(e))}),t.forEach(e=>{_(o.get(e),ViewNavEdgeKind.NPS_CONDITIONAL,"")}),s[i]=void 0!==E,void 0===E)return;const I=e[i+1],T=!!I&&!isResultView(I,r),S=E,v=()=>{_(resolveResultViewIndex(e,l,"errorViewId",ERROR_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,S),l&&!l.alreadySubscribedViewId?_(resolveResultViewIndex(e,l,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,S):_(resolveResultViewIndex(e,l,"alreadySubscribedViewId",ALREADY_SUBSCRIBED_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,S)};if(T)return _(i+1,ViewNavEdgeKind.SUBMIT,S),void(!viewHasControls(I)&&d&&v());const A=null==l?void 0:l.runAction;A?_(c(i,A),A.type,S):(_(resolveResultViewIndex(e,l,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,S),v())});const _=e.map((e,n)=>{var i,o;return{index:n,id:e.id,label:null!==(i=e.label)&&void 0!==i?i:e.id,hasSubmitAction:null!==(o=s[n])&&void 0!==o&&o}});return{nodes:_,edges:E}}export function classifyView(e,n){return e.edges.some(e=>e.fromIndex===n)?ViewTerminalKind.INTERMEDIATE:ViewTerminalKind.TRUE_TERMINAL}export function classifyViews(e){return e.nodes.map(n=>classifyView(e,n.index))}export function isAutoCommitTerminal(e,n){const i=e.nodes[n];return!!i&&(classifyView(e,n)===ViewTerminalKind.TRUE_TERMINAL&&!i.hasSubmitAction)}export function isMultiViewFlow(e){if(e.nodes.length<2)return!1;const n=new Set([0]),i=[0];for(;i.length;){const o=i.shift();for(const t of e.edges)t.fromIndex!==o||n.has(t.toIndex)||(n.add(t.toIndex),i.push(t.toIndex))}return n.size>1}export function isNonLinearFlow(e){return e.edges.some(e=>e.kind===ViewNavEdgeKind.GO_TO_VIEW||e.kind===ViewNavEdgeKind.NPS_CONDITIONAL||e.kind===ViewNavEdgeKind.SUBMIT&&e.toIndex<e.fromIndex)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/common",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0-nonlinear",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"sync:docs": "node ../../scripts/sync-docs.js --package=common"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"velocityjs": "2.
|
|
31
|
+
"velocityjs": "2.0.6"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "^27.5.1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Velocity from"velocityjs";import SysVelocityContext from"./SysVelocityContext";const sysCtx=(new SysVelocityContext).create();export default class SysVelocityRenderer{render(e,t){return Velocity.render(e,Object.assign(Object.assign({},sysCtx),t))}}
|