How pazerw/marginnote-companion works
Main Components
• Plugin Core: The central entry point appears to be src/mn-main.ts, which likely initializes the plugin and sets up the main orchestration.
• Controls: The src/controls folder contains UI-related files (both TypeScript and LESS styling) that likely manage display components or command buttons within the Obsidian UI.
• Handlers: Found in src/handlers (e.g., add-new-video, frontmatter, mn-data-handler), these modules probably process data incoming from MarginNote (such as handling metadata, video imports, or note transformation).
• Receivers: The src/receivers directory holds modules like autopaste, input-handler, and insert, indicating that these components are responsible for catching external events or data (e.g., receiving pasted content or note selections from MarginNote).
• Macros: Under src/macros, these files (autodef, macro-handler) seem to process template expansions or dynamic text generation.
• Templates: The src/template directory provides several files (basic templates, note-template, toc-template) that specify how inserted MarginNote content should be formatted in Obsidian.
• Settings and Configuration: Files like src/settings.ts and related LESS files (e.g., setting-tab.less) likely manage user configuration and plugin settings.
• Language Support: The src/lang subdirectory supports multi-language configurations (with English and Chinese files).
• Type Definitions: The src/typings directory contains TypeScript definitions to ensure type safety across the codebase.
• Build & Configuration: At the top level, you have ESBuild, Rollup, Jest configuration files, and others that set up the development environment and building process.
Out Relationships & Data Flow
• User actions in Obsidian (triggered via commands, toolbar buttons, or hotkeys) likely propagate to the Controls, which then call the Handlers.
• Handlers process the imported data (including video notes and PDF hierarchies) and pass them to the Receivers and Macro processing. For example, the autopaste receiver listens for selections from MarginNote.
• The Template modules then format these processed data inputs according to user-defined or default templates.
• Settings and language modules feed configuration values to the Controls, Handlers, and Template modules.
• Build/Configuration files ensure that these modules are properly bundled and deployed as an Obsidian plugin.
Architectural Patterns and Design Principles
• Modular Design: The clear separation between controls, handlers, receivers, templates, macros, and settings shows a modular architecture. Emphasize independent modules interacting through well-defined interfaces.
• Event-Driven Flow: Many components (such as receivers and handlers) indicate an event-based data flow, with direct responses to incoming commands or data from MarginNote.
• Layered Approach: At the base, build configurations and type definitions support the higher-level business logic layers (handlers and macros), which in turn support the presentation layer (controls and templates).
Relevant Technologies & Tools
• TypeScript is the primary language.
• LESS is used for styling (as seen in various .less files).
• Build tools include esbuild and rollup.
• Testing is set up via Jest (jest.config.ts).
• The plugin also depends on external tools (like media-extended) and interacts with Obsidian’s API.
Elements
• Each major component should be represented as a node with a clear label (e.g., “Plugin Core”, “Controls Module”, “Handlers”, “Receivers”, “Templates”, “Settings”, “Language Support”).
• One for core orchestration (central Hub),
• One for UI/presentation (Controls/Template),
• One for business logic (Handlers/Receivers/Macros),
• One for configuration (Settings/Language).
• Optionally, add annotations or callouts indicating key external integrations, such as the connection with MarginNote 4 and dependency on media-extended.