@oneblink/sdk-core 7.3.2 → 7.4.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.
- package/dist/conditionalLogicService/conditionallyShowElement.d.ts +1 -1
- package/dist/conditionalLogicService/conditionallyShowElement.js.map +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.d.ts +1 -1
- package/dist/conditionalLogicService/conditionallyShowOption.js.map +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.d.ts +1 -1
- package/dist/conditionalLogicService/evaluateConditionalPredicate.js.map +1 -1
- package/dist/conditionalLogicService/generateFormElementsConditionallyShown.js.map +1 -1
- package/dist/{types/index.js → conditionalLogicService/types.js} +1 -1
- package/dist/conditionalLogicService/types.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/sharepointService.d.ts +5 -0
- package/dist/sharepointService.js +87 -0
- package/dist/sharepointService.js.map +1 -0
- package/dist/types/resource-definitions.d.ts +16 -0
- package/dist/types/resource-definitions.js +3 -0
- package/dist/types/resource-definitions.js.map +1 -0
- package/package.json +2 -1
- package/dist/types/index.js.map +0 -1
- /package/dist/{types/index.d.ts → conditionalLogicService/types.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, ConditionTypes } from '@oneblink/types';
|
|
2
|
-
import { FormElementsCtrl } from '
|
|
2
|
+
import { FormElementsCtrl } from './types';
|
|
3
3
|
export declare function conditionallyShowByPredicate(formElementsCtrl: FormElementsCtrl, predicate: ConditionTypes.ConditionalPredicate, elementsEvaluated: Array<{
|
|
4
4
|
id: string;
|
|
5
5
|
label: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":";;;;;;AAEA,kGAAyE;AAEzE,MAAM,qBAAqB,GAAG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AAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;KAC3D;AACH,CAAC;AArDD,2CAqDC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from '
|
|
1
|
+
{"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":";;;;;;AAEA,kGAAyE;AAEzE,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAC1D,CAAA;IACH,CAAC,CAAC,CAAA;IACF,IACE,aAAa;QACb,CAAC,aAAa,CAAC,IAAI,KAAK,MAAM,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,CAAC,EACnE;QACA,OAAO;YACL,aAAa;YACb,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,aAAa,CAAC;SAC1D,CAAA;KACF;IACD,OAAO,EAAE,CAAA;AACX,CAAC,CAAA;AAED,SAAgB,4BAA4B,CAC1C,gBAAkC,EAClC,SAA8C,EAC9C,iBAAuD;IAEvD,MAAM,gBAAgB,GAAG,IAAA,sCAA4B,EAAC;QACpD,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAA;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,KAAK,CAAA;KACb;IAED,2DAA2D;IAC3D,4DAA4D;IAC5D,qDAAqD;IACrD,uCAAuC;IACvC,MAAM,kBAAkB,GAAG,qBAAqB,CAC9C,gBAAgB,EAChB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AAoE;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC,gBAAgB,EAAE,SAAS,EAAE;YAC/D,GAAG,iBAAiB;SACrB,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,iBAAiB,CAAC,sCAAsC,EAAE;QAC5D,OAAO,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;KAC5D;SAAM;QACL,OAAO,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;KAC3D;AACH,CAAC;AArDD,2CAqDC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport evaluateConditionalPredicate from './evaluateConditionalPredicate'\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nexport function conditionallyShowByPredicate(\n formElementsCtrl: FormElementsCtrl,\n predicate: ConditionTypes.ConditionalPredicate,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n const predicateElement = evaluateConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n\n if (!predicateElement) {\n return false\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement(formElementsCtrl, parentFormElement, [\n ...elementsEvaluated,\n ])\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return conditionallyShowElement(\n formElementsCtrl,\n predicateElement,\n elementsEvaluated,\n )\n}\n\nexport default function conditionallyShowElement(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElement,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n 'label' in elementToEvaluate\n ? elementToEvaluate.label\n : elementToEvaluate.name,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.ConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate(formElementsCtrl, predicate, [\n ...elementsEvaluated,\n ])\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FormTypes } from '@oneblink/types';
|
|
2
|
-
import { FormElementsCtrl } from '
|
|
2
|
+
import { FormElementsCtrl } from './types';
|
|
3
3
|
export type ShouldShowOption = 'SHOW' | 'HIDE' | 'LOADING_DYNAMIC_DEPENDENCY' | 'LOADING_STATIC_DEPENDENCY';
|
|
4
4
|
export default function conditionallyShowOption(formElementsCtrl: FormElementsCtrl, elementToEvaluate: FormTypes.FormElementWithOptions, optionToEvaluate: FormTypes.ChoiceElementOption, optionsEvaluated: string[]): ShouldShowOption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AACA,gHAAuF;AAEvF,0BAAoC;AACpC,0FAAiE;AAQjE,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAAqD,EACrD,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,MAAM,CAAC,EACjE;QACA,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAA,6CAAmC,EAAC;QACzC,SAAS,EAAE;YACT,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B;QACD,cAAc,EAAE,MAAM;QACtB,gBAAgB;KACjB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,kCAAkC,GAAG,CACzC,gBAAkC,EAClC,SAAiD,EACjD,iBAA2B,EACT,EAAE;IACpB,iDAAiD;IACjD,gCAAgC;IAChC,IACE,CAAC,SAAS;QACV,CAAC,SAAS,CAAC,SAAS;QACpB,CAAC,SAAS,CAAC,SAAS;QACpB,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAC3B;QACA,OAAO,MAAM,CAAA;KACd;IACD,MA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tC,IAAI,yBAAyB,GAAG,KAAK,CAAA;IACrC,KAAK,MAAM,SAAS,IAAI,eAAe,EAAE;QACvC,MAAM,eAAe,GAAG,kCAAkC,CACxD,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;QACD,QAAQ,eAAe,EAAE;YACvB,KAAK,MAAM,CAAC,CAAC;gBACX,OAAO,MAAM,CAAA;aACd;YACD,KAAK,4BAA4B,CAAC,CAAC;gBACjC,0BAA0B,GAAG,IAAI,CAAA;gBACjC,MAAK;aACN;YACD,KAAK,2BAA2B,CAAC,CAAC;gBAChC,yBAAyB,GAAG,IAAI,CAAA;gBAChC,MAAK;aACN;SACF;KACF;IACD,IAAI,0BAA0B,EAAE;QAC9B,OAAO,4BAA4B,CAAA;KACpC;SAAM,IAAI,yBAAyB,EAAE;QACpC,OAAO,2BAA2B,CAAA;KACnC;SAAM;QACL,OAAO,MAAM,CAAA;KACd;AACH,CAAC;AApED,0CAoEC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { FormElementsCtrl } from '../types'\nimport { typeCastService } from '..'\nimport conditionallyShowElement from './conditionallyShowElement'\n\nexport type ShouldShowOption =\n | 'SHOW'\n | 'HIDE'\n | 'LOADING_DYNAMIC_DEPENDENCY'\n | 'LOADING_STATIC_DEPENDENCY'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: SubmissionTypes.S3SubmissionData['submission'],\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n predicateValue: values,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): ShouldShowOption => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return 'SHOW'\n }\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return 'HIDE'\n }\n }\n\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return 'HIDE'\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 const isLoadingPredicateElementsOptions = !Array.isArray(\n optionsPredicateElement.options,\n )\n if (isLoadingPredicateElementsOptions) {\n if (optionsPredicateElement.optionsType === 'DYNAMIC') {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else {\n return 'LOADING_STATIC_DEPENDENCY'\n }\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = optionsPredicateElement.options?.find(\n (o) => o.id === id,\n )\n if (!predicateOption) return 'HIDE'\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n optionsPredicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return 'HIDE'\n }\n\n // Check to see if the model has one of the valid values to show the element\n const shouldShow = handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n optionsPredicateElement,\n )\n return shouldShow ? 'SHOW' : 'HIDE'\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): ShouldShowOption {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return 'SHOW'\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n if (!validPredicates.length) return 'SHOW'\n\n let isLoadingDynamicDEPENDENCY = false\n let isLoadingStaticDEPENDENCY = false\n for (const predicate of validPredicates) {\n const predicateResult = conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n switch (predicateResult) {\n case 'SHOW': {\n return 'SHOW'\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n isLoadingDynamicDEPENDENCY = true\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n isLoadingStaticDEPENDENCY = true\n break\n }\n }\n }\n if (isLoadingDynamicDEPENDENCY) {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else if (isLoadingStaticDEPENDENCY) {\n return 'LOADING_STATIC_DEPENDENCY'\n } else {\n return 'HIDE'\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"conditionallyShowOption.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowOption.ts"],"names":[],"mappings":";;;;;AACA,gHAAuF;AAEvF,0BAAoC;AACpC,0FAAiE;AAQjE,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAAqD,EACrD,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,MAAM,CAAC,EACjE;QACA,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAA,6CAAmC,EAAC;QACzC,SAAS,EAAE;YACT,IAAI,EAAE,SAAS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M,IAAI,KAAK,CACb,sKAAsK,CACvK,CAAA;KACF;SAAM;QACL,gBAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAA;KAC3C;IACD,MAAM,eAAe,GAAG,CAAC,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAChE,CAAC,SAAS,EAAE,EAAE;QACZ,OAAO,sBAAsB,CAC3B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;IACH,CAAC,CACF,CAAA;IACD,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,OAAO,MAAM,CAAA;IAE1C,IAAI,0BAA0B,GAAG,KAAK,CAAA;IACtC,IAAI,yBAAyB,GAAG,KAAK,CAAA;IACrC,KAAK,MAAM,SAAS,IAAI,eAAe,EAAE;QACvC,MAAM,eAAe,GAAG,kCAAkC,CACxD,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;QACD,QAAQ,eAAe,EAAE;YACvB,KAAK,MAAM,CAAC,CAAC;gBACX,OAAO,MAAM,CAAA;aACd;YACD,KAAK,4BAA4B,CAAC,CAAC;gBACjC,0BAA0B,GAAG,IAAI,CAAA;gBACjC,MAAK;aACN;YACD,KAAK,2BAA2B,CAAC,CAAC;gBAChC,yBAAyB,GAAG,IAAI,CAAA;gBAChC,MAAK;aACN;SACF;KACF;IACD,IAAI,0BAA0B,EAAE;QAC9B,OAAO,4BAA4B,CAAA;KACpC;SAAM,IAAI,yBAAyB,EAAE;QACpC,OAAO,2BAA2B,CAAA;KACnC;SAAM;QACL,OAAO,MAAM,CAAA;KACd;AACH,CAAC;AApED,0CAoEC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService } from '..'\nimport conditionallyShowElement from './conditionallyShowElement'\n\nexport type ShouldShowOption =\n | 'SHOW'\n | 'HIDE'\n | 'LOADING_DYNAMIC_DEPENDENCY'\n | 'LOADING_STATIC_DEPENDENCY'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: SubmissionTypes.S3SubmissionData['submission'],\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n predicateValue: values,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): ShouldShowOption => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return 'SHOW'\n }\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return 'HIDE'\n }\n }\n\n const optionsPredicateElement =\n typeCastService.formElements.toOptionsElement(predicateElement)\n if (!optionsPredicateElement) {\n return 'HIDE'\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 const isLoadingPredicateElementsOptions = !Array.isArray(\n optionsPredicateElement.options,\n )\n if (isLoadingPredicateElementsOptions) {\n if (optionsPredicateElement.optionsType === 'DYNAMIC') {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else {\n return 'LOADING_STATIC_DEPENDENCY'\n }\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = optionsPredicateElement.options?.find(\n (o) => o.id === id,\n )\n if (!predicateOption) return 'HIDE'\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n optionsPredicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return 'HIDE'\n }\n\n // Check to see if the model has one of the valid values to show the element\n const shouldShow = handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n optionsPredicateElement,\n )\n return shouldShow ? 'SHOW' : 'HIDE'\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): ShouldShowOption {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return 'SHOW'\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n if (!validPredicates.length) return 'SHOW'\n\n let isLoadingDynamicDEPENDENCY = false\n let isLoadingStaticDEPENDENCY = false\n for (const predicate of validPredicates) {\n const predicateResult = conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n switch (predicateResult) {\n case 'SHOW': {\n return 'SHOW'\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n isLoadingDynamicDEPENDENCY = true\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n isLoadingStaticDEPENDENCY = true\n break\n }\n }\n }\n if (isLoadingDynamicDEPENDENCY) {\n return 'LOADING_DYNAMIC_DEPENDENCY'\n } else if (isLoadingStaticDEPENDENCY) {\n return 'LOADING_STATIC_DEPENDENCY'\n } else {\n return 'HIDE'\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, ConditionTypes } from '@oneblink/types';
|
|
2
|
-
import { FormElementsCtrl } from '
|
|
2
|
+
import { FormElementsCtrl } from './types';
|
|
3
3
|
export default function evaluateConditionalPredicate({ predicate, formElementsCtrl, }: {
|
|
4
4
|
predicate: ConditionTypes.ConditionalPredicate;
|
|
5
5
|
formElementsCtrl: FormElementsCtrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AAEA,0BAAyD;AACzD,gHAAuF;AACvF,yEAAyE;AACzE,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,GACvB,mBAAe,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAC1D,IAAI,mBAAmB,EAAE;YACvB,OAAO;gBACL,mBAAmB;gBACnB,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC;aACxD,CAAA;SACF;KACF;SAAM,IAAI,gBAAgB,CAAC,sBAAsB,EAAE;QAClD,OAAO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,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;AAjND,+CAiNC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from '../types'\nimport { typeCastService, formElementsService } from '..'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { conditionallyShowByPredicate } from './conditionallyShowElement'\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 =\n typeCastService.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 if (Array.isArray(predicateValue)) {\n return !predicate.hasValue === !predicateValue.length\n ? predicateElement\n : undefined\n }\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 = conditionallyShowByPredicate(\n {\n model: entry,\n flattenedElements: formElementsService.flattenFormElements(\n repeatableSetElement.elements,\n ),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.repeatableSetPredicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n }\n case 'FORM':\n if (predicate.predicate) {\n if (\n !predicateElement ||\n predicateElement.type !== 'form' ||\n !predicateElement.elements\n ) {\n return\n }\n const formModel = formElementsCtrl.model[predicateElement.name] as {\n [name: string]: unknown\n }\n const result = conditionallyShowByPredicate(\n {\n model: formModel,\n flattenedElements: flattenFormElements(predicateElement.elements),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.predicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n case 'ADDRESS_PROPERTY': {\n // Only element that should work as predicate element should be Point or Geoscape.\n if (\n !(\n predicateElement.type === 'pointAddress' ||\n predicateElement.type === 'geoscapeAddress'\n )\n ) {\n return\n }\n if (predicateValue && typeof predicateValue === 'object') {\n if (predicate.definition.property === 'STATE_EQUALITY') {\n // Validate that it has the properties we want, in case submission data\n // is incorrect but has the right element reference.\n if (\n 'addressDetails' in predicateValue &&\n predicateValue.addressDetails &&\n typeof predicateValue.addressDetails === 'object' &&\n 'stateTerritory' in predicateValue.addressDetails &&\n typeof predicateValue.addressDetails.stateTerritory === 'string'\n ) {\n const result =\n predicateValue.addressDetails.stateTerritory ===\n predicate.definition.value\n if (result) {\n return predicateElement\n }\n }\n return\n }\n // If the property isn't State Equality, we are checking Physical addresses. This only exists for Point.\n if (predicateElement.type === 'pointAddress') {\n // If the value is true, we only want to return the element for PO Boxes. If it's false, then we only want\n // to return element for non mail address addresses.\n if (\n 'dataset' in predicateValue &&\n typeof predicateValue.dataset === 'string'\n ) {\n const result = predicate.definition.value\n ? predicateValue.dataset === 'mailAddress'\n : predicateValue.dataset === 'GNAF'\n if (result) {\n return predicateElement\n }\n }\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"]}
|
|
1
|
+
{"version":3,"file":"evaluateConditionalPredicate.js","sourceRoot":"","sources":["../../src/conditionalLogicService/evaluateConditionalPredicate.ts"],"names":[],"mappings":";;;;;AAEA,0BAAyD;AACzD,gHAAuF;AACvF,yEAAyE;AACzE,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,GACvB,mBAAe,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAC1D,IAAI,mBAAmB,EAAE;YACvB,OAAO;gBACL,mBAAmB;gBACnB,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC;aACxD,CAA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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;AAjND,+CAiNC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { typeCastService, formElementsService } from '..'\nimport evaluateConditionalOptionsPredicate from './evaluateConditionalOptionsPredicate'\nimport { conditionallyShowByPredicate } from './conditionallyShowElement'\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 =\n typeCastService.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 if (Array.isArray(predicateValue)) {\n return !predicate.hasValue === !predicateValue.length\n ? predicateElement\n : undefined\n }\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 = conditionallyShowByPredicate(\n {\n model: entry,\n flattenedElements: formElementsService.flattenFormElements(\n repeatableSetElement.elements,\n ),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.repeatableSetPredicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n }\n case 'FORM':\n if (predicate.predicate) {\n if (\n !predicateElement ||\n predicateElement.type !== 'form' ||\n !predicateElement.elements\n ) {\n return\n }\n const formModel = formElementsCtrl.model[predicateElement.name] as {\n [name: string]: unknown\n }\n const result = conditionallyShowByPredicate(\n {\n model: formModel,\n flattenedElements: flattenFormElements(predicateElement.elements),\n parentFormElementsCtrl: formElementsCtrl,\n },\n predicate.predicate,\n [],\n )\n\n if (result) {\n return predicateElement\n }\n }\n return\n case 'ADDRESS_PROPERTY': {\n // Only element that should work as predicate element should be Point or Geoscape.\n if (\n !(\n predicateElement.type === 'pointAddress' ||\n predicateElement.type === 'geoscapeAddress'\n )\n ) {\n return\n }\n if (predicateValue && typeof predicateValue === 'object') {\n if (predicate.definition.property === 'STATE_EQUALITY') {\n // Validate that it has the properties we want, in case submission data\n // is incorrect but has the right element reference.\n if (\n 'addressDetails' in predicateValue &&\n predicateValue.addressDetails &&\n typeof predicateValue.addressDetails === 'object' &&\n 'stateTerritory' in predicateValue.addressDetails &&\n typeof predicateValue.addressDetails.stateTerritory === 'string'\n ) {\n const result =\n predicateValue.addressDetails.stateTerritory ===\n predicate.definition.value\n if (result) {\n return predicateElement\n }\n }\n return\n }\n // If the property isn't State Equality, we are checking Physical addresses. This only exists for Point.\n if (predicateElement.type === 'pointAddress') {\n // If the value is true, we only want to return the element for PO Boxes. If it's false, then we only want\n // to return element for non mail address addresses.\n if (\n 'dataset' in predicateValue &&\n typeof predicateValue.dataset === 'string'\n ) {\n const result = predicate.definition.value\n ? predicateValue.dataset === 'mailAddress'\n : predicateValue.dataset === 'GNAF'\n if (result) {\n return predicateElement\n }\n }\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLogicService/generateFormElementsConditionallyShown.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA4D;AAC5D,0FAAiE;AACjE,wFAEkC;AAClC,0BAAoC;AA8BpC,MAAM,8BAA8B,GAAG,CACrC,gBAAkC,EAClC,OAA8B,EAC9B,aAAwC,EACxC,EAAE;IACF,IAAI;QACF,OAAO,IAAA,kCAAwB,EAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;KAC/D;IAAC,OAAO,KAAK,EAAE;QACd,aAAa,IAAI,aAAa,CAAC,KAAc,CAAC,CAAA;QAC9C,OAAO,KAAK,CAAA;KACb;AACH,CAAC,CAAA;AAED,MAAM,6BAA6B,GAAG,CACpC,gBAAkC,EAClC,OAAyC,EACzC,MAAqC,EACrC,aAAwC,EACtB,EAAE;IACpB,IAAI;QACF,OAAO,IAAA,iCAAuB,EAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;KACtE;IAAC,OAAO,KAAK,EAAE;QACd,aAAa,IAAI,aAAa,CAAC,KAAc,CAAC,CAAA;QAC9C,OAAO,MAAM,CAAA;KACd;AACH,CAAC,CAAA;AAWD,MAAM,gDAAgD,GAAG,CAAC,EACxD,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,aAAa,GAGd,EAAkC,EAAE;IACnC,MAAM,gBAAgB,GAAG;QACvB,iBAAiB,EAAE,IAAA,yCAAmB,EAAC,YAAY,CAAC;QACpD,KAAK,EAAE,UAAU;QACjB,sBAAsB;KACvB,CAAA;IACD,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ACH,SAAgB,sCAAsC,CACpD,UAAoD;IAEpD,OAAO,gDAAgD,CAAC,UAAU,CAAC,CAAA;AACrE,CAAC;AAJD,wFAIC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from '../types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption, {\n ShouldShowOption,\n} from './conditionallyShowOption'\nimport { typeCastService } from '..'\n\nexport type FormElementsConditionallyShown = Record<\n string,\n FormElementConditionallyShown\n>\n\nexport type FormElementConditionallyShownElement = {\n type: 'formElement'\n isHidden: boolean\n options?: FormTypes.ChoiceElementOption[]\n dependencyIsLoading?: boolean\n}\n\nexport type FormElementConditionallyShown =\n | undefined\n | FormElementConditionallyShownElement\n | {\n type: 'formElements'\n isHidden: boolean\n formElements: FormElementsConditionallyShown | undefined\n }\n | {\n type: 'repeatableSet'\n isHidden: boolean\n entries: Record<string, FormElementsConditionallyShown | undefined>\n }\n\nexport type ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback: ErrorCallback | undefined,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback: ErrorCallback | undefined,\n): ShouldShowOption => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return 'HIDE'\n }\n}\n\nexport type FormElementsConditionallyShownParameters = {\n /** Form elements to evaluate */\n formElements: FormTypes.FormElement[]\n /** Current submission data */\n submission: SubmissionTypes.S3SubmissionData['submission']\n /** Optional callback for handling errors caught during the evaluation */\n errorCallback?: ErrorCallback\n}\n\nconst generateFormElementsConditionallyShownWithParent = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: FormElementsConditionallyShownParameters & {\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShownWithParent({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<SubmissionTypes.S3SubmissionData['submission']>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShownWithParent({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n const optionsElement =\n typeCastService.formElements.toOptionsElement(element)\n if (\n optionsElement &&\n optionsElement.conditionallyShowOptions &&\n Array.isArray(optionsElement.options)\n ) {\n const newOptions = []\n for (const option of optionsElement.options) {\n const optionPredicatesResult = handleConditionallyShowOption(\n formElementsCtrl,\n optionsElement,\n option,\n errorCallback,\n )\n switch (optionPredicatesResult) {\n case 'SHOW': {\n newOptions.push(option)\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n newOptions.push(option)\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n }\n }\n formElementConditionallyShown.options = newOptions\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\n/**\n * Given a form element and submission data, evaluate which elements are\n * currently shown. The function also takes an optional errorCallback for\n * handling errors caught during the evaluation.\n *\n * #### Example\n *\n * ```js\n * const formElementsConditionallyShown =\n * conditionalLogicService.generateFormElementsConditionallyShown({\n * submission: {\n * radio: ['hide'],\n * text: 'hidden text',\n * },\n * formElements: [\n * {\n * name: 'radio',\n * label: 'Radio',\n * type: 'radio',\n * required: false,\n * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * conditionallyShow: false,\n * options: [\n * {\n * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',\n * label: 'Show',\n * value: 'show',\n * },\n * {\n * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',\n * label: 'Hide',\n * value: 'Hide',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * },\n * {\n * name: 'text',\n * label: 'Text',\n * type: 'text',\n * required: false,\n * id: '8fbddb41-348d-494c-904b-56a2c4361f13',\n * requiresAllConditionallyShowPredicates: false,\n * conditionallyShow: true,\n * conditionallyShowPredicates: [\n * {\n * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],\n * type: 'OPTIONS',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * },\n * ],\n * parentFormElementsCtrl: undefined,\n * errorCallback: (error) => {\n * //do something with the error here\n * console.error(error)\n * },\n * })\n * ```\n *\n * The above example returns an object like below\n *\n * ```json\n * {\n * \"radio\": {\n * \"isHidden\": false,\n * \"type\": \"formElement\"\n * },\n * \"text\": {\n * \"isHidden\": true,\n * \"type\": \"formElement\"\n * }\n * }\n * ```\n *\n * @param parameters\n * @returns\n */\nexport function generateFormElementsConditionallyShown(\n parameters: FormElementsConditionallyShownParameters,\n): FormElementsConditionallyShown {\n return generateFormElementsConditionallyShownWithParent(parameters)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generateFormElementsConditionallyShown.js","sourceRoot":"","sources":["../../src/conditionalLogicService/generateFormElementsConditionallyShown.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA4D;AAC5D,0FAAiE;AACjE,wFAEkC;AAClC,0BAAoC;AA8BpC,MAAM,8BAA8B,GAAG,CACrC,gBAAkC,EAClC,OAA8B,EAC9B,aAAwC,EACxC,EAAE;IACF,IAAI;QACF,OAAO,IAAA,kCA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AAa,CACd,CAAA;4BACD,QAAQ,sBAAsB,EAAE;gCAC9B,KAAK,MAAM,CAAC,CAAC;oCACX,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;oCACvB,MAAK;iCACN;gCACD,KAAK,2BAA2B,CAAC,CAAC;oCAChC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;oCACvB,6BAA6B,CAAC,mBAAmB,GAAG,IAAI,CAAA;oCACxD,MAAK;iCACN;gCACD,KAAK,4BAA4B,CAAC,CAAC;oCACjC,6BAA6B,CAAC,mBAAmB,GAAG,IAAI,CAAA;oCACxD,MAAK;iCACN;6BACF;yBACF;wBACD,6BAA6B,CAAC,OAAO,GAAG,UAAU,CAAA;qBACnD;iBACF;gBAED,8BAA8B,CAAC,OAAO,CAAC,IAAI,CAAC;oBAC1C,6BAA6B,CAAA;aAChC;SACF;QAED,OAAO,8BAA8B,CAAA;IACvC,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,SAAgB,sCAAsC,CACpD,UAAoD;IAEpD,OAAO,gDAAgD,CAAC,UAAU,CAAC,CAAA;AACrE,CAAC;AAJD,wFAIC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types'\nimport { flattenFormElements } from '../formElementsService'\nimport conditionallyShowElement from './conditionallyShowElement'\nimport conditionallyShowOption, {\n ShouldShowOption,\n} from './conditionallyShowOption'\nimport { typeCastService } from '..'\n\nexport type FormElementsConditionallyShown = Record<\n string,\n FormElementConditionallyShown\n>\n\nexport type FormElementConditionallyShownElement = {\n type: 'formElement'\n isHidden: boolean\n options?: FormTypes.ChoiceElementOption[]\n dependencyIsLoading?: boolean\n}\n\nexport type FormElementConditionallyShown =\n | undefined\n | FormElementConditionallyShownElement\n | {\n type: 'formElements'\n isHidden: boolean\n formElements: FormElementsConditionallyShown | undefined\n }\n | {\n type: 'repeatableSet'\n isHidden: boolean\n entries: Record<string, FormElementsConditionallyShown | undefined>\n }\n\nexport type ErrorCallback = (error: Error) => void\n\nconst handleConditionallyShowElement = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElement,\n errorCallback: ErrorCallback | undefined,\n) => {\n try {\n return conditionallyShowElement(formElementsCtrl, element, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return false\n }\n}\n\nconst handleConditionallyShowOption = (\n formElementsCtrl: FormElementsCtrl,\n element: FormTypes.FormElementWithOptions,\n option: FormTypes.ChoiceElementOption,\n errorCallback: ErrorCallback | undefined,\n): ShouldShowOption => {\n try {\n return conditionallyShowOption(formElementsCtrl, element, option, [])\n } catch (error) {\n errorCallback && errorCallback(error as Error)\n return 'HIDE'\n }\n}\n\nexport type FormElementsConditionallyShownParameters = {\n /** Form elements to evaluate */\n formElements: FormTypes.FormElement[]\n /** Current submission data */\n submission: SubmissionTypes.S3SubmissionData['submission']\n /** Optional callback for handling errors caught during the evaluation */\n errorCallback?: ErrorCallback\n}\n\nconst generateFormElementsConditionallyShownWithParent = ({\n formElements,\n submission,\n parentFormElementsCtrl,\n errorCallback,\n}: FormElementsConditionallyShownParameters & {\n parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl']\n}): FormElementsConditionallyShown => {\n const formElementsCtrl = {\n flattenedElements: flattenFormElements(formElements),\n model: submission,\n parentFormElementsCtrl,\n }\n return formElementsCtrl.flattenedElements.reduce<FormElementsConditionallyShown>(\n (formElementsConditionallyShown, element) => {\n switch (element.type) {\n case 'section':\n case 'page': {\n const formElementConditionallyShown =\n formElementsConditionallyShown[element.id]\n const isHidden = formElementConditionallyShown\n ? formElementConditionallyShown.isHidden\n : !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n )\n\n formElementsConditionallyShown[element.id] = {\n type: 'formElement',\n isHidden,\n }\n\n // If the parent element is hidden, hide all the child elements\n if (isHidden) {\n element.elements.forEach((childElement) => {\n switch (childElement.type) {\n case 'section':\n case 'page': {\n formElementsConditionallyShown[childElement.id] = {\n type: 'formElement',\n isHidden: true,\n }\n break\n }\n default: {\n formElementsConditionallyShown[childElement.name] = {\n type: 'formElement',\n isHidden: true,\n }\n }\n }\n })\n }\n break\n }\n case 'infoPage':\n case 'form': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const nestedModel = submission[element.name] as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'formElements',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n formElements: generateFormElementsConditionallyShownWithParent({\n formElements: element.elements || [],\n submission: nestedModel || {},\n parentFormElementsCtrl: formElementsCtrl,\n }),\n }\n break\n }\n case 'repeatableSet': {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const entries = formElementsCtrl.model[element.name] as\n | Array<SubmissionTypes.S3SubmissionData['submission']>\n | undefined\n formElementsConditionallyShown[element.name] = {\n type: 'repeatableSet',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n entries: (entries || []).reduce(\n (\n result: Record<\n string,\n FormElementsConditionallyShown | undefined\n >,\n entry,\n index,\n ) => {\n result[index.toString()] =\n generateFormElementsConditionallyShownWithParent({\n formElements: element.elements,\n submission: entry,\n parentFormElementsCtrl: formElementsCtrl,\n })\n return result\n },\n {},\n ),\n }\n break\n }\n default: {\n if (formElementsConditionallyShown[element.name]) {\n break\n }\n const formElementConditionallyShown: FormElementConditionallyShown = {\n type: 'formElement',\n isHidden: !handleConditionallyShowElement(\n formElementsCtrl,\n element,\n errorCallback,\n ),\n }\n\n if (!formElementConditionallyShown.isHidden) {\n const optionsElement =\n typeCastService.formElements.toOptionsElement(element)\n if (\n optionsElement &&\n optionsElement.conditionallyShowOptions &&\n Array.isArray(optionsElement.options)\n ) {\n const newOptions = []\n for (const option of optionsElement.options) {\n const optionPredicatesResult = handleConditionallyShowOption(\n formElementsCtrl,\n optionsElement,\n option,\n errorCallback,\n )\n switch (optionPredicatesResult) {\n case 'SHOW': {\n newOptions.push(option)\n break\n }\n case 'LOADING_STATIC_DEPENDENCY': {\n newOptions.push(option)\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n case 'LOADING_DYNAMIC_DEPENDENCY': {\n formElementConditionallyShown.dependencyIsLoading = true\n break\n }\n }\n }\n formElementConditionallyShown.options = newOptions\n }\n }\n\n formElementsConditionallyShown[element.name] =\n formElementConditionallyShown\n }\n }\n\n return formElementsConditionallyShown\n },\n {},\n )\n}\n\n/**\n * Given a form element and submission data, evaluate which elements are\n * currently shown. The function also takes an optional errorCallback for\n * handling errors caught during the evaluation.\n *\n * #### Example\n *\n * ```js\n * const formElementsConditionallyShown =\n * conditionalLogicService.generateFormElementsConditionallyShown({\n * submission: {\n * radio: ['hide'],\n * text: 'hidden text',\n * },\n * formElements: [\n * {\n * name: 'radio',\n * label: 'Radio',\n * type: 'radio',\n * required: false,\n * id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * conditionallyShow: false,\n * options: [\n * {\n * id: '9a44e15a-5929-419d-825e-b3dc0a29591f',\n * label: 'Show',\n * value: 'show',\n * },\n * {\n * id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',\n * label: 'Hide',\n * value: 'Hide',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * buttons: false,\n * optionsType: 'CUSTOM',\n * conditionallyShowOptions: false,\n * },\n * {\n * name: 'text',\n * label: 'Text',\n * type: 'text',\n * required: false,\n * id: '8fbddb41-348d-494c-904b-56a2c4361f13',\n * requiresAllConditionallyShowPredicates: false,\n * conditionallyShow: true,\n * conditionallyShowPredicates: [\n * {\n * elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',\n * optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],\n * type: 'OPTIONS',\n * },\n * ],\n * readOnly: false,\n * isDataLookup: false,\n * isElementLookup: false,\n * },\n * ],\n * parentFormElementsCtrl: undefined,\n * errorCallback: (error) => {\n * //do something with the error here\n * console.error(error)\n * },\n * })\n * ```\n *\n * The above example returns an object like below\n *\n * ```json\n * {\n * \"radio\": {\n * \"isHidden\": false,\n * \"type\": \"formElement\"\n * },\n * \"text\": {\n * \"isHidden\": true,\n * \"type\": \"formElement\"\n * }\n * }\n * ```\n *\n * @param parameters\n * @returns\n */\nexport function generateFormElementsConditionallyShown(\n parameters: FormElementsConditionallyShownParameters,\n): FormElementsConditionallyShown {\n return generateFormElementsConditionallyShownWithParent(parameters)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/conditionalLogicService/types.ts"],"names":[],"mappings":"","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nexport type FormElementsCtrl = {\n model: SubmissionTypes.S3SubmissionData['submission']\n flattenedElements: FormTypes.FormElement[]\n parentFormElementsCtrl?: FormElementsCtrl\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * as resourceDefinitionTypes from './types/resource-definitions';
|
|
1
2
|
/**
|
|
2
3
|
* ## Form Elements Service
|
|
3
4
|
*
|
|
@@ -98,3 +99,13 @@ export * as fileUploadService from './fileUploadService';
|
|
|
98
99
|
* ```
|
|
99
100
|
*/
|
|
100
101
|
export * as webhookSubscriptionService from './webhookSubscriptionService';
|
|
102
|
+
/**
|
|
103
|
+
* ## SharePoint Service
|
|
104
|
+
*
|
|
105
|
+
* Helper functions for handling SharePoint
|
|
106
|
+
*
|
|
107
|
+
* ```js
|
|
108
|
+
* import { sharepointService } from '@oneblink/sdk-core'
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export * as sharepointService from './sharepointService';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.webhookSubscriptionService = exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = void 0;
|
|
26
|
+
exports.sharepointService = exports.webhookSubscriptionService = exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = exports.resourceDefinitionTypes = void 0;
|
|
27
|
+
exports.resourceDefinitionTypes = __importStar(require("./types/resource-definitions"));
|
|
27
28
|
/**
|
|
28
29
|
* ## Form Elements Service
|
|
29
30
|
*
|
|
@@ -124,4 +125,14 @@ exports.fileUploadService = __importStar(require("./fileUploadService"));
|
|
|
124
125
|
* ```
|
|
125
126
|
*/
|
|
126
127
|
exports.webhookSubscriptionService = __importStar(require("./webhookSubscriptionService"));
|
|
128
|
+
/**
|
|
129
|
+
* ## SharePoint Service
|
|
130
|
+
*
|
|
131
|
+
* Helper functions for handling SharePoint
|
|
132
|
+
*
|
|
133
|
+
* ```js
|
|
134
|
+
* import { sharepointService } from '@oneblink/sdk-core'
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
exports.sharepointService = __importStar(require("./sharepointService"));
|
|
127
138
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,6EAA4D;AAC5D;;;;;;;;GAQG;AACH,qFAAoE;AACpE;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,qEAAoD;AACpD;;;;;;;;GAQG;AACH,6DAA4C;AAC5C;;;;;;;;GAQG;AACH,2DAA0C;AAC1C;;;;;;;;GAQG;AACH,mEAAkD;AAClD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,2FAA0E","sourcesContent":["/**\n * ## Form Elements Service\n *\n * Helper functions for handling form elements\n *\n * ```js\n * import { formElementsService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as formElementsService from './formElementsService'\n/**\n * ## Conditional Logic Service\n *\n * Helper functions for handling conditional logic\n *\n * ```js\n * import { conditionalLogicService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as conditionalLogicService from './conditionalLogicService'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submission data\n *\n * ```js\n * import { submissionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as submissionService from './submissionService'\n/**\n * ## Submission Service\n *\n * Helper functions for casting types\n *\n * ```js\n * import { typeCastService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as typeCastService from './typeCastService'\n/**\n * ## User Service\n *\n * Helper functions for handling users\n *\n * ```js\n * import { userService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as userService from './userService'\n/**\n * ## ABN Service\n *\n * Helper functions for handling ABN Records\n *\n * ```js\n * import { abnService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as abnService from './abnService'\n/**\n * ## Payment Service\n *\n * Helper functions for payments\n *\n * ```js\n * import { paymentService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as paymentService from './paymentService'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling\n *\n * ```js\n * import { schedulingService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as schedulingService from './schedulingService'\n/**\n * ## File Upload Service\n *\n * Helper functions for handling file uploads\n *\n * ```js\n * import { fileUploadService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as fileUploadService from './fileUploadService'\n/**\n * ## Webhook Subscription Service\n *\n * Helper functions for handling Webhook subscriptions\n *\n * ```js\n * import { webhookSubscriptionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as webhookSubscriptionService from './webhookSubscriptionService'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAuE;AACvE;;;;;;;;GAQG;AACH,6EAA4D;AAC5D;;;;;;;;GAQG;AACH,qFAAoE;AACpE;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,qEAAoD;AACpD;;;;;;;;GAQG;AACH,6DAA4C;AAC5C;;;;;;;;GAQG;AACH,2DAA0C;AAC1C;;;;;;;;GAQG;AACH,mEAAkD;AAClD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,2FAA0E;AAC1E;;;;;;;;GAQG;AACH,yEAAwD","sourcesContent":["export * as resourceDefinitionTypes from './types/resource-definitions'\n/**\n * ## Form Elements Service\n *\n * Helper functions for handling form elements\n *\n * ```js\n * import { formElementsService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as formElementsService from './formElementsService'\n/**\n * ## Conditional Logic Service\n *\n * Helper functions for handling conditional logic\n *\n * ```js\n * import { conditionalLogicService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as conditionalLogicService from './conditionalLogicService'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submission data\n *\n * ```js\n * import { submissionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as submissionService from './submissionService'\n/**\n * ## Submission Service\n *\n * Helper functions for casting types\n *\n * ```js\n * import { typeCastService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as typeCastService from './typeCastService'\n/**\n * ## User Service\n *\n * Helper functions for handling users\n *\n * ```js\n * import { userService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as userService from './userService'\n/**\n * ## ABN Service\n *\n * Helper functions for handling ABN Records\n *\n * ```js\n * import { abnService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as abnService from './abnService'\n/**\n * ## Payment Service\n *\n * Helper functions for payments\n *\n * ```js\n * import { paymentService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as paymentService from './paymentService'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling\n *\n * ```js\n * import { schedulingService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as schedulingService from './schedulingService'\n/**\n * ## File Upload Service\n *\n * Helper functions for handling file uploads\n *\n * ```js\n * import { fileUploadService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as fileUploadService from './fileUploadService'\n/**\n * ## Webhook Subscription Service\n *\n * Helper functions for handling Webhook subscriptions\n *\n * ```js\n * import { webhookSubscriptionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as webhookSubscriptionService from './webhookSubscriptionService'\n/**\n * ## SharePoint Service\n *\n * Helper functions for handling SharePoint\n *\n * ```js\n * import { sharepointService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as sharepointService from './sharepointService'\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ColumnDefinition } from '@microsoft/microsoft-graph-types';
|
|
2
|
+
import { SubmissionEventTypes } from '@oneblink/types';
|
|
3
|
+
import { ResourceDefinition } from './types/resource-definitions';
|
|
4
|
+
export type SharepointColumnResourceDefinition = ResourceDefinition<SubmissionEventTypes.SharepointColumnResourceDefinitionBase>;
|
|
5
|
+
export declare function generateSharepointColumnResourceDefinitions(columnDefinitions: ColumnDefinition[]): SharepointColumnResourceDefinition[];
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSharepointColumnResourceDefinitions = void 0;
|
|
4
|
+
function generateSharepointColumnResourceDefinitions(columnDefinitions) {
|
|
5
|
+
return columnDefinitions.reduce((memo, columnDefinition) => {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
if (!columnDefinition.readOnly &&
|
|
8
|
+
columnDefinition.columnGroup !== '_Hidden' &&
|
|
9
|
+
columnDefinition.name &&
|
|
10
|
+
columnDefinition.id &&
|
|
11
|
+
columnDefinition.displayName) {
|
|
12
|
+
if ((_a = columnDefinition.text) === null || _a === void 0 ? void 0 : _a.allowMultipleLines) {
|
|
13
|
+
memo.push({
|
|
14
|
+
id: columnDefinition.id,
|
|
15
|
+
isRequired: false,
|
|
16
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
17
|
+
displayName: columnDefinition.displayName,
|
|
18
|
+
type: 'TEXT_MULTI_LINE',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else if (columnDefinition.text) {
|
|
22
|
+
memo.push({
|
|
23
|
+
id: columnDefinition.id,
|
|
24
|
+
isRequired: false,
|
|
25
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
26
|
+
displayName: columnDefinition.displayName,
|
|
27
|
+
type: 'TEXT_SINGLE_LINE',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if ((_c = (_b = columnDefinition.choice) === null || _b === void 0 ? void 0 : _b.choices) === null || _c === void 0 ? void 0 : _c.length) {
|
|
31
|
+
memo.push({
|
|
32
|
+
id: columnDefinition.id,
|
|
33
|
+
isRequired: false,
|
|
34
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
35
|
+
displayName: columnDefinition.displayName,
|
|
36
|
+
type: 'CHOICE_SINGLE',
|
|
37
|
+
choices: columnDefinition.choice.choices.map((choice) => ({
|
|
38
|
+
label: choice,
|
|
39
|
+
value: choice,
|
|
40
|
+
})),
|
|
41
|
+
checkIsFormElementSupported() {
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if (((_d = columnDefinition.dateTime) === null || _d === void 0 ? void 0 : _d.format) === 'dateOnly') {
|
|
47
|
+
memo.push({
|
|
48
|
+
id: columnDefinition.id,
|
|
49
|
+
isRequired: false,
|
|
50
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
51
|
+
displayName: columnDefinition.displayName,
|
|
52
|
+
type: 'DATE',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (columnDefinition.dateTime) {
|
|
56
|
+
memo.push({
|
|
57
|
+
id: columnDefinition.id,
|
|
58
|
+
isRequired: false,
|
|
59
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
60
|
+
displayName: columnDefinition.displayName,
|
|
61
|
+
type: 'DATETIME',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (columnDefinition.number) {
|
|
65
|
+
memo.push({
|
|
66
|
+
id: columnDefinition.id,
|
|
67
|
+
isRequired: false,
|
|
68
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
69
|
+
displayName: columnDefinition.displayName,
|
|
70
|
+
type: 'NUMBER',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (columnDefinition.boolean) {
|
|
74
|
+
memo.push({
|
|
75
|
+
id: columnDefinition.id,
|
|
76
|
+
isRequired: false,
|
|
77
|
+
sharepointColumnDefinitionName: columnDefinition.name,
|
|
78
|
+
displayName: columnDefinition.displayName,
|
|
79
|
+
type: 'BOOLEAN',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return memo;
|
|
84
|
+
}, []);
|
|
85
|
+
}
|
|
86
|
+
exports.generateSharepointColumnResourceDefinitions = generateSharepointColumnResourceDefinitions;
|
|
87
|
+
//# sourceMappingURL=sharepointService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharepointService.js","sourceRoot":"","sources":["../src/sharepointService.ts"],"names":[],"mappings":";;;AAOA,SAAgB,2CAA2C,CACzD,iBAAqC;IAErC,OAAO,iBAAiB,CAAC,MAAM,CAC7B,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE;;QACzB,IACE,CAAC,gBAAgB,CAAC,QAAQ;YAC1B,gBAAgB,CAAC,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AAQ,0CAAE,MAAM,MAAK,UAAU,EAAE;gBAC3D,IAAI,CAAC,IAAI,CAAC;oBACR,EAAE,EAAE,gBAAgB,CAAC,EAAE;oBACvB,UAAU,EAAE,KAAK;oBACjB,8BAA8B,EAAE,gBAAgB,CAAC,IAAI;oBACrD,WAAW,EAAE,gBAAgB,CAAC,WAAW;oBACzC,IAAI,EAAE,MAAM;iBACb,CAAC,CAAA;aACH;iBAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE;gBACpC,IAAI,CAAC,IAAI,CAAC;oBACR,EAAE,EAAE,gBAAgB,CAAC,EAAE;oBACvB,UAAU,EAAE,KAAK;oBACjB,8BAA8B,EAAE,gBAAgB,CAAC,IAAI;oBACrD,WAAW,EAAE,gBAAgB,CAAC,WAAW;oBACzC,IAAI,EAAE,UAAU;iBACjB,CAAC,CAAA;aACH;iBAAM,IAAI,gBAAgB,CAAC,MAAM,EAAE;gBAClC,IAAI,CAAC,IAAI,CAAC;oBACR,EAAE,EAAE,gBAAgB,CAAC,EAAE;oBACvB,UAAU,EAAE,KAAK;oBACjB,8BAA8B,EAAE,gBAAgB,CAAC,IAAI;oBACrD,WAAW,EAAE,gBAAgB,CAAC,WAAW;oBACzC,IAAI,EAAE,QAAQ;iBACf,CAAC,CAAA;aACH;iBAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBACnC,IAAI,CAAC,IAAI,CAAC;oBACR,EAAE,EAAE,gBAAgB,CAAC,EAAE;oBACvB,UAAU,EAAE,KAAK;oBACjB,8BAA8B,EAAE,gBAAgB,CAAC,IAAI;oBACrD,WAAW,EAAE,gBAAgB,CAAC,WAAW;oBACzC,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAA;aACH;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC,EACD,EAAE,CACH,CAAA;AACH,CAAC;AAlFD,kGAkFC","sourcesContent":["import { ColumnDefinition } from '@microsoft/microsoft-graph-types'\nimport { SubmissionEventTypes } from '@oneblink/types'\nimport { ResourceDefinition } from './types/resource-definitions'\n\nexport type SharepointColumnResourceDefinition =\n ResourceDefinition<SubmissionEventTypes.SharepointColumnResourceDefinitionBase>\n\nexport function generateSharepointColumnResourceDefinitions(\n columnDefinitions: ColumnDefinition[],\n) {\n return columnDefinitions.reduce<SharepointColumnResourceDefinition[]>(\n (memo, columnDefinition) => {\n if (\n !columnDefinition.readOnly &&\n columnDefinition.columnGroup !== '_Hidden' &&\n columnDefinition.name &&\n columnDefinition.id &&\n columnDefinition.displayName\n ) {\n if (columnDefinition.text?.allowMultipleLines) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'TEXT_MULTI_LINE',\n })\n } else if (columnDefinition.text) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'TEXT_SINGLE_LINE',\n })\n } else if (columnDefinition.choice?.choices?.length) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'CHOICE_SINGLE',\n choices: columnDefinition.choice.choices.map((choice) => ({\n label: choice,\n value: choice,\n })),\n checkIsFormElementSupported() {\n return false\n },\n })\n } else if (columnDefinition.dateTime?.format === 'dateOnly') {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'DATE',\n })\n } else if (columnDefinition.dateTime) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'DATETIME',\n })\n } else if (columnDefinition.number) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'NUMBER',\n })\n } else if (columnDefinition.boolean) {\n memo.push({\n id: columnDefinition.id,\n isRequired: false,\n sharepointColumnDefinitionName: columnDefinition.name,\n displayName: columnDefinition.displayName,\n type: 'BOOLEAN',\n })\n }\n }\n\n return memo\n },\n [],\n )\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FormTypes } from '@oneblink/types';
|
|
2
|
+
export type ResourceDefinitionChoice = {
|
|
3
|
+
value: string | number;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type ResourceDefinition<T> = T & {
|
|
7
|
+
id: string;
|
|
8
|
+
isRequired: boolean;
|
|
9
|
+
displayName: string;
|
|
10
|
+
} & ({
|
|
11
|
+
type: 'TEXT_SINGLE_LINE' | 'TEXT_MULTI_LINE' | 'EMAIL' | 'DATE' | 'DATETIME' | 'NUMBER' | 'BOOLEAN';
|
|
12
|
+
} | {
|
|
13
|
+
type: 'CHOICE_SINGLE' | 'CHOICE_MULTIPLE';
|
|
14
|
+
choices: ResourceDefinitionChoice[];
|
|
15
|
+
checkIsFormElementSupported: (formElementWithOptions: FormTypes.FormElementWithOptions) => boolean;
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-definitions.js","sourceRoot":"","sources":["../../src/types/resource-definitions.ts"],"names":[],"mappings":"","sourcesContent":["import { FormTypes } from '@oneblink/types'\n\nexport type ResourceDefinitionChoice = {\n value: string | number\n label: string\n}\n\nexport type ResourceDefinition<T> = T & {\n id: string\n isRequired: boolean\n displayName: string\n} & (\n | {\n type:\n | 'TEXT_SINGLE_LINE'\n | 'TEXT_MULTI_LINE'\n | 'EMAIL'\n | 'DATE'\n | 'DATETIME'\n | 'NUMBER'\n | 'BOOLEAN'\n }\n | {\n type: 'CHOICE_SINGLE' | 'CHOICE_MULTIPLE'\n choices: ResourceDefinitionChoice[]\n checkIsFormElementSupported: (\n formElementWithOptions: FormTypes.FormElementWithOptions,\n ) => boolean\n }\n )\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/sdk-core",
|
|
3
3
|
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.4.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
|
+
"@microsoft/microsoft-graph-types": "^2.40.0",
|
|
11
12
|
"@oneblink/release-cli": "^3.2.2",
|
|
12
13
|
"@oneblink/types": "github:oneblink/types",
|
|
13
14
|
"@types/jest": "^29.5.0",
|
package/dist/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nexport type FormElementsCtrl = {\n model: SubmissionTypes.S3SubmissionData['submission']\n flattenedElements: FormTypes.FormElement[]\n parentFormElementsCtrl?: FormElementsCtrl\n}\n"]}
|
|
File without changes
|