@oneblink/sdk-core 4.1.0 → 4.2.0-beta.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.
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const __1 = require("..");
|
|
7
7
|
const typeCastService_1 = require("../typeCastService");
|
|
8
8
|
const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
|
|
9
|
+
const formElementsService_1 = require("../formElementsService");
|
|
9
10
|
const fnMap = {
|
|
10
11
|
'>': (lhs, rhs) => lhs > rhs,
|
|
11
12
|
'>=': (lhs, rhs) => lhs >= rhs,
|
|
@@ -81,6 +82,30 @@ function evaluateConditionalPredicate({ predicate, formElementsCtrl, }) {
|
|
|
81
82
|
? predicateElement
|
|
82
83
|
: undefined;
|
|
83
84
|
}
|
|
85
|
+
case 'REPEATABLESET': {
|
|
86
|
+
const { formElementWithName: repeatableSetElement, value: repeatableSetValue, } = getElementAndValue(formElementsCtrl, predicate.elementId);
|
|
87
|
+
if (!repeatableSetElement) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (repeatableSetElement.type !== 'repeatableSet' ||
|
|
91
|
+
!Array.isArray(repeatableSetValue)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (const entry of repeatableSetValue) {
|
|
95
|
+
const result = evaluateConditionalPredicate({
|
|
96
|
+
predicate: predicate.repeatableSetPredicate,
|
|
97
|
+
formElementsCtrl: {
|
|
98
|
+
model: entry,
|
|
99
|
+
flattenedElements: (0, formElementsService_1.flattenFormElements)(repeatableSetElement.elements),
|
|
100
|
+
parentFormElementsCtrl: formElementsCtrl,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
if (result) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
84
109
|
case 'OPTIONS':
|
|
85
110
|
default: {
|
|
86
111
|
const optionsPredicateElement = __1.typeCastService.formElements.toOptionsElement(predicateElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AACA,0BAAoC;AACpC,wDAAiD;AAEjD,gHAAuF;
|
|
1
|
+
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AACA,0BAAoC;AACpC,wDAAiD;AAEjD,gHAAuF;AACvF,gEAA4D;AAE5D,MAAM,KAAK,GAAG;IACZ,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;IAC5C,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,KAAK,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG;IAChD,IAAI,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG;IAC9C,GAAG,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG;CAC7C,CAAA;AAED,SAAS,kBAAkB,CACzB,gBAAkC,EAClC,SAAiB;IAEjB,MAAM,WAAW,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CACzD,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,SAAS,CAC9C,CAAA;IACD,IAAI,WAAW,EAAE;QACf,MAAM,mBAAmB,GAAG,8BAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QACpE,IAAI,mBAAmB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BACA,OAAM;aACP;YAED,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE;gBACtC,MAAM,MAAM,GAAG,4BAA4B,CAAC;oBAC1C,SAAS,EAAE,SAAS,CAAC,sBAAsB;oBAC3C,gBAAgB,EAAE;wBAChB,KAAK,EAAE,KAAK;wBACZ,iBAAiB,EAAE,IAAA,yCAAmB,EACpC,oBAAoB,CAAC,QAAQ,CAC9B;wBACD,sBAAsB,EAAE,gBAAgB;qBACzC;iBACF,CAAC,CAAA;gBAEF,IAAI,MAAM,EAAE;oBACV,OAAO,MAAM,CAAA;iBACd;aACF;YACD,OAAM;SACP;QACD,KAAK,SAAS,CAAC;QACf,OAAO,CAAC,CAAC;YACP,MAAM,uBAAuB,GAC3B,mBAAe,CAAC,YAAY,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;YACjE,IAAI,CAAC,uBAAuB,EAAE;gBAC5B,OAAO,SAAS,CAAA;aACjB;YAED,kEAAkE;YAClE,4BAA4B;YAC5B,uDAAuD;YACvD,qCAAqC;YACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE;gBACnD,OAAO,uBAAuB,CAAC,WAAW,KAAK,SAAS;oBACtD,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;iBAAM;gBACL,OAAO,IAAA,6CAAmC,EAAC;oBACzC,SAAS;oBACT,cAAc;oBACd,gBAAgB,EAAE,uBAAuB;iBAC1C,CAAC;oBACA,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,SAAS,CAAA;aACd;SACF;KACF;AACH,CAAC;AA/HD,+CA+HC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { typeCastService } from '..'\nimport { formElements } from '../typeCastService'\nimport { FormElementsCtrl } from '../types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { flattenFormElements } from '../formElementsService'\n\nconst fnMap = {\n '>': (lhs: number, rhs: number) => lhs > rhs,\n '>=': (lhs: number, rhs: number) => lhs >= rhs,\n '===': (lhs: number, rhs: number) => lhs === rhs,\n '!==': (lhs: number, rhs: number) => lhs !== rhs,\n '<=': (lhs: number, rhs: number) => lhs <= rhs,\n '<': (lhs: number, rhs: number) => lhs < rhs,\n}\n\nfunction getElementAndValue(\n formElementsCtrl: FormElementsCtrl,\n elementId: string,\n): { formElementWithName?: FormTypes.FormElementWithName; value?: unknown } {\n const formElement = formElementsCtrl.flattenedElements.find(\n (formElement) => formElement.id === elementId,\n )\n if (formElement) {\n const formElementWithName = formElements.toNamedElement(formElement)\n if (formElementWithName) {\n return {\n formElementWithName,\n value: formElementsCtrl.model[formElementWithName.name],\n }\n }\n } else if (formElementsCtrl.parentFormElementsCtrl) {\n return getElementAndValue(\n formElementsCtrl.parentFormElementsCtrl,\n elementId,\n )\n }\n return {}\n}\n\nexport default function evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n}: {\n predicate: ConditionTypes.ConditionalPredicate\n formElementsCtrl: FormElementsCtrl\n}): FormTypes.FormElementWithName | undefined {\n const { formElementWithName: predicateElement, value: predicateValue } =\n getElementAndValue(formElementsCtrl, predicate.elementId)\n if (!predicateElement) {\n return\n }\n switch (predicate.type) {\n case 'VALUE': {\n return !predicate.hasValue === !predicateValue\n ? predicateElement\n : undefined\n }\n case 'NUMERIC': {\n // if the operator fn doesn't exist, hide the control\n const operatorFn = fnMap[predicate.operator]\n if (!operatorFn) return undefined\n\n const lhs = Number.parseFloat(predicateValue as string)\n // if left is not a number, hide the control\n if (isNaN(lhs)) return undefined\n\n let rhsValue = NaN\n switch (predicate.compareWith) {\n case 'ELEMENT': {\n const { value: comparisonValue } = getElementAndValue(\n formElementsCtrl,\n predicate.value,\n )\n rhsValue =\n comparisonValue === 'string'\n ? Number.parseFloat(comparisonValue)\n : (comparisonValue as number)\n break\n }\n case 'VALUE':\n default: {\n rhsValue = predicate.value\n break\n }\n }\n\n const rhs =\n typeof rhsValue === 'string' ? Number.parseFloat(rhsValue) : rhsValue\n\n // if right is not a number, hide the control\n if (isNaN(rhs)) return undefined\n\n return operatorFn(lhs, rhs) ? predicateElement : undefined\n }\n case 'BETWEEN': {\n const value = Number.parseFloat(predicateValue as string)\n if (Number.isNaN(value)) {\n return undefined\n }\n\n return value >= predicate.min && value <= predicate.max\n ? predicateElement\n : undefined\n }\n case 'REPEATABLESET': {\n const {\n formElementWithName: repeatableSetElement,\n value: repeatableSetValue,\n } = getElementAndValue(formElementsCtrl, predicate.elementId)\n\n if (!repeatableSetElement) {\n return\n }\n\n if (\n repeatableSetElement.type !== 'repeatableSet' ||\n !Array.isArray(repeatableSetValue)\n ) {\n return\n }\n\n for (const entry of repeatableSetValue) {\n const result = evaluateConditionalPredicate({\n predicate: predicate.repeatableSetPredicate,\n formElementsCtrl: {\n model: entry,\n flattenedElements: flattenFormElements(\n repeatableSetElement.elements,\n ),\n parentFormElementsCtrl: formElementsCtrl,\n },\n })\n\n if (result) {\n return result\n }\n }\n return\n }\n case 'OPTIONS':\n default: {\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return undefined\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(optionsPredicateElement.options)) {\n return optionsPredicateElement.optionsType !== 'DYNAMIC'\n ? predicateElement\n : undefined\n } else {\n return evaluateConditionalOptionsPredicate({\n predicate,\n predicateValue,\n predicateElement: optionsPredicateElement,\n })\n ? predicateElement\n : undefined\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/sdk-core",
|
|
3
3
|
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0-beta.1",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@microsoft/eslint-plugin-sdl": "^0.2.0",
|
|
11
|
-
"@oneblink/release-cli": "^2.0.
|
|
11
|
+
"@oneblink/release-cli": "^2.0.3",
|
|
12
12
|
"@oneblink/types": "github:oneblink/types",
|
|
13
13
|
"@types/jest": "^29.5.0",
|
|
14
14
|
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"format": "prettier --write .",
|
|
57
57
|
"prepare": "npm run build",
|
|
58
58
|
"pretest": "npm run fixpack && npm run eslint",
|
|
59
|
-
"release": "
|
|
59
|
+
"release": "oneblink-release --no-name",
|
|
60
60
|
"start": "tsc-watch",
|
|
61
61
|
"test": "jest",
|
|
62
62
|
"types": "npm install --save-dev github:oneblink/types",
|