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Z,EAAqBiB,cACtB,OAAO,EACX,QACI,OAAO,OArCf,OAAQf,GACJ,KAAKF,EAAqBO,OACtB,OAAOJ,IAAgBC,EAC3B,KAAKJ,EAAqBS,UACtB,OAAON,IAAgBC,EAC3B,KAAKJ,EAAqBU,SACtB,OAAOP,EAAYK,SAASJ,GAChC,KAAKJ,EAAqBa,YACtB,OAAQV,EAAYK,SAASJ,GACjC,KAAKJ,EAAqBc,uBACtB,OAAO,IAAIC,OAAOX,GAAgBY,KAAKb,GAC3C,KAAKH,EAAqBiB,cACtB,OAAO,EACX,QACI,OAAO,EAwBf,EAmDR,MAhDuCC,CACnCC,EACAhC,KAEA,GAAIgC,GAAchC,EAAS,CACvB,MAAM,qBAAEiC,EAAoB,OAAEC,GAAWF,EACnCG,GACI,OAAND,QAAM,IAANA,OAAM,EAANA,EAAQE,oBAAqBxB,EAAoByB,KAE/CC,EAAaN,EAAWM,YAAc,GACtCC,EAAgBD,EAAWE,KAC5BC,IACGC,EAAAA,EAAAA,IAAS,CACL1C,UACA2C,KAAMF,EAAUG,aACd,KAGd,OAAIX,IAAyBtB,EAAwBkC,IAC1CP,EACFE,KAAI,CAACC,EAAWK,KACb,MAAM,SAAE/B,EAAQ,WAAEgC,GAAeN,EAC3BO,EAAeT,EAAcO,GACnC,OAAOhC,EACHC,EACAiC,EACAD,GAAc,IAEZZ,GACCA,CAAW,IAErBX,KAAKyB,SAEHX,EAAWY,OAAM,CAACT,EAAWK,KAChC,MAAM,SAAE/B,EAAQ,WAAEgC,GAAeN,EAC3BO,EAAeT,EAAcO,GACnC,OAAOhC,EACHC,EACAiC,EACAD,GAAc,IAEZZ,GACCA,CAAW,GAE9B,CACA,OAAO,CAAI,C","sources":["components/FormContent/FormContent.styled.ts","components/FormContent/FormContent.tsx","types/EpiElementDependency.ts","utils/evaluteVisibilityFromDependencies.ts"],"sourcesContent":["import { styled } from \"styled-components\";\n\nexport const Container = styled.div`\n grid-column: auto / span 6;\n`;\n","import React, { ReactElement } from \"react\";\n\nimport { Container } from \"./FormContent.styled\";\nimport FormContentProps from \"./FormContentProps\";\n\nimport evaluteVisibilityFromDependencies from \"../../utils/evaluteVisibilityFromDependencies\";\nimport getComponentTypeForContent from \"../../utils/getComponentTypeForContent\";\nimport ContentArea from \"../ContentArea/ContentAreaLoader\";\n\nexport const ComponentName = \"FormContentBlock\";\n\nconst FormContent = ({\n blocks,\n dependencies,\n control,\n}: FormContentProps): ReactElement => {\n const visibleFromDependencies =\n dependencies && control\n ? evaluteVisibilityFromDependencies(dependencies, control)\n : true;\n return (\n <>\n {visibleFromDependencies && (\n \n \n \n )}\n >\n );\n};\n\nexport default React.memo(FormContent);\n","export default interface EpiElementDependency {\n action?: {\n displayName?: string;\n name?: string;\n order?: number;\n clientsideAction?: EpiDependencyAction;\n };\n conditionCombination?: EpiConditionCombination;\n conditions: EpiCondition[];\n}\n\nexport interface EpiCondition {\n fieldName: string;\n operator: EpiConditionOperator;\n fieldValue: string;\n}\n\nexport enum EpiConditionCombination {\n All = \"All\",\n Any = \"Any\",\n}\n\nexport enum EpiDependencyAction {\n Hide = \"hide\",\n Show = \"show\",\n}\n\nexport enum EpiConditionOperator {\n NotApplicable = \"NotApplicable\",\n MatchRegularExpression = \"MatchRegularExpression\",\n Equals = \"Equals\",\n NotEquals = \"NotEquals\",\n Contains = \"Contains\",\n NotContains = \"NotContains\",\n}\n","import { useWatch, Control } from \"react-hook-form\";\n\nimport EpiElementDependency, {\n EpiConditionCombination,\n EpiConditionOperator,\n EpiDependencyAction,\n} from \"types/EpiElementDependency\";\n\nconst evaluateConditionByOperator = (\n operator: EpiConditionOperator,\n targetValue: string | string[],\n conditionValue: string,\n): boolean => {\n if (typeof targetValue === \"undefined\") return false;\n\n if (!Array.isArray(targetValue))\n switch (operator) {\n case EpiConditionOperator.Equals:\n return targetValue === conditionValue;\n case EpiConditionOperator.NotEquals:\n return targetValue !== conditionValue;\n case EpiConditionOperator.Contains:\n return targetValue.includes(conditionValue);\n case EpiConditionOperator.NotContains:\n return !targetValue.includes(conditionValue);\n case EpiConditionOperator.MatchRegularExpression:\n return new RegExp(conditionValue).test(targetValue);\n case EpiConditionOperator.NotApplicable:\n return true;\n default:\n return false;\n }\n else\n switch (operator) {\n case EpiConditionOperator.Equals:\n return targetValue.includes(conditionValue);\n case EpiConditionOperator.NotEquals:\n return !targetValue.includes(conditionValue);\n case EpiConditionOperator.Contains:\n return targetValue.some((value) =>\n value.includes(conditionValue),\n );\n case EpiConditionOperator.NotContains:\n return !targetValue.some((value) =>\n value.includes(conditionValue),\n );\n case EpiConditionOperator.MatchRegularExpression:\n return targetValue.some((value) =>\n new RegExp(conditionValue).test(value),\n );\n case EpiConditionOperator.NotApplicable:\n return true;\n default:\n return false;\n }\n};\n\nconst evaluteVisibleFromDependencies = (\n dependency: EpiElementDependency | undefined,\n control: Control, any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n): boolean => {\n if (dependency && control) {\n const { conditionCombination, action } = dependency;\n const returnValue =\n action?.clientsideAction === EpiDependencyAction.Show;\n\n const conditions = dependency.conditions || [];\n const elementValues = conditions.map(\n (condition) =>\n useWatch({\n control,\n name: condition.fieldName,\n }) || \"\",\n );\n\n if (conditionCombination === EpiConditionCombination.Any)\n return conditions\n .map((condition, index) => {\n const { operator, fieldValue } = condition;\n const elementValue = elementValues[index];\n return evaluateConditionByOperator(\n operator,\n elementValue,\n fieldValue || \"\",\n )\n ? returnValue\n : !returnValue;\n })\n .some(Boolean);\n else\n return conditions.every((condition, index) => {\n const { operator, fieldValue } = condition;\n const elementValue = elementValues[index];\n return evaluateConditionByOperator(\n operator,\n elementValue,\n fieldValue || \"\",\n )\n ? returnValue\n : !returnValue;\n });\n }\n return true;\n};\n\nexport default evaluteVisibleFromDependencies;\n"],"names":["Container","styled","div","withConfig","componentId","ComponentName","FormContent","blocks","dependencies","control","visibleFromDependencies","evaluteVisibilityFromDependencies","_jsx","_Fragment","children","ContentArea","items","componentSelector","getComponentTypeForContent","React","EpiConditionCombination","EpiDependencyAction","EpiConditionOperator","evaluateConditionByOperator","operator","targetValue","conditionValue","Array","isArray","Equals","includes","NotEquals","Contains","some","value","NotContains","MatchRegularExpression","RegExp","test","NotApplicable","evaluteVisibleFromDependencies","dependency","conditionCombination","action","returnValue","clientsideAction","Show","conditions","elementValues","map","condition","useWatch","name","fieldName","Any","index","fieldValue","elementValue","Boolean","every"],"sourceRoot":""}