@legalplace/wizardx-core 2.6.4 → 2.7.1
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/CHANGELOG.md +49 -0
- package/dist/App.js +13 -4
- package/dist/PluginLoader.d.ts +3 -1
- package/dist/PluginLoader.js +12 -0
- package/dist/ThemeLoader.d.ts +2 -2
- package/dist/components/SmartScript.d.ts +2 -2
- package/dist/components/SmartScript.js +2 -0
- package/dist/componentsConnectors/connectBox.d.ts +3 -1
- package/dist/componentsConnectors/connectDocument.d.ts +3 -1
- package/dist/componentsConnectors/connectHeader.d.ts +3 -1
- package/dist/componentsConnectors/connectMetaTitle.d.ts +3 -1
- package/dist/componentsConnectors/connectOption.d.ts +6 -2
- package/dist/componentsConnectors/connectOption.js +1 -1
- package/dist/componentsConnectors/connectPagination.d.ts +3 -1
- package/dist/componentsConnectors/connectPreview.d.ts +3 -1
- package/dist/componentsConnectors/connectProgress.d.ts +3 -1
- package/dist/componentsConnectors/connectRootOption.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.js +7 -10
- package/dist/componentsConnectors/connectSummary.d.ts +3 -1
- package/dist/componentsConnectors/connectSummaryItem.d.ts +3 -1
- package/dist/componentsConnectors/connectVariable.d.ts +6 -2
- package/dist/componentsConnectors/connectVariable.js +1 -1
- package/dist/componentsConnectors/connectWizardWrapper.d.ts +3 -1
- package/dist/componentsConnectors/connector/componentConnector.d.ts +5 -1
- package/dist/componentsConnectors/connector/componentConnector.js +43 -4
- package/dist/componentsConnectors/connector/index.d.ts +1 -0
- package/dist/componentsConnectors/connector/index.js +1 -0
- package/dist/componentsConnectors/index.d.ts +17 -0
- package/dist/componentsConnectors/index.js +17 -0
- package/dist/componentsConnectors/library.d.ts +43 -15
- package/dist/helpers/apiEndpoint.d.ts +1 -0
- package/dist/helpers/apiEndpoint.js +4 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/propsEqualityCheck.d.ts +1 -0
- package/dist/helpers/propsEqualityCheck.js +10 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useActions.d.ts +2 -0
- package/dist/hooks/useActions.js +4 -0
- package/dist/hooks/useDispatch.d.ts +1 -0
- package/dist/hooks/useDispatch.js +4 -0
- package/dist/hooks/useSelectors.d.ts +2 -0
- package/dist/hooks/useSelectors.js +4 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/libs/PathReader.d.ts +10 -6
- package/dist/libs/PathReader.js +47 -28
- package/dist/libs/index.d.ts +5 -0
- package/dist/libs/index.js +5 -0
- package/dist/redux/actions/index.d.ts +9 -0
- package/dist/redux/actions/index.js +9 -0
- package/dist/redux/actions/library.d.ts +59 -63
- package/dist/redux/actions/sagas/index.d.ts +3 -0
- package/dist/redux/actions/sagas/index.js +3 -0
- package/dist/redux/actions/sagas/model.d.ts +1 -5
- package/dist/redux/constants/app.d.ts +2 -0
- package/dist/redux/constants/app.js +2 -0
- package/dist/redux/constants/index.d.ts +8 -0
- package/dist/redux/constants/index.js +8 -0
- package/dist/redux/constants/sagas/index.d.ts +3 -0
- package/dist/redux/constants/sagas/index.js +3 -0
- package/dist/redux/index.d.ts +5 -0
- package/dist/redux/index.js +5 -0
- package/dist/redux/middlewares/conditionsWatcherMiddleware.js +11 -5
- package/dist/redux/middlewares/conditionsWatcherMiddleware.test.js +120 -113
- package/dist/redux/middlewares/paginationWatcherMiddleware.js +2 -2
- package/dist/redux/middlewares/smartscriptMiddleware.js +8 -0
- package/dist/redux/reducers/pluginsStore.d.ts +3 -0
- package/dist/redux/reducers/pluginsStore.js +12 -0
- package/dist/redux/routerHistory.js +2 -2
- package/dist/redux/sagas/fetchModel.js +22 -6
- package/dist/redux/sagas/initInputs.js +6 -7
- package/dist/redux/sagas/saveData.js +2 -0
- package/dist/redux/selectors/app.js +13 -18
- package/dist/redux/selectors/cache.d.ts +17 -0
- package/dist/redux/selectors/cache.js +35 -0
- package/dist/redux/selectors/conditions.js +7 -7
- package/dist/redux/selectors/index.d.ts +8 -0
- package/dist/redux/selectors/index.js +8 -0
- package/dist/redux/selectors/inputs.js +3 -3
- package/dist/redux/selectors/library.d.ts +2 -2
- package/dist/redux/selectors/references.js +26 -26
- package/dist/redux/selectors/selectors.d.ts +2 -2
- package/dist/redux/selectors/selectors.js +19 -8
- package/dist/redux/selectors/selectors.test.js +6 -6
- package/dist/redux/selectors/user.js +5 -5
- package/dist/redux/store.d.ts +1 -1
- package/dist/redux/store.js +12 -4
- package/dist/service/api.manager.d.ts +1 -6
- package/dist/service/index.d.ts +3 -0
- package/dist/service/index.js +3 -0
- package/dist/types/PluginConfig.type.d.ts +57 -0
- package/dist/types/PluginConfig.type.js +1 -0
- package/dist/types/State.type.d.ts +6 -0
- package/dist/types/config.type.d.ts +3 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +11 -0
- package/package.json +13 -13
- package/.depcheckrc +0 -1
- package/.eslintignore +0 -2
- package/.eslintrc +0 -5
- package/__mocks__/fileMock.js +0 -1
- package/babel.config.json +0 -3
- package/jest.config.ts +0 -193
- package/setupJest.ts +0 -8
- package/src/App.test.tsx +0 -41
- package/src/App.tsx +0 -152
- package/src/Globals.ts +0 -69
- package/src/Loader.tsx +0 -8
- package/src/PluginLoader.test.tsx +0 -70
- package/src/PluginLoader.tsx +0 -407
- package/src/Shimmer.tsx +0 -108
- package/src/ThemeLoader.test.tsx +0 -82
- package/src/ThemeLoader.tsx +0 -95
- package/src/components/PluginRoute.tsx +0 -48
- package/src/components/SmartScript.tsx +0 -166
- package/src/components/UserLocked/UserLockedComponent.tsx +0 -33
- package/src/components/View.test.tsx +0 -110
- package/src/components/View.tsx +0 -114
- package/src/componentsConnectors/connectBox.test.tsx +0 -226
- package/src/componentsConnectors/connectBox.tsx +0 -70
- package/src/componentsConnectors/connectDocument.test.tsx +0 -108
- package/src/componentsConnectors/connectDocument.tsx +0 -64
- package/src/componentsConnectors/connectHeader.tsx +0 -21
- package/src/componentsConnectors/connectMetaTitle.test.tsx +0 -40
- package/src/componentsConnectors/connectMetaTitle.tsx +0 -8
- package/src/componentsConnectors/connectOption.tsx +0 -222
- package/src/componentsConnectors/connectPagination.tsx +0 -102
- package/src/componentsConnectors/connectPreview.tsx +0 -5
- package/src/componentsConnectors/connectProgress.tsx +0 -59
- package/src/componentsConnectors/connectRootOption.tsx +0 -95
- package/src/componentsConnectors/connectSection.tsx +0 -79
- package/src/componentsConnectors/connectSummary.tsx +0 -21
- package/src/componentsConnectors/connectSummaryItem.tsx +0 -102
- package/src/componentsConnectors/connectTermsheet.tsx +0 -359
- package/src/componentsConnectors/connectVariable.tsx +0 -191
- package/src/componentsConnectors/connectWizardWrapper.tsx +0 -30
- package/src/componentsConnectors/connector/componentConnector.tsx +0 -219
- package/src/componentsConnectors/library.ts +0 -35
- package/src/config.test.ts +0 -63
- package/src/config.ts +0 -11
- package/src/constants/emailValidation.ts +0 -2
- package/src/constants/phoneValidation.ts +0 -4
- package/src/definitions/path.join.d.ts +0 -4
- package/src/helpers/outputsParsing.ts +0 -412
- package/src/helpers/preloadTheme.ts +0 -17
- package/src/helpers/scriptsLoader.ts +0 -20
- package/src/hooks/usePrevious.ts +0 -9
- package/src/libs/ConditionsInitiator.ts +0 -164
- package/src/libs/ConditionsRunner/DataPopulator.ts +0 -266
- package/src/libs/ConditionsRunner.ts +0 -454
- package/src/libs/DocumentsOutputs.ts +0 -171
- package/src/libs/Eval/EvalBase.ts +0 -116
- package/src/libs/Eval/EvalFunctions.ts +0 -724
- package/src/libs/Eval/NumbersToLetters.ts +0 -185
- package/src/libs/EvalVariable.ts +0 -265
- package/src/libs/EventsTracking.ts +0 -250
- package/src/libs/InputsInitiator.ts +0 -136
- package/src/libs/NumAuto.test.ts +0 -55
- package/src/libs/NumAuto.ts +0 -56
- package/src/libs/OvcConverter.ts +0 -285
- package/src/libs/PathReader.ts +0 -272
- package/src/libs/SectionValidity.test.ts +0 -146
- package/src/libs/SectionValidity.ts +0 -110
- package/src/libs/SmartScriptStore.ts +0 -492
- package/src/misc/test_model.ts +0 -14603
- package/src/misc/test_models/connectDocumen.testmodel.json +0 -178
- package/src/misc/test_models/setDefaults.testmodel.json +0 -279
- package/src/misc/test_models/testmodel.json +0 -1
- package/src/polyfills/index.ts +0 -5
- package/src/polyfills/objectValues.ts +0 -4
- package/src/polyfills/prepend.ts +0 -31
- package/src/polyfills/stringRepeat.ts +0 -44
- package/src/redux/actions/app.test.ts +0 -123
- package/src/redux/actions/app.ts +0 -249
- package/src/redux/actions/conditions.test.ts +0 -84
- package/src/redux/actions/conditions.ts +0 -135
- package/src/redux/actions/inputs.test.ts +0 -85
- package/src/redux/actions/inputs.ts +0 -111
- package/src/redux/actions/library.ts +0 -23
- package/src/redux/actions/mandatories.ts +0 -98
- package/src/redux/actions/references.test.ts +0 -48
- package/src/redux/actions/references.ts +0 -37
- package/src/redux/actions/sagas/data.test.ts +0 -11
- package/src/redux/actions/sagas/data.ts +0 -18
- package/src/redux/actions/sagas/model.test.ts +0 -14
- package/src/redux/actions/sagas/model.ts +0 -48
- package/src/redux/actions/sagas/user.ts +0 -25
- package/src/redux/actions/smartscript.ts +0 -55
- package/src/redux/actions/user.test.ts +0 -18
- package/src/redux/actions/user.ts +0 -41
- package/src/redux/constants/app.ts +0 -36
- package/src/redux/constants/conditions.ts +0 -25
- package/src/redux/constants/inputs.ts +0 -15
- package/src/redux/constants/mandatories.ts +0 -11
- package/src/redux/constants/references.ts +0 -7
- package/src/redux/constants/sagas/data.ts +0 -1
- package/src/redux/constants/sagas/model.ts +0 -2
- package/src/redux/constants/sagas/user.ts +0 -2
- package/src/redux/constants/smartscript.ts +0 -9
- package/src/redux/constants/user.ts +0 -6
- package/src/redux/listeners/subscriber.test.ts +0 -45
- package/src/redux/listeners/subscriber.ts +0 -29
- package/src/redux/middlewares/conditionsWatcherMiddleware.test.ts +0 -370
- package/src/redux/middlewares/conditionsWatcherMiddleware.ts +0 -321
- package/src/redux/middlewares/evaluationsWatcherMiddleware.test.ts +0 -323
- package/src/redux/middlewares/evaluationsWatcherMiddleware.ts +0 -250
- package/src/redux/middlewares/mandatoriesWatcherMiddleware.ts +0 -473
- package/src/redux/middlewares/multiplesActionsMiddleware.test.ts +0 -230
- package/src/redux/middlewares/multiplesActionsMiddleware.ts +0 -121
- package/src/redux/middlewares/paginationWatcherMiddleware.ts +0 -251
- package/src/redux/middlewares/pluginsHookMiddleware.ts +0 -24
- package/src/redux/middlewares/prefillerWatcherMiddleware.test.ts +0 -118
- package/src/redux/middlewares/prefillerWatcherMiddleware.ts +0 -462
- package/src/redux/middlewares/smartscriptMiddleware.ts +0 -228
- package/src/redux/middlewares/thirdpartyScriptsMiddleware.ts +0 -41
- package/src/redux/reducers/app/customizations/initCustomizationAutoDefault.ts +0 -16
- package/src/redux/reducers/app/customizations/initCustomizationMeta.ts +0 -16
- package/src/redux/reducers/app/instance/initInstance.ts +0 -29
- package/src/redux/reducers/app/instance/setDataStatus.ts +0 -16
- package/src/redux/reducers/app/instance/updateInstance.ts +0 -30
- package/src/redux/reducers/app/instance/updateInstancePaid.ts +0 -20
- package/src/redux/reducers/app/instance.test.ts +0 -106
- package/src/redux/reducers/app/meta/fetchModelFailed.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelNonBlocking.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelSucceeded.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelUnhealthy.ts +0 -18
- package/src/redux/reducers/app/meta/fetchModelUserLocked.ts +0 -11
- package/src/redux/reducers/app/meta/initMeta.ts +0 -22
- package/src/redux/reducers/app/meta/setModelUuid.ts +0 -17
- package/src/redux/reducers/app/meta.test.ts +0 -90
- package/src/redux/reducers/app/pagination/goNextPage.ts +0 -69
- package/src/redux/reducers/app/pagination/goPage.ts +0 -81
- package/src/redux/reducers/app/pagination/goPreviousPage.ts +0 -60
- package/src/redux/reducers/app/pagination/initPagination.ts +0 -46
- package/src/redux/reducers/app/pagination/updateAvailableAppStates.ts +0 -77
- package/src/redux/reducers/app/pagination.test.ts +0 -363
- package/src/redux/reducers/app/wizard/updateAvailableSections.ts +0 -40
- package/src/redux/reducers/app/wizard.test.ts +0 -84
- package/src/redux/reducers/app.test.ts +0 -336
- package/src/redux/reducers/app.ts +0 -150
- package/src/redux/reducers/conditions/addMultipleOccurency.test.ts +0 -131
- package/src/redux/reducers/conditions/addMultipleOccurency.ts +0 -155
- package/src/redux/reducers/conditions/deleteMultipleOccurency.test.ts +0 -95
- package/src/redux/reducers/conditions/deleteMultipleOccurency.ts +0 -141
- package/src/redux/reducers/conditions/initConditions.ts +0 -18
- package/src/redux/reducers/conditions/updateDocumentConditions.test.ts +0 -47
- package/src/redux/reducers/conditions/updateDocumentConditions.ts +0 -21
- package/src/redux/reducers/conditions/updateOptionConditions.ts +0 -24
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions/updatePrefillerConditions.ts +0 -29
- package/src/redux/reducers/conditions/updateSectionConditions.ts +0 -28
- package/src/redux/reducers/conditions/updateVariableConditions.ts +0 -25
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions.test.ts +0 -241
- package/src/redux/reducers/conditions.ts +0 -68
- package/src/redux/reducers/inputs/addMultipleOccurency.test.ts +0 -117
- package/src/redux/reducers/inputs/addMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/deleteMultipleOccurency.test.ts +0 -70
- package/src/redux/reducers/inputs/deleteMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/initOption.ts +0 -16
- package/src/redux/reducers/inputs/initVariable.ts +0 -16
- package/src/redux/reducers/inputs/updateOptionInput.ts +0 -24
- package/src/redux/reducers/inputs/updateVariableInput.ts +0 -24
- package/src/redux/reducers/inputs.test.ts +0 -221
- package/src/redux/reducers/inputs.ts +0 -51
- package/src/redux/reducers/mandatories/addMultipleOccurency.ts +0 -52
- package/src/redux/reducers/mandatories/deleteMultipleOccurency.ts +0 -55
- package/src/redux/reducers/mandatories/initMandatoryOption.ts +0 -17
- package/src/redux/reducers/mandatories/initMandatoryVariable.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryIgnore.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryOption.ts +0 -25
- package/src/redux/reducers/mandatories/setMandatorySection.ts +0 -20
- package/src/redux/reducers/mandatories/setMandatoryVariable.ts +0 -24
- package/src/redux/reducers/mandatories.ts +0 -56
- package/src/redux/reducers/references/initReferences.ts +0 -37
- package/src/redux/reducers/references/updateOptionMeta.ts +0 -73
- package/src/redux/reducers/references/updateVariableMeta.ts +0 -72
- package/src/redux/reducers/references.ts +0 -59
- package/src/redux/reducers/smartscript/enableSmartScript.ts +0 -13
- package/src/redux/reducers/smartscript/initSmartScriptTriggers.ts +0 -14
- package/src/redux/reducers/smartscript/updateSmartscriptOptionHidden.ts +0 -30
- package/src/redux/reducers/smartscript/updateSmartscriptVariableHidden.ts +0 -30
- package/src/redux/reducers/smartscript.ts +0 -47
- package/src/redux/reducers/user/initUser.ts +0 -15
- package/src/redux/reducers/user/setUserStatus.ts +0 -13
- package/src/redux/reducers/user/setUserValidToken.ts +0 -13
- package/src/redux/reducers/user.test.ts +0 -51
- package/src/redux/reducers/user.ts +0 -40
- package/src/redux/routerHistore.test.ts +0 -19
- package/src/redux/routerHistory.ts +0 -26
- package/src/redux/sagas/fetchModel.test.ts +0 -76
- package/src/redux/sagas/fetchModel.ts +0 -683
- package/src/redux/sagas/homogeneousRadioInputsSaga.ts +0 -42
- package/src/redux/sagas/initInputs.ts +0 -110
- package/src/redux/sagas/runner.test.ts +0 -12
- package/src/redux/sagas/runner.ts +0 -26
- package/src/redux/sagas/saveData.test.ts +0 -125
- package/src/redux/sagas/saveData.ts +0 -55
- package/src/redux/sagas/setDefaults.test.ts +0 -100
- package/src/redux/sagas/setDefaults.ts +0 -167
- package/src/redux/sagas/setUserEmail.ts +0 -175
- package/src/redux/selectors/app.test.ts +0 -162
- package/src/redux/selectors/app.ts +0 -331
- package/src/redux/selectors/conditions.test.ts +0 -92
- package/src/redux/selectors/conditions.ts +0 -293
- package/src/redux/selectors/inputs.test.ts +0 -72
- package/src/redux/selectors/inputs.ts +0 -76
- package/src/redux/selectors/library.ts +0 -17
- package/src/redux/selectors/mandatories.ts +0 -83
- package/src/redux/selectors/references.test.ts +0 -660
- package/src/redux/selectors/references.ts +0 -413
- package/src/redux/selectors/selectors.test.ts +0 -21
- package/src/redux/selectors/selectors.ts +0 -87
- package/src/redux/selectors/smartscript.ts +0 -30
- package/src/redux/selectors/user.test.ts +0 -39
- package/src/redux/selectors/user.ts +0 -45
- package/src/redux/store.test.ts +0 -22
- package/src/redux/store.ts +0 -100
- package/src/service/api.manager.ts +0 -261
- package/src/service/auth.service.ts +0 -5
- package/src/service/pardot.service.ts +0 -10
- package/src/tests-misc/plugins/jestTestPlugin/after.tsx +0 -5
- package/src/tests-misc/plugins/jestTestPlugin/before.tsx +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/index.ts +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/title.tsx +0 -8
- package/src/tests-misc/themes/jestTestTheme/components/EmailComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/TermsheetComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/WizardComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/faltyIndex.ts +0 -3
- package/src/tests-misc/themes/jestTestTheme/faltyIndexLoader.ts +0 -1
- package/src/tests-misc/themes/jestTestTheme/index.ts +0 -13
- package/src/types/Actions.type.ts +0 -612
- package/src/types/Components.type.ts +0 -181
- package/src/types/State.type.ts +0 -323
- package/src/types/Termsheet.type.ts +0 -28
- package/src/types/api.type.ts +0 -37
- package/src/types/config.type.ts +0 -55
- package/src/types/env.type.ts +0 -5
- package/src/types/getActions.type.ts +0 -3
- package/src/types/getConnectors.type.ts +0 -5
- package/src/types/getSelectors.type.ts +0 -3
- package/src/wizard-params.ts +0 -56
- package/tsconfig.json +0 -43
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import { MiddlewareAPI, Dispatch } from "redux";
|
|
3
|
-
import { filterXSS } from "xss";
|
|
4
|
-
import ConditionsMapper from "@legalplace/referencesparser/dist/libs/ConditionsMapper";
|
|
5
|
-
import { ActionsType } from "../../types/Actions.type";
|
|
6
|
-
import { UPDATE_PREFILLER_CONDITION } from "../constants/conditions";
|
|
7
|
-
import {
|
|
8
|
-
selectVariableInputByIndex,
|
|
9
|
-
selectVariableInput,
|
|
10
|
-
selectOptionInput,
|
|
11
|
-
} from "../selectors/inputs";
|
|
12
|
-
import {
|
|
13
|
-
areVariablesSiblings,
|
|
14
|
-
selectOptionRelations,
|
|
15
|
-
selectVariableReference,
|
|
16
|
-
selectVariableRelations,
|
|
17
|
-
} from "../selectors/references";
|
|
18
|
-
import { updateVariableAction } from "../actions/inputs";
|
|
19
|
-
import { StateType } from "../../types/State.type";
|
|
20
|
-
import {
|
|
21
|
-
ADD_MULTIPLE_OCCURENCY,
|
|
22
|
-
UPDATE_VARIABLE_INPUT,
|
|
23
|
-
} from "../constants/inputs";
|
|
24
|
-
import { selectPrefillerConditionValue } from "../selectors/conditions";
|
|
25
|
-
import { FETCH_MODEL_SUCCEEDED } from "../constants/app";
|
|
26
|
-
|
|
27
|
-
export type WatcherActions = ActionsType.Conditions.updatePrefillerCondition;
|
|
28
|
-
|
|
29
|
-
const parsePrefillerValue = (
|
|
30
|
-
variableId: number,
|
|
31
|
-
inputIndex: number,
|
|
32
|
-
prefillerIndex: number
|
|
33
|
-
) => {
|
|
34
|
-
const prefillerValue =
|
|
35
|
-
selectVariableReference(variableId)?.prefillings?.[prefillerIndex]?.value;
|
|
36
|
-
|
|
37
|
-
if (!prefillerValue) return "";
|
|
38
|
-
|
|
39
|
-
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
40
|
-
// Extracting variables
|
|
41
|
-
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
42
|
-
let variables: number[] = [];
|
|
43
|
-
if (tagsMatch !== null) {
|
|
44
|
-
// Tranforming tags into integer ids
|
|
45
|
-
const variablesTags: string[] = [...tagsMatch];
|
|
46
|
-
variables = variablesTags.map((current) => {
|
|
47
|
-
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
48
|
-
if (outputVariableMatch === null) return 0;
|
|
49
|
-
return parseInt(outputVariableMatch[0], 10);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Removing duplicated variables
|
|
54
|
-
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
55
|
-
|
|
56
|
-
// Making sure all variables exist
|
|
57
|
-
variables = variables.filter(
|
|
58
|
-
(c) => selectVariableReference(c) !== undefined
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// Getting values
|
|
62
|
-
const variablesValues: Record<string, string> = {};
|
|
63
|
-
variables.forEach((currentVariableId) => {
|
|
64
|
-
const index = areVariablesSiblings(currentVariableId, variableId)
|
|
65
|
-
? inputIndex
|
|
66
|
-
: 0;
|
|
67
|
-
const value = selectVariableInputByIndex(currentVariableId, index);
|
|
68
|
-
if (
|
|
69
|
-
value === undefined ||
|
|
70
|
-
value === null ||
|
|
71
|
-
(typeof value === "string" && value.trim().length === 0)
|
|
72
|
-
) {
|
|
73
|
-
variablesValues[currentVariableId] = "";
|
|
74
|
-
} else {
|
|
75
|
-
variablesValues[currentVariableId] = value.toString();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Inserting values
|
|
80
|
-
let parsedPrefillerValue = `${prefillerValue}`;
|
|
81
|
-
variables.forEach((currentVariableId) => {
|
|
82
|
-
const value: string = variablesValues[currentVariableId];
|
|
83
|
-
parsedPrefillerValue = parsedPrefillerValue.replace(
|
|
84
|
-
new RegExp(`\\[var:${currentVariableId}\\]`, "gi"),
|
|
85
|
-
filterXSS(value)
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Returning parsed value
|
|
90
|
-
return parsedPrefillerValue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return prefillerValue;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Watching UPDATE_PREFILLER_CONDITION action
|
|
98
|
-
* @param mpi MiddlewareAPI
|
|
99
|
-
* @param next Dispatch function
|
|
100
|
-
* @param action Actions
|
|
101
|
-
*/
|
|
102
|
-
const watchUpdatePrefillerCondition = (
|
|
103
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
104
|
-
next: Dispatch,
|
|
105
|
-
action: ActionsType.Conditions.updatePrefillerCondition
|
|
106
|
-
) => {
|
|
107
|
-
const result = next(action);
|
|
108
|
-
|
|
109
|
-
// Extracting variable data from the action (the prefiller id is the variable id)
|
|
110
|
-
const variableId = action.id;
|
|
111
|
-
const variableIndex = action.index;
|
|
112
|
-
const prefillerConditions = action.value;
|
|
113
|
-
|
|
114
|
-
// Getting variable's reference
|
|
115
|
-
const variableReference = selectVariableReference(variableId);
|
|
116
|
-
if (variableReference === undefined)
|
|
117
|
-
throw new Error(`Variable ${variableId} does not exist`);
|
|
118
|
-
|
|
119
|
-
// Getting the index of the first true condition (if none is true -1 means the prefiller is empty)
|
|
120
|
-
const firstTrueIndex = prefillerConditions.indexOf(true);
|
|
121
|
-
|
|
122
|
-
// Getting current variable value
|
|
123
|
-
let currentValue = selectVariableInputByIndex(variableId, variableIndex);
|
|
124
|
-
currentValue =
|
|
125
|
-
typeof currentValue === "number" ? currentValue.toString() : currentValue;
|
|
126
|
-
currentValue = typeof currentValue === "string" ? currentValue : "";
|
|
127
|
-
|
|
128
|
-
// Getting first undefined value
|
|
129
|
-
const firstUnconditionnedIndex = variableReference.prefillings
|
|
130
|
-
? variableReference.prefillings
|
|
131
|
-
.map(
|
|
132
|
-
(c) =>
|
|
133
|
-
c.conditions === undefined ||
|
|
134
|
-
ConditionsMapper.countConditions(c.conditions) === 0
|
|
135
|
-
)
|
|
136
|
-
.indexOf(true)
|
|
137
|
-
: -1;
|
|
138
|
-
|
|
139
|
-
// Getting prefillers values
|
|
140
|
-
let prefillersValues = variableReference.prefillings
|
|
141
|
-
? variableReference.prefillings
|
|
142
|
-
: new Array(prefillerConditions.length).fill("");
|
|
143
|
-
prefillersValues = prefillersValues.map((prefiller) => prefiller.value);
|
|
144
|
-
|
|
145
|
-
// Filling prefillers values with variables
|
|
146
|
-
prefillersValues = prefillersValues.map((prefillerValue, prefillerIndex) => {
|
|
147
|
-
// Checking whether prefiller valuecontains a variable
|
|
148
|
-
if (/\[var:([0-9]+)\]/gi.test(prefillerValue))
|
|
149
|
-
return parsePrefillerValue(variableId, variableIndex, prefillerIndex);
|
|
150
|
-
|
|
151
|
-
// Removing whitespaces from beginning and end of each prefiller value
|
|
152
|
-
return prefillerValue.replace(/^\s+|\s+$/g, "");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// Getting the value to prefill
|
|
156
|
-
const newPrefillerValue =
|
|
157
|
-
// eslint-disable-next-line no-nested-ternary
|
|
158
|
-
firstTrueIndex > -1
|
|
159
|
-
? prefillersValues[firstTrueIndex]
|
|
160
|
-
: firstUnconditionnedIndex > -1
|
|
161
|
-
? prefillersValues[firstUnconditionnedIndex]
|
|
162
|
-
: "";
|
|
163
|
-
|
|
164
|
-
// Prefilling the variable if it's current value is empty or equals another prefillers
|
|
165
|
-
if (
|
|
166
|
-
currentValue === "" ||
|
|
167
|
-
(prefillersValues.includes(currentValue) &&
|
|
168
|
-
currentValue !== newPrefillerValue)
|
|
169
|
-
) {
|
|
170
|
-
mpi.dispatch(
|
|
171
|
-
updateVariableAction(variableId, newPrefillerValue, variableIndex)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return result;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Watching UPDATE_PREFILLER_CONDITION action
|
|
180
|
-
* @param mpi MiddlewareAPI
|
|
181
|
-
* @param next Dispatch function
|
|
182
|
-
* @param action Actions
|
|
183
|
-
*/
|
|
184
|
-
const watchAddMultipleOccurency = (
|
|
185
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
186
|
-
next: Dispatch,
|
|
187
|
-
action: ActionsType.Inputs.addMultipleOccurency
|
|
188
|
-
) => {
|
|
189
|
-
const result = next(action);
|
|
190
|
-
|
|
191
|
-
// Extracting variable data from the action (the prefiller id is the variable id)
|
|
192
|
-
const optionId = action.id;
|
|
193
|
-
|
|
194
|
-
// Getting child variables
|
|
195
|
-
const childrenVariables = selectOptionRelations(optionId).children.variables;
|
|
196
|
-
const variableIndex = selectOptionInput(optionId).length - 1;
|
|
197
|
-
|
|
198
|
-
childrenVariables.forEach((variableId) => {
|
|
199
|
-
// Getting variable's reference
|
|
200
|
-
const variableReference = selectVariableReference(variableId);
|
|
201
|
-
|
|
202
|
-
if (variableReference === undefined)
|
|
203
|
-
throw new Error(`Variable ${variableId} does not exist`);
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
variableReference.prefillings?.length &&
|
|
207
|
-
variableReference.prefillings.length > 0
|
|
208
|
-
) {
|
|
209
|
-
const prefillerConditions =
|
|
210
|
-
selectPrefillerConditionValue(variableId)?.[variableIndex];
|
|
211
|
-
|
|
212
|
-
if (prefillerConditions === undefined) return;
|
|
213
|
-
|
|
214
|
-
// Getting the index of the first true condition (if none is true -1 means the prefiller is empty)
|
|
215
|
-
const firstTrueIndex = prefillerConditions.indexOf(true);
|
|
216
|
-
|
|
217
|
-
// Getting current variable value
|
|
218
|
-
let currentValue = selectVariableInputByIndex(variableId, variableIndex);
|
|
219
|
-
currentValue =
|
|
220
|
-
typeof currentValue === "number"
|
|
221
|
-
? currentValue.toString()
|
|
222
|
-
: currentValue;
|
|
223
|
-
currentValue = typeof currentValue === "string" ? currentValue : "";
|
|
224
|
-
currentValue = currentValue.trim();
|
|
225
|
-
|
|
226
|
-
// Getting first undefined value
|
|
227
|
-
const firstUndefinedCondition = variableReference.prefillings
|
|
228
|
-
? variableReference.prefillings
|
|
229
|
-
.map((c) => c.conditions)
|
|
230
|
-
.indexOf(undefined)
|
|
231
|
-
: -1;
|
|
232
|
-
|
|
233
|
-
// Getting prefillers values
|
|
234
|
-
let prefillersValues = variableReference.prefillings
|
|
235
|
-
? variableReference.prefillings
|
|
236
|
-
: new Array(prefillerConditions.length).fill("");
|
|
237
|
-
prefillersValues = prefillersValues.map((prefiller) => prefiller.value);
|
|
238
|
-
|
|
239
|
-
// Filling prefillers values with variables
|
|
240
|
-
prefillersValues = prefillersValues.map((prefillerValue) => {
|
|
241
|
-
// Checking whether prefiller valuecontains a variable
|
|
242
|
-
if (/\[var:([0-9]+)\]/gi.test(prefillerValue)) {
|
|
243
|
-
// Extracting variables
|
|
244
|
-
const tagsMatch = prefillerValue.match(/\[var:([0-9]+)\]/gi);
|
|
245
|
-
let variables: number[] = [];
|
|
246
|
-
if (tagsMatch !== null) {
|
|
247
|
-
// Tranforming tags into integer ids
|
|
248
|
-
const variablesTags: string[] = [...tagsMatch];
|
|
249
|
-
variables = variablesTags.map((current) => {
|
|
250
|
-
const outputVariableMatch = current.match(/([0-9]+)/);
|
|
251
|
-
if (outputVariableMatch === null) return 0;
|
|
252
|
-
return parseInt(outputVariableMatch[0], 10);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Removing duplicated variables
|
|
257
|
-
variables = variables.filter((c, i) => variables.indexOf(c) === i);
|
|
258
|
-
|
|
259
|
-
// Making sure all variables exist
|
|
260
|
-
variables = variables.filter(
|
|
261
|
-
(c) => selectVariableReference(c) !== undefined
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
// Getting values
|
|
265
|
-
const variablesValues: Record<string, string> = {};
|
|
266
|
-
variables.forEach((currentVariableId) => {
|
|
267
|
-
const index = areVariablesSiblings(currentVariableId, variableId)
|
|
268
|
-
? variableIndex
|
|
269
|
-
: 0;
|
|
270
|
-
const value = selectVariableInputByIndex(currentVariableId, index);
|
|
271
|
-
if (
|
|
272
|
-
value === undefined ||
|
|
273
|
-
value === null ||
|
|
274
|
-
(typeof value === "string" && value.trim().length === 0)
|
|
275
|
-
) {
|
|
276
|
-
variablesValues[currentVariableId] = "";
|
|
277
|
-
} else {
|
|
278
|
-
variablesValues[currentVariableId] = value.toString();
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// Inserting values
|
|
283
|
-
let parsedPrefillerValue = `${prefillerValue}`;
|
|
284
|
-
variables.forEach((currentVariableId) => {
|
|
285
|
-
const value: string = variablesValues[currentVariableId];
|
|
286
|
-
parsedPrefillerValue = parsedPrefillerValue.replace(
|
|
287
|
-
new RegExp(`\\[var:${currentVariableId}\\]`, "gi"),
|
|
288
|
-
filterXSS(value)
|
|
289
|
-
);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
// Returning parsed value
|
|
293
|
-
return parsedPrefillerValue;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Removing whitespaces from beginning and end of each prefiller value
|
|
297
|
-
return prefillerValue.replace(/^\s+|\s+$/g, "");
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
// Getting the value to prefill
|
|
301
|
-
const newPrefillerValue =
|
|
302
|
-
// eslint-disable-next-line no-nested-ternary
|
|
303
|
-
firstTrueIndex > -1
|
|
304
|
-
? prefillersValues[firstTrueIndex]
|
|
305
|
-
: firstUndefinedCondition > -1
|
|
306
|
-
? prefillersValues[firstUndefinedCondition]
|
|
307
|
-
: "";
|
|
308
|
-
|
|
309
|
-
// Prefilling the variable if it's current value is empty or equals another prefiller
|
|
310
|
-
if (
|
|
311
|
-
currentValue === "" ||
|
|
312
|
-
(prefillersValues.includes(currentValue) &&
|
|
313
|
-
currentValue !== newPrefillerValue)
|
|
314
|
-
) {
|
|
315
|
-
mpi.dispatch(
|
|
316
|
-
updateVariableAction(variableId, newPrefillerValue, variableIndex)
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
return result;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const watchUpdateVariableInput = (
|
|
326
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
327
|
-
next: Dispatch,
|
|
328
|
-
action: ActionsType.Inputs.updateVariableInput,
|
|
329
|
-
noDispatch = false
|
|
330
|
-
) => {
|
|
331
|
-
const { id, index } = action;
|
|
332
|
-
|
|
333
|
-
// Checking whether prefillers should update
|
|
334
|
-
const { prefillingsContents } = selectVariableRelations(id);
|
|
335
|
-
|
|
336
|
-
// Getting list of prefillers to update
|
|
337
|
-
const prefillersToUpdate: {
|
|
338
|
-
variableId: number;
|
|
339
|
-
inputIndex: number;
|
|
340
|
-
prefillingIndex: number;
|
|
341
|
-
}[] = [];
|
|
342
|
-
|
|
343
|
-
// NOTE: This should be done before executing "next" action
|
|
344
|
-
// in order to parse prefilling contents with previous variable
|
|
345
|
-
// values
|
|
346
|
-
if (prefillingsContents.length > 0) {
|
|
347
|
-
prefillingsContents.forEach(({ variableId, prefillingIndex }) => {
|
|
348
|
-
// Getting relation's current value
|
|
349
|
-
const relationValues = selectVariableInput(variableId);
|
|
350
|
-
const relationReference = selectVariableReference(variableId);
|
|
351
|
-
|
|
352
|
-
// Going throught relation
|
|
353
|
-
relationValues.forEach((currentRelationValue, currentRelationIndex) => {
|
|
354
|
-
// Checking if prefiller and variable are siblings
|
|
355
|
-
if (
|
|
356
|
-
areVariablesSiblings(variableId, id) &&
|
|
357
|
-
currentRelationIndex !== index
|
|
358
|
-
)
|
|
359
|
-
return;
|
|
360
|
-
|
|
361
|
-
// If current relation's value is equal to the prefiller
|
|
362
|
-
// we needed
|
|
363
|
-
if (
|
|
364
|
-
relationReference.prefillings &&
|
|
365
|
-
currentRelationValue ===
|
|
366
|
-
parsePrefillerValue(variableId, index, prefillingIndex)
|
|
367
|
-
) {
|
|
368
|
-
prefillersToUpdate.push({
|
|
369
|
-
variableId,
|
|
370
|
-
inputIndex: currentRelationIndex,
|
|
371
|
-
prefillingIndex,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// Executing action
|
|
379
|
-
if (noDispatch !== true) next(action);
|
|
380
|
-
|
|
381
|
-
// Updating prefillers
|
|
382
|
-
prefillersToUpdate.forEach(({ variableId, inputIndex, prefillingIndex }) => {
|
|
383
|
-
const value = parsePrefillerValue(variableId, index, prefillingIndex);
|
|
384
|
-
mpi.dispatch(updateVariableAction(variableId, value, inputIndex));
|
|
385
|
-
});
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
const watchFetchModelSucceeded = (
|
|
389
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
390
|
-
next: Dispatch,
|
|
391
|
-
action: ActionsType.App.fetchModelSucceeded
|
|
392
|
-
) => {
|
|
393
|
-
next(action);
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Initiating Prefillers
|
|
397
|
-
*/
|
|
398
|
-
const { variables } = mpi.getState().inputs;
|
|
399
|
-
|
|
400
|
-
// Initiating prefillers with no conditions
|
|
401
|
-
const { prefillers } = mpi.getState().conditions;
|
|
402
|
-
Object.keys(prefillers).forEach((variableStrId) => {
|
|
403
|
-
const variableId = parseInt(variableStrId, 10);
|
|
404
|
-
|
|
405
|
-
// Getting prefillers reference
|
|
406
|
-
const { prefillings } = selectVariableReference(variableId);
|
|
407
|
-
|
|
408
|
-
if (Array.isArray(prefillings)) {
|
|
409
|
-
// Getting first undefined value
|
|
410
|
-
const firstUnconditionnedIndex = prefillings
|
|
411
|
-
.map(
|
|
412
|
-
(c) =>
|
|
413
|
-
c.conditions === undefined ||
|
|
414
|
-
ConditionsMapper.countConditions(c.conditions) === 0
|
|
415
|
-
)
|
|
416
|
-
.indexOf(true);
|
|
417
|
-
|
|
418
|
-
if (firstUnconditionnedIndex > -1) {
|
|
419
|
-
variables[variableId].forEach((value, variableIndex) => {
|
|
420
|
-
const prefillerValue = parsePrefillerValue(
|
|
421
|
-
variableId,
|
|
422
|
-
variableIndex,
|
|
423
|
-
firstUnconditionnedIndex
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
if (value.toString().trim().length === 0) {
|
|
427
|
-
mpi.dispatch(
|
|
428
|
-
updateVariableAction(variableId, prefillerValue, variableIndex)
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
// Enumerating watchers
|
|
438
|
-
const watchersEnum: Record<
|
|
439
|
-
string,
|
|
440
|
-
(mpi: MiddlewareAPI<Dispatch, StateType>, next: Dispatch, action: any) => void
|
|
441
|
-
> = {
|
|
442
|
-
[UPDATE_PREFILLER_CONDITION]: watchUpdatePrefillerCondition,
|
|
443
|
-
[UPDATE_VARIABLE_INPUT]: watchUpdateVariableInput,
|
|
444
|
-
[FETCH_MODEL_SUCCEEDED]: watchFetchModelSucceeded,
|
|
445
|
-
[ADD_MULTIPLE_OCCURENCY]: watchAddMultipleOccurency,
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Prefiller Watcher Middleware
|
|
450
|
-
* @param mpi MiddlewareAPI
|
|
451
|
-
* @param next Dispatch function
|
|
452
|
-
* @param action Actions
|
|
453
|
-
*/
|
|
454
|
-
const prefillerWatcherMiddleware =
|
|
455
|
-
(mpi: MiddlewareAPI) => (next: Dispatch) => (action: WatcherActions) => {
|
|
456
|
-
if (Object.prototype.hasOwnProperty.call(watchersEnum, action.type)) {
|
|
457
|
-
return watchersEnum[action.type].apply(null, [mpi, next, action]);
|
|
458
|
-
}
|
|
459
|
-
return next(action);
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
export default prefillerWatcherMiddleware;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { MiddlewareAPI, Dispatch } from "redux";
|
|
2
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
3
|
-
import { generatePath } from "react-router-dom";
|
|
4
|
-
import { getConfig } from "../../config";
|
|
5
|
-
import { ActionsType } from "../../types/Actions.type";
|
|
6
|
-
import { StateType } from "../../types/State.type";
|
|
7
|
-
import {
|
|
8
|
-
INIT_INPUTS,
|
|
9
|
-
ADD_MULTIPLE_OCCURENCY,
|
|
10
|
-
DELETE_MULTIPLE_OCCURENCY,
|
|
11
|
-
UPDATE_OPTION_INPUT,
|
|
12
|
-
UPDATE_VARIABLE_INPUT,
|
|
13
|
-
} from "../constants/inputs";
|
|
14
|
-
import { ENABLE_SMARTSCRIPT } from "../constants/smartscript";
|
|
15
|
-
import { PathReader } from "../../libs/PathReader";
|
|
16
|
-
import { initSmartscriptTriggersAction } from "../actions/smartscript";
|
|
17
|
-
import { updateOptionAction, updateVariableAction } from "../actions/inputs";
|
|
18
|
-
|
|
19
|
-
let iframe: HTMLIFrameElement | null = null;
|
|
20
|
-
|
|
21
|
-
const watchEnableSmartScript = (
|
|
22
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
23
|
-
next: Dispatch,
|
|
24
|
-
action: WatcherActions
|
|
25
|
-
) => {
|
|
26
|
-
next(action);
|
|
27
|
-
|
|
28
|
-
// Creating iframe
|
|
29
|
-
iframe = document.createElement("iframe");
|
|
30
|
-
iframe.id = "lp-smartscript";
|
|
31
|
-
iframe.setAttribute(
|
|
32
|
-
"style",
|
|
33
|
-
"position: absolute; width:0; height:0; border:0;"
|
|
34
|
-
);
|
|
35
|
-
const { permalink, prefix } = mpi.getState().app.meta;
|
|
36
|
-
const { uniqid } = mpi.getState().app.instance;
|
|
37
|
-
const { modelVersion } = new PathReader(mpi.getState());
|
|
38
|
-
|
|
39
|
-
if (getConfig().router.smartscriptPath) {
|
|
40
|
-
// Generating path
|
|
41
|
-
const path = generatePath(getConfig().router.smartscriptPath, {
|
|
42
|
-
permalink,
|
|
43
|
-
prefix: prefix.trim().length > 0 ? prefix : undefined,
|
|
44
|
-
uniqid: uniqid.trim().length > 0 ? uniqid : undefined,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
iframe.src = `${window.location.protocol}//${window.location.host}${path}${
|
|
48
|
-
modelVersion ? `?version=${modelVersion}` : ""
|
|
49
|
-
}`;
|
|
50
|
-
} else {
|
|
51
|
-
iframe.src = `${window.location.protocol}//${
|
|
52
|
-
window.location.host
|
|
53
|
-
}/contrats/${permalink}/smartscript/${uniqid || ""}${
|
|
54
|
-
modelVersion ? `?version=${modelVersion}` : ""
|
|
55
|
-
}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Checking if it's a new instance
|
|
59
|
-
const isNewInstance = !(
|
|
60
|
-
typeof uniqid === "string" && uniqid.trim().length > 0
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
// Initiating triggers
|
|
64
|
-
iframe.onload = () => {
|
|
65
|
-
iframe?.contentWindow?.initTriggers?.(
|
|
66
|
-
(triggers, actions) => {
|
|
67
|
-
mpi.dispatch(initSmartscriptTriggersAction(triggers));
|
|
68
|
-
if (Array.isArray(actions)) {
|
|
69
|
-
actions.forEach((_action) => {
|
|
70
|
-
mpi.dispatch(_action);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
cloneDeep(mpi.getState().inputs),
|
|
75
|
-
isNewInstance
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
document.body.append(iframe);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Watches option input update
|
|
84
|
-
* @param mpi MiddlewareAPI
|
|
85
|
-
* @param next Dispatch function
|
|
86
|
-
* @param action Actions
|
|
87
|
-
*/
|
|
88
|
-
const watchUpdateOptionInput = (
|
|
89
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
90
|
-
next: Dispatch,
|
|
91
|
-
action: ActionsType.Inputs.updateOptionInput
|
|
92
|
-
) => {
|
|
93
|
-
next(action);
|
|
94
|
-
|
|
95
|
-
// Getting inputs
|
|
96
|
-
const state = mpi.getState();
|
|
97
|
-
|
|
98
|
-
const { id } = action;
|
|
99
|
-
|
|
100
|
-
if (state.smartscript.triggers.options.includes(id)) {
|
|
101
|
-
try {
|
|
102
|
-
const actions = iframe?.contentWindow?.triggerListeners(
|
|
103
|
-
"option",
|
|
104
|
-
id,
|
|
105
|
-
cloneDeep(state.inputs)
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
if (Array.isArray(actions)) {
|
|
109
|
-
actions.forEach((_action) => {
|
|
110
|
-
mpi.dispatch(_action);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
} catch (e) {
|
|
114
|
-
// eslint-disable-next-line no-console
|
|
115
|
-
console.error(e);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Watches variable input update
|
|
122
|
-
* @param mpi MiddlewareAPI
|
|
123
|
-
* @param next Dispatch function
|
|
124
|
-
* @param action Actions
|
|
125
|
-
*/
|
|
126
|
-
const watchUpdateVariableInput = (
|
|
127
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
128
|
-
next: Dispatch,
|
|
129
|
-
action: ActionsType.Inputs.updateVariableInput
|
|
130
|
-
) => {
|
|
131
|
-
next(action);
|
|
132
|
-
|
|
133
|
-
// Getting inputs
|
|
134
|
-
const state = mpi.getState();
|
|
135
|
-
|
|
136
|
-
const { id } = action;
|
|
137
|
-
|
|
138
|
-
if (state.smartscript.triggers.variables.includes(id)) {
|
|
139
|
-
try {
|
|
140
|
-
const actions = iframe?.contentWindow?.triggerListeners(
|
|
141
|
-
"variable",
|
|
142
|
-
id,
|
|
143
|
-
cloneDeep(state.inputs)
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
if (Array.isArray(actions)) {
|
|
147
|
-
actions.forEach((_action) => {
|
|
148
|
-
mpi.dispatch(_action);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
// eslint-disable-next-line no-console
|
|
153
|
-
console.error(e);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Watches inputs init
|
|
160
|
-
* @param mpi MiddlewareAPI
|
|
161
|
-
* @param next Dispatch function
|
|
162
|
-
* @param action INIT_INPUT action
|
|
163
|
-
*/
|
|
164
|
-
const watchInitInputs = (
|
|
165
|
-
mpi: MiddlewareAPI<Dispatch, StateType>,
|
|
166
|
-
next: Dispatch,
|
|
167
|
-
action: ActionsType.Inputs.initInputs
|
|
168
|
-
) => {
|
|
169
|
-
next(action);
|
|
170
|
-
|
|
171
|
-
if (!iframe) return;
|
|
172
|
-
|
|
173
|
-
const { inputs } = action;
|
|
174
|
-
|
|
175
|
-
Object.keys(inputs.options).forEach((id) => {
|
|
176
|
-
inputs.options[id].forEach((value, index) => {
|
|
177
|
-
watchUpdateOptionInput(
|
|
178
|
-
mpi,
|
|
179
|
-
next,
|
|
180
|
-
updateOptionAction(parseInt(id, 10), value, index)
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
Object.keys(inputs.variables).forEach((id) => {
|
|
186
|
-
inputs.variables[id].forEach((value, index) => {
|
|
187
|
-
watchUpdateVariableInput(
|
|
188
|
-
mpi,
|
|
189
|
-
next,
|
|
190
|
-
updateVariableAction(parseInt(id, 10), value, index)
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
export type WatcherActions =
|
|
197
|
-
| ActionsType.SmartScript.enableSmartScript
|
|
198
|
-
| ActionsType.Inputs.updateOptionInput
|
|
199
|
-
| ActionsType.Inputs.updateVariableInput;
|
|
200
|
-
|
|
201
|
-
// Enumerating watchers
|
|
202
|
-
const watchersEnum: Record<
|
|
203
|
-
string,
|
|
204
|
-
(mpi: MiddlewareAPI<Dispatch, StateType>, next: Dispatch, action: any) => void
|
|
205
|
-
> = {
|
|
206
|
-
[ENABLE_SMARTSCRIPT]: watchEnableSmartScript,
|
|
207
|
-
[UPDATE_OPTION_INPUT]: watchUpdateOptionInput,
|
|
208
|
-
[UPDATE_VARIABLE_INPUT]: watchUpdateVariableInput,
|
|
209
|
-
[ADD_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
|
|
210
|
-
[DELETE_MULTIPLE_OCCURENCY]: watchUpdateOptionInput,
|
|
211
|
-
[INIT_INPUTS]: watchInitInputs,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* SmartScript Middleware
|
|
216
|
-
* @param mpi MiddlewareAPI
|
|
217
|
-
* @param next Dispatch function
|
|
218
|
-
* @param action Actions
|
|
219
|
-
*/
|
|
220
|
-
const smartscriptMiddleware =
|
|
221
|
-
(mpi: MiddlewareAPI) => (next: Dispatch) => (action: WatcherActions) => {
|
|
222
|
-
if (Object.prototype.hasOwnProperty.call(watchersEnum, action.type)) {
|
|
223
|
-
return watchersEnum[action.type].apply(null, [mpi, next, action]);
|
|
224
|
-
}
|
|
225
|
-
return next(action);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
export default smartscriptMiddleware;
|