Skip to content

feat: DrawIO export (CLI, Playground, round-trip)#23

Merged
sraphaz merged 1 commit intomainfrom
feat/drawio-export
Feb 14, 2026
Merged

feat: DrawIO export (CLI, Playground, round-trip)#23
sraphaz merged 1 commit intomainfrom
feat/drawio-export

Conversation

@sraphaz
Copy link
Copy Markdown
Owner

@sraphaz sraphaz commented Feb 14, 2026

Summary

This PR adds DrawIO (draw.io) export to LikeC4: export views to .drawio XML (single or multi-file), with optional round-trip options (layout, stroke colors/widths, edge waypoints), CLI command, and Playground context menu integration. It also includes a cleanup pass: removal of build artifacts that were accidentally committed, and addressing CodeRabbit review (actionable fixes + nitpicks).


Features

Export to DrawIO

  • @likec4/generators: generateDrawio, generateDrawioMulti produce draw.io-compatible XML; optional GenerateDrawioOptions for layout override, stroke colors/widths per node, edge waypoints, and round-trip comment blocks in source.
  • Round-trip: Export can embed // likec4.layout.viewId, // likec4.strokeColor, // likec4.strokeWidth, // likec4.edge.waypoints in .c4 source; parseDrawioRoundtripComments reads them for re-export after editing in draw.io.
  • CLI: likec4 export drawio <path> -o <outdir> with options --all-in-one, --roundtrip, --uncompressed, --project, --use-dot.
  • Playground: Right-click on diagram canvas → “Export to DrawIO” (current view) or “Export all” (all views). Optional getSourceContent for round-trip when used outside the provider.

Tests & E2E

  • Unit: generate-drawio.spec.ts, drawio-demo-export-import.spec.ts (cloud-system demo, element/edge counts, loadable XML). Timeouts increased for fromWorkspace/layoutedModel tests.
  • E2E: Playwright tests for DrawIO context menu in Playground (pnpm test:playground from e2e/).

Cleanup & CodeRabbit fixes

Build artifacts removal

  • Removed ~1555 compiled .js/.d.ts and PR temp docs that had been added in a previous commit (git add -A). All were verified to match strict criteria (only artifacts).
  • .gitignore updated: *.spec.js, *.test.js, apps/playground/src/**/*.js, packages/*/src/**/*.js, .cursor/, and comments on scope.

Actionable (CodeRabbit)

  • packages/config filenames: isLikeC4Config / isLikeC4NonJsonConfig return boolean instead of type predicates (they only check basename; narrowing full path was unsound).
  • .cursor/: Directory gitignored; git-push-remotes.mdc removed from tracking. AGENTS.md notes that contributors may use .cursor/rules/ locally and should not commit it.
  • pako: pako and @types/pako added to pnpm workspace catalog; packages/generators uses catalog:.
  • parse-drawio: In computeContainerTitles, title cells are created with parent="${containerId}" by the generator; parse logic now uses v.parent === cont.id instead of v.parent === cont.parent. Self-closing tag detection uses full trimmed open tag. TODO added for round-trip comment parser deduplication.
  • logger: ViteLogger type now omits both debug and hasErrorLogged so they are optional for Vite.
  • ci-validate-in-docker: NODE_ENV=production moved to after pnpm install so devDependencies are installed; Corepack pnpm set to 10.29.3 (match .tool-versions); comment added for version sync.
  • vitest: Root config merges configDefaults.exclude with custom patterns so default exclusions are preserved.

Nitpicks

  • Scripts: ci-validate-in-docker.ps1 uses Write-Output instead of Write-Host.
  • documentation-provider: Null guards for parseDeploymentNode and parseDeployedInstance (aligned with parseElement).
  • JSDoc: HoverProvider (class + constructor), browser startLanguageServer, drawio handler (sequential export comment).
  • Playground: useDrawioContextMenuActions — pass onExportError directly; comment on stabilizing viewStates for useMemo. Monaco: pass setLayoutedModelApi directly. LanguageClientSync: logger.warn in catch blocks for layouted model / layout view failures.
  • generate-drawio: Removed duplicate html=1; at end of vertex style; comments for getDefaultStrokeWidth and node sort. generate-drawio.spec: Comment on duplication with drawio-test-utils; mockViewModel as plain function (no vi.fn). e2e: Removed redundant $.nothrow = false; simplified assertion message (dead branch). .gitignore: Comments on glob scope and personal workflow files.

Changesets

  • drawio-related changesets are in .changeset/ (e.g. drawio-cli-roundtrip-e2e, drawio-roundtrip-options, drawio-import-postpack).

Checklist

  • Build and typecheck pass
  • Tests updated/added (unit + e2e)
  • CodeRabbit actionable and nitpick comments addressed
  • No build artifacts or personal config committed

