Mind Elixir Core Documentation

repository·master·Indexed 25 days ago

https://github.com/ssshooter/mind-elixir-core

Mind Elixir is a free, open-source, framework-agnostic JavaScript mind map engine. Version 5.15.0-beta.3 provides a high-performance core for building interactive mind maps with features including bulk operations, undo/redo, custom styling, and operation guards. It supports data import/export via JSON, PNG image export (built-in or via @ssshooter/modern-screenshot), and dynamic theme customization.

Tokens
18.9K
Snippets
47
Records
107
Agent score
83%

What's inside Mind Elixir

  1. Understand the Undo/Redo implementation mechanism

    master

    Mind Elixir uses a Snapshot pattern for undo/redo functionality. Instead of calculating diffs or patches, the system saves a complete data snapshot (MindElixirData) for every operation.

    Key Architecture Components:

    • history: A stack of History entries.
    • currentIndex: A pointer tracking the current position in history (-1 indicates the initial state).
    • current: The current data snapshot.
    • currentSelectedNodes: The context of currently selected nodes used to restore state.

    Important Note on Memory: Because it uses full snapshots rather than diffs, memory usage grows linearly with the number of operations.

  2. Explore the Mind Elixir Ecosystem

    master

    The Mind Elixir ecosystem includes several specialized packages for extending functionality, such as node menus, XMind export, HTML export, and React integration.

    Available packages:

    • @mind-elixir/node-menu: Node menu functionality.
    • @mind-elixir/node-menu-neo: Neo version of node menus.
    • @mind-elixir/export-xmind: Export mind maps to XMind format.
    • @mind-elixir/export-html: Export mind maps to HTML.
    • mind-elixir-react: React component wrapper for Mind Elixir.
  3. Enable Markdown rendering in Mind Elixir

    master

    By default, Mind Elixir does not parse markdown. To enable markdown rendering in nodes, you must provide a markdown function in the MindElixir constructor options. This function receives the node text as input and must return the HTML string to be rendered.

    let mind = new MindElixir({
      // ... other options
      markdown: text => {
        // Return HTML string here
        return text;
      },
    })
  4. Plaintext Format Specification

    master

    The plaintext format is an indentation-based representation used to describe mind map structures, including tree hierarchies, arrow connections, and summaries.

    Basic Structure

    • Each node starts with - .
    • Hierarchy is determined by indentation (2 spaces per level).

    Node Metadata

    Nodes can include optional information after the topic text:

    • Reference ID: [^refId] (format: [^alphanumeric-or-dash]). Used by arrows to link to specific nodes. Stored in node.metadata.refId.
    • Style Object: {JSON}. Supports keys like fontSize, fontFamily, color, background, and fontWeight. Stored in node.style.
    • Combination: - Node [^id1] {"color": "#ff0000"} (Order: Topic $\rightarrow$ RefId $\rightarrow$ Style).

    Arrow Connections

    Arrows describe relationships between nodes and start with > :

    • Bidirectional: > [^fromId] <-label-> [^toId]
    • Unidirectional: > [^fromId] >-label-> [^toId]
    • The indentation of the arrow line determines its parent node.

    Summaries

    Summaries describe a group of sibling nodes and start with }:

    • }:N label: Summarizes the $N$ sibling nodes immediately preceding this line.
    • } label: Summarizes all preceding sibling nodes.
    - Root Node
      - Child Node 1
        - Child Node 1-1 {"color": "#e87a90", "fontSize": "18px"}
        - Child Node 1-2
        - Child Node 1-3
        - }:2 Summary of first two nodes
      - Child Node 2
        - Child Node 2-1 [^node-2-1]
        - Child Node 2-2 [^id2]
        - > [^node-2-1] <-Bidirectional Link-> [^id2]
  5. Integrate `marked` for full Markdown support

    master

    For comprehensive markdown support, integrate a third-party library like marked.

    1. Install the library:
    npm i marked
    1. Pass the library's parsing function to the markdown option during initialization.
    import { marked } from 'marked'
    import MindElixir from 'mind-elixir'
    
    let mind = new MindElixir({
      // ... other options
      markdown: text => marked(text),
    })
  6. Export Mind Map as Image

    master

    To export the mind map as an image (JPG, PNG, etc.), use the @zumer/snapdom library.

    Note: The mind.exportSvg() method is deprecated and will be removed in future versions. Use snapdom instead.

    1. Install @zumer/snapdom.
    2. Pass mind.nodes to snapdom().
    3. Call .download() on the result.
    import { snapdom } from '@zumer/snapdom'
    
    const download = async () => {
      const result = await snapdom(mind.nodes)
      await result.download({ format: 'jpg', filename: 'my-capture' })
    }
  7. Install Mind Elixir via NPM or Script Tag

    master

    You can install Mind Elixir as a dependency using npm or include it directly in your HTML via a script tag.

    NPM Installation:

    npm i mind-elixir -S

    Script Tag (CDN): Include the module script in your HTML:

    <script type="module" src="https://cdn.jsdelivr.net/npm/mind-elixir/dist/MindElixir.js"></script>

    CSS Requirement: If using the script tag, you must also import the styles in your CSS file:

    @import 'https://cdn.jsdelivr.net/npm/mind-elixir/dist/style.css';
  8. Export Mind Map as Image using snapdom

    master

    Use the snapdom function from @zumer/snapdom to capture the mind map nodes from your Mind Elixir instance (mind.nodes). You can then call .download() on the result to save the image.

    Note: The built-in mind.exportSvg() method is deprecated. Use this @zumer/snapdom approach for new projects.

    import { snapdom } from '@zumer/snapdom'
    // Assuming `mind` is your MindElixir instance
    
    const downloadImage = async () => {
      // 1. Capture the nodes
      const result = await snapdom(mind.nodes)
    
      // 2. Download as JPG or PNG
      await result.download({
        format: 'jpg', // or 'png'
        filename: 'mind-map-export',
      })
    }