(
config: SubBlockConfig,
subBlockValues: Record<string, { value?: unknown }>
)
| 160 | } |
| 161 | |
| 162 | function isFieldRequired( |
| 163 | config: SubBlockConfig, |
| 164 | subBlockValues: Record<string, { value?: unknown }> |
| 165 | ): boolean { |
| 166 | if (!config.required) return false |
| 167 | if (typeof config.required === 'boolean') return config.required |
| 168 | |
| 169 | const evalCond = ( |
| 170 | cond: { |
| 171 | field: string |
| 172 | value: string | number | boolean | Array<string | number | boolean> |
| 173 | not?: boolean |
| 174 | and?: { |
| 175 | field: string |
| 176 | value: string | number | boolean | Array<string | number | boolean> | undefined |
| 177 | not?: boolean |
| 178 | } |
| 179 | }, |
| 180 | values: Record<string, { value?: unknown }> |
| 181 | ): boolean => { |
| 182 | const fieldValue = values[cond.field]?.value |
| 183 | const condValue = cond.value |
| 184 | |
| 185 | let match = Array.isArray(condValue) |
| 186 | ? condValue.includes(fieldValue as string | number | boolean) |
| 187 | : fieldValue === condValue |
| 188 | |
| 189 | if (cond.not) match = !match |
| 190 | |
| 191 | if (cond.and) { |
| 192 | const andFieldValue = values[cond.and.field]?.value |
| 193 | const andCondValue = cond.and.value |
| 194 | let andMatch = Array.isArray(andCondValue) |
| 195 | ? (andCondValue || []).includes(andFieldValue as string | number | boolean) |
| 196 | : andFieldValue === andCondValue |
| 197 | if (cond.and.not) andMatch = !andMatch |
| 198 | match = match && andMatch |
| 199 | } |
| 200 | |
| 201 | return match |
| 202 | } |
| 203 | |
| 204 | const condition = typeof config.required === 'function' ? config.required() : config.required |
| 205 | return evalCond(condition, subBlockValues) |
| 206 | } |
| 207 | |
| 208 | function resolveTriggerId(block: BlockState): string | undefined { |
| 209 | const blockConfig = getBlock(block.type) |
no test coverage detected