Summary by CodeRabbit

  • Bug Fixes

    • DrawIO export XML now properly escapes special characters
    • Context menu matching and download validation improved
    • Enhanced XML attribute parsing for consistent handling
  • Tests

    • Stricter menu item and download filename assertions
    • Improved test efficiency with shared initialization
  • Chores

    • Updated CI validation scripts and Vite configuration
    • Repository maintenance and workspace dependency updates

…LanguageClientSync void, parse-drawio switch(true), drawio-demo beforeAll, e2e/ci-validate)

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

The changes comprise multiple DrawIO export refinements: XML attribute escaping, improved attribute parsing logic, pre-flight validation for empty exports, stricter test assertions, error handling adjustments, test suite refactoring to centralize setup, and CI/configuration updates including dependency reordering.

Changes

Cohort / File(s) Summary
DrawIO Generation & Parsing
packages/generators/src/drawio/generate-drawio.ts, packages/generators/src/drawio/parse-drawio.ts
XML-escape modified attribute in mxfile output; improve attribute parsing to handle both single and double quotes; refactor element-kind inference with switch-based logic.
DrawIO Playground & Export
apps/playground/src/components/drawio/useDrawioContextMenuActions.ts, apps/playground/src/monaco/LanguageClientSync.tsx, packages/likec4/src/cli/export/drawio/handler.ts
Prevent view overwrites in model filling; add DEV-only warning on export layout fetch failure; remove error handling from requestLayoutViewCallback; add pre-flight validation to check for zero views before export.
DrawIO Tests
e2e/src/likec4-cli-export-drawio.spec.ts, e2e/tests/drawio-playground.spec.ts, packages/likec4/src/drawio-demo-export-import.spec.ts
Clean workspace directory before test execution; enforce exact text and stricter filename matching in assertions; refactor test suite to centralize LikeC4 and DrawIO XML initialization using beforeAll hook.
Configuration & CI Scripts
.gitignore, pnpm-workspace.yaml, packages/likec4/src/vite/vite-dev.ts, scripts/ci-validate-in-docker.ps1, scripts/ci-validate-in-docker.sh
Consolidate PR/docs .gitignore patterns; reorder @types/pako dependency; remove fs.deny from Vite dev config; remove NODE_ENV from Docker invocation; add --frozen-lockfile to pnpm install and refactor CRLF stripping via temp file.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #13: Directly related—modifies the same DrawIO export files (generate-drawio.ts, parse-drawio.ts, useDrawioContextMenuActions.ts, LanguageClientSync.tsx, CLI handler) that this PR also updates.
  • PR #15: Related—contains follow-up fixes and tweaks to DrawIO export features and .gitignore entries, overlapping many of the same files modified here.
  • PR #14: Related—makes changes to the same DrawIO export, parsing, playground, and CLI handler files that this PR addresses.

Poem

🐰 XML tags now safely escaped, no quotes left untraced,
Pre-flight checks catch empty views before they're misplaced,
Tests rebuild their homes anew, on solid beforeAll ground,
ParseDrawio reads with sharper eyes, every quote it's found,
Scripts now frozen, configs neat—a DrawIO export's finest feat! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is comprehensive, covering features, cleanup, fixes, tests, and includes a detailed checklist; however, it does not follow the provided template structure with checkboxes and contribution guidelines confirmation. Add the checklist from the template with checkboxes (rebasing, conventional commits, tests, documentation, contribution guidelines) to align with repository standards.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (13 files):

⚔️ .gitignore (content)
⚔️ apps/playground/src/components/drawio/useDrawioContextMenuActions.ts (content)
⚔️ apps/playground/src/monaco/LanguageClientSync.tsx (content)
⚔️ e2e/src/likec4-cli-export-drawio.spec.ts (content)
⚔️ e2e/tests/drawio-playground.spec.ts (content)
⚔️ packages/generators/src/drawio/generate-drawio.ts (content)
⚔️ packages/generators/src/drawio/parse-drawio.ts (content)
⚔️ packages/likec4/src/cli/export/drawio/handler.ts (content)
⚔️ packages/likec4/src/drawio-demo-export-import.spec.ts (content)
⚔️ packages/likec4/src/vite/vite-dev.ts (content)
⚔️ pnpm-workspace.yaml (content)
⚔️ scripts/ci-validate-in-docker.ps1 (content)
⚔️ scripts/ci-validate-in-docker.sh (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: DrawIO export (CLI, Playground, round-trip)' clearly and concisely summarizes the main features added in this PR, matching the primary changes across multiple files and modules.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/drawio-export
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch feat/drawio-export
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
packages/likec4/src/drawio-demo-export-import.spec.ts (1)

27-30: Consider simplifying the viewmodels type annotation.

The conditional type inference is complex. If @likec4/generators or the core package exports a type for view models (e.g., LayoutedLikeC4ModelGraph or similar), importing it directly would improve readability.

That said, the current approach works correctly and is acceptable for test code.


Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant