(options: BlockFactoryOptions = {})
| 49 | * ``` |
| 50 | */ |
| 51 | export function createBlock(options: BlockFactoryOptions = {}): any { |
| 52 | const id = options.id ?? generateBlockId(options.type ?? 'block') |
| 53 | |
| 54 | const data: BlockData = options.data ?? {} |
| 55 | if (options.parentId) { |
| 56 | data.parentId = options.parentId |
| 57 | data.extent = 'parent' |
| 58 | } |
| 59 | |
| 60 | return { |
| 61 | id, |
| 62 | type: options.type ?? 'function', |
| 63 | name: options.name ?? `Block ${id.substring(0, 8)}`, |
| 64 | position: options.position ?? { x: 0, y: 0 }, |
| 65 | subBlocks: options.subBlocks ?? {}, |
| 66 | outputs: options.outputs ?? {}, |
| 67 | enabled: options.enabled ?? true, |
| 68 | horizontalHandles: options.horizontalHandles ?? true, |
| 69 | height: options.height ?? 0, |
| 70 | advancedMode: options.advancedMode ?? false, |
| 71 | triggerMode: options.triggerMode ?? false, |
| 72 | locked: options.locked ?? false, |
| 73 | data: Object.keys(data).length > 0 ? data : undefined, |
| 74 | layout: {}, |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Creates a starter block (workflow entry point). |
no test coverage detected