-
Notifications
You must be signed in to change notification settings - Fork 14
feat: support reverse and bidirectional arrows in DSL #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,25 @@ describe('CLI export command', () => { | |
| expect(existsSync(autoSvg)).toBe(true); | ||
| }, 60000); | ||
|
|
||
| it('should preserve reverse and bidirectional arrowheads through CLI create output', () => { | ||
| const outputFile = tmpFile('arrow-directions.excalidraw'); | ||
|
|
||
| runCLI([ | ||
| 'create', | ||
| '--inline', | ||
| '[A] <- [B]\n[C] <-> [D]', | ||
| '-o', | ||
| outputFile, | ||
| ]); | ||
|
|
||
| const file = JSON.parse(readFileSync(outputFile, 'utf-8')); | ||
| const arrows = file.elements.filter((element: { type: string }) => element.type === 'arrow'); | ||
|
|
||
| expect(arrows).toHaveLength(2); | ||
| expect(arrows[0]).toMatchObject({ startArrowhead: 'arrow', endArrowhead: null }); | ||
| expect(arrows[1]).toMatchObject({ startArrowhead: 'arrow', endArrowhead: 'arrow' }); | ||
|
Comment on lines
+135
to
+139
|
||
| }, 60000); | ||
|
|
||
| it('should export with --verbose flag', () => { | ||
| const inputFile = tmpFile('verbose-test.excalidraw'); | ||
| writeFileSync(inputFile, JSON.stringify(createMinimalFile()), 'utf-8'); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,18 @@ describe('DSL Parser', () => { | |
| expect(result.nodes[0].label).toBe('email@company.com'); | ||
| expect(result.nodes[0].style).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should generate Excalidraw arrows for reverse and bidirectional connections', async () => { | ||
| const graph = parseDSL(`[A] <- [B] | ||
| [C] <-> [D]`); | ||
| const layouted = await layoutGraph(graph); | ||
| const file = generateExcalidraw(layouted); | ||
| const arrows = file.elements.filter((element) => element.type === 'arrow'); | ||
|
|
||
| expect(arrows).toHaveLength(2); | ||
| expect(arrows[0]).toMatchObject({ startArrowhead: 'arrow', endArrowhead: null }); | ||
| expect(arrows[1]).toMatchObject({ startArrowhead: 'arrow', endArrowhead: 'arrow' }); | ||
|
Comment on lines
+74
to
+78
|
||
| }); | ||
| }); | ||
|
|
||
| describe('connection parsing', () => { | ||
|
|
@@ -86,6 +98,28 @@ describe('DSL Parser', () => { | |
| expect(result.edges[0].style?.strokeStyle).toBe('dashed'); | ||
| }); | ||
|
|
||
| it('should parse reverse connections as logical right-to-left edges', () => { | ||
| const result = parseDSL('[A] <- [B]'); | ||
| expect(result.edges).toHaveLength(1); | ||
| expect(result.edges[0].source).toBe(result.nodes[1].id); | ||
| expect(result.edges[0].target).toBe(result.nodes[0].id); | ||
| expect(result.edges[0].style).toEqual({ | ||
| startArrowhead: 'arrow', | ||
| endArrowhead: null, | ||
| }); | ||
|
Comment on lines
+105
to
+109
|
||
| }); | ||
|
|
||
| it('should parse bidirectional connections with arrowheads on both ends', () => { | ||
| const result = parseDSL('[A] <-> [B]'); | ||
| expect(result.edges).toHaveLength(1); | ||
| expect(result.edges[0].source).toBe(result.nodes[0].id); | ||
| expect(result.edges[0].target).toBe(result.nodes[1].id); | ||
| expect(result.edges[0].style).toEqual({ | ||
| startArrowhead: 'arrow', | ||
| endArrowhead: 'arrow', | ||
| }); | ||
| }); | ||
|
|
||
| it('should parse chains of connections', () => { | ||
| const result = parseDSL('[A] -> [B] -> [C]'); | ||
| expect(result.nodes).toHaveLength(3); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
<-you’re currently (a) swappingsource/target(so the edge is already B→A) and (b) also forcingstartArrowhead: 'arrow'+endArrowhead: null. Those two together invert the rendered arrow direction relative to the logical edge. If the edge direction is reversed viasource/targetswap, the arrowheads should typically remain the default (start null, end 'arrow') or explicitly setstartArrowhead: null, endArrowhead: 'arrow'—but not start-only.