* Extracts subblock IDs from the `subBlocks: [ ... ]` section of a block * definition. Only grabs the top-level `id:` of each subblock object — * ignores nested IDs inside `options`, `columns`, etc.
(source: string)
| 42 | * ignores nested IDs inside `options`, `columns`, etc. |
| 43 | */ |
| 44 | function extractSubBlockIds(source: string): string[] { |
| 45 | const startIdx = source.indexOf('subBlocks:') |
| 46 | if (startIdx === -1) return [] |
| 47 | |
| 48 | const bracketStart = source.indexOf('[', startIdx) |
| 49 | if (bracketStart === -1) return [] |
| 50 | |
| 51 | const ids: string[] = [] |
| 52 | let braceDepth = 0 |
| 53 | let bracketDepth = 0 |
| 54 | let i = bracketStart + 1 |
| 55 | bracketDepth = 1 |
| 56 | |
| 57 | while (i < source.length && bracketDepth > 0) { |
| 58 | const ch = source[i] |
| 59 | |
| 60 | if (ch === '[') bracketDepth++ |
| 61 | else if (ch === ']') { |
| 62 | bracketDepth-- |
| 63 | if (bracketDepth === 0) break |
| 64 | } else if (ch === '{') { |
| 65 | braceDepth++ |
| 66 | if (braceDepth === 1) { |
| 67 | const ahead = source.slice(i, i + 200) |
| 68 | const idMatch = ahead.match(/{\s*(?:\/\/[^\n]*\n\s*)*id:\s*['"]([^'"]+)['"]/) |
| 69 | if (idMatch) { |
| 70 | ids.push(idMatch[1]) |
| 71 | } |
| 72 | } |
| 73 | } else if (ch === '}') { |
| 74 | braceDepth-- |
| 75 | } |
| 76 | |
| 77 | i++ |
| 78 | } |
| 79 | |
| 80 | return ids |
| 81 | } |
| 82 | |
| 83 | function getCurrentIds(): IdMap { |
| 84 | const map: IdMap = {} |