mcpField
I
Integrate Mind Elixir

Integrate Mind Elixir

github.com/ssshooter開発3.2k69 回インストール1 週間前に更新
リポジトリ

Integrate Mind Elixir について

Integrate Mind Elixirは、フレームワークに依存しないJavaScriptのマインドマップコアmind-elixirをフロントエンドに組み込むスキルです。初期化、データ操作、イベント、操作ガード、テーマ設定を扱います。

主な機能

  1. 01パッケージマネージャーまたはスクリプトで導入
  2. 02マインドマップのインスタンスを初期化
  3. 03マップデータの取得と更新
  4. 04操作やノードイベントを監視
  5. 05ユーザー操作を遮断して検証
  6. 06テーマのカスタマイズと変更

活用シーン

  1. 01フロントエンドにmind-elixirを組み込む
  2. 02外部データからマインドマップを更新
  3. 03ノード選択やマップ操作を監視
  4. 04保存前に操作を非同期で検証

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/ssshooter/mind-elixir-core --skill integrate-mind-elixir

インストール後、Claude Code で/integrate-mind-elixirを入力して読み込まれたか確認します。

詳細

Mind Elixir の統合

このスキルでは、フロントエンドプロジェクトに mind-elixir を統合する手順を説明します。Mind Elixir は、特定のフレームワークに依存しない JavaScript 製のマインドマップコアです。

1. インストール

パッケージマネージャーを使って Mind Elixir をインストールするか、スクリプトタグを使用できます。

NPM / Yarn / PNPM
npm i mind-elixir -S
# or
pnpm i mind-elixir
# or
yarn add mind-elixir
スクリプトタグ
<script type="module" src="https://cdn.jsdelivr.net/npm/mind-elixir/dist/MindElixir.js"></script>

CSS: スクリプトタグを使用する場合は、CSS もインポートする必要があります。

@import 'https://cdn.jsdelivr.net/npm/mind-elixir/dist/style.css';

2. 基本的な使い方

HTML 構造

マインドマップ用のコンテナを作成します。

<div id="map"></div>
<style>
  #map {
    height: 500px;
    width: 100%;
  }
</style>
初期化

JavaScript/TypeScript ファイルで Mind Elixir をインポートして初期化します。

import MindElixir from 'mind-elixir'
import { en } from 'mind-elixir/i18n'
import 'mind-elixir/style.css'

// 1. Define options
let options = {
  el: '#map', // or HTMLDivElement
  direction: MindElixir.LEFT,
  toolBar: true, // default true
  keypress: true, // default true
  overflowHidden: false, // default false
  mouseSelectionButton: 0, // 0 for left button, 2 for right button, default 0
  contextMenu: {
    locale: en, // [cn,zh_CN,zh_TW,en,ru,ja,pt,it,es,fr,ko,ro,da,fi,de,nl,nb,sv]
    focus: true,
    link: true,
    extend: [
      {
        name: 'Node edit',
        onclick: () => {
          alert('extend menu')
        },
      },
    ],
  }, // default true
  before: {
    insertSibling(type, obj) {
      return true
    },
  },
  // Custom markdown parser (optional)
  // markdown: (text) => customMarkdownParser(text), // provide your own markdown parser function
}

// 2. Create instance
let mind = new MindElixir(options)

// 3. Initialize with data
// Create new data
const data = MindElixir.new('new topic')
// Or use existing data passed from backend
// const data = { ... }

mind.init(data)

3. データ構造

標準的なノードのデータ構造は次のとおりです。

const nodeData = {
  topic: 'node topic',
  id: 'bd1c24420cd2c2f5',
  style: { fontSize: '32', color: '#3298db', background: '#ecf0f1' },
  expanded: true,
  parent: null,
  tags: ['Tag'],
  icons: ['😀'],
  hyperLink: 'https://github.com/ssshooter/mind-elixir-core',
  image: {
    url: 'https://raw.githubusercontent.com/ssshooter/mind-elixir-core/master/images/logo2.png',
    height: 90,
    width: 90,
  },
  children: [
    {
      topic: 'child',
      id: 'xxxx',
      // ...
    },
  ],
}

4. 基本操作

データの取得
const data = mind.getData() // Returns the current data object
const dataString = mind.getDataString() // Returns serialized data string
データの更新

外部ソースからデータを更新した場合、または再レンダリングが必要な場合:

mind.refresh(data)

5. イベント処理

mind.bus を使用して、さまざまなイベントをリッスンできます。

// Listen to all operations
mind.bus.addListener('operation', operation => {
  console.log(operation)
  // operation: { name: 'action_name', obj: target_object }
})

// Listen to node selection
mind.bus.addListener('selectNodes', nodes => {
  console.log(nodes)
})

// Listen to node expansion
mind.bus.addListener('expandNode', node => {
  console.log('expandNode: ', node)
})

6. 操作ガード

before フックを使用して、ユーザーの操作をインターセプトし、制御できます。これは、非同期の検証や変更を適用する前のデータ保存に役立ちます。

let mind = new MindElixir({
  // ... other options
  before: {
    // Return true to allow, false to prevent
    // Supports async functions
    async addChild(el, obj) {
      try {
        await saveDataToDb()
        return true
      } catch (err) {
        return false // Operation blocked
      }
    },
    // Other hooks: insertSibling, removeNode, moveNode, etc.
  },
})

7. テーマのカスタマイズ

初期化時または動的にテーマをカスタマイズできます。

const options = {
  // ...
  theme: {
    name: 'Dark',
    // main lines color palette
    palette: ['#848FA0', '#748BE9', '#D2F9FE', '#4145A5', '#789AFA', '#706CF4', '#EF987F', '#775DD5', '#FCEECF', '#DA7FBC'],
    // overwrite css variables
    cssVar: {
      '--main-color': '#ffffff',
      '--main-bgcolor': '#4c4f69',
      '--color': '#cccccc',
      '--bgcolor': '#252526',
      '--panel-color': '255, 255, 255',
      '--panel-bgcolor': '45, 55, 72',
    },
    // all variables see /src/index.less
  },
  // ...
}

テーマを動的に変更します:

mind.changeTheme({
  name: 'Latte',
  palette: ['#dd7878', '#ea76cb', '#8839ef', '#e64553', '#fe640b', '#df8e1d', '#40a02b', '#209fb5', '#1e66f5', '#7287fd'],
  cssVar: {
    '--main-color': '#444446',
    '--main-bgcolor': '#ffffff',
    '--color': '#777777',
    '--bgcolor': '#f6f6f6',
  },
})

コメント