(
condition:
| SubBlockCondition
| ((values?: Record<string, unknown>) => SubBlockCondition)
| undefined,
values: Record<string, unknown>
)
| 173 | * Evaluate a subblock condition against a map of raw values. |
| 174 | */ |
| 175 | export function evaluateSubBlockCondition( |
| 176 | condition: |
| 177 | | SubBlockCondition |
| 178 | | ((values?: Record<string, unknown>) => SubBlockCondition) |
| 179 | | undefined, |
| 180 | values: Record<string, unknown> |
| 181 | ): boolean { |
| 182 | if (!condition) return true |
| 183 | const actual = typeof condition === 'function' ? condition(values) : condition |
| 184 | const fieldValue = values[actual.field] |
| 185 | const valueMatch = Array.isArray(actual.value) |
| 186 | ? fieldValue != null && |
| 187 | (actual.not |
| 188 | ? !actual.value.includes(fieldValue as any) |
| 189 | : actual.value.includes(fieldValue as any)) |
| 190 | : actual.not |
| 191 | ? fieldValue !== actual.value |
| 192 | : fieldValue === actual.value |
| 193 | const andMatch = !actual.and |
| 194 | ? true |
| 195 | : (() => { |
| 196 | const andFieldValue = values[actual.and!.field] |
| 197 | const andValueMatch = Array.isArray(actual.and!.value) |
| 198 | ? andFieldValue != null && |
| 199 | (actual.and!.not |
| 200 | ? !actual.and!.value.includes(andFieldValue as any) |
| 201 | : actual.and!.value.includes(andFieldValue as any)) |
| 202 | : actual.and!.not |
| 203 | ? andFieldValue !== actual.and!.value |
| 204 | : andFieldValue === actual.and!.value |
| 205 | return andValueMatch |
| 206 | })() |
| 207 | |
| 208 | return valueMatch && andMatch |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Check if a value is considered set for advanced visibility/selection. |
no test coverage detected