Files
obsidian-excalidraw-plugin/CONTRIBUTING.md

19 KiB
Raw Permalink Blame History

Contributing to Obsidian Excalidraw Plugin

First off, thank you for considering contributing to the Obsidian Excalidraw plugin! This project integrates a heavily customized Excalidraw fork into Obsidian.

Because this is not a generic React canvas app, but rather a deeply integrated Obsidian plugin with popout window support, mobile compatibility constraints, and performance optimizations, please read the following guidelines carefully before making any changes.

Coding requirements

Read CODING_STANDARDS.md before implementing or reviewing changes. It is the canonical source for mandatory coding practices, including timer and window ownership, DOM helpers, cleanup, security, compatibility, logging, localization, and validation. Add future cross-cutting rules there. See AGENTS.md for architecture, subsystem constraints, and agent workflows.

💬 Discuss First

Before spending your valuable time writing code for a new feature or significant refactor, please open an issue to discuss it first. This ensures your idea aligns with the project's roadmap and architecture, and helps prevent wasted effort or complex merge conflicts later.

Compatibility with another plugin is out of scope by default. Agents MUST explicitly ask for maintainer consent before attempting compatibility work. A request to investigate or fix an issue does not implicitly approve workarounds for another plugin. Identify the plugin, proposed accommodation and maintenance cost first; see the mandatory compatibility consent control.

🚀 Getting Started

  1. Fork the repository and clone it locally.
  2. Use Node.js 22 or newer and verify it with node --version. A shell that mixes a different Node binary with another installation's Corepack can fail before a build starts.
  3. Run npm install in the root directory to install the main dependencies. (Note: The MathjaxToSVG sub-component has its own separate dependencies. You do not need to install them manually; the first time you run npm run build, it will take care of this automatically).
  4. Run npm run test:native to prepare and test .test-work/vaults/excalidraw-auto-test/; follow Obsidian runtime testing for the one-time Obsidian opening/trust/CLI prerequisite. The runner builds and installs the current workspace plugin and available Extras files, applies declared settings and enables the plugins automatically. Never use a personal vault or the historical desktop test vault. Generated binaries remain ignored; the immutable seed contains tracked fixtures and configuration.

After changing checkouts, refresh locked producer dependencies too: npm ci in Extras and yarn install --frozen-lockfile in the fork. A freshly rebuilt bundle can still contain an old dependency from stale node_modules. Native preparation checks the installed converter package and live Extras service contract separately. Follow native failure recovery to resolve recoverable blockers and rerun affected cases.

🛠️ Build and Lint Commands

Dependency scanner warnings

The published @zsviczian/excalidraw 0.18.140 package lists the build-only Sass compiler as a runtime dependency. Until a component release moves Sass to devDependencies, this repository overrides that transitive dependency to Sass 1.98.0, which uses Chokidar 4 without braces. Remove the Sass override after installing a component release with the corrected manifest. The plugin consumes prebuilt component JavaScript and CSS; it does not run Sass.

source-map-js is overridden to patched version 1.2.2 for both runtime-classified and development paths (advisory). The build copies its manifest and top-level declaration files with Node's native file APIs instead of rollup-plugin-copy, eliminating the other braces path. The braces advisory has no patched release as of October 11, 2026; these changes remove it from this plugin's dependency graph rather than suppressing the warning. Check with npm ls braces source-map-js sass --all after npm install.

Commands

  • Build the project: Run npm run build (Note: Our Rollup build is non-trivial as it merges CSS, handles MathjaxToSVG dependencies, and embeds runtime payloads. Run this command frequently to validate your changes).
  • Build readable development payloads: Run npm run dev
  • Check production packaging: Run npm run test:bundle after npm run build to verify the private React bootstrap, bundled font bytes, compressed locales, and release size target.
  • Build the public library API: Run npm run lib when changing exports or ExcalidrawAutomate APIs
  • Run ESLint: Run npm run code
  • Check CSS scanner policy: Run npm run lint:css. This uses the public stylelint-config-obsidianmd policy rules, with the browser target derived from manifest.json's minAppVersion using Obsidian's published Electron mapping. It follows the scanner workflow without adding the theme package's formatting rules. The command fails on warnings, so newly introduced policy findings can be caught before submission. This is a local CSS check, not the complete hosted CodeScanner review.
  • Fix ESLint Warnings: Run node ./scripts/fix-eslint-warnings.mjs

