Integrate Mind Elixir by ssshooter/mind-elixir-core
npx skills add https://github.com/ssshooter/mind-elixir-core --skill 'Integrate Mind Elixir'本技能将指导您将 mind-elixir 集成到前端项目中的过程。Mind Elixir 是一个与框架无关的 JavaScript 思维导图核心库。
您可以通过包管理器安装 Mind Elixir,或者使用 script 标签。
npm i mind-elixir -S
# 或者
pnpm i mind-elixir
# 或者
yarn add mind-elixir
<script type="module" src="https://cdn.jsdelivr.net/npm/mind-elixir/dist/MindElixir.js"></script>
CSS : 如果您使用 script 标签,还需要导入 CSS:
@import 'https://cdn.jsdelivr.net/npm/mind-elixir/dist/style.css';
为思维导图创建一个容器。
<div id="map"></div>
<style>
#map {
height: 500px;
width: 100%;
}
</style>
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在您的 JavaScript/TypeScript 文件中导入并初始化 Mind Elixir。
import MindElixir from 'mind-elixir'
import { en } from 'mind-elixir/i18n'
import 'mind-elixir/style.css'
// 1. 定义选项
let options = {
el: '#map', // 或者 HTMLDivElement
direction: MindElixir.LEFT,
toolBar: true, // 默认为 true
keypress: true, // 默认为 true
overflowHidden: false, // 默认为 false
mouseSelectionButton: 0, // 0 代表左键,2 代表右键,默认 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')
},
},
],
}, // 默认为 true
before: {
insertSibling(type, obj) {
return true
},
},
// 自定义 markdown 解析器(可选)
// markdown: (text) => customMarkdownParser(text), // 提供您自己的 markdown 解析函数
}
// 2. 创建实例
let mind = new MindElixir(options)
// 3. 使用数据初始化
// 创建新数据
const data = MindElixir.new('new topic')
// 或者使用从后端传递的现有数据
// const data = { ... }
mind.init(data)
标准的节点数据结构如下:
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',
// ...
},
],
}
const data = mind.getData() // 返回当前数据对象
const dataString = mind.getDataString() // 返回序列化的数据字符串
如果您从外部源更新了数据或需要重新渲染:
mind.refresh(data)
您可以使用 mind.bus 监听各种事件。
// 监听所有操作
mind.bus.addListener('operation', operation => {
console.log(operation)
// operation: { name: 'action_name', obj: target_object }
})
// 监听节点选择
mind.bus.addListener('selectNodes', nodes => {
console.log(nodes)
})
// 监听节点展开
mind.bus.addListener('expandNode', node => {
console.log('expandNode: ', node)
})
您可以使用 before 钩子来拦截和控制用户操作。这在应用更改前进行异步验证或保存数据时非常有用。
let mind = new MindElixir({
// ... 其他选项
before: {
// 返回 true 允许,false 阻止
// 支持异步函数
async addChild(el, obj) {
try {
await saveDataToDb()
return true
} catch (err) {
return false // 操作被阻止
}
},
// 其他钩子:insertSibling, removeNode, moveNode 等
},
})
您可以在初始化时或动态地自定义主题。
const options = {
// ...
theme: {
name: 'Dark',
// 主线颜色调色板
palette: ['#848FA0', '#748BE9', '#D2F9FE', '#4145A5', '#789AFA', '#706CF4', '#EF987F', '#775DD5', '#FCEECF', '#DA7FBC'],
// 覆盖 css 变量
cssVar: {
'--main-color': '#ffffff',
'--main-bgcolor': '#4c4f69',
'--color': '#cccccc',
'--bgcolor': '#252526',
'--panel-color': '255, 255, 255',
'--panel-bgcolor': '45, 55, 72',
},
// 所有变量请参见 /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',
},
})
每周安装量
–
代码仓库
GitHub 星标数
3.0K
首次出现
–
安全审计
This skill guides you through the process of integrating mind-elixir into a frontend project. Mind Elixir is a framework-agnostic JavaScript mind map core.
You can install Mind Elixir via your package manager or use a script tag.
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 : If you use the script tag, you also need to import the CSS:
@import 'https://cdn.jsdelivr.net/npm/mind-elixir/dist/style.css';
Create a container for the mind map.
<div id="map"></div>
<style>
#map {
height: 500px;
width: 100%;
}
</style>
Import and initialize Mind Elixir in your JavaScript/TypeScript file.
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)
The standard node data structure is as follows:
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',
// ...
},
],
}
const data = mind.getData() // Returns the current data object
const dataString = mind.getDataString() // Returns serialized data string
If you have updated data from an external source or need to re-render:
mind.refresh(data)
You can listen to various events using 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)
})
You can use before hooks to intercept and control user operations. This is useful for asynchronous validation or saving data before applying changes.
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.
},
})
You can customize the theme during initialization or dynamically.
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
},
// ...
}
Change theme dynamically:
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',
},
})
Weekly Installs
–
Repository
GitHub Stars
3.0K
First Seen
–
Security Audits
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装