The shipped plugin is dist/main.js, dist/styles.css, and dist/manifest.json. Keep main.js below the 5 MB release target (5 × 1024 × 1024 = 5,242,880 bytes) and report its byte size and remaining headroom after dependency or packaging changes.

Updating the EA script template

npm run doc and npm run skill both build the public library declarations, then run full documentation generation. When ../ea-script-template exists, they also refresh its local agent references, generated EA declaration graph and provenance, type dependencies, and template update manifest. The template consumes declarations only; personal script workspaces no longer need this plugin as a Git dependency.

For a plugin-only reference update, run npm run lib followed by node scripts/generate-script-library.mjs --no-template-sync to leave the sibling template untouched. Review generated changes for unrelated stale snapshots.

After generation, run npm install, npm run check, npm run build, and npm run test:template in the template. Review both repositories separately and publish the template's updated master so users can receive the snapshot with npm run update-template. See the template's .template/README.md for ownership, conflict handling, and the one-time adoption procedure for older workspaces.

🧪 Testing

Use npm run test:regression with the dedicated native test vault, or npm run test:regression:portable for hosted checks. Follow the test guide for setup, fixtures, repeatable reports and additional native profiles. The independent suite accepts current fork behavior and protects fork-specific contracts and affected upstream workflows. Historical upstream tests are an optional compatibility investigation, not a required regression gate. Build before focused fast tests because they inspect the shipped bundle. Keep inventory and feature mappings current without treating discovery as behavioral coverage. Report suspected product defects for maintainer review; do not silently change behavior or bless failed snapshots. Focus on core Excalidraw and ExcalidrawAutomate; maintained scripts have their own tests in ea-scripts.

The native CLI lane supports macOS and Windows. Run npm run test:obsidian:runner for offline harness tests, then npm run test:native for the prepared local-vault regression profile. Focused verify:obsidian commands use the same fixed vault and rebuild the current workspace fork, plugin and available Extras before every sequence. They apply settings, deploy and hash-check the files automatically. See the one-time opening/trust/CLI prerequisites, reports and cleanup contract.

For Markdown embed changes, also run npm run test:markdown-embeds and npm run verify:obsidian:plugin -- --embed-recovery. See the runtime guide for fixture ownership, deferred rendering, popout coverage, and remaining manual checks.

For relative links, detached Reading sections and area-padding controls, use the six-case node scripts/testing/host/verify.mjs --embed-regressions lane. See drawing embed controls for behavior and scope.

For drawing-load warning changes, run npm run test:drawing-load-error to check file identity, read-only details, filename truncation, and unchanged confirmation results.

Because Obsidian runs across a variety of environments, please manually test your changes on as many of the following platforms as possible to avoid breaking the plugin for other users:

  • Desktop: Mac, Windows, Linux
  • Mobile: Android, iOS (Test on both Phones and Tablets)

Desktop mobile emulation is useful for checking responsive layout, but it does not reproduce every touch event, synthesized click, focus, scroll gesture, or mobile WebView behavior. If a change affects an interactive mobile control, validate it on at least one physical phone or tablet.

Use a risk-based test plan rather than a generic smoke test. Every change should identify the most likely regression and whether it needs separate coverage in:

  • the main Obsidian window
  • a newly opened and restored popout window
  • plugin reload and cold application startup
  • desktop and mobile layouts
  • offline mode, when the change affects packaged assets or runtime loading

🏗️ Architecture & Sub-components

This project consists of multiple sub-components and non-standard integrations to support Obsidian-specific features.

1. React & Package Manager

The plugin inflates one private React/ReactDOM runtime and combines it with one evaluated Excalidraw runtime. Every main-window and popout view leases that shared package while supplying its own stable ownerDocument.

  • References to React and ReactDOM are handled via PackageManager.ts (src/core/managers/PackageManager.ts).
  • React and its JSX runtimes are built from official npm entry points, compressed into the plugin, and inflated once during bundle bootstrap. The bootstrap uses a local window alias with the same indirect evaluation mechanism that underlies Excalidraw's error-handled evaluator. They remain external to the separately built Excalidraw artifact and to the plugin's library build so neither path creates a second React copy.
  • Do not introduce direct ReactDOM.createRoot() calls outside this package-manager model.
  • Do not publish React or ReactDOM on window. The documented window.ExcalidrawLib scripting surface is the deliberate exception.

Rendering and persistence have different window-ownership rules. DOM, events, portals, and React roots should use the owning view window. Existing plugin-level IndexedDB and local-storage data belongs to the main Obsidian application window and is shared with popouts; do not move it to view.ownerWindow without an explicit storage design and migration.

Typed Excalidraw host boundary

Obsidian-specific capabilities used inside the customized component must cross the typed host-adapter boundary configured by PackageManager. Do not pass the plugin, its settings object, or an active view through Excalidraw props or appState, and do not recover them through globals. Adapters should expose small semantic operations, read current plugin state, and remain owned by the evaluated window runtime. View-specific behavior must stay instance-scoped.

The fork is the source of truth for adapter contracts and protocol versions. Reuse its published types instead of defining parallel plugin-local unions or interfaces. The adapters are an internal protocol paired with this plugin's exact Excalidraw dependency: coordinate breaking changes across both repositories and fail fast on a missing or incompatible boundary rather than retaining legacy global bridges.

2. MathjaxToSVG

LaTeX support is provided by the MathjaxToSVG library, which is packaged as a separate sub-component (located in the MathjaxToSVG/ folder).

  • It is compressed using LZString during build time.
  • It is decompressed and executed dynamically during runtime only when needed, maintaining optimal Obsidian startup times.

3. Excalidraw Fork Guidelines

This plugin relies on a custom Excalidraw component fork: zsviczian/excalidraw.

If you must submit a PR to the Excalidraw fork, keep changes to the absolute minimum. Compounding changes to the fork make merging upstream updates from excalidraw/excalidraw exponentially harder.

  • Resist the temptation: Do not implement features in the fork if they can be achieved using plugin wrappers, monkey patches, or API integrations within the main Obsidian plugin repo.
  • Use ringfenced areas: Place changes in files clearly marked for the fork whenever possible:
    • packages/excalidraw/obsidianUtils.ts
    • packages/common/src/commonObsidianUtils.ts
    • packages/excalidraw/css/obsidianStylingOverrides.css
  • Mark your changes explicitly: Add a comment with your initials and the Issue or PR ID to easily identify custom additions during merge conflicts.
    private shouldRenderAllEmbeddables: boolean = false; //zsviczian
    
  • Use dedicated functions: If your code extension doesn't fit neatly into the ringfenced files, extract it into a dedicated new function rather than putting huge chunks of logic inline.
    //mfuria #329. Right-click pan support when enabled via host plugin setting
    if (
      isPanWithRightMouseEnabled() &&
      event.pointerType === "mouse" &&
      event.button === POINTER_BUTTON.SECONDARY &&
      !this.state.editingTextElement
    ) {
      // prevent native context menu
      const onContextMenu = (e: MouseEvent) => {
        e.preventDefault();
      };
      window.addEventListener('contextmenu', onContextMenu, { once: true });
    
      // Start right-click panning
      this.startRightClickPanning(event);
      return;
    }
    
    //mfuria #329. start right-click panning
    private startRightClickPanning(event) { ... }
    

4. Working Across Both Repositories

The customized component is maintained in the separate zsviczian/excalidraw repository. When both repositories are checked out as siblings, the usual path is ../excalidraw.

The repositories deliberately use different package managers:

  • obsidian-excalidraw-plugin: npm
  • zsviczian/excalidraw: Yarn

From ../excalidraw/packages/excalidraw, yarn build:obsidian produces four consumer-specific files in dist/obsidian: development and production JavaScript and CSS. This plugin reads the corresponding four files from node_modules/@zsviczian/excalidraw/dist/obsidian/.

For an unpublished integration test, you may temporarily copy those four generated files into the installed package under this repository's ignored node_modules. Keep the declared npm dependency unchanged. Running npm install restores the published package. The durable workflow is to publish a new component version, update the plugin dependency, run npm install, and rebuild.

Keep component commit readiness, local integration readiness, and durable consumer handoff separate. A copied artifact can validate the pair locally, but a plugin change that consumes a new fork API is not release-ready until the published package is installed and package.json plus package-lock.json reference that version.

For a maintainer-coordinated host-protocol release, update and test the fork contract first, inspect the package tarball, publish the fork package, then update this repository's exact dependency and lockfile. The final production build and smoke test must use the published package installed by npm install, not the temporary copied artifacts. Unit tests in the fork use structural fake adapters and do not require Obsidian; integration testing here must cover startup, reload, the main window, and popout creation and teardown.

The Excalidraw Obsidian artifact has strict runtime constraints:

  • one function-evaluable JavaScript file, with no runtime chunks
  • React, ReactDOM, and their JSX runtimes remain external and are supplied by this plugin
  • Mermaid remains external and is loaded lazily through Excalidraw Extras
  • all required assets work offline except deliberately lazy CJK font subsets
  • production is minified; development retains debugger-friendly source information

Radix menus and popovers may be portaled to the owning document body by ObsidianRadixPortal. Portaled content no longer has its original component ancestors and can sit behind modal stacking contexts. Style portaled content through a class that survives the portal, and test visibility, positioning, click-outside, and Escape behavior in the main window and a popout.

5. Incremental Refactoring

Use RefactorPlan.md as the living record for ongoing structural work. Refactors should be small enough to build and test independently. Move cohesive code intact before redesigning it, update the progress table and action log, and provide a risk-based test checklist at the end of each step.

ExcalidrawView must remain an Obsidian TextFileView; it should not be converted wholesale into React. React owns the child UI, while the view remains the Obsidian lifecycle and compatibility boundary. ExcalidrawAutomate, command IDs, settings, serialized data, and existing plugin integrations must remain backwards compatible.

6. Settings UI and persistence

The plugin keeps Obsidian 1.8.7 compatibility while using searchable declarative settings on Obsidian 1.13 and newer.

  • Do not bump the Obsidian dependency or minimum version just to use the declarative API. Gate it at runtime; returning an empty definition array is the intentional legacy fallback.
  • Maintain one canonical settings hierarchy and shared control behavior for both the declarative multi-page and legacy single-page layouts, including descriptions and Markdown export. Do not fork the two experiences into independent implementations.
  • Keep interdependent controls together and apply their visibility, options, and disabled state during initial render as well as after changes.
  • Persist settings through PluginSettingsManager; do not add independent saveData() calls or rely on plugin shutdown to finish an asynchronous save.
  • Treat a missing data.json, invalid/corrupted data, and a valid externally synchronized update as separate cases. Preserve the device-local recovery workflow and unknown forward-compatible setting keys.

🌍 Localization & User-Facing Text

Follow the user-facing change workflow for release notes, localization keys, and maintained translations.

📦 Pull Requests & Versioning

  • Do NOT bump versions: Please do not bump the version numbers in manifest.json, manifest-beta.json, or package.json in your Pull Requests. Version bumping and release coordination are handled exclusively by the maintainer during the final GitHub Release workflow.
  • Release notes: Follow the user-facing change workflow.

Once again, thank you for contributing to the plugin!