Compare commits

..

227 Commits

Author SHA1 Message Date
wanglin2
68cb24c0b6 Merge branch 'feature' into main 2023-08-19 08:04:45 +08:00
wanglin2
e3959107bd Demo:修复单独编辑大纲时能给根节点添加兄弟节点的bug 2023-08-19 08:04:28 +08:00
wanglin2
4b3c81ab91 Merge branch 'feature' into main 2023-08-18 23:11:03 +08:00
wanglin2
76b5d9d11d 打包0.6.15-fix.2 2023-08-18 23:10:29 +08:00
wanglin2
22d0fe5ac4 打包0.6.15-fix.2 2023-08-18 23:10:01 +08:00
wanglin2
8b8d549abd Fix:修复在Firefox浏览器中富文本节点无法显示的问题 2023-08-18 23:06:30 +08:00
wanglin2
731a5a504d Merge branch 'feature' into main 2023-08-18 15:13:42 +08:00
wanglin2
008e697b74 打包0.6.15-fix.1 2023-08-18 15:13:24 +08:00
wanglin2
fe1745e779 Merge branch 'feature' into main 2023-08-18 14:55:15 +08:00
wanglin2
e6ac9be402 打包0.6.15 2023-08-18 14:54:49 +08:00
wanglin2
b427a9ed1b Doc: update 2023-08-18 14:51:42 +08:00
wanglin2
a4dc9210b3 Fix:修复节点边框会重合的问题 2023-08-18 14:25:24 +08:00
wanglin2
fb681de1f5 Feat:增加错误处理 2023-08-18 11:02:24 +08:00
wanglin2
3757622521 Fix:修复画布距浏览器窗口左上角不为0时鼠标缩放时不以鼠标为中心的问题 2023-08-18 10:33:52 +08:00
wanglin2
12265be7d4 Feat:新增禁止鼠标滚轮缩放的配置 2023-08-18 10:16:19 +08:00
wanglin2
df1aed7e04 Fix:优化展开收起按钮的占位元素:1.没有子节点的节点不渲染该元素;2.根据是否存在子节点动态更新该元素 2023-08-18 10:09:23 +08:00
wanglin2
c32c9d1ba1 更新群二维码 2023-08-17 10:06:16 +08:00
wanglin2
26d75c9203 打包 2023-08-17 10:04:49 +08:00
wanglin2
8d1e9fa8e9 Demo:侧边栏涉及图形的选项增加可视化效果 2023-08-17 10:00:33 +08:00
wanglin2
ebc99e97af Feat:导出pdf支持根据长宽比自动调整方向 2023-08-17 08:49:40 +08:00
wanglin2
efe4aa0ec2 Feat:导出pdf支持根据图片大小分页导出 2023-08-16 17:45:34 +08:00
wanglin2
3f659af1e1 Featc:删除重复的exportPadding配置,改为使用exportPaddingX和exportPaddingY配置;去除导出图片时的双重padding设置 2023-08-16 17:20:05 +08:00
wanglin2
64209a6392 Featc:删除重复的exportPadding配置,改为使用exportPaddingX和exportPaddingY配置;去除导出图片时的双重padding设置 2023-08-16 17:19:35 +08:00
wanglin2
8d1e5dd2e9 Feat:导出svg的图形的paddingX和paddingY改为单侧padding 2023-08-16 17:17:18 +08:00
wanglin2
d218122752 '打包' 2023-08-16 09:31:03 +08:00
wanglin2
9af8afca22 Demo:单独编辑大纲不再和画布联动,优化大数据量下的编辑体验 2023-08-16 09:25:33 +08:00
wanglin2
002ec41ba8 Fix:修复节点文本为空时显示异常问题 2023-08-15 09:30:00 +08:00
wanglin2
ffff257f57 Demo:修复打开本地文件右上角的提示无法关闭的问 2023-08-15 09:03:26 +08:00
街角小林
41d0b675a0 Merge pull request #269 from suka233/main
fix: 修复尝试赋值给const常量导致的vite启动dev服务报错
2023-08-15 08:48:43 +08:00
suka233
7601d6730d Merge pull request #1 from suka233/suka233-patch-1
fix: 修复尝试赋值给const常量导致的vite启动dev服务报错
2023-08-14 17:07:29 +08:00
suka233
f0e9b76bb5 fix: 修复尝试赋值给const常量导致的vite启动dev服务报错 2023-08-14 15:13:42 +08:00
wanglin2
4ec33062a4 Merge branch 'feature' into main 2023-08-14 09:39:03 +08:00
wanglin2
edc63b1293 打包 2023-08-14 09:38:49 +08:00
wanglin2
ec83976818 Doc:调整首页文档 2023-08-14 09:36:10 +08:00
wanglin2
393410757b Demo:调整小地图位置,解决被侧边按钮遮挡的问题 2023-08-14 09:29:11 +08:00
wanglin2
f20748744a Demo:右下角支持跳转相关链接 2023-08-14 09:27:59 +08:00
wanglin2
067131f76d Merge branch 'feature' into main 2023-08-13 12:21:16 +08:00
wanglin2
f689d333f9 打包0.6.14 2023-08-13 12:20:31 +08:00
wanglin2
b3059bb6a3 Doc: update 2023-08-13 12:18:25 +08:00
wanglin2
b135f6a61c Demo:支持粘贴知犀思维导图的节点数据 2023-08-13 11:43:44 +08:00
wanglin2
2a8b71497f Feat:自定义处理剪贴板函数支持返回Promise实例 2023-08-13 09:49:29 +08:00
wanglin2
726ebc5e88 Feat:支持自定义处理剪贴板中的文本数据 2023-08-13 08:47:35 +08:00
wanglin2
2c56cd453c Demo:支持从右键菜单删除节点的超链接,备注 2023-08-12 22:45:41 +08:00
wanglin2
bf2f9b2697 Demo:修复退出禅模式后左下角的节点和字数统计未更新的问题 2023-08-12 22:17:38 +08:00
wanglin2
fbd061e8b3 Demo:修复大纲修改一个节点的文本后再点击其他节点时不聚焦的问题 2023-08-12 15:43:10 +08:00
wanglin2
680320ba76 Demo:修复基础样式侧边栏打开状态下,导入思维导图数据后侧边栏数据未更新的问题 2023-08-12 15:10:46 +08:00
wanglin2
0d992bd6b1 Demo:颜色选择器支持选择透明颜色 2023-08-12 14:58:32 +08:00
wanglin2
c80eacc5e7 Demo:修复在节点样式侧边栏里无法去除节点的文本修饰线样式的问题 2023-08-12 14:42:14 +08:00
wanglin2
6d202b4b7d Demo:修复无法在节点图片弹窗里删除节点图片的问题 2023-08-12 14:21:11 +08:00
wanglin2
94478fe9f3 Demo:修复开启输入自动进入文本编辑模式和其他输入框冲突的问题 2023-08-12 11:12:11 +08:00
wanglin2
5745e4567b Feat:修改复制粘贴实现方式,去除创建隐藏输入框,支持跨浏览器粘贴思维导图数据 2023-08-12 10:57:51 +08:00
wanglin2
c6a3f4ac7b Feat:去除创建隐藏输入框,通过navigator.clipboard实现复制粘贴 2023-08-11 17:39:04 +08:00
wanglin2
f6609b3050 更新群二维码 2023-08-11 09:11:30 +08:00
wanglin2
4d69778a50 打包0.6.13 2023-08-11 09:10:34 +08:00
wanglin2
c8dfbd3b87 Doc: update 2023-08-11 09:08:44 +08:00
wanglin2
c0aab1e921 Demo:分类整理图片文件 2023-08-10 16:56:04 +08:00
wanglin2
6efee6e859 打包 2023-08-10 10:09:08 +08:00
wanglin2
dd82bf0879 优化代码 2023-08-10 10:06:02 +08:00
街角小林
2d41b5f9e6 Merge pull request #250 from kalcaddle/main
修复部分小问题
2023-08-10 09:23:02 +08:00
街角小林
7e7b6fae9d Merge branch 'main' into main 2023-08-10 09:22:56 +08:00
街角小林
29020daaf0 Merge pull request #248 from Xbs233/main
fix:手势缩小时 会先放大一次 再缩小
2023-08-10 08:55:25 +08:00
wanglin2
6bcead7784 Demo:修复在大纲中插入新节点报错的问题 2023-08-10 08:50:26 +08:00
wanglin2
9625129691 Demo:完善右键菜单和富文本工具条的暗黑模式 2023-08-10 08:47:16 +08:00
warlee
765d0ee212 还原. 2023-08-09 18:58:52 +08:00
warlee
099d4cd78e 画布背景图为none时处理为空. 2023-08-09 18:56:14 +08:00
wanglin2
d9a6981df4 Fix:修复主题配置中背景图片为none时会发起一个异常请求的问题 2023-08-09 18:43:43 +08:00
wanglin2
bbf424c6d2 Feat:1.非富文本输入框进入编辑状态时取消默认全选;2.存在一个激活节点时,支持按下中文、数字、英文按键时自动进入文本编辑模式 2023-08-09 18:26:50 +08:00
warlee
5cde3b76fe Merge branch 'main' of https://github.com/kalcaddle/mind-map
* 'main' of https://github.com/kalcaddle/mind-map:
  打包
  Demo:组件卸载时解除绑定的事件
  打包
  Demo:一些耗时的操作添加loading
  Feat:去掉异步渲染节点的逻辑
2023-08-09 18:14:46 +08:00
warlee
75af742053 Merge branch 'wanglin2:main' into main 2023-08-09 18:04:00 +08:00
wanglin2
69e192ea9d Fix:修复在移动端激活节点、展开收起时等操作时会拉起输入法的问题 2023-08-09 17:22:23 +08:00
wanglin2
5a32c1d99d Fix:修复在移动端激活节点、展开收起时等操作时会拉起输入法的问题 2023-08-09 17:16:31 +08:00
wanglin2
e81e0a5512 Fix:修复快速拖动节点几次后会概率性报错的问题 2023-08-09 17:12:55 +08:00
wanglin2
2fef76c55c Feat:导出图片由html2canvas库改为dom-to-image-more库 2023-08-09 17:01:35 +08:00
wanglin2
49735950f2 打包 2023-08-09 09:37:20 +08:00
wanglin2
c005455144 Demo:组件卸载时解除绑定的事件 2023-08-09 09:36:08 +08:00
wanglin2
ca4afb5440 打包 2023-08-09 09:13:57 +08:00
wanglin2
885647cedf Demo:一些耗时的操作添加loading 2023-08-09 09:09:43 +08:00
wanglin2
dc8efbe3ef Feat:去掉异步渲染节点的逻辑 2023-08-09 09:08:45 +08:00
Xbs233
888b8e725a fix:手势缩小时 会先放大一次 再缩小
修复初次onTouchmove时 必然是放大的情况
2023-08-08 21:23:12 +08:00
warlee
15d65db19d Merge branch 'main' of https://github.com/kalcaddle/mind-map
* 'main' of https://github.com/kalcaddle/mind-map:
  '打包'
  Demo:保存视图数据的逻辑增加防抖操作,优化性能
2023-08-08 17:22:00 +08:00
warlee
2ce0d4cd11 no message 2023-08-08 17:21:50 +08:00
warlee
13f3c2c20c - 移动端手势缩放优化: 按线性关系进行缩放,双指位移可以调整画布位置;
- 拖动画布优化: 只读模式拖拽画布时点击在子元素上时无法拖动问题处理(只读模式拖拽,鼠标中键拖拽,移动端拖拽)
2023-08-08 17:21:05 +08:00
wanglin2
d707329526 '打包' 2023-08-08 16:31:15 +08:00
wanglin2
69faa8bb3e Demo:保存视图数据的逻辑增加防抖操作,优化性能 2023-08-08 16:29:29 +08:00
wanglin2
86b184d5c1 Doc: update 2023-08-08 09:51:05 +08:00
wanglin2
2b6263acb4 打包0.6.12 2023-08-07 18:07:58 +08:00
wanglin2
187c940e56 Doc: update 2023-08-07 17:54:56 +08:00
wanglin2
4b59bec01c Demo:优化界面暗黑效果 2023-08-07 17:05:47 +08:00
街角小林
9427ee550c Merge pull request #240 from kalcaddle/main
部分问题修复及细节优化
2023-08-07 16:25:18 +08:00
街角小林
14975e117c Merge branch 'main' into main 2023-08-07 16:25:08 +08:00
wanglin2
d6254c0cc2 Merge branch 'feature' into main 2023-08-07 16:07:12 +08:00
wanglin2
4a81ce9cc2 修复本地开发热更新失效的问题 2023-08-07 10:32:42 +08:00
wanglin2
d17191c890 Demo:优化大纲编辑 2023-08-07 10:09:05 +08:00
wanglin2
ff56fe3e68 Demo:扩展大纲功能,支持拖拽,删除 2023-08-06 22:37:13 +08:00
wanglin2
6bdcec0fca Demo:支持全屏编辑大纲 2023-08-05 18:38:22 +08:00
wanglin2
27885aabe7 Demo:大纲不再使用节点默认样式 2023-08-05 12:04:43 +08:00
wanglin2
e345037f9b Doc:update 2023-08-04 22:38:34 +08:00
warlee
da5290e649 ### 问题修复
- mindMap.setFullData设置文件内容,主题为深色时主界面没有自动切换到深色,要点击主题按钮才切换;
- xmind 部分老版本文件解析报错;(xmind解析导出给外部可用)
- 点击节点图片上的缩放按钮,点击后松开(没有拖拽缩放),后续图片缩放按钮都不显示问题;

### 细节优化
- 右侧边栏展开关闭添加css activeSidebar到container上,方便界面样式自适应调整;
- 节点插入图片后无法删除图片(添加贴纸也如此)
- 双击节点输入时,输入框样式边框覆盖到完整节点的话会更好;
- 双击节点选中文字;
- 鼠标中键按住拖拽画布支持(左键拖拽可能误操作在节点上,右键框选, 中键拖拽画布就很完善了);
2023-08-04 21:19:39 +08:00
wanglin2
516676b484 更新群二维码 2023-08-04 20:14:26 +08:00
wanglin2
20a8934da9 Fix:修复大纲里点击文字编辑时输入框焦点丢失的问题 2023-08-04 16:19:08 +08:00
wanglin2
0075c44b29 Fix:修复富文本模式下,搜索替换后换行会丢失的问题 2023-08-04 15:54:16 +08:00
wanglin2
ec7a8cdd43 Feat:搜索支持连续替换 2023-08-04 15:38:03 +08:00
wanglin2
1629bb7ccf Fix:修复搜索不能替换为空字符串的问题 2023-08-04 14:21:36 +08:00
wanglin2
35bff6ab57 Feat:曲线风格下,根节点的连接线样式支持和其他节点保持一致 2023-08-04 09:39:21 +08:00
wanglin2
ef9d8b0ea4 Fix:修复移动节点时新位置的提示块过大的问题 2023-08-04 09:11:02 +08:00
wanglin2
5d4c5703bb Fix:修复当思维导图距浏览器窗口左上角不为0时,小地图渲染不正确的问题 2023-08-03 17:04:41 +08:00
wanglin2
11bb519db8 Feat:支持格式刷功能 2023-08-03 16:50:07 +08:00
wanglin2
1952280003 Demo:给对话框添加唯一的class,方便开发者调整样式 2023-08-03 08:49:29 +08:00
wanglin2
c845a0b7fa Fix:修复只读模式下按住节点无法拖动画布的问题 2023-08-02 20:00:08 +08:00
wanglin2
f1748e7e42 Fix:修复移动端双指缩放过于灵敏的问题 2023-08-02 19:49:12 +08:00
wanglin2
49063d257b Feat:支持通过配置指定内部一些元素添加到的位置 2023-08-02 19:36:03 +08:00
wanglin2
803c83ac4f Feat:节点移动结束事件node_dragend增加回调参数,可以获取到移动到节点的uid 2023-08-02 19:05:15 +08:00
wanglin2
0bdf9f3add Fix:修复当思维导图全部移除可视区域后小地图中的指示器也会移除小地图区域的问题 2023-08-02 18:48:08 +08:00
wanglin2
10ed3d4f7c Merge branch 'feature' into main 2023-08-01 18:55:55 +08:00
wanglin2
8fc7f7d32c 打包 2023-08-01 18:55:32 +08:00
wanglin2
27a0efa4e0 Demo:1.打包不修改静态资源的文件名;2.支持运行时设置静态资源路径 2023-08-01 18:54:40 +08:00
wanglin2
7d227e901a Merge branch 'feature' into main 2023-08-01 09:51:30 +08:00
wanglin2
080d7489e7 打包 2023-08-01 09:51:12 +08:00
wanglin2
b11bd5a7ef Demo:提供应用接管模式,方便对接自己的存储服务 2023-08-01 09:49:44 +08:00
wanglin2
80ae38d295 Merge branch 'feature' into main 2023-07-31 09:48:07 +08:00
wanglin2
a4b7915196 Doc:update 2023-07-31 09:45:20 +08:00
wanglin2
4d4f1b993e Merge branch 'feature' into main 2023-07-30 21:55:37 +08:00
wanglin2
b814bd35ca 打包0.6.11-fix.1 2023-07-30 21:55:20 +08:00
wanglin2
c57361a360 Fix:修复节点文字为白色时编辑的时候看不见的问题 2023-07-30 21:53:32 +08:00
wanglin2
f8c2a62bd6 Merge branch 'feature' into main 2023-07-30 10:58:19 +08:00
wanglin2
59241717f5 打包0.6.11 2023-07-30 10:57:42 +08:00
wanglin2
e90509cac9 Doc: update 2023-07-30 10:56:35 +08:00
wanglin2
8a8cc26c1d Feat:优化小地图,去除小地图内的节点内容,优化性能 2023-07-30 10:51:38 +08:00
wanglin2
1d443b9f94 Doc: update 2023-07-30 09:44:00 +08:00
wanglin2
60a4f443a7 Demo:节点图片上传支持输入网络图片 2023-07-30 09:41:58 +08:00
wanglin2
72c2540dcc Merge branch 'feature' into main 2023-07-29 23:18:46 +08:00
wanglin2
18cec3b75a 打包 2023-07-29 23:18:18 +08:00
wanglin2
d4aae5268e Demo:1.新增主题;2.主题列表新增tab分类 2023-07-29 23:16:59 +08:00
wanglin2
99ca0738d4 Merge branch 'feature' into main 2023-07-29 19:50:07 +08:00
wanglin2
408ca6d711 Doc:updagte 2023-07-29 19:49:08 +08:00
wanglin2
99dcb55397 Merge branch 'feature' into main 2023-07-29 19:23:43 +08:00
wanglin2
e11b6647b8 打包0.6.10 2023-07-29 19:22:40 +08:00
wanglin2
78f5d4ec88 Demo:支持点击节点内的图标显示一个图标快捷替换和删除悬浮面板 2023-07-29 16:08:12 +08:00
wanglin2
20eba7b29b Demo:修复在搜索框回车后输入框焦点丢失的问题 2023-07-29 14:24:50 +08:00
wanglin2
4c9698a147 Fix:1.修复内部数据深拷贝位置不正确的问题;2.修复富文本节点换行不生效的问题;3.修复切换主题等场景时节点换行会丢失的问题; 2023-07-29 14:23:57 +08:00
wanglin2
55da8eac83 Fix:修复调整图片大小的按钮在节点操作后没有更新的问题 2023-07-29 10:45:25 +08:00
wanglin2
17ea049393 Demo:调整添加节点图标的UI;新增节点图标;新增贴纸 2023-07-29 10:36:57 +08:00
wanglin2
d2e468287d Demo:优化搜索,鼠标不在搜索区域内不聚焦,解决鼠标不在搜索区域内无法删除输入的文字的问题 2023-07-28 21:29:05 +08:00
wanglin2
ad6085890e Demo:1.支持通过图标调出搜索;2.支持通过图标切换暗黑模式 2023-07-28 17:45:53 +08:00
wanglin2
cd4f1b1bd8 Feat:搜索支持搜索空白字符和替换为空白字符 2023-07-28 17:34:55 +08:00
wanglin2
a2acf810cb Fix:修复搜索定位到某个节点后删除该节点,再次搜索搜索结果未更新的问题 2023-07-28 17:05:44 +08:00
wanglin2
14bd7c3705 Merge branch 'feature' into main 2023-07-28 16:47:17 +08:00
wanglin2
5d0c9dcab1 打包0.6.9-fix.1 2023-07-28 16:46:38 +08:00
wanglin2
def2f02eea 1.修复搜索进行一次单个替换后再全部替换不正确的问题;2.不会再直接修改传入的data对象,内部会深拷贝一份 2023-07-28 16:36:56 +08:00
wanglin2
a74a60c22d 更新群二维码 2023-07-28 09:38:00 +08:00
wanglin2
74d37f2cbc Merge branch 'feature' into main 2023-07-28 09:36:54 +08:00
wanglin2
6ca9a116c2 打包0.6.9 2023-07-28 09:36:25 +08:00
wanglin2
8e59677623 Doc: update 2023-07-28 09:33:18 +08:00
wanglin2
d06f57a5dc Demo:优化暗黑模式 2023-07-28 08:55:35 +08:00
wanglin2
07be48d342 Feat:支持搜索和替换 2023-07-28 08:50:29 +08:00
wanglin2
5a5c7702f5 修改注释 2023-07-28 08:48:51 +08:00
wanglin2
7e1a43143d Demo:切换主题时支持选择是否覆盖设置过的基础样式 2023-07-26 09:17:48 +08:00
wanglin2
5ff9137745 Fix:1.修复节点处于编辑中时添加新节点时新节点的焦点丢失问题;2.修复连续按tab键无法连续创建子节点的问题 2023-07-26 09:04:24 +08:00
wanglin2
8e30d4a94f Fix:修复自定义节点内容时,二次创建根实例时节点内容不渲染的问题 2023-07-25 18:35:41 +08:00
wanglin2
4b2ebb2e1c Doc: update 2023-07-25 16:29:14 +08:00
wanglin2
8c79ffd723 Feat:导出svg时替换svg中存在的 字符,防止导出的svg报错 2023-07-25 09:38:50 +08:00
wanglin2
839c79405f Fix:修复给概要节点设置样式概要节点会消失的问题 2023-07-25 09:25:42 +08:00
wanglin2
d645adfd37 Merge branch 'feature' into main 2023-07-24 14:20:43 +08:00
wanglin2
1b1551c6e3 Demo:完善暗黑模式 2023-07-24 14:20:29 +08:00
wanglin2
78638dc291 更新群二维码 2023-07-24 11:26:55 +08:00
wanglin2
e972924143 打包0.6.8 2023-07-24 11:25:10 +08:00
wanglin2
8871d8727b Doc: update 2023-07-24 11:21:09 +08:00
wanglin2
55945a1a2c Demo:支持根据主题自动切换为暗黑模式 2023-07-24 10:25:02 +08:00
wanglin2
d5e4044fb2 Demo:支持夜间模式 2023-07-24 10:12:53 +08:00
wanglin2
4ee458c509 Demo:修复节点正在编辑时切换富文本编辑配置输入框出现异常的问题 2023-07-24 08:53:08 +08:00
wanglin2
a76ec0dad8 Feat:修改复制、剪切、粘贴逻辑;支持粘贴剪切板中的数据 2023-07-21 17:40:09 +08:00
wanglin2
f2b247e85c Demo:修复基础样式-设置节点外边距未保存的问题 2023-07-21 14:10:40 +08:00
wanglin2
3aed09a8c3 Feat:修改插入概要的快捷键为Ctrl+G 2023-07-21 11:28:49 +08:00
wanglin2
17b7a023ba Merge branch 'main' of https://github.com/wanglin2/mind-map into feature 2023-07-19 09:02:05 +08:00
wanglin2
10cb36829f Doc: update 2023-07-19 09:01:47 +08:00
wanglin2
90a55bb995 Merge branch 'feature' into main 2023-07-18 10:55:57 +08:00
wanglin2
08a37d8971 Doc: update 2023-07-18 10:55:28 +08:00
wanglin2
89983f9f47 Merge branch 'feature' into main 2023-07-18 09:30:32 +08:00
wanglin2
b71a80e383 打包0.6.7 2023-07-18 09:29:19 +08:00
wanglin2
2bf146816b Doc:update 2023-07-18 09:21:58 +08:00
wanglin2
daf9888da4 Fix:修复节点收起再展开后展开收起按钮占位元素丢失的问题 2023-07-18 08:44:44 +08:00
wanglin2
b42cee7a2f Feat:支持根据id定位到某个节点、优化大纲的节点定位 2023-07-18 08:35:40 +08:00
wanglin2
9ecb199608 更新群二维码 2023-07-17 22:16:08 +08:00
wanglin2
adccef5699 Feat:修改节点uid的创建 2023-07-17 09:59:47 +08:00
wanglin2
94230f8ec6 Fix:修复大纲里创建新节点时节点样式丢失的问题 2023-07-17 09:43:22 +08:00
wanglin2
a161661c6b 删除节点过渡动画效果 2023-07-17 09:07:58 +08:00
wanglin2
08b971cd9a Demo:优化大纲编辑 2023-07-16 22:20:09 +08:00
wanglin2
b64c8f132b Demo:优化页面:侧边栏按钮支持收起;优化小屏适配 2023-07-15 17:29:26 +08:00
wanglin2
d6181591c5 Fix:修复只读模式下可以缩放图片的bug 2023-07-15 15:26:57 +08:00
wanglin2
e093cb1741 Merge branch 'feature' into main 2023-07-13 09:50:01 +08:00
wanglin2
a63a92c423 打包 2023-07-13 09:48:30 +08:00
wanglin2
2c4f065626 新增文档首页 2023-07-13 09:44:55 +08:00
wanglin2
ae5d4dd2a6 Merge branch 'feature' into main 2023-07-11 16:36:51 +08:00
wanglin2
e574883e5f Doc: update 2023-07-11 16:31:48 +08:00
wanglin2
1bf60c49c7 Merge branch 'feature' into main 2023-07-11 14:52:35 +08:00
wanglin2
ddc173cf84 update README 2023-07-11 14:52:15 +08:00
wanglin2
2c71c7d102 Merge branch 'feature' into main 2023-07-11 14:44:01 +08:00
wanglin2
f6cb08bdaa update Doc and README 2023-07-11 14:08:00 +08:00
wanglin2
05728de21b Merge branch 'feature' into main 2023-07-10 16:08:26 +08:00
wanglin2
b51027f641 Doc: update 2023-07-10 16:07:48 +08:00
wanglin2
ea4fdf8290 更新群二维码 2023-07-10 09:16:20 +08:00
wanglin2
55796b4e39 Merge branch 'feature' into main 2023-07-06 17:13:07 +08:00
wanglin2
e534c3138d Doc: update 2023-07-06 17:12:42 +08:00
wanglin2
e185abd223 Merge branch 'feature' into main 2023-07-06 10:49:19 +08:00
wanglin2
3b73f72866 打包0.6.6 2023-07-06 10:45:44 +08:00
wanglin2
0db2f47133 Doc: update 2023-07-06 10:37:02 +08:00
wanglin2
80c7ec0fac Demo:更新结构示意图 2023-07-06 10:05:00 +08:00
wanglin2
780ce363de Fix:修复切换结构后展开收起按钮的隐藏占位元素不更新的问题 2023-07-06 09:31:58 +08:00
wanglin2
eaa8929457 Fix:修复除了向右生长的结构,其他结构鼠标移入展开收起按钮位置时不会触发按钮显示的问题 2023-07-06 09:12:18 +08:00
wanglin2
ad0f62a5ac Demo:增加竖向时间轴图片 2023-07-05 18:11:02 +08:00
wanglin2
31f21ce013 Feat:新增竖向时间轴 2023-07-05 16:49:32 +08:00
wanglin2
7a20ce2f79 Fix:修复二级节点拖拽成3级节点时节点边框样式未更新的问题 2023-07-05 14:21:15 +08:00
wanglin2
b98e7a97ec Demo:支持导出xmind文件 2023-07-05 14:00:57 +08:00
wanglin2
0bb50b3371 Feat:1.支持导出为xmind新版文件;2.导入xmind新版文件支持处理图片 2023-07-05 13:58:55 +08:00
wanglin2
a03091b28c Fix:修复拖拽移动一个节点为另一个节点的子节点时该节点的父节点指向未更新的问题 2023-07-04 09:10:32 +08:00
wanglin2
6c33984b8c 优化:刚创建的节点默认全选方便删除默认文本 2023-07-04 08:42:31 +08:00
wanglin2
28a4be0631 Fix:TouchEvent插件去除派发click事件,解决移动端点击超链接会打开两个窗口的问题 2023-07-03 22:39:47 +08:00
wanglin2
b8a3be7a62 优化触控板缩放画布时幅度过大的问题 2023-07-03 22:26:11 +08:00
wanglin2
259d4028f3 更新群二维码 2023-07-03 08:42:37 +08:00
wanglin2
fb1251afc1 Doc: update 2023-06-29 13:51:57 +08:00
wanglin2
06e3fd428a Fix:修复缩放情况下调整图片大小不正确的问题 2023-06-28 18:22:43 +08:00
wanglin2
a48e52f1f4 打包0.6.5 2023-06-28 16:37:19 +08:00
wanglin2
f8a345d8de Doc: update 2023-06-28 16:28:47 +08:00
wanglin2
d900c2f122 Feat:节点图片支持拖拽调整大小 2023-06-28 15:03:15 +08:00
wanglin2
443a714549 Feat:支持配置鼠标滚轮方向对应的缩放行为 2023-06-27 16:46:37 +08:00
wanglin2
74618a8a2b Feat:打包后的库支持获取内置常量、主题等数据 2023-06-27 16:27:46 +08:00
wanglin2
a25bd4c556 Fix:修复xmind导入报错 2023-06-27 16:15:42 +08:00
518 changed files with 14088 additions and 1217 deletions

View File

@@ -11,13 +11,13 @@
本项目包含两部分:
1.一个js思维导图库不依赖任何框架你可以使用它来快速完成Web思维导图产品的开发。
1.一个 js 思维导图库,不依赖任何框架,你可以使用它来快速完成 Web 思维导图产品的开发。
开发文档:[https://wanglin2.github.io/mind-map/#/doc/zh/](https://wanglin2.github.io/mind-map/#/doc/zh/)
开发文档:[https://wanglin2.github.io/mind-map/#/doc/zh/](https://wanglin2.github.io/mind-map/#/doc/zh/)
2.一个Web思维导图基于思维导图库、Vue2.x、ElementUI开发可以操作电脑本地文件所以你可以直接把它当做一个在线版思维导图应用使用如果觉得github的响应速度慢你也可以部署到你的服务器上。
2.一个 Web 思维导图基于思维导图库、Vue2.x、ElementUI 开发,可以操作电脑本地文件,所以你可以直接把它当做一个在线版思维导图应用使用,如果觉得 github 的响应速度慢,你也可以部署到你的服务器上。
在线地址:[https://wanglin2.github.io/mind-map/](https://wanglin2.github.io/mind-map/)
在线地址:[https://wanglin2.github.io/mind-map/](https://wanglin2.github.io/mind-map/)
另外也提供了客户端可供下载使用,支持`Windows``Mac``Linux`,下载地址:
@@ -28,18 +28,15 @@ Github[releases](https://github.com/wanglin2/mind-map/releases)。
# 特性
- [x] 插件化架构,除核心功能外,其他功能作为插件提供,按需使用,减小打包体积
- [x] 支持逻辑结构图、思维导图、组织结构图、目录组织图、时间轴、鱼骨图六种结构
- [x] 支持逻辑结构图、思维导图、组织结构图、目录组织图、时间轴(横向、竖向)、鱼骨图结构
- [x] 内置多种主题,允许高度自定义样式,支持注册新主题
- [x] 支持快捷键
- [x] 节点内容支持图片、图标、超链接、备注、标签、概要
- [x] 支持前进后退
- [x] 支持拖动、缩放
- [x] 支持右键和Ctrl+左键两种多选方式
- [x] 支持节点自由拖拽、拖拽调整
- [x] 支持多种节点形状
- [x] 支持导出为`json``png``svg``pdf``markdown`,支持从`json``xmind``markdown`导入
- [x] 支持小地图、支持水印
- [x] 支持关联线
- [x] 节点内容支持文本(普通文本、富文本)、图片、图标、超链接、备注、标签、概要
- [x] 节点支持拖拽(拖拽移动、自由调整)、多种节点形状,支持使用 DDM 完全自定义节点内容
- [x] 支持画布拖动、缩放
- [x] 支持鼠标按键拖动选择和Ctrl+左键两种多选节点方式
- [x] 支持导出为`json``png``svg``pdf``markdown``xmind`,支持从`json``xmind``markdown`导入
- [x] 支持快捷键、前进后退、关联线、搜索替换、小地图、水印
- [x] 提供丰富的配置,满足各种场景各种使用习惯
# 安装
@@ -86,7 +83,7 @@ const mindMap = new MindMap({
# License
MIT
[MIT](./LICENSE)
# 微信交流群
@@ -96,11 +93,64 @@ MIT
# 请作者喝杯咖啡
开源不易,如果本项目有帮助到你的话,可以考虑请作者喝杯咖啡哟~
> 厚椰乳一盒 + 纯牛奶半盒 + 冰块 + 咖啡液 = 生椰拿铁 yyds
> 转账请备注哦~你的头像和名会出现在[文档页面](https://wanglin2.github.io/mind-map/#/doc/zh/introduction/%E8%AF%B7%E4%BD%9C%E8%80%85%E5%96%9D%E6%9D%AF%E5%92%96%E5%95%A1)
> 转账请备注【思维导图】。你的头像和名字将会出现在下面和[文档页面](https://wanglin2.github.io/mind-map/#/doc/zh/introduction/%E8%AF%B7%E4%BD%9C%E8%80%85%E5%96%9D%E6%9D%AF%E5%92%96%E5%95%A1)
<p>
<img src="./web/src/assets/img/alipay.jpg" style="width: 300px" />
<img src="./web/src/assets/img/wechat.jpg" style="width: 300px" />
</p>
<p>
<span>
<img src="./web/src/assets/avatar/Think.jpg" style="width: 50px;height: 50px;" />
<span>Think</span>
</span>
<span>
<img src="./web/src/assets/avatar/志斌.jpg" style="width: 50px;height: 50px;" />
<span>志斌</span>
</span>
<span>
<img src="./web/src/assets/avatar/小土渣的宇宙.jpeg" style="width: 50px;height: 50px;" />
<span>小土渣的宇宙</span>
</span>
<span>
<img src="./web/src/assets/avatar/qp.jpg" style="width: 50px;height: 50px;" />
<span>qp</span>
</span>
<span>
<img src="./web/src/assets/avatar/ZXR.jpg" style="width: 50px;height: 50px;" />
<span>ZXR</span>
</span>
<span>
<img src="./web/src/assets/avatar/花儿朵朵.jpg" style="width: 50px;height: 50px;" />
<span>花儿朵朵</span>
</span>
<span>
<img src="./web/src/assets/avatar/suka.jpg" style="width: 50px;height: 50px;" />
<span>suka</span>
</span>
<span>
<img src="./web/src/assets/avatar/Chris.jpg" style="width: 50px;height: 50px;" />
<span>Chris</span>
</span>
<span>
<img src="./web/src/assets/avatar/水车.jpg" style="width: 50px;height: 50px;" />
<span>水车</span>
</span>
<span>
<img src="./web/src/assets/avatar/仓鼠.jpg" style="width: 50px;height: 50px;" />
<span>仓鼠</span>
</span>
<span>
<img src="./web/src/assets/avatar/千帆.jpg" style="width: 50px;height: 50px;" />
<span>千帆</span>
</span>
<span>
<img src="./web/src/assets/avatar/才镇.jpg" style="width: 50px;height: 50px;" />
<span>才镇</span>
</span>
</p>

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

@@ -2,29 +2,45 @@ import MindMap from './index'
import MiniMap from './src/plugins/MiniMap.js'
import Watermark from './src/plugins/Watermark.js'
import KeyboardNavigation from './src/plugins/KeyboardNavigation.js'
import ExportXMind from './src/plugins/ExportXMind.js'
import ExportPDF from './src/plugins/ExportPDF.js'
import Export from './src/plugins/Export.js'
import Drag from './src/plugins/Drag.js'
import Select from './src/plugins/Select.js'
import AssociativeLine from './src/plugins/AssociativeLine'
import RichText from './src/plugins/RichText'
import NodeImgAdjust from './src/plugins/NodeImgAdjust.js'
import TouchEvent from './src/plugins/TouchEvent.js'
import Search from './src/plugins/Search.js'
import Painter from './src/plugins/Painter.js'
import xmind from './src/parse/xmind.js'
import markdown from './src/parse/markdown.js'
import icons from './src/svg/icons.js'
import * as constants from './src/constants/constant.js'
import themes from './src/themes/index.js'
import * as defaultTheme from './src/themes/default.js'
MindMap.xmind = xmind
MindMap.markdown = markdown
MindMap.iconList = icons.nodeIconList
MindMap.constants = constants
MindMap.themes = themes
MindMap.defaultTheme = defaultTheme
MindMap
.usePlugin(MiniMap)
.usePlugin(Watermark)
.usePlugin(Drag)
.usePlugin(KeyboardNavigation)
.usePlugin(ExportXMind)
.usePlugin(ExportPDF)
.usePlugin(Export)
.usePlugin(Select)
.usePlugin(AssociativeLine)
.usePlugin(RichText)
.usePlugin(TouchEvent)
.usePlugin(NodeImgAdjust)
.usePlugin(Search)
.usePlugin(Painter)
export default MindMap

View File

@@ -7,10 +7,17 @@ import Style from './src/core/render/node/Style'
import KeyCommand from './src/core/command/KeyCommand'
import Command from './src/core/command/Command'
import BatchExecution from './src/utils/BatchExecution'
import { layoutValueList, CONSTANTS } from './src/constants/constant'
import {
layoutValueList,
CONSTANTS,
commonCaches,
ERROR_TYPES
} from './src/constants/constant'
import { SVG } from '@svgdotjs/svg.js'
import { simpleDeepClone } from './src/utils'
import defaultTheme, { checkIsNodeSizeIndependenceConfig } from './src/themes/default'
import { simpleDeepClone, getType } from './src/utils'
import defaultTheme, {
checkIsNodeSizeIndependenceConfig
} from './src/themes/default'
import { defaultOpt } from './src/constants/defaultOptions'
// 思维导图
@@ -22,22 +29,24 @@ class MindMap {
// 容器元素
this.el = this.opt.el
if (!this.el) throw new Error('缺少容器元素el')
this.elRect = this.el.getBoundingClientRect()
// 画布宽高
this.width = this.elRect.width
this.height = this.elRect.height
if (this.width <= 0 || this.height <= 0) throw new Error('容器元素el的宽高不能为0')
// 画布
this.svg = SVG().addTo(this.el).size(this.width, this.height)
this.draw = this.svg.group()
// 节点id
this.uid = 1
// 初始化主题
this.initTheme()
// 初始化缓存数据
this.initCache()
// 事件类
this.event = new Event({
mindMap: this
@@ -68,7 +77,7 @@ class MindMap {
this.batchExecution = new BatchExecution()
// 注册插件
MindMap.pluginList.forEach((plugin) => {
MindMap.pluginList.forEach(plugin => {
this.initPlugin(plugin)
})
@@ -81,6 +90,8 @@ class MindMap {
// 配置参数处理
handleOpt(opt) {
// 深拷贝一份节点数据
opt.data = simpleDeepClone(opt.data || {})
// 检查布局配置
if (!layoutValueList.includes(opt.layout)) {
opt.layout = CONSTANTS.LAYOUT.LOGICAL_STRUCTURE
@@ -132,6 +143,23 @@ class MindMap {
this.event.off(event, fn)
}
// 初始化缓存数据
initCache() {
Object.keys(commonCaches).forEach(key => {
let type = getType(commonCaches[key])
let value = ''
switch (type) {
case 'Boolean':
value = false
break
default:
value = null
break
}
commonCaches[key] = value
})
}
// 设置主题
initTheme() {
// 合并主题配置
@@ -145,6 +173,7 @@ class MindMap {
this.renderer.clearAllActive()
this.opt.theme = theme
this.render(null, CONSTANTS.CHANGE_THEME)
this.emit('view_theme_change', theme)
}
// 获取当前主题
@@ -194,7 +223,7 @@ class MindMap {
this.opt.layout = layout
this.view.reset()
this.renderer.setLayout()
this.render()
this.render(null, CONSTANTS.CHANGE_LAYOUT)
}
// 执行命令
@@ -238,7 +267,7 @@ class MindMap {
// 获取思维导图数据,节点树、主题、布局等
getData(withConfig) {
let nodeData = this.command.removeDataUid(this.command.getCopyData())
let nodeData = this.command.getCopyData()
let data = {}
if (withConfig) {
data = {
@@ -258,8 +287,12 @@ class MindMap {
// 导出
async export(...args) {
let result = await this.doExport.export(...args)
return result
try {
let result = await this.doExport.export(...args)
return result
} catch (error) {
this.mindMap.opt.errorHandler(ERROR_TYPES.EXPORT_ERROR, error)
}
}
// 转换位置
@@ -297,9 +330,9 @@ class MindMap {
// 获取变换后的位置尺寸信息其实是getBoundingClientRect方法的包装方法
const rect = draw.rbox()
// 内边距
rect.width += paddingX
rect.height += paddingY
draw.translate(paddingX / 2, paddingY / 2)
rect.width += paddingX * 2
rect.height += paddingY * 2
draw.translate(paddingX, paddingY)
// 将svg设置为实际内容的宽高
svg.size(rect.width, rect.height)
// 把实际内容变换
@@ -307,7 +340,11 @@ class MindMap {
// 克隆一份数据
let clone = svg.clone()
// 如果实际图形宽高超出了屏幕宽高,且存在水印的话需要重新绘制水印,否则会出现超出部分没有水印的问题
if ((rect.width > origWidth || rect.height > origHeight) && this.watermark && this.watermark.hasWatermark()) {
if (
(rect.width > origWidth || rect.height > origHeight) &&
this.watermark &&
this.watermark.hasWatermark()
) {
this.width = rect.width
this.height = rect.height
this.watermark.draw()
@@ -368,7 +405,7 @@ class MindMap {
// 销毁
destroy() {
// 移除插件
[...MindMap.pluginList].forEach((plugin) => {
;[...MindMap.pluginList].forEach(plugin => {
this[plugin.instanceName] = null
})
// 解绑事件
@@ -388,8 +425,8 @@ MindMap.usePlugin = (plugin, opt = {}) => {
MindMap.pluginList.push(plugin)
return MindMap
}
MindMap.hasPlugin = (plugin) => {
return MindMap.pluginList.findIndex((item) => {
MindMap.hasPlugin = plugin => {
return MindMap.pluginList.findIndex(item => {
return item === plugin
})
}

View File

@@ -1,17 +1,17 @@
{
"name": "simple-mind-map",
"version": "0.6.0",
"version": "0.6.13",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "0.6.0",
"version": "0.6.13",
"license": "MIT",
"dependencies": {
"@svgdotjs/svg.js": "^3.0.16",
"deepmerge": "^1.5.2",
"dom-to-image-more": "^3.1.6",
"eventemitter3": "^4.0.7",
"html2canvas": "^1.4.1",
"jspdf": "^2.5.1",
"jszip": "^3.10.1",
"mdast-util-from-markdown": "^1.3.0",
@@ -255,6 +255,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
"optional": true,
"engines": {
"node": ">= 0.6.0"
}
@@ -411,6 +412,7 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"optional": true,
"dependencies": {
"utrie": "^1.0.2"
}
@@ -516,6 +518,11 @@
"node": ">=6.0.0"
}
},
"node_modules/dom-to-image-more": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/dom-to-image-more/-/dom-to-image-more-3.1.6.tgz",
"integrity": "sha512-VMO0jNme32T06mWtkOC9QXfj+1npoJxkaTFW0DCwBLguwBKMjqwndiDANxDnbZ0kvNEecwxkv0Zmgdr96cGtAA=="
},
"node_modules/dompurify": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.1.tgz",
@@ -937,6 +944,7 @@
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"optional": true,
"dependencies": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
@@ -2142,6 +2150,7 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"optional": true,
"dependencies": {
"utrie": "^1.0.2"
}
@@ -2206,6 +2215,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"optional": true,
"dependencies": {
"base64-arraybuffer": "^1.0.2"
}
@@ -2461,7 +2471,8 @@
"base64-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ=="
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
@@ -2576,6 +2587,7 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"optional": true,
"requires": {
"utrie": "^1.0.2"
}
@@ -2648,6 +2660,11 @@
"esutils": "^2.0.2"
}
},
"dom-to-image-more": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/dom-to-image-more/-/dom-to-image-more-3.1.6.tgz",
"integrity": "sha512-VMO0jNme32T06mWtkOC9QXfj+1npoJxkaTFW0DCwBLguwBKMjqwndiDANxDnbZ0kvNEecwxkv0Zmgdr96cGtAA=="
},
"dompurify": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.1.tgz",
@@ -2966,6 +2983,7 @@
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"optional": true,
"requires": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
@@ -3749,6 +3767,7 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"optional": true,
"requires": {
"utrie": "^1.0.2"
}
@@ -3800,6 +3819,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"optional": true,
"requires": {
"base64-arraybuffer": "^1.0.2"
}

View File

@@ -1,6 +1,6 @@
{
"name": "simple-mind-map",
"version": "0.6.4-fix.1",
"version": "0.6.15-fix.2",
"description": "一个简单的web在线思维导图",
"authors": [
{
@@ -26,8 +26,8 @@
"dependencies": {
"@svgdotjs/svg.js": "^3.0.16",
"deepmerge": "^1.5.2",
"dom-to-image-more": "^3.1.6",
"eventemitter3": "^4.0.7",
"html2canvas": "^1.4.1",
"jspdf": "^2.5.1",
"jszip": "^3.10.1",
"mdast-util-from-markdown": "^1.3.0",

View File

@@ -27,136 +27,169 @@ export const themeList = [
{
name: '默认',
value: 'default',
dark: false
},
{
name: '暗色2',
value: 'dark2',
dark: true
},
{
name: '天清绿',
value: 'skyGreen',
dark: false
},
{
name: '脑图经典2',
value: 'classic2',
dark: false
},
{
name: '脑图经典3',
value: 'classic3',
dark: false
},
{
name: '经典绿',
value: 'classicGreen',
dark: false
},
{
name: '经典蓝',
value: 'classicBlue',
dark: false
},
{
name: '天空蓝',
value: 'blueSky',
dark: false
},
{
name: '脑残粉',
value: 'brainImpairedPink',
dark: false
},
{
name: '暗色',
value: 'dark',
dark: true
},
{
name: '泥土黄',
value: 'earthYellow',
dark: false
},
{
name: '清新绿',
value: 'freshGreen',
dark: false
},
{
name: '清新红',
value: 'freshRed',
dark: false
},
{
name: '浪漫紫',
value: 'romanticPurple',
dark: false
},
{
name: '粉红葡萄',
value: 'pinkGrape',
dark: false
},
{
name: '薄荷',
value: 'mint',
dark: false
},
{
name: '金色vip',
value: 'gold',
dark: false
},
{
name: '活力橙',
value: 'vitalityOrange',
dark: false
},
{
name: '绿叶',
value: 'greenLeaf',
dark: false
},
{
name: '脑图经典',
value: 'classic',
dark: true
},
{
name: '脑图经典4',
value: 'classic4',
dark: false
},
{
name: '小黄人',
value: 'minions',
dark: false
},
{
name: '简约黑',
value: 'simpleBlack',
dark: false
},
{
name: '课程绿',
value: 'courseGreen',
dark: false
},
{
name: '咖啡',
value: 'coffee',
dark: false
},
{
name: '红色精神',
value: 'redSpirit',
dark: false
},
{
name: '黑色幽默',
value: 'blackHumour',
dark: true
},
{
name: '深夜办公室',
value: 'lateNightOffice',
dark: true
},
{
name: '黑金',
value: 'blackGold',
dark: true
},
{
name: '牛油果',
value: 'avocado',
dark: false
},
{
name: '秋天',
value: 'autumn',
dark: false
},
{
name: '橙汁',
value: 'orangeJuice',
dark: true
}
]
// 常量
export const CONSTANTS = {
CHANGE_THEME: 'changeTheme',
CHANGE_LAYOUT: 'changeLayout',
SET_DATA: 'setData',
TRANSFORM_TO_NORMAL_NODE: 'transformAllNodesToNormalNode',
MODE: {
@@ -170,7 +203,8 @@ export const CONSTANTS = {
CATALOG_ORGANIZATION: 'catalogOrganization',
TIMELINE: 'timeline',
TIMELINE2: 'timeline2',
FISHBONE: 'fishbone'
FISHBONE: 'fishbone',
VERTICAL_TIMELINE: 'verticalTimeline'
},
DIR: {
UP: 'up',
@@ -206,9 +240,15 @@ export const CONSTANTS = {
BOTTOM: 'bottom',
CENTER: 'center'
},
TIMELINE_DIR: {
LAYOUT_GROW_DIR: {
LEFT: 'left',
TOP: 'top',
RIGHT: 'right',
BOTTOM: 'bottom'
},
PASTE_TYPE: {
CLIP_BOARD: 'clipBoard',
CANVAS: 'canvas'
}
}
@@ -246,6 +286,10 @@ export const layoutList = [
name: '时间轴2',
value: CONSTANTS.LAYOUT.TIMELINE2,
},
{
name: '竖向时间轴',
value: CONSTANTS.LAYOUT.VERTICAL_TIMELINE,
},
{
name: '鱼骨图',
value: CONSTANTS.LAYOUT.FISHBONE,
@@ -258,6 +302,7 @@ export const layoutValueList = [
CONSTANTS.LAYOUT.ORGANIZATION_STRUCTURE,
CONSTANTS.LAYOUT.TIMELINE,
CONSTANTS.LAYOUT.TIMELINE2,
CONSTANTS.LAYOUT.VERTICAL_TIMELINE,
CONSTANTS.LAYOUT.FISHBONE
]
@@ -278,5 +323,23 @@ export const nodeDataNoStylePropList = [
'richText',
'resetRichText',
'uid',
'activeStyle'
]
'activeStyle',
'associativeLineTargets',
'associativeLineTargetControlOffsets'
]
// 数据缓存
export const commonCaches = {
measureCustomNodeContentSizeEl: null,
measureRichtextNodeTextSizeEl: null
}
// 错误类型
export const ERROR_TYPES = {
READ_CLIPBOARD_ERROR: 'read_clipboard_error',
PARSE_PASTE_DATA_ERROR: 'parse_paste_data_error',
CUSTOM_HANDLE_CLIPBOARD_TEXT_ERROR: 'custom_handle_clipboard_text_error',
LOAD_CLIPBOARD_IMAGE_ERROR: 'load_clipboard_image_error',
BEFORE_TEXT_EDIT_ERROR: 'before_text_edit_error',
EXPORT_ERROR: 'export_error'
}

View File

@@ -18,8 +18,6 @@ export const defaultOpt = {
mouseScaleCenterUseMousePosition: true,
// 最多显示几个标签
maxTag: 5,
// 导出图片时的内边距
exportPadding: 20,
// 展开收缩按钮尺寸
expandBtnSize: 20,
// 节点里图片和文字的间距
@@ -61,6 +59,8 @@ export const defaultOpt = {
mousewheelAction: CONSTANTS.MOUSE_WHEEL_ACTION.ZOOM, // zoom放大缩小、move上下移动
// 当mousewheelAction设为move时可以通过该属性控制鼠标滚动一下视图移动的步长单位px
mousewheelMoveStep: 100,
// 当mousewheelAction设为zoom时默认向前滚动是缩小向后滚动是放大如果该属性设为true那么会反过来
mousewheelZoomActionReverse: false,
// 默认插入的二级节点的文字
defaultInsertSecondLevelNodeText: '二级节点',
// 默认插入的二级以下节点的文字
@@ -77,13 +77,9 @@ export const defaultOpt = {
},
// 是否只有当鼠标在画布内才响应快捷键事件
enableShortcutOnlyWhenMouseInSvg: true,
// 是否开启节点动画过渡
enableNodeTransitionMove: true,
// 如果开启节点动画过渡可以通过该属性设置过渡的时间单位ms
nodeTransitionMoveDuration: 300,
// 初始根节点的位置
initRootNodePosition: null,
// 导出png、svg、pdf时的图形内边距
// 导出png、svg、pdf时的图形内边距,注意是单侧内边距
exportPaddingX: 10,
exportPaddingY: 10,
// 节点文本编辑框的z-index
@@ -124,5 +120,40 @@ export const defaultOpt = {
// 是否开启自定义节点内容
isUseCustomNodeContent: false,
// 自定义返回节点内容的方法
customCreateNodeContent: null
customCreateNodeContent: null,
// 指定内部一些元素节点文本编辑元素、节点备注显示元素、关联线文本编辑元素、节点图片调整按钮元素添加到的位置默认添加到document.body下
customInnerElsAppendTo: null,
// 拖拽元素时,指示元素新位置的块的最大高度
nodeDragPlaceholderMaxSize: 20,
// 是否在存在一个激活节点时,当按下中文、英文、数字按键时自动进入文本编辑模式
// 开启该特性后需要给你的输入框绑定keydown事件并禁止冒泡
enableAutoEnterTextEditWhenKeydown: false,
// 设置富文本节点编辑框和节点大小一致,形成伪原地编辑的效果
// 需要注意的是,只有当节点内只有文本、且形状是矩形才会有比较好的效果
richTextEditFakeInPlace: false,
// 自定义对剪贴板文本的处理。当按ctrl+v粘贴时会读取用户剪贴板中的文本和图片默认只会判断文本是否是普通文本和simple-mind-map格式的节点数据如果你想处理其他思维导图的数据比如processon、zhixi等那么可以传递一个函数接受当前剪贴板中的文本为参数返回处理后的数据可以返回两种类型
/*
1.返回一个纯文本,那么会直接以该文本创建一个子节点
2.返回一个节点对象,格式如下:
{
// 代表是simple-mind-map格式的数据
simpleMindMap: true,
// 节点数据同simple-mind-map节点数据格式
data: {
data: {
text: ''
},
children: []
}
}
*/
// 如果你的处理逻辑存在异步逻辑也可以返回一个promise
customHandleClipboardText: null,
// 禁止鼠标滚轮缩放你仍旧可以使用api进行缩放
disableMouseWheelZoom: false,
// 错误处理函数
errorHandler: (code, error) => {
console.error(code, error)
}
}

View File

@@ -89,7 +89,7 @@ class Command {
this.history.shift()
}
this.activeHistoryIndex = this.history.length - 1
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
this.mindMap.emit(
'back_forward',
this.activeHistoryIndex,
@@ -110,7 +110,7 @@ class Command {
this.history.length
)
let data = simpleDeepClone(this.history[this.activeHistoryIndex])
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
return data
}
}
@@ -125,7 +125,7 @@ class Command {
this.activeHistoryIndex += step
this.mindMap.emit('back_forward', this.activeHistoryIndex, this.history.length)
let data = simpleDeepClone(this.history[this.activeHistoryIndex])
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
return data
}
}

View File

@@ -57,8 +57,11 @@ export default class KeyCommand {
}
Object.keys(this.shortcutMap).forEach(key => {
if (this.checkKey(e, key)) {
e.stopPropagation()
e.preventDefault()
// 粘贴事件不组织因为要监听paste事件
if (!this.checkKey(e, 'Control+v')) {
e.stopPropagation()
e.preventDefault()
}
this.shortcutMap[key].forEach(fn => {
fn()
})
@@ -105,6 +108,11 @@ export default class KeyCommand {
return arr
}
// 判断是否按下了组合键
hasCombinationKey(e) {
return e.ctrlKey || e.metaKey || e.altKey || e.shiftKey
}
// 获取快捷键对应的键值数组
getKeyCodeArr(key) {
let keyArr = key.split(/\s*\+\s*/)

View File

@@ -10,6 +10,7 @@ class Event extends EventEmitter {
this.mindMap = opt.mindMap
this.isLeftMousedown = false
this.isRightMousedown = false
this.isMiddleMousedown = false
this.mousedownPos = {
x: 0,
y: 0
@@ -92,6 +93,8 @@ class Event extends EventEmitter {
this.isLeftMousedown = true
} else if (e.which === 3) {
this.isRightMousedown = true
} else if (e.which === 2) {
this.isMiddleMousedown = true
}
this.mousedownPos.x = e.clientX
this.mousedownPos.y = e.clientY
@@ -107,9 +110,10 @@ class Event extends EventEmitter {
this.mousemoveOffset.y = e.clientY - this.mousedownPos.y
this.emit('mousemove', e, this)
if (
useLeftKeySelectionRightKeyDrag
this.isMiddleMousedown ||
(useLeftKeySelectionRightKeyDrag
? this.isRightMousedown
: this.isLeftMousedown
: this.isLeftMousedown)
) {
e.preventDefault()
this.emit('drag', e, this)
@@ -120,6 +124,7 @@ class Event extends EventEmitter {
onMouseup(e) {
this.isLeftMousedown = false
this.isRightMousedown = false
this.isMiddleMousedown = false
this.emit('mouseup', e, this)
}

View File

@@ -4,12 +4,20 @@ import MindMap from '../../layouts/MindMap'
import CatalogOrganization from '../../layouts/CatalogOrganization'
import OrganizationStructure from '../../layouts/OrganizationStructure'
import Timeline from '../../layouts/Timeline'
import VerticalTimeline from '../../layouts/VerticalTimeline'
import Fishbone from '../../layouts/Fishbone'
import TextEdit from './TextEdit'
import { copyNodeTree, simpleDeepClone, walk } from '../../utils'
import {
copyNodeTree,
simpleDeepClone,
walk,
bfsWalk,
loadImage,
isUndef
} from '../../utils'
import { shapeList } from './node/Shape'
import { lineStyleProps } from '../../themes/default'
import { CONSTANTS } from '../../constants/constant'
import { CONSTANTS, ERROR_TYPES } from '../../constants/constant'
// 布局列表
const layouts = {
@@ -25,8 +33,10 @@ const layouts = {
[CONSTANTS.LAYOUT.TIMELINE]: Timeline,
// 时间轴2
[CONSTANTS.LAYOUT.TIMELINE2]: Timeline,
// 竖向时间轴
[CONSTANTS.LAYOUT.VERTICAL_TIMELINE]: VerticalTimeline,
// 鱼骨图
[CONSTANTS.LAYOUT.FISHBONE]: Fishbone,
[CONSTANTS.LAYOUT.FISHBONE]: Fishbone
}
// 渲染
@@ -57,6 +67,12 @@ class Render {
this.root = null
// 文本编辑框需要再bindEvent之前实例化否则单击事件只能触发隐藏文本编辑框而无法保存文本修改
this.textEdit = new TextEdit(this)
// 当前复制的数据
this.lastBeingCopyData = null
this.beingCopyData = null
this.beingPasteText = ''
this.beingPasteImgSize = 0
this.currentBeingPasteType = ''
// 布局
this.setLayout()
// 绑定事件
@@ -79,18 +95,27 @@ class Render {
// 绑定事件
bindEvent() {
// 点击事件
this.mindMap.on('draw_click', (e) => {
this.mindMap.on('draw_click', e => {
// 清除激活状态
let isTrueClick = true
let { useLeftKeySelectionRightKeyDrag } = this.mindMap.opt
if (useLeftKeySelectionRightKeyDrag) {
let mousedownPos = this.mindMap.event.mousedownPos
isTrueClick = Math.abs(e.clientX - mousedownPos.x) <= 5 && Math.abs(e.clientY - mousedownPos.y) <= 5
isTrueClick =
Math.abs(e.clientX - mousedownPos.x) <= 5 &&
Math.abs(e.clientY - mousedownPos.y) <= 5
}
if (isTrueClick && this.activeNodeList.length > 0) {
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
}
})
// let timer = null
// this.mindMap.on('view_data_change', () => {
// clearTimeout(timer)
// timer = setTimeout(() => {
// this.render()
// }, 300)
// })
}
// 注册命令
@@ -132,9 +157,12 @@ class Render {
// 剪切节点
this.cutNode = this.cutNode.bind(this)
this.mindMap.command.add('CUT_NODE', this.cutNode)
// 修改节点样式
// 修改节点单个样式
this.setNodeStyle = this.setNodeStyle.bind(this)
this.mindMap.command.add('SET_NODE_STYLE', this.setNodeStyle)
// 修改节点多个样式
this.setNodeStyles = this.setNodeStyles.bind(this)
this.mindMap.command.add('SET_NODE_STYLES', this.setNodeStyles)
// 切换节点是否激活
this.setNodeActive = this.setNodeActive.bind(this)
this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive)
@@ -192,6 +220,9 @@ class Render {
// 设置节点形状
this.setNodeShape = this.setNodeShape.bind(this)
this.mindMap.command.add('SET_NODE_SHAPE', this.setNodeShape)
// 定位节点
this.goTargetNode = this.goTargetNode.bind(this)
this.mindMap.command.add('GO_TARGET_NODE', this.goTargetNode)
}
// 注册快捷键
@@ -209,7 +240,7 @@ class Render {
}
this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap)
// 插入概要
this.mindMap.keyCommand.addShortcut('Control+s', this.addGeneralization)
this.mindMap.keyCommand.addShortcut('Control+g', this.addGeneralization)
// 展开/收起节点
this.toggleActiveExpand = this.toggleActiveExpand.bind(this)
this.mindMap.keyCommand.addShortcut('/', this.toggleActiveExpand)
@@ -236,6 +267,13 @@ class Render {
// 下移节点
this.mindMap.keyCommand.addShortcut('Control+Down', this.downNode)
// 复制节点、剪切节点、粘贴节点的快捷键需开发者自行注册实现可参考demo
this.copy = this.copy.bind(this)
this.mindMap.keyCommand.addShortcut('Control+c', this.copy)
this.mindMap.keyCommand.addShortcut('Control+v', () => {
this.onPaste()
})
this.cut = this.cut.bind(this)
this.mindMap.keyCommand.addShortcut('Control+x', this.cut)
}
// 开启文字编辑,会禁用回车键和删除键相关快捷键防止冲突
@@ -256,7 +294,6 @@ class Render {
// 渲染
render(callback = () => {}, source) {
let t = Date.now()
// 如果当前还没有渲染完毕,不再触发渲染
if (this.isRendering) {
// 等待当前渲染完毕后再进行一次渲染
@@ -276,7 +313,7 @@ class Render {
// 计算布局
this.layout.doLayout(root => {
// 删除本次渲染时不再需要的节点
Object.keys(this.lastNodeCache).forEach((uid) => {
Object.keys(this.lastNodeCache).forEach(uid => {
if (!this.nodeCache[uid]) {
this.lastNodeCache[uid].destroy()
if (this.lastNodeCache[uid].parent) {
@@ -287,7 +324,7 @@ class Render {
// 更新根节点
this.root = root
// 渲染节点
const onEnd = () => {
this.root.render(() => {
this.isRendering = false
this.mindMap.emit('node_tree_render_end')
callback && callback()
@@ -296,22 +333,13 @@ class Render {
this.render(callback, source)
} else {
// 触发一次保存,因为修改了渲染树的数据
if (this.mindMap.richText && [CONSTANTS.CHANGE_THEME, CONSTANTS.SET_DATA].includes(source)) {
if (
this.mindMap.richText &&
[CONSTANTS.CHANGE_THEME, CONSTANTS.SET_DATA].includes(source)
) {
this.mindMap.command.addHistory()
}
}
}
let { enableNodeTransitionMove, nodeTransitionMoveDuration } =
this.mindMap.opt
this.root.render(() => {
let dur = Date.now() - t
if (enableNodeTransitionMove && dur <= nodeTransitionMoveDuration) {
setTimeout(() => {
onEnd()
}, nodeTransitionMoveDuration - dur);
} else {
onEnd()
}
})
})
this.mindMap.emit('node_active', null, this.activeNodeList)
@@ -413,16 +441,25 @@ class Render {
// 规范指定节点数据
formatAppointNodes(appointNodes) {
if (!appointNodes) return []
return Array.isArray(appointNodes) ? appointNodes: [appointNodes]
return Array.isArray(appointNodes) ? appointNodes : [appointNodes]
}
// 插入同级节点,多个节点只会操作第一个节点
insertNode(openEdit = true, appointNodes = [], appointData = null) {
insertNode(
openEdit = true,
appointNodes = [],
appointData = null,
appointChildren = []
) {
appointNodes = this.formatAppointNodes(appointNodes)
if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) {
return
}
let { defaultInsertSecondLevelNodeText, defaultInsertBelowSecondLevelNodeText } = this.mindMap.opt
this.textEdit.hideEditTextBox()
let {
defaultInsertSecondLevelNodeText,
defaultInsertBelowSecondLevelNodeText
} = this.mindMap.opt
let list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
let first = list[0]
if (first.isGeneralization) {
@@ -431,31 +468,46 @@ class Render {
if (first.isRoot) {
this.insertChildNode(openEdit, appointNodes, appointData)
} else {
let text = first.layerIndex === 1 ? defaultInsertSecondLevelNodeText : defaultInsertBelowSecondLevelNodeText
let text =
first.layerIndex === 1
? defaultInsertSecondLevelNodeText
: defaultInsertBelowSecondLevelNodeText
if (first.layerIndex === 1) {
first.parent.destroy()
}
let index = this.getNodeIndex(first)
let isRichText = !!this.mindMap.richText
first.parent.nodeData.children.splice(index + 1, 0, {
inserting: openEdit,
data: {
text: text,
expand: true,
richText: isRichText,
resetRichText: isRichText,
...(appointData || {})
},
children: []
children: [...appointChildren]
})
this.mindMap.render()
}
}
// 插入子节点
insertChildNode(openEdit = true, appointNodes = [], appointData = null) {
insertChildNode(
openEdit = true,
appointNodes = [],
appointData = null,
appointChildren = []
) {
appointNodes = this.formatAppointNodes(appointNodes)
if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) {
return
}
let { defaultInsertSecondLevelNodeText, defaultInsertBelowSecondLevelNodeText } = this.mindMap.opt
this.textEdit.hideEditTextBox()
let {
defaultInsertSecondLevelNodeText,
defaultInsertBelowSecondLevelNodeText
} = this.mindMap.opt
let list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
list.forEach(node => {
if (node.isGeneralization) {
@@ -464,15 +516,20 @@ class Render {
if (!node.nodeData.children) {
node.nodeData.children = []
}
let text = node.isRoot ? defaultInsertSecondLevelNodeText : defaultInsertBelowSecondLevelNodeText
let text = node.isRoot
? defaultInsertSecondLevelNodeText
: defaultInsertBelowSecondLevelNodeText
let isRichText = !!this.mindMap.richText
node.nodeData.children.push({
inserting: openEdit,
data: {
text: text,
expand: true,
richText: isRichText,
resetRichText: isRichText,
...(appointData || {})
},
children: []
children: [...appointChildren]
})
// 插入子节点时自动展开子节点
node.nodeData.data.expand = true
@@ -537,13 +594,159 @@ class Render {
this.mindMap.render()
}
// 复制节点
copy() {
this.beingCopyData = this.copyNode()
this.setCoptyDataToClipboard(this.beingCopyData)
}
// 剪切节点
cut() {
this.mindMap.execCommand('CUT_NODE', copyData => {
this.beingCopyData = copyData
this.setCoptyDataToClipboard(copyData)
})
}
// 将粘贴或剪切的数据设置到用户剪切板中
setCoptyDataToClipboard(data) {
if (navigator.clipboard) {
navigator.clipboard.writeText(
JSON.stringify({
simpleMindMap: true,
data
})
)
}
}
// 粘贴节点
paste() {
if (this.beingCopyData) {
this.mindMap.execCommand('PASTE_NODE', this.beingCopyData)
}
}
// 粘贴事件
async onPaste() {
const { errorHandler } = this.mindMap.opt
// 读取剪贴板的文字和图片
let text = null
let img = null
if (navigator.clipboard) {
try {
text = await navigator.clipboard.readText()
const items = await navigator.clipboard.read()
if (items && items.length > 0) {
for (const clipboardItem of items) {
for (const type of clipboardItem.types) {
if (/^image\//.test(type)) {
img = await clipboardItem.getType(type)
break
}
}
}
}
} catch (error) {
errorHandler(ERROR_TYPES.READ_CLIPBOARD_ERROR, error)
}
}
// 检查剪切板数据是否有变化
// 通过图片大小来判断图片是否发生变化,可能是不准确的,但是目前没有其他好方法
const imgSize = img ? img.size : 0
if (this.beingPasteText !== text || this.beingPasteImgSize !== imgSize) {
this.currentBeingPasteType = CONSTANTS.PASTE_TYPE.CLIP_BOARD
this.beingPasteText = text
this.beingPasteImgSize = imgSize
}
// 检查要粘贴的节点数据是否有变化,节点优先级高于剪切板
if (this.lastBeingCopyData !== this.beingCopyData) {
this.lastBeingCopyData = this.beingCopyData
this.currentBeingPasteType = CONSTANTS.PASTE_TYPE.CANVAS
}
// 粘贴剪切板的数据
if (this.currentBeingPasteType === CONSTANTS.PASTE_TYPE.CLIP_BOARD) {
// 存在文本,则创建子节点
if (text) {
// 判断粘贴的是否是simple-mind-map的数据
let smmData = null
let useDefault = true
// 用户自定义处理
if (this.mindMap.opt.customHandleClipboardText) {
try {
const res = await this.mindMap.opt.customHandleClipboardText(text)
if (!isUndef(res)) {
useDefault = false
if (typeof res === 'object' && res.simpleMindMap) {
smmData = res.data
} else {
text = String(res)
}
}
} catch (error) {
errorHandler(ERROR_TYPES.CUSTOM_HANDLE_CLIPBOARD_TEXT_ERROR, error)
}
}
// 默认处理
if (useDefault) {
try {
const parsedData = JSON.parse(text)
if (parsedData && parsedData.simpleMindMap) {
smmData = parsedData.data
}
} catch (error) {
errorHandler(ERROR_TYPES.PARSE_PASTE_DATA_ERROR, error)
}
}
if (smmData) {
this.mindMap.execCommand(
'INSERT_CHILD_NODE',
false,
[],
{
...smmData.data
},
[...smmData.children]
)
} else {
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], {
text
})
}
}
// 存在图片,则添加到当前激活节点
if (img) {
try {
let imgData = await loadImage(img)
if (this.activeNodeList.length > 0) {
this.activeNodeList.forEach(node => {
this.mindMap.execCommand('SET_NODE_IMAGE', node, {
url: imgData.url,
title: '',
width: imgData.size.width,
height: imgData.size.height
})
})
}
} catch (error) {
errorHandler(ERROR_TYPES.LOAD_CLIPBOARD_IMAGE_ERROR, error)
}
}
} else {
// 粘贴节点数据
this.paste()
}
}
// 将节点移动到另一个节点的前面
insertBefore(node, exist) {
if (node.isRoot) {
return
}
// 如果是二级节点变成了下级节点,或是下级节点变成了二级节点,节点样式需要更新
let nodeLayerChanged = (node.layerIndex === 1 && exist.layerIndex !== 1) || (node.layerIndex !== 1 && exist.layerIndex === 1)
let nodeLayerChanged =
(node.layerIndex === 1 && exist.layerIndex !== 1) ||
(node.layerIndex !== 1 && exist.layerIndex === 1)
// 移动节点
let nodeParent = node.parent
let nodeBorthers = nodeParent.children
@@ -580,7 +783,9 @@ class Render {
return
}
// 如果是二级节点变成了下级节点,或是下级节点变成了二级节点,节点样式需要更新
let nodeLayerChanged = (node.layerIndex === 1 && exist.layerIndex !== 1) || (node.layerIndex !== 1 && exist.layerIndex === 1)
let nodeLayerChanged =
(node.layerIndex === 1 && exist.layerIndex !== 1) ||
(node.layerIndex !== 1 && exist.layerIndex === 1)
// 移动节点
let nodeParent = node.parent
let nodeBorthers = nodeParent.children
@@ -620,7 +825,7 @@ class Render {
}
let isAppointNodes = appointNodes.length > 0
let list = isAppointNodes ? appointNodes : this.activeNodeList
let root = list.find((node) => {
let root = list.find(node => {
return node.isRoot
})
if (root) {
@@ -693,11 +898,11 @@ class Render {
if (node.isRoot) {
return
}
let copyData = copyNodeTree({}, node, false, true)
// let copyData = copyNodeTree({}, node, false, true)
this.removeActiveNode(node)
this.removeOneNode(node)
this.mindMap.emit('node_active', null, this.activeNodeList)
toNode.nodeData.children.push(copyData)
toNode.nodeData.children.push(node.nodeData)
this.mindMap.render()
if (toNode.isRoot) {
toNode.destroy()
@@ -706,7 +911,7 @@ class Render {
// 粘贴节点到节点
pasteNode(data) {
if (this.activeNodeList.length <= 0) {
if (this.activeNodeList.length <= 0 || !data) {
return
}
this.activeNodeList.forEach(item => {
@@ -748,6 +953,42 @@ class Render {
}
}
// 设置节点多个样式
setNodeStyles(node, style, isActive) {
let data = {}
if (isActive) {
data = {
activeStyle: {
...(node.nodeData.data.activeStyle || {}),
...style
}
}
} else {
data = style
}
// 如果开启了富文本,则需要应用到富文本上
if (this.mindMap.richText) {
let config = this.mindMap.richText.normalStyleToRichTextStyle(style)
if (Object.keys(config).length > 0) {
this.mindMap.richText.showEditText(node)
this.mindMap.richText.formatAllText(config)
this.mindMap.richText.hideEditText([node])
}
}
this.setNodeDataRender(node, data)
// 更新了连线的样式
let props = Object.keys(style)
let hasLineStyleProps = false
props.forEach(key => {
if (lineStyleProps.includes(key)) {
hasLineStyleProps = true
}
})
if (hasLineStyleProps) {
;(node.parent || node).renderLine(true)
}
}
// 设置节点是否激活
setNodeActive(node, active) {
this.setNodeData(node, {
@@ -861,21 +1102,24 @@ class Render {
}
// 设置节点文本
setNodeText(node, text, richText) {
setNodeText(node, text, richText, resetRichText) {
this.setNodeDataRender(node, {
text,
richText
richText,
resetRichText
})
}
// 设置节点图片
setNodeImage(node, { url, title, width, height }) {
setNodeImage(node, data) {
const { url, title, width, height, custom = false } = data || { url: '', title: '', width: 0, height: 0, custom: false }
this.setNodeDataRender(node, {
image: url,
imageTitle: title || '',
imageSize: {
width,
height
height,
custom
}
})
}
@@ -988,6 +1232,20 @@ class Render {
})
}
// 定位到指定节点
goTargetNode(node, callback = () => {}) {
let uid = typeof node === 'string' ? node : node.nodeData.data.uid
if (!uid) return
this.expandToNodeUid(uid, () => {
let targetNode = this.findNodeByUid(uid)
if (targetNode) {
targetNode.active()
this.moveNodeToCenter(targetNode)
callback()
}
})
}
// 更新节点数据
setNodeData(node, data) {
Object.keys(data).forEach(key => {
@@ -996,7 +1254,7 @@ class Render {
}
// 设置节点数据,并判断是否渲染
setNodeDataRender(node, data) {
setNodeDataRender(node, data, notRender = false) {
this.setNodeData(node, data)
let changed = node.reRender()
if (changed) {
@@ -1004,7 +1262,9 @@ class Render {
// 概要节点
node.generalizationBelongNode.updateGeneralization()
}
this.mindMap.render()
if (!notRender) this.mindMap.render()
} else {
this.mindMap.emit('node_tree_render_end')
}
}
@@ -1024,6 +1284,44 @@ class Render {
this.mindMap.view.translateY(offsetY)
this.mindMap.view.setScale(1)
}
// 展开到指定uid的节点
expandToNodeUid(uid, callback = () => {}) {
let parentsList = []
const cache = {}
bfsWalk(this.renderTree, (node, parent) => {
if (node.data.uid === uid) {
parentsList = parent ? [...cache[parent.data.uid], parent] : []
return 'stop'
} else {
cache[node.data.uid] = parent ? [...cache[parent.data.uid], parent] : []
}
})
let needRender = false
parentsList.forEach(node => {
if (!node.data.expand) {
needRender = true
node.data.expand = true
}
})
if (needRender) {
this.mindMap.render(callback)
} else {
callback()
}
}
// 根据uid找到对应的节点实例
findNodeByUid(uid) {
let res = null
walk(this.root, null, node => {
if (node.nodeData.data.uid === uid) {
res = node
return true
}
})
return res
}
}
export default Render

View File

@@ -1,4 +1,5 @@
import { getStrWithBrFromHtml, checkNodeOuter } from '../../utils'
import { ERROR_TYPES } from '../../constants/constant'
// 节点文字编辑类
export default class TextEdit {
@@ -54,6 +55,29 @@ export default class TextEdit {
this.show(this.renderer.activeNodeList[0])
})
this.mindMap.on('scale', this.onScale)
// // 监听按键事件,判断是否自动进入文本编辑模式
if (this.mindMap.opt.enableAutoEnterTextEditWhenKeydown) {
window.addEventListener('keydown', e => {
const activeNodeList = this.mindMap.renderer.activeNodeList
if (activeNodeList.length <= 0 || activeNodeList.length > 1) return
const node = activeNodeList[0]
// 当正在输入中文或英文或数字时,如果没有按下组合键,那么自动进入文本编辑模式
if (node && this.checkIsAutoEnterTextEditKey(e)) {
this.show(node)
}
})
}
}
// 判断是否是自动进入文本编模式的按钮
checkIsAutoEnterTextEditKey(e) {
const keyCode = e.keyCode
return (
(keyCode === 229 ||
(keyCode >= 65 && keyCode <= 90) ||
(keyCode >= 48 && keyCode <= 57)) &&
!this.mindMap.keyCommand.hasCombinationKey(e)
)
}
// 注册临时快捷键
@@ -62,10 +86,14 @@ export default class TextEdit {
this.mindMap.keyCommand.addShortcut('Enter', () => {
this.hideEditTextBox()
})
this.mindMap.keyCommand.addShortcut('Tab', () => {
this.hideEditTextBox()
})
}
// 显示文本编辑框
async show(node) {
// isInserting是否是刚创建的节点
async show(node, e, isInserting = false) {
// 使用了自定义节点内容那么不响应编辑事件
if (node.isUseCustomNodeContent()) {
return
@@ -74,9 +102,10 @@ export default class TextEdit {
if (typeof beforeTextEdit === 'function') {
let isShow = false
try {
isShow = await beforeTextEdit(node)
isShow = await beforeTextEdit(node, isInserting)
} catch (error) {
isShow = false
this.mindMap.opt.errorHandler(ERROR_TYPES.BEFORE_TEXT_EDIT_ERROR, error)
}
if (!isShow) return
}
@@ -85,17 +114,18 @@ export default class TextEdit {
this.mindMap.view.translateXY(offsetLeft, offsetTop)
let rect = node._textData.node.node.getBoundingClientRect()
if (this.mindMap.richText) {
this.mindMap.richText.showEditText(node, rect)
this.mindMap.richText.showEditText(node, rect, isInserting)
return
}
this.showEditTextBox(node, rect)
this.showEditTextBox(node, rect, isInserting)
}
// 处理画布缩放
onScale() {
if (!this.currentNode) return
if (this.mindMap.richText) {
this.mindMap.richText.cacheEditingText = this.mindMap.richText.getEditText()
this.mindMap.richText.cacheEditingText =
this.mindMap.richText.getEditText()
this.mindMap.richText.showTextEdit = false
} else {
this.cacheEditingText = this.getEditText()
@@ -105,7 +135,8 @@ export default class TextEdit {
}
// 显示文本编辑框
showEditTextBox(node, rect) {
showEditTextBox(node, rect, isInserting) {
if (this.showTextEdit) return
this.mindMap.emit('before_show_text_edit')
this.registerTmpShortcut()
if (!this.textEditNode) {
@@ -118,12 +149,24 @@ export default class TextEdit {
this.textEditNode.addEventListener('click', e => {
e.stopPropagation()
})
document.body.appendChild(this.textEditNode)
this.textEditNode.addEventListener('mousedown', e => {
e.stopPropagation()
})
this.textEditNode.addEventListener('keydown', e => {
if (this.checkIsAutoEnterTextEditKey(e)) {
e.stopPropagation()
}
})
const targetNode =
this.mindMap.opt.customInnerElsAppendTo || document.body
targetNode.appendChild(this.textEditNode)
}
let scale = this.mindMap.view.scale
let lineHeight = node.style.merge('lineHeight')
let fontSize = node.style.merge('fontSize')
let textLines = (this.cacheEditingText || node.nodeData.data.text).split(/\n/gim)
let textLines = (this.cacheEditingText || node.nodeData.data.text).split(
/\n/gim
)
let isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true'
node.style.domText(this.textEditNode, scale, isMultiLine)
this.textEditNode.style.zIndex = this.mindMap.opt.nodeTextEditZIndex
@@ -133,18 +176,36 @@ export default class TextEdit {
this.textEditNode.style.left = rect.left + 'px'
this.textEditNode.style.top = rect.top + 'px'
this.textEditNode.style.display = 'block'
this.textEditNode.style.maxWidth = this.mindMap.opt.textAutoWrapWidth * scale + 'px'
this.textEditNode.style.maxWidth =
this.mindMap.opt.textAutoWrapWidth * scale + 'px'
if (isMultiLine && lineHeight !== 1) {
this.textEditNode.style.transform = `translateY(${-((lineHeight * fontSize - fontSize) / 2) * scale}px)`
this.textEditNode.style.transform = `translateY(${
-((lineHeight * fontSize - fontSize) / 2) * scale
}px)`
}
this.showTextEdit = true
// 选中文本
if (!this.cacheEditingText) {
// if (!this.cacheEditingText) {
// this.selectNodeText()
// }
if (isInserting) {
this.selectNodeText()
} else {
this.focus()
}
this.cacheEditingText = ''
}
// 聚焦
focus() {
let selection = window.getSelection()
let range = document.createRange()
range.selectNodeContents(this.textEditNode)
range.collapse()
selection.removeAllRanges()
selection.addRange(range)
}
// 选中文本
selectNodeText() {
let selection = window.getSelection()

View File

@@ -1,11 +1,11 @@
import Style from './Style'
import Shape from './Shape'
import { asyncRun, nodeToHTML } from '../../../utils'
import { G, Rect, ForeignObject, SVG } from '@svgdotjs/svg.js'
import { G, ForeignObject, SVG } from '@svgdotjs/svg.js'
import nodeGeneralizationMethods from './nodeGeneralization'
import nodeExpandBtnMethods from './nodeExpandBtn'
import nodeCommandWrapsMethods from './nodeCommandWraps'
import nodeCreateContentsMethods from './nodeCreateContents'
import nodeExpandBtnPlaceholderRectMethods from './nodeExpandBtnPlaceholderRect'
import { CONSTANTS } from '../../../constants/constant'
// 节点类
@@ -98,6 +98,8 @@ class Node {
this.isMultipleChoice = false
// 是否需要重新layout
this.needLayout = false
// 当前是否是隐藏状态
this.isHide = false
// 概要相关方法
Object.keys(nodeGeneralizationMethods).forEach(item => {
this[item] = nodeGeneralizationMethods[item].bind(this)
@@ -106,6 +108,10 @@ class Node {
Object.keys(nodeExpandBtnMethods).forEach(item => {
this[item] = nodeExpandBtnMethods[item].bind(this)
})
// 展开收起按钮占位元素相关方法
Object.keys(nodeExpandBtnPlaceholderRectMethods).forEach(item => {
this[item] = nodeExpandBtnPlaceholderRectMethods[item].bind(this)
})
// 命令的相关方法
Object.keys(nodeCommandWrapsMethods).forEach(item => {
this[item] = nodeCommandWrapsMethods[item].bind(this)
@@ -251,9 +257,11 @@ class Node {
this.shapeInstance.getShapePadding(_width, _height, paddingX, paddingY)
this.shapePadding.paddingX = shapePaddingX
this.shapePadding.paddingY = shapePaddingY
// 边框宽度,因为边框是以中线向两端发散,所以边框会超出节点
const borderWidth = this.getBorderWidth()
return {
width: _width + paddingX * 2 + shapePaddingX * 2,
height: _height + paddingY * 2 + margin + shapePaddingY * 2
width: _width + paddingX * 2 + shapePaddingX * 2 + borderWidth,
height: _height + paddingY * 2 + margin + shapePaddingY * 2 + borderWidth
}
}
@@ -263,21 +271,16 @@ class Node {
this.group.clear()
let { width, height, textContentItemMargin } = this
let { paddingY } = this.getPaddingVale()
paddingY += this.shapePadding.paddingY
const halfBorderWidth = this.getBorderWidth() / 2
paddingY += this.shapePadding.paddingY + halfBorderWidth
// 节点形状
this.shapeNode = this.shapeInstance.createShape()
this.shapeNode.addClass('smm-node-shape')
this.shapeNode.translate(halfBorderWidth, halfBorderWidth)
this.group.add(this.shapeNode)
this.updateNodeShape()
// 渲染一个隐藏的矩形区域,用来触发展开收起按钮的显示
if (!this.mindMap.opt.alwaysShowExpandBtn) {
if (!this._unVisibleRectRegionNode) {
this._unVisibleRectRegionNode = new Rect()
}
this._unVisibleRectRegionNode.fill({
color: 'transparent'
}).size(this.expandBtnSize, height).x(width).y(0)
this.group.add(this._unVisibleRectRegionNode)
}
this.renderExpandBtnPlaceholderRect()
// 概要节点添加一个带所属节点id的类名
if (this.isGeneralization && this.generalizationBelongNode) {
this.group.addClass('generalization_' + this.generalizationBelongNode.uid)
@@ -289,7 +292,7 @@ class Node {
foreignObject.height(height)
foreignObject.add(SVG(this._customNodeContent))
this.group.add(foreignObject)
return
return
}
// 图片节点
let imgHeight = 0
@@ -377,10 +380,10 @@ class Node {
this.active(e)
})
this.group.on('mousedown', e => {
if (this.isRoot && e.which === 3) {
if (this.isRoot && e.which === 3 && !this.mindMap.opt.readonly) {
e.stopPropagation()
}
if (!this.isRoot) {
if (!this.isRoot && e.which !== 2 && !this.mindMap.opt.readonly) {
e.stopPropagation()
}
// 多选和取消多选
@@ -406,7 +409,7 @@ class Node {
this.mindMap.emit('node_mousedown', this, e)
})
this.group.on('mouseup', e => {
if (!this.isRoot) {
if (!this.isRoot && e.which !== 2 && !this.mindMap.opt.readonly) {
e.stopPropagation()
}
this.mindMap.emit('node_mouseup', this, e)
@@ -433,7 +436,8 @@ class Node {
// 右键菜单事件
this.group.on('contextmenu', e => {
// 按住ctrl键点击鼠标左键不知为何触发的是contextmenu事件
if (this.mindMap.opt.readonly || e.ctrlKey) {// || this.isGeneralization
if (this.mindMap.opt.readonly || e.ctrlKey) {
// || this.isGeneralization
return
}
e.stopPropagation()
@@ -467,8 +471,7 @@ class Node {
if (!this.group) {
return
}
let { enableNodeTransitionMove, nodeTransitionMoveDuration, alwaysShowExpandBtn } =
this.mindMap.opt
let { alwaysShowExpandBtn } = this.mindMap.opt
if (alwaysShowExpandBtn) {
// 需要移除展开收缩按钮
if (this._expandBtn && this.nodeData.children.length <= 0) {
@@ -490,14 +493,45 @@ class Node {
this.renderGeneralization()
// 更新节点位置
let t = this.group.transform()
// // 如果上次不在可视区内,且本次也不在,那么直接返回
// let { left: ox, top: oy } = this.getNodePosInClient(
// t.translateX,
// t.translateY
// )
// let oldIsInClient =
// ox > 0 && oy > 0 && ox < this.mindMap.width && oy < this.mindMap.height
// let { left: nx, top: ny } = this.getNodePosInClient(this.left, this.top)
// let newIsNotInClient =
// nx + this.width < 0 ||
// ny + this.height < 0 ||
// nx > this.mindMap.width ||
// ny > this.mindMap.height
// if (!oldIsInClient && newIsNotInClient) {
// if (!this.isHide) {
// this.isHide = true
// this.group.hide()
// }
// return
// }
// // 如果当前是隐藏状态,那么先显示
// if (this.isHide) {
// this.isHide = false
// this.group.show()
// }
// 如果节点位置没有变化,则返回
if (this.left === t.translateX && this.top === t.translateY) return
if (!isLayout && enableNodeTransitionMove) {
this.group
.animate(nodeTransitionMoveDuration)
.translate(this.left - t.translateX, this.top - t.translateY)
} else {
this.group.translate(this.left - t.translateX, this.top - t.translateY)
this.group.translate(this.left - t.translateX, this.top - t.translateY)
}
// 获取节点相当于画布的位置
getNodePosInClient(_left, _top) {
let drawTransform = this.mindMap.draw.transform()
let { scaleX, scaleY, translateX, translateY } = drawTransform
let left = _left * scaleX + translateX
let top = _top * scaleY + translateY
return {
left,
top
}
}
@@ -520,8 +554,6 @@ class Node {
// 递归渲染
render(callback = () => {}) {
let { enableNodeTransitionMove, nodeTransitionMoveDuration } =
this.mindMap.opt
// 节点
// 重新渲染连线
this.renderLine()
@@ -530,6 +562,7 @@ class Node {
isLayout = true
// 创建组
this.group = new G()
this.group.addClass('smm-node')
this.group.css({
cursor: 'default'
})
@@ -543,6 +576,7 @@ class Node {
this.needLayout = false
this.layout()
}
this.updateExpandBtnPlaceholderRect()
this.update()
}
// 子节点
@@ -552,33 +586,23 @@ class Node {
this.nodeData.data.expand !== false
) {
let index = 0
asyncRun(
this.children.map(item => {
return () => {
item.render(() => {
index++
if (index >= this.children.length) {
callback()
}
})
this.children.forEach(item => {
item.render(() => {
index++
if (index >= this.children.length) {
callback()
}
})
)
})
} else {
if (enableNodeTransitionMove && !isLayout) {
setTimeout(() => {
callback()
}, nodeTransitionMoveDuration)
} else {
callback()
}
callback()
}
// 手动插入的节点立即获得焦点并且开启编辑模式
if (this.nodeData.inserting) {
delete this.nodeData.inserting
this.active()
setTimeout(() => {
this.mindMap.emit('node_dblclick', this)
this.mindMap.emit('node_dblclick', this, null, true)
}, 0)
}
}
@@ -591,13 +615,9 @@ class Node {
this.removeLine()
// 子节点
if (this.children && this.children.length) {
asyncRun(
this.children.map(item => {
return () => {
item.remove()
}
})
)
this.children.forEach(item => {
item.remove()
})
}
}
@@ -623,13 +643,9 @@ class Node {
}
// 子节点
if (this.children && this.children.length) {
asyncRun(
this.children.map(item => {
return () => {
item.hide()
}
})
)
this.children.forEach(item => {
item.hide()
})
}
}
@@ -649,13 +665,9 @@ class Node {
}
// 子节点
if (this.children && this.children.length) {
asyncRun(
this.children.map(item => {
return () => {
item.show()
}
})
)
this.children.forEach(item => {
item.show()
})
}
}
@@ -783,7 +795,7 @@ class Node {
// 获取padding值
getPaddingVale() {
let { isActive }= this.nodeData.data
let { isActive } = this.nodeData.data
return {
paddingX: this.getStyle('paddingX', true, isActive),
paddingY: this.getStyle('paddingY', true, isActive)
@@ -819,6 +831,11 @@ class Node {
) // 父级
}
// 获取节点非节点状态的边框大小
getBorderWidth() {
return this.style.merge('borderWidth', false, false) || 0
}
// 获取数据
getData(key) {
return key ? this.nodeData.data[key] || '' : this.nodeData.data

View File

@@ -62,7 +62,10 @@ export default class Shape {
// 创建形状节点
createShape() {
const shape = this.node.getShape()
const borderWidth = this.node.getBorderWidth()
let { width, height } = this.node
width -= borderWidth
height -= borderWidth
let node = null
// 矩形
if (shape === CONSTANTS.SHAPE.RECTANGLE) {

View File

@@ -17,7 +17,7 @@ class Style {
// 设置新样式
let { backgroundColor, backgroundImage, backgroundRepeat, backgroundPosition, backgroundSize } = themeConfig
el.style.backgroundColor = backgroundColor
if (backgroundImage) {
if (backgroundImage && backgroundImage !== 'none') {
el.style.backgroundImage = `url(${backgroundImage})`
el.style.backgroundRepeat = backgroundRepeat
el.style.backgroundPosition = backgroundPosition

View File

@@ -4,8 +4,8 @@ function setData(data = {}) {
}
// 设置文本
function setText(text, richText) {
this.mindMap.execCommand('SET_NODE_TEXT', this, text, richText)
function setText(text, richText, resetRichText) {
this.mindMap.execCommand('SET_NODE_TEXT', this, text, richText, resetRichText)
}
// 设置图片
@@ -43,6 +43,11 @@ function setStyle(prop, value, isActive) {
this.mindMap.execCommand('SET_NODE_STYLE', this, prop, value, isActive)
}
// 修改多个样式
function setStyles(style, isActive) {
this.mindMap.execCommand('SET_NODE_STYLES', this, style, isActive)
}
export default {
setData,
setText,
@@ -52,5 +57,6 @@ export default {
setNote,
setTag,
setShape,
setStyle
setStyle,
setStyles
}

View File

@@ -1,7 +1,13 @@
import { measureText, resizeImgSize, getTextFromHtml } from '../../../utils'
import {
measureText,
resizeImgSize,
removeHtmlStyle,
addHtmlStyle,
checkIsRichText
} from '../../../utils'
import { Image, SVG, A, G, Rect, Text, ForeignObject } from '@svgdotjs/svg.js'
import iconsSvg from '../../../svg/icons'
import { CONSTANTS } from '../../../constants/constant'
import { CONSTANTS, commonCaches } from '../../../constants/constant'
// 创建图片节点
function createImgNode() {
@@ -17,6 +23,15 @@ function createImgNode() {
node.on('dblclick', e => {
this.mindMap.emit('node_img_dblclick', this, e)
})
node.on('mouseenter', e => {
this.mindMap.emit('node_img_mouseenter', this, node, e)
})
node.on('mouseleave', e => {
this.mindMap.emit('node_img_mouseleave', this, node, e)
})
node.on('mousemove', e => {
this.mindMap.emit('node_img_mousemove', this, node, e)
})
return {
node,
width: imgSize[0],
@@ -26,9 +41,12 @@ function createImgNode() {
// 获取图片显示宽高
function getImgShowSize() {
const { custom, width, height } = this.nodeData.data.imageSize
// 如果是自定义了图片的宽高,那么不受最大宽高限制
if (custom) return [width, height]
return resizeImgSize(
this.nodeData.data.imageSize.width,
this.nodeData.data.imageSize.height,
width,
height,
this.mindMap.themeConfig.imgMaxWidth,
this.mindMap.themeConfig.imgMaxHeight
)
@@ -42,7 +60,10 @@ function createIconNode() {
}
let iconSize = this.mindMap.themeConfig.iconSize
return _data.icon.map(item => {
let src = iconsSvg.getNodeIconListIcon(item, this.mindMap.opt.iconList || [])
let src = iconsSvg.getNodeIconListIcon(
item,
this.mindMap.opt.iconList || []
)
let node = null
// svg图标
if (/^<svg/.test(src)) {
@@ -52,6 +73,9 @@ function createIconNode() {
node = new Image().load(src)
}
node.size(iconSize, iconSize)
node.on('click', e => {
this.mindMap.emit('node_icon_click', this, item, e)
})
return {
node,
width: iconSize,
@@ -76,11 +100,27 @@ function createRichTextNode() {
}
}
if (recoverText) {
let text = getTextFromHtml(this.nodeData.data.text)
this.nodeData.data.text = `<p><span style="${this.style.createStyleText()}">${text}</span></p>`
let text = this.nodeData.data.text
// 判断节点内容是否是富文本
let isRichText = checkIsRichText(text)
// 样式字符串
let style = this.style.createStyleText()
if (isRichText) {
// 如果是富文本那么线移除内联样式
text = removeHtmlStyle(text)
// 再添加新的内联样式
text = addHtmlStyle(text, 'span', style)
} else {
// 非富文本
text = `<p><span style="${style}">${text}</span></p>`
}
this.nodeData.data.text = text
}
let html = `<div>${this.nodeData.data.text}</div>`
let div = document.createElement('div')
if (!commonCaches.measureRichtextNodeTextSizeEl) {
commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div')
}
let div = commonCaches.measureRichtextNodeTextSizeEl
div.innerHTML = html
div.style.cssText = `position: fixed; left: -999999px;`
let el = div.children[0]
@@ -89,16 +129,21 @@ function createRichTextNode() {
el.style.maxWidth = this.mindMap.opt.textAutoWrapWidth + 'px'
this.mindMap.el.appendChild(div)
let { width, height } = el.getBoundingClientRect()
width = Math.ceil(width)
// 如果文本为空,那么需要计算一个默认高度
if (height <= 0) {
div.innerHTML = '<p>abc123我和你</p>'
let elTmp = div.children[0]
elTmp.classList.add('smm-richtext-node-wrap')
height = elTmp.getBoundingClientRect().height
}
width = Math.ceil(width) + 1 // 修复getBoundingClientRect方法对实际宽度是小数的元素获取到的值是整数导致宽度不够文本发生换行的问题
height = Math.ceil(height)
g.attr('data-width', width)
g.attr('data-height', height)
html = div.innerHTML
this.mindMap.el.removeChild(div)
let foreignObject = new ForeignObject()
foreignObject.width(width)
foreignObject.height(height)
foreignObject.add(SVG(html))
foreignObject.add(div.children[0])
g.add(foreignObject)
return {
node: g,
@@ -240,15 +285,17 @@ function createNoteNode() {
if (!this.noteEl) {
this.noteEl = document.createElement('div')
this.noteEl.style.cssText = `
position: absolute;
position: fixed;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
display: none;
background-color: #fff;
z-index: ${ this.mindMap.opt.nodeNoteTooltipZIndex }
z-index: ${this.mindMap.opt.nodeNoteTooltipZIndex}
`
document.body.appendChild(this.noteEl)
const targetNode =
this.mindMap.opt.customInnerElsAppendTo || document.body
targetNode.appendChild(this.noteEl)
}
this.noteEl.innerText = this.nodeData.data.note
}
@@ -281,20 +328,19 @@ function createNoteNode() {
}
// 测量自定义节点内容元素的宽高
let warpEl = null
function measureCustomNodeContentSize (content) {
if (!warpEl) {
warpEl = document.createElement('div')
warpEl.style.cssText = `
function measureCustomNodeContentSize(content) {
if (!commonCaches.measureCustomNodeContentSizeEl) {
commonCaches.measureCustomNodeContentSizeEl = document.createElement('div')
commonCaches.measureCustomNodeContentSizeEl.style.cssText = `
position: fixed;
left: -99999px;
top: -99999px;
`
this.mindMap.el.appendChild(warpEl)
this.mindMap.el.appendChild(commonCaches.measureCustomNodeContentSizeEl)
}
warpEl.innerHTML = ''
warpEl.appendChild(content)
let rect = warpEl.getBoundingClientRect()
commonCaches.measureCustomNodeContentSizeEl.innerHTML = ''
commonCaches.measureCustomNodeContentSizeEl.appendChild(content)
let rect = commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect()
return {
width: rect.width,
height: rect.height
@@ -302,19 +348,19 @@ function measureCustomNodeContentSize (content) {
}
// 是否使用的是自定义节点内容
function isUseCustomNodeContent() {
function isUseCustomNodeContent() {
return !!this._customNodeContent
}
export default {
createImgNode,
getImgShowSize,
createIconNode,
createRichTextNode,
createTextNode,
createHyperlinkNode,
createTagNode,
createNoteNode,
measureCustomNodeContentSize,
isUseCustomNodeContent
}
createImgNode,
getImgShowSize,
createIconNode,
createRichTextNode,
createTextNode,
createHyperlinkNode,
createTagNode,
createNoteNode,
measureCustomNodeContentSize,
isUseCustomNodeContent
}

View File

@@ -0,0 +1,66 @@
import { Rect } from '@svgdotjs/svg.js'
// 渲染展开收起按钮的隐藏占位元素
function renderExpandBtnPlaceholderRect() {
// 根节点或没有子节点不需要渲染
if (
!this.nodeData.children ||
this.nodeData.children.length <= 0 ||
this.isRoot
) {
return
}
// 默认显示展开按钮的情况下也不需要渲染
if (!this.mindMap.opt.alwaysShowExpandBtn) {
let { width, height } = this
if (!this._unVisibleRectRegionNode) {
this._unVisibleRectRegionNode = new Rect()
this._unVisibleRectRegionNode.fill({
color: 'transparent'
})
}
this.group.add(this._unVisibleRectRegionNode)
this.renderer.layout.renderExpandBtnRect(
this._unVisibleRectRegionNode,
this.expandBtnSize,
width,
height,
this
)
}
}
// 删除展开收起按钮的隐藏占位元素
function clearExpandBtnPlaceholderRect() {
if (!this._unVisibleRectRegionNode) {
return
}
this._unVisibleRectRegionNode.remove()
this._unVisibleRectRegionNode = null
}
// 更新展开收起按钮的隐藏占位元素
function updateExpandBtnPlaceholderRect() {
// 布局改变需要重新渲染
if (this.needRerenderExpandBtnPlaceholderRect) {
this.needRerenderExpandBtnPlaceholderRect = false
this.renderExpandBtnPlaceholderRect()
}
// 没有子节点到有子节点需要渲染
if (this.nodeData.children && this.nodeData.children.length > 0) {
if (!this._unVisibleRectRegionNode) {
this.renderExpandBtnPlaceholderRect()
}
} else {
// 有子节点到没子节点,需要删除
if (this._unVisibleRectRegionNode) {
this.clearExpandBtnPlaceholderRect()
}
}
}
export default {
renderExpandBtnPlaceholderRect,
clearExpandBtnPlaceholderRect,
updateExpandBtnPlaceholderRect
}

View File

@@ -1,4 +1,5 @@
import Node from './Node'
import { createUid } from '../../../utils/index'
// 检查是否存在概要
function checkHasGeneralization () {
@@ -18,7 +19,7 @@ function createGeneralizationNode () {
data: {
data: this.nodeData.data.generalization
},
uid: this.mindMap.uid++,
uid: createUid(),
renderer: this.renderer,
mindMap: this.mindMap,
draw: this.draw,
@@ -35,15 +36,14 @@ function createGeneralizationNode () {
// 更新概要节点
function updateGeneralization () {
if (this.isGeneralization) return
this.removeGeneralization()
this.createGeneralizationNode()
}
// 渲染概要节点
function renderGeneralization () {
if (this.isGeneralization) {
return
}
if (this.isGeneralization) return
if (!this.checkHasGeneralization()) {
this.removeGeneralization()
this._generalizationNodeWidth = 0
@@ -66,6 +66,7 @@ function renderGeneralization () {
// 删除概要节点
function removeGeneralization () {
if (this.isGeneralization) return
if (this._generalizationLine) {
this._generalizationLine.remove()
this._generalizationLine = null
@@ -86,6 +87,7 @@ function removeGeneralization () {
// 隐藏概要节点
function hideGeneralization () {
if (this.isGeneralization) return
if (this._generalizationLine) {
this._generalizationLine.hide()
}
@@ -96,6 +98,7 @@ function hideGeneralization () {
// 显示概要节点
function showGeneralization () {
if (this.isGeneralization) return
if (this._generalizationLine) {
this._generalizationLine.show()
}

View File

@@ -64,7 +64,9 @@ class View {
customHandleMousewheel,
mousewheelAction,
mouseScaleCenterUseMousePosition,
mousewheelMoveStep
mousewheelMoveStep,
mousewheelZoomActionReverse,
disableMouseWheelZoom
} = this.mindMap.opt
// 是否自定义鼠标滚轮事件
if (
@@ -75,21 +77,28 @@ class View {
}
// 鼠标滚轮事件控制缩放
if (mousewheelAction === CONSTANTS.MOUSE_WHEEL_ACTION.ZOOM) {
let cx = mouseScaleCenterUseMousePosition ? e.clientX : undefined
let cy = mouseScaleCenterUseMousePosition ? e.clientY : undefined
if (disableMouseWheelZoom) return
const { x: clientX, y: clientY } = this.mindMap.toPos(e.clientX, e.clientY)
let cx = mouseScaleCenterUseMousePosition ? clientX : undefined
let cy = mouseScaleCenterUseMousePosition ? clientY : undefined
switch (dir) {
// 鼠标滚轮,向上和向左,都是缩小
case CONSTANTS.DIR.UP:
case CONSTANTS.DIR.LEFT:
this.narrow(cx, cy)
mousewheelZoomActionReverse
? this.enlarge(cx, cy, isTouchPad)
: this.narrow(cx, cy, isTouchPad)
break
// 鼠标滚轮,向下和向右,都是放大
case CONSTANTS.DIR.DOWN:
case CONSTANTS.DIR.RIGHT:
this.enlarge(cx, cy)
mousewheelZoomActionReverse
? this.narrow(cx, cy, isTouchPad)
: this.enlarge(cx, cy, isTouchPad)
break
}
} else {// 鼠标滚轮事件控制画布移动
} else {
// 鼠标滚轮事件控制画布移动
let step = mousewheelMoveStep
if (isTouchPad) {
step = 5
@@ -146,6 +155,7 @@ class View {
// 平移x,y方向
translateXY(x, y) {
if (x === 0 && y === 0) return
this.x += x
this.y += y
this.transform()
@@ -153,24 +163,28 @@ class View {
// 平移x方向
translateX(step) {
if (step === 0) return
this.x += step
this.transform()
}
// 平移x方式到
translateXTo(x) {
if (x === 0) return
this.x = x
this.transform()
}
// 平移y方向
translateY(step) {
if (step === 0) return
this.y += step
this.transform()
}
// 平移y方向到
translateYTo(y) {
if (y === 0) return
this.y = y
this.transform()
}
@@ -198,16 +212,18 @@ class View {
}
// 缩小
narrow(cx, cy) {
const scale = Math.max(this.scale - this.mindMap.opt.scaleRatio, 0.1)
narrow(cx, cy, isTouchPad) {
const scaleRatio = this.mindMap.opt.scaleRatio / (isTouchPad ? 5 : 1)
const scale = Math.max(this.scale - scaleRatio, 0.1)
this.scaleInCenter(scale, cx, cy)
this.transform()
this.mindMap.emit('scale', this.scale)
}
// 放大
enlarge(cx, cy) {
const scale = this.scale + this.mindMap.opt.scaleRatio
enlarge(cx, cy, isTouchPad) {
const scaleRatio = this.mindMap.opt.scaleRatio / (isTouchPad ? 5 : 1)
const scale = this.scale + scaleRatio
this.scaleInCenter(scale, cx, cy)
this.transform()
this.mindMap.emit('scale', this.scale)

View File

@@ -1,6 +1,7 @@
import Node from '../core/render/node/Node'
import { CONSTANTS, initRootNodePositionMap } from '../constants/constant'
import Lru from '../utils/Lru'
import { createUid } from '../utils/index'
// 布局基类
class Base {
@@ -48,6 +49,20 @@ class Base {
return [CONSTANTS.CHANGE_THEME, CONSTANTS.TRANSFORM_TO_NORMAL_NODE].includes(this.renderer.renderSource)
}
// 层级类型改变
checkIsLayerTypeChange(oldIndex, newIndex) {
if (oldIndex >= 2 && newIndex >= 2) return false
if (oldIndex >= 2 && newIndex < 2) return true
if (oldIndex < 2 && newIndex >= 2) return true
}
// 检查是否是结构布局改变重新渲染展开收起按钮占位元素
checkIsLayoutChangeRerenderExpandBtnPlaceholderRect(node) {
if (this.renderer.renderSource === CONSTANTS.CHANGE_LAYOUT) {
node.needRerenderExpandBtnPlaceholderRect = true
}
}
// 创建节点实例
createNode(data, parent, isRoot, layerIndex) {
// 创建节点
@@ -55,11 +70,13 @@ class Base {
// 数据上保存了节点引用,那么直接复用节点
if (data && data._node && !this.renderer.reRender) {
newNode = data._node
let isLayerTypeChange = this.checkIsLayerTypeChange(newNode.layerIndex, layerIndex)
newNode.reset()
newNode.layerIndex = layerIndex
this.cacheNode(data._node.uid, newNode)
this.checkIsLayoutChangeRerenderExpandBtnPlaceholderRect(newNode)
// 主题或主题配置改变了需要重新计算节点大小和布局
if (this.checkIsNeedResizeSources()) {
if (this.checkIsNeedResizeSources() || isLayerTypeChange) {
newNode.getSize()
newNode.needLayout = true
}
@@ -68,22 +85,24 @@ class Base {
newNode = this.lru.get(data.data.uid)
// 保存该节点上一次的数据
let lastData = JSON.stringify(newNode.nodeData.data)
let isLayerTypeChange = this.checkIsLayerTypeChange(newNode.layerIndex, layerIndex)
newNode.reset()
newNode.nodeData = newNode.handleData(data || {})
newNode.layerIndex = layerIndex
this.cacheNode(data.data.uid, newNode)
this.checkIsLayoutChangeRerenderExpandBtnPlaceholderRect(newNode)
data._node = newNode
// 主题或主题配置改变了需要重新计算节点大小和布局
let isResizeSource = this.checkIsNeedResizeSources()
// 节点数据改变了需要重新计算节点大小和布局
let isNodeDataChange = lastData !== JSON.stringify(data.data)
if (isResizeSource || isNodeDataChange) {
if (isResizeSource || isNodeDataChange || isLayerTypeChange) {
newNode.getSize()
newNode.needLayout = true
}
} else {
// 创建新节点
let uid = this.mindMap.uid++
let uid = data.data.uid || createUid()
newNode = new Node({
data,
uid,

View File

@@ -349,6 +349,11 @@ class CatalogOrganization extends Base {
gNode.left = right + generalizationNodeMargin
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
rect.size(width, expandBtnSize).x(0).y(height)
}
}
export default CatalogOrganization

View File

@@ -51,8 +51,8 @@ class Fishbone extends Base {
// 节点生长方向
newNode.dir =
index % 2 === 0
? CONSTANTS.TIMELINE_DIR.TOP
: CONSTANTS.TIMELINE_DIR.BOTTOM
? CONSTANTS.LAYOUT_GROW_DIR.TOP
: CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
}
// 计算二级节点的top值
if (parent._node.isRoot) {
@@ -222,7 +222,7 @@ class Fishbone extends Base {
// 检查节点是否是上方节点
checkIsTop(node) {
return node.dir === CONSTANTS.TIMELINE_DIR.TOP
return node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP
}
// 绘制连线,连接该节点到其子节点
@@ -239,7 +239,7 @@ class Fishbone extends Base {
// 当前节点是根节点
// 根节点的子节点是和根节点同一水平线排列
let maxx = -Infinity
node.children.forEach((item) => {
node.children.forEach(item => {
if (item.left > maxx) {
maxx = item.left
}
@@ -250,15 +250,15 @@ class Fishbone extends Base {
let line = this.draw.path()
if (this.checkIsTop(item)) {
line.plot(
`M ${nodeLineX - offsetX},${item.top + item.height + offset} L ${item.left},${
item.top + item.height
}`
`M ${nodeLineX - offsetX},${item.top + item.height + offset} L ${
item.left
},${item.top + item.height}`
)
} else {
line.plot(
`M ${nodeLineX - offsetX},${
item.top - offset
} L ${nodeLineX},${item.top}`
`M ${nodeLineX - offsetX},${item.top - offset} L ${nodeLineX},${
item.top
}`
)
}
node.style.line(line)
@@ -373,6 +373,27 @@ class Fishbone extends Base {
gNode.left = right + generalizationNodeMargin
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
let dir = ''
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP) {
dir =
node.layerIndex === 1
? CONSTANTS.LAYOUT_GROW_DIR.TOP
: CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
} else {
dir =
node.layerIndex === 1
? CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
: CONSTANTS.LAYOUT_GROW_DIR.TOP
}
if (dir === CONSTANTS.LAYOUT_GROW_DIR.TOP) {
rect.size(width, expandBtnSize).x(0).y(-expandBtnSize)
} else {
rect.size(width, expandBtnSize).x(0).y(height)
}
}
}
export default Fishbone

View File

@@ -52,8 +52,8 @@ class Fishbone extends Base {
// 节点生长方向
newNode.dir =
index % 2 === 0
? CONSTANTS.TIMELINE_DIR.TOP
: CONSTANTS.TIMELINE_DIR.BOTTOM
? CONSTANTS.LAYOUT_GROW_DIR.TOP
: CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
}
// 计算二级节点的top值
if (parent._node.isRoot) {

View File

@@ -52,8 +52,8 @@ class Fishbone extends Base {
// 节点生长方向
newNode.dir =
index % 2 === 0
? CONSTANTS.TIMELINE_DIR.TOP
: CONSTANTS.TIMELINE_DIR.BOTTOM
? CONSTANTS.LAYOUT_GROW_DIR.TOP
: CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
}
// 计算二级节点的top值
if (parent._node.isRoot) {
@@ -281,7 +281,7 @@ class Fishbone extends Base {
if (
node.parent &&
node.parent.isRoot &&
node.dir === CONSTANTS.TIMELINE_DIR.TOP
node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP
) {
line.plot(
`M ${x},${top} L ${x + lineLength},${

View File

@@ -172,9 +172,7 @@ class LogicalStructure extends Base {
let x2 = item.left
let y2 = item.top + item.height / 2
// 节点使用横线风格,需要额外渲染横线
let nodeUseLineStyleOffset = nodeUseLineStyle
? item.width
: 0
let nodeUseLineStyleOffset = nodeUseLineStyle ? item.width : 0
y1 = nodeUseLineStyle && !node.isRoot ? y1 + height / 2 : y1
y2 = nodeUseLineStyle ? y2 + item.height / 2 : y2
let path = `M ${x1},${y1} L ${x1 + s1},${y1} L ${x1 + s1},${y2} L ${
@@ -236,7 +234,7 @@ class LogicalStructure extends Base {
let nodeUseLineStylePath = nodeUseLineStyle
? ` L ${item.left + item.width},${y2}`
: ''
if (node.isRoot) {
if (node.isRoot && !this.mindMap.themeConfig.rootLineKeepSameInCurve) {
path = this.quadraticCurvePath(x1, y1, x2, y2) + nodeUseLineStylePath
} else {
path = this.cubicBezierPath(x1, y1, x2, y2) + nodeUseLineStylePath
@@ -260,10 +258,7 @@ class LogicalStructure extends Base {
if (_x === translateX && _y === translateY) {
return
}
btn.translate(
_x - translateX,
_y - translateY
)
btn.translate(_x - translateX, _y - translateY)
}
// 创建概要节点
@@ -286,6 +281,11 @@ class LogicalStructure extends Base {
gNode.left = right + generalizationNodeMargin
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
rect.size(expandBtnSize, height).x(width).y(0)
}
}
export default LogicalStructure

View File

@@ -1,5 +1,6 @@
import Base from './Base'
import { walk, asyncRun } from '../utils'
import { CONSTANTS } from '../constants/constant'
// 思维导图
class MindMap extends Base {
@@ -45,11 +46,14 @@ class MindMap extends Base {
newNode.dir = parent._node.dir
} else {
// 节点生长方向
newNode.dir = index % 2 === 0 ? 'right' : 'left'
newNode.dir =
index % 2 === 0
? CONSTANTS.LAYOUT_GROW_DIR.RIGHT
: CONSTANTS.LAYOUT_GROW_DIR.LEFT
}
// 根据生长方向定位到父节点的左侧或右侧
newNode.left =
newNode.dir === 'right'
newNode.dir === CONSTANTS.LAYOUT_GROW_DIR.RIGHT
? parent._node.left +
parent._node.width +
this.getMarginX(layerIndex)
@@ -72,7 +76,7 @@ class MindMap extends Base {
let leftChildrenAreaHeight = 0
let rightChildrenAreaHeight = 0
cur._node.children.forEach(item => {
if (item.dir === 'left') {
if (item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
leftLen++
leftChildrenAreaHeight += item.height
} else {
@@ -109,7 +113,7 @@ class MindMap extends Base {
let leftTotalTop = baseTop - node.leftChildrenAreaHeight / 2
let rightTotalTop = baseTop - node.rightChildrenAreaHeight / 2
node.children.forEach(cur => {
if (cur.dir === 'left') {
if (cur.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
cur.top = leftTotalTop
leftTotalTop += cur.height + marginY
} else {
@@ -162,7 +166,10 @@ class MindMap extends Base {
return
}
let _offset = 0
let addHeight = item.dir === 'left' ? leftAddHeight : rightAddHeight
let addHeight =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? leftAddHeight
: rightAddHeight
// 上面的节点往上移
if (_index < index) {
_offset = -addHeight
@@ -208,10 +215,8 @@ class MindMap extends Base {
let x1 = 0
let _s = 0
// 节点使用横线风格,需要额外渲染横线
let nodeUseLineStyleOffset = nodeUseLineStyle
? item.width
: 0
if (item.dir === 'left') {
let nodeUseLineStyleOffset = nodeUseLineStyle ? item.width : 0
if (item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
_s = -s1
x1 = node.layerIndex === 0 ? left : left - expandBtnSize
nodeUseLineStyleOffset = -nodeUseLineStyleOffset
@@ -220,7 +225,10 @@ class MindMap extends Base {
x1 = node.layerIndex === 0 ? left + width : left + width + expandBtnSize
}
let y1 = top + height / 2
let x2 = item.dir === 'left' ? item.left + item.width : item.left
let x2 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? item.left + item.width
: item.left
let y2 = item.top + item.height / 2
y1 = nodeUseLineStyle && !node.isRoot ? y1 + height / 2 : y1
y2 = nodeUseLineStyle ? y2 + item.height / 2 : y2
@@ -246,18 +254,21 @@ class MindMap extends Base {
let x1 =
node.layerIndex === 0
? left + width / 2
: item.dir === 'left'
: item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? left - expandBtnSize
: left + width + expandBtnSize
let y1 = top + height / 2
let x2 = item.dir === 'left' ? item.left + item.width : item.left
let x2 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? item.left + item.width
: item.left
let y2 = item.top + item.height / 2
y1 = nodeUseLineStyle && !node.isRoot ? y1 + height / 2 : y1
y2 = nodeUseLineStyle ? y2 + item.height / 2 : y2
// 节点使用横线风格,需要额外渲染横线
let nodeUseLineStylePath = ''
if (nodeUseLineStyle) {
if (item.dir === 'left') {
if (item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
nodeUseLineStylePath = ` L ${item.left},${y2}`
} else {
nodeUseLineStylePath = ` L ${item.left + item.width},${y2}`
@@ -283,11 +294,14 @@ class MindMap extends Base {
let x1 =
node.layerIndex === 0
? left + width / 2
: item.dir === 'left'
: item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? left - expandBtnSize
: left + width + expandBtnSize
let y1 = top + height / 2
let x2 = item.dir === 'left' ? item.left + item.width : item.left
let x2 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? item.left + item.width
: item.left
let y2 = item.top + item.height / 2
let path = ''
y1 = nodeUseLineStyle && !node.isRoot ? y1 + height / 2 : y1
@@ -295,13 +309,13 @@ class MindMap extends Base {
// 节点使用横线风格,需要额外渲染横线
let nodeUseLineStylePath = ''
if (this.mindMap.themeConfig.nodeUseLineStyle) {
if (item.dir === 'left') {
if (item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
nodeUseLineStylePath = ` L ${item.left},${y2}`
} else {
nodeUseLineStylePath = ` L ${item.left + item.width},${y2}`
}
}
if (node.isRoot) {
if (node.isRoot && !this.mindMap.themeConfig.rootLineKeepSameInCurve) {
path = this.quadraticCurvePath(x1, y1, x2, y2) + nodeUseLineStylePath
} else {
path = this.cubicBezierPath(x1, y1, x2, y2) + nodeUseLineStylePath
@@ -320,7 +334,8 @@ class MindMap extends Base {
? height / 2
: 0
// 位置没有变化则返回
let _x = (node.dir === 'left' ? 0 - expandBtnSize : width)
let _x =
node.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT ? 0 - expandBtnSize : width
let _y = height / 2 + nodeUseLineStyleOffset
if (_x === translateX && _y === translateY) {
return
@@ -332,7 +347,7 @@ class MindMap extends Base {
// 创建概要节点
renderGeneralization(node, gLine, gNode) {
let isLeft = node.dir === 'left'
let isLeft = node.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
let {
top,
bottom,
@@ -358,6 +373,15 @@ class MindMap extends Base {
(isLeft ? gNode.width : 0)
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
rect.size(expandBtnSize, height).x(-expandBtnSize).y(0)
} else {
rect.size(expandBtnSize, height).x(width).y(0)
}
}
}
export default MindMap

View File

@@ -255,6 +255,11 @@ class OrganizationStructure extends Base {
gNode.top = bottom + generalizationNodeMargin
gNode.left = left + (right - left - gNode.width) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
rect.size(width, expandBtnSize).x(0).y(height)
}
}
export default OrganizationStructure

View File

@@ -50,8 +50,8 @@ class Timeline extends Base {
// 节点生长方向
newNode.dir =
index % 2 === 0
? CONSTANTS.TIMELINE_DIR.BOTTOM
: CONSTANTS.TIMELINE_DIR.TOP
? CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
: CONSTANTS.LAYOUT_GROW_DIR.TOP
}
} else {
newNode.dir = ''
@@ -151,7 +151,7 @@ class Timeline extends Base {
if (
parent &&
parent.isRoot &&
node.dir === CONSTANTS.TIMELINE_DIR.TOP
node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP
) {
// 遍历二级节点的子节点
node.children.forEach(item => {
@@ -280,7 +280,7 @@ class Timeline extends Base {
if (
node.parent &&
node.parent.isRoot &&
node.dir === CONSTANTS.TIMELINE_DIR.TOP
node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP
) {
line.plot(`M ${x},${top} L ${x},${miny}`)
} else {
@@ -301,7 +301,7 @@ class Timeline extends Base {
if (
node.parent &&
node.parent.isRoot &&
node.dir === CONSTANTS.TIMELINE_DIR.TOP
node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP
) {
btn.translate(
width * 0.3 - expandBtnSize / 2 - translateX,
@@ -336,6 +336,28 @@ class Timeline extends Base {
gNode.left = right + generalizationNodeMargin
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
if (this.layout === CONSTANTS.LAYOUT.TIMELINE) {
rect.size(width, expandBtnSize).x(0).y(height)
} else {
let dir = ''
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.TOP) {
dir =
node.layerIndex === 1
? CONSTANTS.LAYOUT_GROW_DIR.TOP
: CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
} else {
dir = CONSTANTS.LAYOUT_GROW_DIR.BOTTOM
}
if (dir === CONSTANTS.LAYOUT_GROW_DIR.TOP) {
rect.size(width, expandBtnSize).x(0).y(-expandBtnSize)
} else {
rect.size(width, expandBtnSize).x(0).y(height)
}
}
}
}
export default Timeline

View File

@@ -0,0 +1,431 @@
import Base from './Base'
import { walk, asyncRun } from '../utils'
import { CONSTANTS } from '../constants/constant'
// 竖向时间轴
class VerticalTimeline extends Base {
// 构造函数
constructor(opt = {}, layout) {
super(opt)
this.layout = layout
}
// 布局
doLayout(callback) {
let task = [
() => {
this.computedBaseValue()
},
() => {
this.computedTopValue()
},
() => {
this.adjustLeftTopValue()
},
() => {
callback(this.root)
}
]
asyncRun(task)
}
// 遍历数据创建节点、计算根节点的位置计算根节点的子节点的top值
computedBaseValue() {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex, index) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)
} else {
// 非根节点
// 节点生长方向
// 三级及以下节点以上级为准
if (parent._node.dir) {
newNode.dir = parent._node.dir
} else {
newNode.dir =
index % 2 === 0
? CONSTANTS.LAYOUT_GROW_DIR.RIGHT
: CONSTANTS.LAYOUT_GROW_DIR.LEFT
}
// 定位二级节点的left
if (parent._node.isRoot) {
newNode.left =
parent._node.left +
(cur._node.width > parent._node.width
? -(cur._node.width - parent._node.width) / 2
: (parent._node.width - cur._node.width) / 2)
} else {
newNode.left =
newNode.dir === CONSTANTS.LAYOUT_GROW_DIR.RIGHT
? parent._node.left +
parent._node.width +
this.getMarginX(layerIndex)
: parent._node.left -
this.getMarginX(layerIndex) -
newNode.width
}
}
if (!cur.data.expand) {
return true
}
},
(cur, parent, isRoot, layerIndex) => {
// 返回时计算节点的areaHeight也就是子节点所占的高度之和包括外边距
if (isRoot) {
return
}
let len = cur.data.expand === false ? 0 : cur._node.children.length
cur._node.childrenAreaHeight = len
? cur._node.children.reduce((h, item) => {
return h + item.height
}, 0) +
(len + 1) * this.getMarginY(layerIndex + 1)
: 0
},
true,
0
)
}
// 遍历节点树计算节点的top
computedTopValue() {
walk(
this.root,
null,
(node, parent, isRoot, layerIndex, index) => {
if (
node.nodeData.data.expand &&
node.children &&
node.children.length
) {
let marginY = this.getMarginY(layerIndex + 1)
// 定位二级节点的top
if (isRoot) {
let top = node.top + node.height
let totalTop = top + marginY
node.children.forEach(cur => {
cur.top = totalTop
totalTop += cur.height + marginY
})
} else {
// 定位三级及以下节点的top
let marginY = this.getMarginY(layerIndex + 1)
let baseTop = node.top + node.height / 2 + marginY
// 第一个子节点的top值 = 该节点中心的top值 - 子节点的高度之和的一半
let totalTop = baseTop - node.childrenAreaHeight / 2
node.children.forEach(cur => {
cur.top = totalTop
totalTop += cur.height + marginY
})
}
}
},
null,
true
)
}
// 调整节点left、top
adjustLeftTopValue() {
walk(
this.root,
null,
(node, parent, isRoot, layerIndex) => {
if (!node.nodeData.data.expand) {
return
}
if (isRoot) return
// 判断子节点所占的高度之和是否大于该节点自身,大于则需要调整位置
let base = this.getMarginY(layerIndex + 1) * 2 + node.height
let difference = node.childrenAreaHeight - base
if (difference > 0) {
this.updateBrothers(node, difference / 2)
}
},
null,
true
)
}
// 更新兄弟节点的top
updateBrothers(node, addHeight) {
if (node.parent) {
let childrenList = node.parent.children
let index = childrenList.findIndex(item => {
return item === node
})
childrenList.forEach((item, _index) => {
// 自定义节点位置
if (item.hasCustomPosition()) return
// 三级或三级以下节点自身位置不需要动
if (!node.parent.isRoot && item === node) return
let _offset = 0
// 二级节点上面的兄弟节点不需要移动,自身需要往下移动
if (node.parent.isRoot) {
// 上面的节点不用移
if (_index < index) {
_offset = 0
} else if (_index > index) {
// 下面的节点往下移
_offset = addHeight * 2
} else {
// 自身也要移动
_offset = addHeight
}
} else {
// 三级或三级以下节点两侧的兄弟节点向两侧移动
// 上面的节点往上移
if (_index < index) {
_offset = -addHeight
} else if (_index > index) {
// 下面的节点往下移
_offset = addHeight
}
}
item.top += _offset
// 同步更新子节点的位置
if (item.children && item.children.length) {
this.updateChildren(item.children, 'top', _offset)
}
})
// 更新父节点的位置
this.updateBrothers(node.parent, addHeight)
}
}
// 调整兄弟节点的top
updateBrothersTop(node, addHeight) {
if (node.parent && !node.parent.isRoot) {
let childrenList = node.parent.children
let index = childrenList.findIndex(item => {
return item === node
})
childrenList.forEach((item, _index) => {
if (item.hasCustomPosition()) {
// 适配自定义位置
return
}
let _offset = 0
// 下面的节点往下移
if (_index > index) {
_offset = addHeight
}
item.top += _offset
// 同步更新子节点的位置
if (item.children && item.children.length) {
this.updateChildren(item.children, 'top', _offset)
}
})
// 更新父节点的位置
this.updateBrothersTop(node.parent, addHeight)
}
}
// 绘制连线,连接该节点到其子节点
renderLine(node, lines, style, lineStyle) {
if (lineStyle === 'curve') {
this.renderLineCurve(node, lines, style)
} else if (lineStyle === 'direct') {
this.renderLineDirect(node, lines, style)
} else {
this.renderLineStraight(node, lines, style)
}
}
// 直线连接
renderLineStraight(node, lines, style) {
if (node.children.length <= 0) {
return []
}
let { expandBtnSize } = node
if (!this.mindMap.opt.alwaysShowExpandBtn) {
expandBtnSize = 0
}
if (node.isRoot) {
// 当前节点是根节点
let prevBother = node
// 根节点的子节点是和根节点同一水平线排列
node.children.forEach((item, index) => {
let y1 = prevBother.top + prevBother.height
let y2 = item.top
let x = node.left + node.width / 2
let path = `M ${x},${y1} L ${x},${y2}`
lines[index].plot(path)
style && style(lines[index], item)
prevBother = item
})
} else {
// 当前节点为非根节点
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.RIGHT) {
let nodeRight = node.left + node.width
let nodeYCenter = node.top + node.height / 2
let marginX = this.getMarginX(node.layerIndex + 1)
let offset = (marginX - expandBtnSize) * 0.6
node.children.forEach((item, index) => {
let itemLeft = item.left
let itemYCenter = item.top + item.height / 2
let path = `
M ${nodeRight},${nodeYCenter}
L ${nodeRight + offset},${nodeYCenter}
L ${nodeRight + offset},${itemYCenter}
L ${itemLeft},${itemYCenter}`
lines[index].plot(path)
style && style(lines[index], item)
})
} else {
let nodeLeft = node.left
let nodeYCenter = node.top + node.height / 2
let marginX = this.getMarginX(node.layerIndex + 1)
let offset = (marginX - expandBtnSize) * 0.6
node.children.forEach((item, index) => {
let itemRight = item.left + item.width
let itemYCenter = item.top + item.height / 2
let path = `
M ${nodeLeft},${nodeYCenter}
L ${nodeLeft - offset},${nodeYCenter}
L ${nodeLeft - offset},${itemYCenter}
L ${itemRight},${itemYCenter}`
lines[index].plot(path)
style && style(lines[index], item)
})
}
}
}
// 直连
renderLineDirect(node, lines, style) {
if (node.children.length <= 0) {
return []
}
let { left, top, width, height, expandBtnSize } = node
if (!this.mindMap.opt.alwaysShowExpandBtn) {
expandBtnSize = 0
}
node.children.forEach((item, index) => {
if (node.isRoot) {
let prevBother = node
// 根节点的子节点是和根节点同一水平线排列
node.children.forEach((item, index) => {
let y1 = prevBother.top + prevBother.height
let y2 = item.top
let x = node.left + node.width / 2
let path = `M ${x},${y1} L ${x},${y2}`
lines[index].plot(path)
style && style(lines[index], item)
prevBother = item
})
} else {
let x1 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? left - expandBtnSize
: left + width + expandBtnSize
let y1 = top + height / 2
let x2 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? item.left + item.width
: item.left
let y2 = item.top + item.height / 2
let path = `M ${x1},${y1} L ${x2},${y2}`
lines[index].plot(path)
style && style(lines[index], item)
}
})
}
// 曲线风格连线
renderLineCurve(node, lines, style) {
if (node.children.length <= 0) {
return []
}
let { left, top, width, height, expandBtnSize } = node
if (!this.mindMap.opt.alwaysShowExpandBtn) {
expandBtnSize = 0
}
node.children.forEach((item, index) => {
if (node.isRoot) {
let prevBother = node
// 根节点的子节点是和根节点同一水平线排列
node.children.forEach((item, index) => {
let y1 = prevBother.top + prevBother.height
let y2 = item.top
let x = node.left + node.width / 2
let path = `M ${x},${y1} L ${x},${y2}`
lines[index].plot(path)
style && style(lines[index], item)
prevBother = item
})
} else {
let x1 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? left - expandBtnSize
: left + width + expandBtnSize
let y1 = top + height / 2
let x2 =
item.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
? item.left + item.width
: item.left
let y2 = item.top + item.height / 2
let path = this.cubicBezierPath(x1, y1, x2, y2)
lines[index].plot(path)
style && style(lines[index], item)
}
})
}
// 渲染按钮
renderExpandBtn(node, btn) {
let { width, height, expandBtnSize, isRoot } = node
if (!isRoot) {
let { translateX, translateY } = btn.transform()
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.RIGHT) {
btn.translate(width - translateX, height / 2 - translateY)
} else {
btn.translate(-expandBtnSize - translateX, height / 2 - translateY)
}
}
}
// 创建概要节点
renderGeneralization(node, gLine, gNode) {
let isLeft = node.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT
let {
top,
bottom,
left,
right,
generalizationLineMargin,
generalizationNodeMargin
} = this.getNodeBoundaries(node, 'h', isLeft)
let x = isLeft
? left - generalizationLineMargin
: right + generalizationLineMargin
let x1 = x
let y1 = top
let x2 = x
let y2 = bottom
let cx = x1 + (isLeft ? -20 : 20)
let cy = y1 + (y2 - y1) / 2
let path = `M ${x1},${y1} Q ${cx},${cy} ${x2},${y2}`
gLine.plot(path)
gNode.left =
x +
(isLeft ? -generalizationNodeMargin : generalizationNodeMargin) -
(isLeft ? gNode.width : 0)
gNode.top = top + (bottom - top - gNode.height) / 2
}
// 渲染展开收起按钮的隐藏占位元素
renderExpandBtnRect(rect, expandBtnSize, width, height, node) {
if (node.dir === CONSTANTS.LAYOUT_GROW_DIR.LEFT) {
rect.size(expandBtnSize, height).x(-expandBtnSize).y(0)
} else {
rect.size(expandBtnSize, height).x(width).y(0)
}
}
}
export default VerticalTimeline

View File

@@ -28,7 +28,7 @@ const handleList = node => {
}
// 将markdown转换成节点树
export const transformMarkdownTo = async md => {
export const transformMarkdownTo = md => {
const tree = fromMarkdown(md)
let root = {
children: []

View File

@@ -1,5 +1,11 @@
import JSZip from 'jszip'
import xmlConvert from 'xml-js'
import {
getTextFromHtml,
imgToDataUrl,
parseDataUrl,
getImageSize
} from '../utils/index'
// 解析.xmind文件
const parseXmindFile = file => {
@@ -10,7 +16,7 @@ const parseXmindFile = file => {
let content = ''
if (zip.files['content.json']) {
let json = await zip.files['content.json'].async('string')
content = transformXmind(json)
content = await transformXmind(json, zip.files)
} else if (zip.files['content.xml']) {
let xml = await zip.files['content.xml'].async('string')
let json = xmlConvert.xml2json(xml)
@@ -33,18 +39,20 @@ const parseXmindFile = file => {
}
// 转换xmind数据
const transformXmind = content => {
const transformXmind = async (content, files) => {
let data = JSON.parse(content)[0]
let nodeTree = data.rootTopic
let newTree = {}
let walk = (node, newNode) => {
let waitLoadImageList = []
let walk = async (node, newNode) => {
newNode.data = {
// 节点内容
text: node.title
}
// 节点备注
if (node.notes) {
newNode.data.note = (node.notes.realHTML || node.notes.plain).content
let notesData = node.notes.realHTML || node.notes.plain
newNode.data.note = notesData ? notesData.content || '' : ''
}
// 超链接
if (node.href && /^https?:\/\//.test(node.href)) {
@@ -54,6 +62,42 @@ const transformXmind = content => {
if (node.labels && node.labels.length > 0) {
newNode.data.tag = node.labels
}
// 图片
if (node.image && /\.(jpg|jpeg|png|gif|webp)$/.test(node.image.src)) {
// 处理异步逻辑
let resolve = null
let promise = new Promise(_resolve => {
resolve = _resolve
})
waitLoadImageList.push(promise)
try {
// 读取图片
let imageType = /\.([^.]+)$/.exec(node.image.src)[1]
let imageBase64 =
`data:image/${imageType};base64,` +
(await files['resources/' + node.image.src.split('/')[1]].async(
'base64'
))
newNode.data.image = imageBase64
// 如果图片尺寸不存在
if (!node.image.width && !node.image.height) {
let imageSize = await getImageSize(imageBase64)
newNode.data.imageSize = {
width: imageSize.width,
height: imageSize.height
}
} else {
newNode.data.imageSize = {
width: node.image.width,
height: node.image.height
}
}
resolve()
} catch (error) {
console.log(error)
resolve()
}
}
// 子节点
newNode.children = []
if (
@@ -69,6 +113,7 @@ const transformXmind = content => {
}
}
walk(nodeTree, newTree)
await Promise.all(waitLoadImageList)
return newTree
}
@@ -78,6 +123,7 @@ const transformOldXmind = content => {
let elements = data.elements
let root = null
let getRoot = arr => {
if (!arr) return
for (let i = 0; i < arr.length; i++) {
if (!root && arr[i].name === 'topic') {
root = arr[i]
@@ -97,9 +143,10 @@ const transformOldXmind = content => {
}
let walk = (node, newNode) => {
let nodeElements = node.elements
let nodeTitle = getItemByName(nodeElements, 'title')
newNode.data = {
// 节点内容
text: getItemByName(nodeElements, 'title').elements[0].text
text: nodeTitle && nodeTitle.elements && nodeTitle.elements[0].text
}
try {
// 节点备注
@@ -157,8 +204,127 @@ const transformOldXmind = content => {
return newTree
}
// 数据转换为xmind文件
const transformToXmind = async (data, name) => {
const id = 'simpleMindMap_' + Date.now()
const imageList = []
// 转换核心数据
let newTree = {}
let waitLoadImageList = []
let walk = async (node, newNode, isRoot) => {
let newData = {
structureClass: 'org.xmind.ui.logic.right',
title: getTextFromHtml(node.data.text), // 节点文本
children: {
attached: []
}
}
// 备注
if (node.data.note !== undefined) {
newData.notes = {
realHTML: {
content: node.data.note
},
plain: {
content: node.data.note
}
}
}
// 超链接
if (node.data.hyperlink !== undefined) {
newData.href = node.data.hyperlink
}
// 标签
if (node.data.tag !== undefined) {
newData.labels = node.data.tag || []
}
// 图片
if (node.data.image) {
try {
// 处理异步逻辑
let resolve = null
let promise = new Promise(_resolve => {
resolve = _resolve
})
waitLoadImageList.push(promise)
let imgName = ''
let imgData = node.data.image
// 网络图片要先转换成data:url
if (/^https?:\/\//.test(node.data.image)) {
imgData = await imgToDataUrl(node.data.image)
}
// 从data:url中解析出图片类型和base64
let dataUrlRes = parseDataUrl(imgData)
imgName = 'image_' + imageList.length + '.' + dataUrlRes.type
imageList.push({
name: imgName,
data: dataUrlRes.base64
})
newData.image = {
src: 'xap:resources/' + imgName,
width: node.data.imageSize.width,
height: node.data.imageSize.height
}
resolve()
} catch (error) {
console.log(error)
resolve()
}
}
// 样式
// 暂时不考虑样式
if (isRoot) {
newData.class = 'topic'
newNode.id = id
newNode.class = 'sheet'
newNode.title = name
newNode.extensions = []
newNode.topicPositioning = 'fixed'
newNode.topicOverlapping = 'overlap'
newNode.coreVersion = '2.100.0'
newNode.rootTopic = newData
} else {
Object.keys(newData).forEach(key => {
newNode[key] = newData[key]
})
}
if (node.children && node.children.length > 0) {
node.children.forEach(child => {
let newChild = {}
walk(child, newChild)
newData.children.attached.push(newChild)
})
}
}
walk(data, newTree, true)
await Promise.all(waitLoadImageList)
const contentData = [newTree]
// 创建压缩包
const zip = new JSZip()
zip.file('content.json', JSON.stringify(contentData))
zip.file(
'metadata.json',
`{"modifier":"","dataStructureVersion":"1","layoutEngineVersion":"2","activeSheetId":"${id}"}`
)
const manifestData = {
'file-entries': { 'content.json': {}, 'metadata.json': {} }
}
// 图片
if (imageList.length > 0) {
imageList.forEach(item => {
manifestData['file-entries']['resources/' + item.name] = {}
const img = zip.folder('resources')
img.file(item.name, item.data, { base64: true })
})
}
zip.file('manifest.json', JSON.stringify(manifestData))
const zipData = await zip.generateAsync({ type: 'blob' })
return zipData
}
export default {
parseXmindFile,
transformXmind,
transformOldXmind
transformOldXmind,
transformToXmind
}

View File

@@ -11,7 +11,7 @@ import {
import associativeLineControlsMethods from './associativeLine/associativeLineControls'
import associativeLineTextMethods from './associativeLine/associativeLineText'
// 关联线
// 关联线插件
class AssociativeLine {
constructor(opt = {}) {
this.mindMap = opt.mindMap

View File

@@ -1,8 +1,7 @@
import { bfsWalk, throttle } from '../utils'
import Base from '../layouts/Base'
// 节点拖动
// 节点拖动插件
class Drag extends Base {
// 构造函数
constructor({ mindMap }) {
@@ -45,6 +44,7 @@ class Drag extends Base {
this.mouseMoveY = 0
// 鼠标移动的距离距鼠标按下的位置距离多少以上才认为是拖动事件
this.checkDragOffset = 10
this.minOffset = 10
}
// 绑定事件
@@ -106,6 +106,9 @@ class Drag extends Base {
this.node.isDrag = false
this.node.show()
this.removeCloneNode()
let overlapNodeUid = this.overlapNode ? this.overlapNode.nodeData.data.uid : ''
let prevNodeUid = this.prevNode ? this.prevNode.nodeData.data.uid : ''
let nextNodeUid = this.nextNode ? this.nextNode.nodeData.data.uid : ''
// 存在重叠子节点,则移动作为其子节点
if (this.overlapNode) {
this.mindMap.renderer.setNodeActive(this.overlapNode, false)
@@ -135,7 +138,11 @@ class Drag extends Base {
this.mindMap.render()
}
this.reset()
this.mindMap.emit('node_dragend')
this.mindMap.emit('node_dragend', {
overlapNodeUid,
prevNodeUid,
nextNodeUid
})
}
// 创建克隆节点
@@ -197,9 +204,10 @@ class Drag extends Base {
// 检测重叠节点
checkOverlapNode() {
if (!this.drawTransform) {
if (!this.drawTransform || !this.placeholder) {
return
}
const { nodeDragPlaceholderMaxSize } = this.mindMap.opt
let x = this.mouseMoveX
let y = this.mouseMoveY
this.overlapNode = null
@@ -241,19 +249,19 @@ class Drag extends Base {
let prevNodeRect = this.getNodeRect(prevBrother)
prevBrotherOffset = nodeRect.top - prevNodeRect.bottom
// 间距小于10就当它不存在
prevBrotherOffset = prevBrotherOffset >= 10 ? prevBrotherOffset / 2 : 0
prevBrotherOffset = prevBrotherOffset >= this.minOffset ? prevBrotherOffset / 2 : 0
} else {
// 没有前一个兄弟节点那么假设和前一个节点的距离为20
prevBrotherOffset = 10
prevBrotherOffset = this.minOffset
}
// 和后一个兄弟节点的距离
let nextBrotherOffset = 0
if (nextBrother) {
let nextNodeRect = this.getNodeRect(nextBrother)
nextBrotherOffset = nextNodeRect.top - nodeRect.bottom
nextBrotherOffset = nextBrotherOffset >= 10 ? nextBrotherOffset / 2 : 0
nextBrotherOffset = nextBrotherOffset >= this.minOffset ? nextBrotherOffset / 2 : 0
} else {
nextBrotherOffset = 10
nextBrotherOffset = this.minOffset
}
if (nodeRect.left <= x && nodeRect.right >= x) {
// 检测兄弟节点位置
@@ -266,11 +274,11 @@ class Drag extends Base {
y >= nodeRect.top && y <= nodeRect.top + oneFourthHeight
if (checkIsPrevNode) {
this.prevNode = node
let size = nextBrotherOffset > 0 ? nextBrotherOffset : 5
let size = nextBrotherOffset > 0 ? Math.min(nextBrotherOffset, nodeDragPlaceholderMaxSize) : 5
this.placeholder.size(node.width, size).move(nodeRect.originLeft, nodeRect.originBottom)
} else if (checkIsNextNode) {
this.nextNode = node
let size = prevBrotherOffset > 0 ? prevBrotherOffset : 5
let size = prevBrotherOffset > 0 ? Math.min(prevBrotherOffset, nodeDragPlaceholderMaxSize) : 5
this.placeholder.size(node.width, size).move(nodeRect.originLeft, nodeRect.originTop - size)
}
}

View File

@@ -1,14 +1,18 @@
import { imgToDataUrl, downloadFile, readBlob } from '../utils'
import {
imgToDataUrl,
downloadFile,
readBlob,
removeHTMLEntities
} from '../utils'
import { SVG } from '@svgdotjs/svg.js'
import drawBackgroundImageToCanvas from '../utils/simulateCSSBackgroundInCanvas'
import { transformToMarkdown } from '../parse/toMarkdown'
// 导出
// 导出插件
class Export {
// 构造函数
constructor(opt) {
this.mindMap = opt.mindMap
this.exportPadding = this.mindMap.opt.exportPadding
}
// 导出
@@ -49,7 +53,7 @@ class Export {
}
// svg转png
svgToPng(svgSrc, transparent) {
svgToPng(svgSrc, transparent, rotateWhenWidthLongerThenHeight = false) {
return new Promise((resolve, reject) => {
const img = new Image()
// 跨域图片需要添加这个属性,否则画布被污染了无法导出图片
@@ -57,12 +61,24 @@ class Export {
img.onload = async () => {
try {
let canvas = document.createElement('canvas')
canvas.width = img.width + this.exportPadding * 2
canvas.height = img.height + this.exportPadding * 2
// 如果宽比高长那么旋转90度
let needRotate =
rotateWhenWidthLongerThenHeight && img.width / img.height > 1
if (needRotate) {
canvas.width = img.height
canvas.height = img.width
} else {
canvas.width = img.width
canvas.height = img.height
}
let ctx = canvas.getContext('2d')
if (needRotate) {
ctx.rotate(0.5 * Math.PI)
ctx.translate(0, -img.height)
}
// 绘制背景
if (!transparent) {
await this.drawBackgroundToCanvas(ctx, canvas.width, canvas.height)
await this.drawBackgroundToCanvas(ctx, img.width, img.height)
}
// 图片绘制到canvas里
ctx.drawImage(
@@ -71,8 +87,8 @@ class Export {
0,
img.width,
img.height,
this.exportPadding,
this.exportPadding,
0,
0,
img.width,
img.height
)
@@ -96,7 +112,7 @@ class Export {
backgroundImage,
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center center',
backgroundSize = 'cover',
backgroundSize = 'cover'
} = this.mindMap.themeConfig
// 背景颜色
ctx.save()
@@ -107,18 +123,25 @@ class Export {
// 背景图片
if (backgroundImage && backgroundImage !== 'none') {
ctx.save()
drawBackgroundImageToCanvas(ctx, width, height, backgroundImage, {
backgroundRepeat,
backgroundPosition,
backgroundSize
}, (err) => {
if (err) {
reject(err)
} else {
resolve()
drawBackgroundImageToCanvas(
ctx,
width,
height,
backgroundImage,
{
backgroundRepeat,
backgroundPosition,
backgroundSize
},
err => {
if (err) {
reject(err)
} else {
resolve()
}
ctx.restore()
}
ctx.restore()
})
)
} else {
resolve()
}
@@ -152,12 +175,17 @@ class Export {
* 方法1.把svg的图片都转化成data:url格式再转换
* 方法2.把svg的图片提取出来再挨个绘制到canvas里最后一起转换
*/
async png(name, transparent = false) {
async png(name, transparent = false, rotateWhenWidthLongerThenHeight) {
let { node, str } = await this.getSvgData()
str = removeHTMLEntities(str)
// 如果开启了富文本则使用htmltocanvas转换为图片
if (this.mindMap.richText) {
let res = await this.mindMap.richText.handleExportPng(node.node)
let imgDataUrl = await this.svgToPng(res, transparent)
let res = await this.mindMap.richText.handleExportPng(node.node)
let imgDataUrl = await this.svgToPng(
res,
transparent,
rotateWhenWidthLongerThenHeight
)
return imgDataUrl
}
// 转换成blob数据
@@ -167,17 +195,32 @@ class Export {
// 转换成data:url数据
let svgUrl = await readBlob(blob)
// 绘制到canvas上
let res = await this.svgToPng(svgUrl, transparent)
let res = await this.svgToPng(
svgUrl,
transparent,
rotateWhenWidthLongerThenHeight
)
return res
}
// 导出为pdf
async pdf(name) {
async pdf(name, useMultiPageExport) {
if (!this.mindMap.doExportPDF) {
throw new Error('请注册ExportPDF插件')
}
let img = await this.png()
this.mindMap.doExportPDF.pdf(name, img)
let img = await this.png('', false, true)
this.mindMap.doExportPDF.pdf(name, img, useMultiPageExport)
}
// 导出为xmind
async xmind(name) {
if (!this.mindMap.doExportXMind) {
throw new Error('请注册ExportXMind插件')
}
const data = this.mindMap.getData()
const blob = await this.mindMap.doExportXMind.xmind(data, name)
const res = await readBlob(blob)
return res
}
// 导出为svg
@@ -196,6 +239,7 @@ class Export {
node.first().before(SVG(`<title>${name}</title>`))
await this.drawBackgroundToSvg(node)
let str = node.svg()
str = removeHTMLEntities(str)
// 转换成blob数据
let blob = new Blob([str], {
type: 'image/svg+xml'

View File

@@ -1,6 +1,6 @@
import JsPDF from 'jspdf'
// 导出PDF需要通过Export插件使用
// 导出PDF插件需要通过Export插件使用
class ExportPDF {
// 构造函数
constructor(opt) {
@@ -8,7 +8,16 @@ class ExportPDF {
}
// 导出为pdf
pdf(name, img) {
pdf(name, img, useMultiPageExport = false) {
if (useMultiPageExport) {
this.multiPageExport(name, img)
} else {
this.onePageExport(name, img)
}
}
// 单页导出
onePageExport(name, img) {
let pdf = new JsPDF('', 'pt', 'a4')
let a4Width = 595
let a4Height = 841
@@ -37,6 +46,52 @@ class ExportPDF {
}
image.src = img
}
// 多页导出
multiPageExport(name, img) {
let image = new Image()
const a4Width = 592.28
const a4Height = 841.89
image.onload = () => {
let imageWidth = image.width
let imageHeight = image.height
// 一页pdf显示高度
let pageHeight = (imageWidth / a4Width) * a4Height
// 未生成pdf的高度
let leftHeight = imageHeight
// 偏移
let position = 0
// a4纸的尺寸[595.28,841.89]图片在pdf中图片的宽高
let imgWidth = a4Width
let imgHeight = (a4Width / imageWidth) * imageHeight
let pdf = new JsPDF('', 'pt', 'a4')
// 有两个高度需要区分一个是图片的实际高度和生成pdf的页面高度(841.89)
// 当内容未超过pdf一页显示的范围无需分页
if (leftHeight < pageHeight) {
pdf.addImage(
img,
'PNG',
(a4Width - imgWidth) / 2,
(a4Height - imgHeight) / 2,
imgWidth,
imgHeight
)
} else {
// 分页
while (leftHeight > 0) {
pdf.addImage(img, 'PNG', 0, position, imgWidth, imgHeight)
leftHeight -= pageHeight
position -= a4Height
// 避免添加空白页
if (leftHeight > 0) {
pdf.addPage()
}
}
}
pdf.save(name)
}
image.src = img
}
}
ExportPDF.instanceName = 'doExportPDF'

View File

@@ -0,0 +1,24 @@
import xmind from '../parse/xmind'
// 导出XMind插件需要通过Export插件使用
class ExportXMind {
// 构造函数
constructor(opt) {
this.mindMap = opt.mindMap
}
// 导出xmind
async xmind(data, name) {
const zipData = await xmind.transformToXmind(data, name)
return zipData
}
// 获取解析器
getXmind() {
return xmind
}
}
ExportXMind.instanceName = 'doExportXMind'
export default ExportXMind

View File

@@ -1,7 +1,7 @@
import { bfsWalk } from '../utils'
import { CONSTANTS } from '../constants/constant'
// 键盘导航
// 键盘导航插件
class KeyboardNavigation {
// 构造函数
constructor(opt) {
@@ -28,8 +28,7 @@ class KeyboardNavigation {
this.focus(dir)
} else {
let root = this.mindMap.renderer.root
this.mindMap.renderer.moveNodeToCenter(root)
root.active()
this.mindMap.execCommand('GO_TARGET_NODE', root)
}
}
@@ -81,8 +80,7 @@ class KeyboardNavigation {
// 找到了则让目标节点聚焦
if (targetNode) {
this.mindMap.renderer.moveNodeToCenter(targetNode)
targetNode.active()
this.mindMap.execCommand('GO_TARGET_NODE', targetNode)
}
}

View File

@@ -1,4 +1,6 @@
// 小地图类
import { isWhite, isTransparent, getVisibleColorFromTheme } from '../utils/index'
// 小地图插件
class MiniMap {
// 构造函数
constructor(opt) {
@@ -20,9 +22,14 @@ class MiniMap {
* boxHeight小地图容器的高度
*/
calculationMiniMap(boxWidth, boxHeight) {
let { svgHTML, rect, origWidth, origHeight, scaleX, scaleY } =
let { svg, rect, origWidth, origHeight, scaleX, scaleY } =
this.mindMap.getSvgData()
// 计算数据
const elRect = this.mindMap.elRect
rect.x -= elRect.left
rect.x2 -= elRect.left
rect.y -= elRect.top
rect.y2 -= elRect.top
let boxRatio = boxWidth / boxHeight
let actWidth = 0
let actHeight = 0
@@ -53,20 +60,31 @@ class MiniMap {
bottom: 0
}
viewBoxStyle.left =
Math.max(0, (-_rectX / _rectWidth) * actWidth) + miniMapBoxLeft + 'px'
Math.max(0, (-_rectX / _rectWidth) * actWidth) + miniMapBoxLeft
viewBoxStyle.right =
Math.max(0, ((_rectX2 - origWidth) / _rectWidth) * actWidth) +
miniMapBoxLeft +
'px'
miniMapBoxLeft
viewBoxStyle.top =
Math.max(0, (-_rectY / _rectHeight) * actHeight) + miniMapBoxTop + 'px'
Math.max(0, (-_rectY / _rectHeight) * actHeight) + miniMapBoxTop
viewBoxStyle.bottom =
Math.max(0, ((_rectY2 - origHeight) / _rectHeight) * actHeight) +
miniMapBoxTop +
'px'
miniMapBoxTop
if (viewBoxStyle.top > miniMapBoxTop + actHeight) {
viewBoxStyle.top = miniMapBoxTop + actHeight
}
if (viewBoxStyle.left > miniMapBoxLeft + actWidth) {
viewBoxStyle.left = miniMapBoxLeft + actWidth
}
Object.keys(viewBoxStyle).forEach((key) => {
viewBoxStyle[key] = viewBoxStyle[key] + 'px'
})
this.removeNodeContent(svg)
return {
svgHTML, // 小地图html
svgHTML: svg.svg(), // 小地图html
viewBoxStyle, // 视图框的位置信息
miniMapBoxScale, // 视图框的缩放值
miniMapBoxLeft, // 视图框的left值
@@ -74,6 +92,26 @@ class MiniMap {
}
}
// 移除节点的内容
removeNodeContent(svg) {
if (svg.hasClass('smm-node')) {
let shape = svg.findOne('.smm-node-shape')
let fill = shape.attr('fill')
if (isWhite(fill) || isTransparent(fill)) {
shape.attr('fill', getVisibleColorFromTheme(this.mindMap.themeConfig))
}
svg.clear()
svg.add(shape)
return
}
let children = svg.children()
if (children && children.length > 0) {
children.forEach((node) => {
this.removeNodeContent(node)
})
}
}
// 小地图鼠标按下事件
onMousedown(e) {
this.isMousedown = true

View File

@@ -0,0 +1,270 @@
// 节点图片大小调整插件
import { resizeImgSizeByOriginRatio } from '../utils/index'
import btnsSvg from '../svg/btns'
class NodeImgAdjust {
// 构造函数
constructor({ mindMap }) {
this.mindMap = mindMap
this.resizeBtnSize = 26 // 调整按钮的大小
this.handleEl = null // 自定义元素,用来渲染临时图片、调整按钮
this.isShowHandleEl = false // 自定义元素是否在显示中
this.node = null // 当前节点实例
this.img = null // 当前节点的图片节点
this.rect = null // 当前图片节点的尺寸信息
this.isMousedown = false // 当前是否是按住调整按钮状态
this.currentImgWidth = 0 // 当前拖拽实时图片的大小
this.currentImgHeight = 0
this.isAdjusted = false // 是否是拖拽结束后的渲染期间
this.bindEvent()
}
// 监听事件
bindEvent() {
this.onNodeImgMouseleave = this.onNodeImgMouseleave.bind(this)
this.onNodeImgMousemove = this.onNodeImgMousemove.bind(this)
this.onMousemove = this.onMousemove.bind(this)
this.onMouseup = this.onMouseup.bind(this)
this.onRenderEnd = this.onRenderEnd.bind(this)
this.mindMap.on('node_img_mouseleave', this.onNodeImgMouseleave)
this.mindMap.on('node_img_mousemove', this.onNodeImgMousemove)
this.mindMap.on('mousemove', this.onMousemove)
this.mindMap.on('mouseup', this.onMouseup)
this.mindMap.on('node_mouseup', this.onMouseup)
this.mindMap.on('node_tree_render_end', this.onRenderEnd)
}
// 解绑事件
unBindEvent() {
this.mindMap.off('node_img_mouseleave', this.onNodeImgMouseleave)
this.mindMap.off('node_img_mousemove', this.onNodeImgMousemove)
this.mindMap.off('mousemove', this.onMousemove)
this.mindMap.off('mouseup', this.onMouseup)
this.mindMap.off('node_mouseup', this.onMouseup)
this.mindMap.off('node_tree_render_end', this.onRenderEnd)
}
// 节点图片鼠标移动事件
onNodeImgMousemove(node, img) {
// 如果当前正在拖动调整中那么直接返回
if (this.isMousedown || this.isAdjusted || this.mindMap.opt.readonly) return
// 如果在当前节点内移动,以及自定义元素已经是显示状态,那么直接返回
if (this.node === node && this.isShowHandleEl) return
// 更新当前节点信息
this.node = node
this.img = img
this.rect = this.img.rbox()
// 显示自定义元素
this.showHandleEl()
}
// 节点图片鼠标移出事件
onNodeImgMouseleave() {
if (this.isMousedown) return
this.hideHandleEl()
}
// 隐藏节点实际的图片
hideNodeImage() {
if (!this.img) return
this.img.hide()
}
// 显示节点实际的图片
showNodeImage() {
if (!this.img) return
this.img.show()
}
// 显示自定义元素
showHandleEl() {
if (!this.handleEl) {
this.createResizeBtnEl()
}
this.setHandleElRect()
this.handleEl.style.display = 'block'
this.isShowHandleEl = true
}
// 隐藏自定义元素
hideHandleEl() {
if (!this.isShowHandleEl) return
this.isShowHandleEl = false
this.handleEl.style.display = 'none'
this.handleEl.style.backgroundImage = ``
this.handleEl.style.width = 0
this.handleEl.style.height = 0
this.handleEl.style.left = 0
this.handleEl.style.top = 0
}
// 设置自定义元素尺寸位置信息
setHandleElRect() {
let { width, height, x, y } = this.rect
this.handleEl.style.left = `${x}px`
this.handleEl.style.top = `${y}px`
this.currentImgWidth = width
this.currentImgHeight = height
this.updateHandleElSize()
}
// 更新自定义元素宽高
updateHandleElSize() {
this.handleEl.style.width = `${this.currentImgWidth}px`
this.handleEl.style.height = `${this.currentImgHeight}px`
}
// 创建调整按钮元素
createResizeBtnEl() {
// 容器元素
this.handleEl = document.createElement('div')
this.handleEl.style.cssText = `
pointer-events: none;
position: fixed;
display:none;
background-size: cover;
`
this.handleEl.className = 'node-img-handle'
// 调整按钮元素
const btnEl = document.createElement('div')
btnEl.innerHTML = btnsSvg.imgAdjust
btnEl.style.cssText = `
position: absolute;
right: 0;
bottom: 0;
pointer-events: auto;
background-color: rgba(0, 0, 0, 0.3);
width: ${this.resizeBtnSize}px;
height: ${this.resizeBtnSize}px;
display: flex;
justify-content: center;
align-items: center;
cursor: nwse-resize;
`
btnEl.className = 'node-image-resize'
// 给按钮元素绑定事件
btnEl.addEventListener('mouseenter', () => {
// 移入按钮,会触发节点图片的移出事件,所以需要再次显示按钮
this.showHandleEl()
})
btnEl.addEventListener('mouseleave', () => {
// 移除按钮,需要隐藏按钮
if (this.isMousedown) return
this.hideHandleEl()
})
btnEl.addEventListener('mousedown', e => {
e.stopPropagation()
this.onMousedown(e)
})
btnEl.addEventListener('mouseup', e => {
setTimeout(() => {
//点击后直接松开异常处理; 其他事件响应之后处理
this.hideHandleEl()
this.isAdjusted = false
}, 0)
})
btnEl.addEventListener('click', e => {
e.stopPropagation()
})
this.handleEl.appendChild(btnEl)
// 删除按钮
const btnRemove = document.createElement('div')
this.handleEl.prepend(btnRemove)
btnRemove.className = 'node-image-remove'
btnRemove.innerHTML = btnsSvg.remove
btnRemove.style.cssText = `
position: absolute;
right: 0;top:0;color:#fff;
pointer-events: auto;
background-color: rgba(0, 0, 0, 0.3);
width: ${this.resizeBtnSize}px;
height: ${this.resizeBtnSize}px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
`
btnRemove.addEventListener('mouseenter', e => {
this.showHandleEl()
})
btnRemove.addEventListener('mouseleave', e => {
if (this.isMousedown) return
this.hideHandleEl()
})
btnRemove.addEventListener('click', e => {
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, { url: null })
})
// 添加元素到页面
const targetNode = this.mindMap.opt.customInnerElsAppendTo || document.body
targetNode.appendChild(this.handleEl)
}
// 鼠标按钮按下事件
onMousedown() {
this.isMousedown = true
// 隐藏节点实际图片
this.hideNodeImage()
// 将节点图片渲染到自定义元素上
this.handleEl.style.backgroundImage = `url(${this.node.nodeData.data.image})`
}
// 鼠标移动
onMousemove(e) {
if (!this.isMousedown) return
e.preventDefault()
// 计算当前拖拽位置对应的图片的实时大小
let { width: imageOriginWidth, height: imageOriginHeight } =
this.node.nodeData.data.imageSize
let newWidth = e.clientX - this.rect.x
let newHeight = e.clientY - this.rect.y
if (newWidth <= 0 || newHeight <= 0) return
let [actWidth, actHeight] = resizeImgSizeByOriginRatio(
imageOriginWidth,
imageOriginHeight,
newWidth,
newHeight
)
this.currentImgWidth = actWidth
this.currentImgHeight = actHeight
this.updateHandleElSize()
}
// 鼠标松开
onMouseup() {
if (!this.isMousedown) return
// 显示节点实际图片
this.showNodeImage()
// 隐藏自定义元素
this.hideHandleEl()
// 更新节点图片为新的大小
let { image, imageTitle } = this.node.nodeData.data
let { scaleX, scaleY } = this.mindMap.draw.transform()
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, {
url: image,
title: imageTitle,
width: this.currentImgWidth / scaleX,
height: this.currentImgHeight / scaleY,
custom: true // 代表自定义了图片大小
})
this.isAdjusted = true
this.isMousedown = false
}
// 渲染完成事件
onRenderEnd() {
if (!this.isAdjusted) {
this.hideHandleEl()
return
}
this.isAdjusted = false
}
// 插件被移除前做的事情
beforePluginRemove() {
this.unBindEvent()
}
}
NodeImgAdjust.instanceName = 'nodeImgAdjust'
export default NodeImgAdjust

View File

@@ -0,0 +1,76 @@
import { nodeDataNoStylePropList } from '../constants/constant'
// 格式刷插件
class Painter {
constructor({ mindMap }) {
this.mindMap = mindMap
this.isInPainter = false
this.painterNode = null
this.bindEvent()
}
bindEvent() {
this.painterOneNode = this.painterOneNode.bind(this)
this.onEndPainter = this.onEndPainter.bind(this)
this.mindMap.on('node_click', this.painterOneNode)
this.mindMap.on('draw_click', this.onEndPainter)
}
unBindEvent() {
this.mindMap.off('node_click', this.painterOneNode)
this.mindMap.off('draw_click', this.onEndPainter)
}
// 开始格式刷
startPainter() {
if (this.mindMap.opt.readonly) return
let activeNodeList = this.mindMap.renderer.activeNodeList
if (activeNodeList.length <= 0) return
this.painterNode = activeNodeList[0]
this.isInPainter = true
this.mindMap.emit('painter_start')
}
// 结束格式刷
endPainter() {
this.painterNode = null
this.isInPainter = false
}
onEndPainter() {
this.endPainter()
this.mindMap.emit('painter_end')
}
// 格式刷某个节点
painterOneNode(node) {
if (
!node ||
!this.isInPainter ||
!this.painterNode ||
!node ||
node === this.painterNode
)
return
const style = {}
const painterNodeData = this.painterNode.nodeData.data
Object.keys(painterNodeData).forEach(key => {
if (!nodeDataNoStylePropList.includes(key)) {
style[key] = painterNodeData[key]
}
})
node.setStyles(style)
if (painterNodeData.activeStyle) {
node.setStyles(painterNodeData.activeStyle, true)
}
}
// 插件被移除前做的事情
beforePluginRemove() {
this.unBindEvent()
}
}
Painter.instanceName = 'painter'
export default Painter

View File

@@ -1,7 +1,12 @@
import Quill from 'quill'
import 'quill/dist/quill.snow.css'
import html2canvas from 'html2canvas'
import { walk, getTextFromHtml } from '../utils'
import domtoimage from 'dom-to-image-more'
import {
walk,
getTextFromHtml,
isWhite,
getVisibleColorFromTheme
} from '../utils'
import { CONSTANTS } from '../constants/constant'
let extended = false
@@ -28,7 +33,7 @@ let fontSizeList = new Array(100).fill(0).map((_, index) => {
return index + 'px'
})
// 节点支持富文本编辑功能
// 富文本编辑插件
class RichText {
constructor({ mindMap, pluginOpt }) {
this.mindMap = mindMap
@@ -39,6 +44,7 @@ class RichText {
this.range = null
this.lastRange = null
this.node = null
this.isInserting = false
this.styleEl = null
this.cacheEditingText = ''
this.lostStyle = false
@@ -145,11 +151,18 @@ class RichText {
}
// 显示文本编辑控件
showEditText(node, rect) {
showEditText(node, rect, isInserting) {
if (this.showTextEdit) {
return
}
const {
richTextEditFakeInPlace,
customInnerElsAppendTo,
nodeTextEditZIndex,
textAutoWrapWidth
} = this.mindMap.opt
this.node = node
this.isInserting = isInserting
if (!rect) rect = node._textData.node.node.getBoundingClientRect()
this.mindMap.emit('before_show_text_edit')
this.mindMap.renderer.textEdit.registerTmpShortcut()
@@ -161,33 +174,65 @@ class RichText {
let scaleX = rect.width / originWidth
let scaleY = rect.height / originHeight
// 内边距
const paddingX = 6
const paddingY = 4
let paddingX = 6
let paddingY = 4
if (richTextEditFakeInPlace) {
let paddingValue = node.getPaddingVale()
paddingX = paddingValue.paddingX
paddingY = paddingValue.paddingY
}
if (!this.textEditNode) {
this.textEditNode = document.createElement('div')
this.textEditNode.classList.add('smm-richtext-node-edit-wrap')
this.textEditNode.style.cssText = `position:fixed;box-sizing: border-box;box-shadow: 0 0 20px rgba(0,0,0,.5);outline: none; word-break: break-all;padding: ${paddingY}px ${paddingX}px;`
this.textEditNode.style.cssText = `
position:fixed;
box-sizing: border-box;
box-shadow: 0 0 20px rgba(0,0,0,.5);
outline: none;
word-break:
break-all;padding: ${paddingY}px ${paddingX}px;
`
this.textEditNode.addEventListener('click', e => {
e.stopPropagation()
})
document.body.appendChild(this.textEditNode)
this.textEditNode.addEventListener('mousedown', e => {
e.stopPropagation()
})
this.textEditNode.addEventListener('keydown', e => {
if (this.mindMap.renderer.textEdit.checkIsAutoEnterTextEditKey(e)) {
e.stopPropagation()
}
})
const targetNode = customInnerElsAppendTo || document.body
targetNode.appendChild(this.textEditNode)
}
// 使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见
let bgColor = node.style.merge('fillColor')
let color = node.style.merge('color')
this.textEditNode.style.marginLeft = `-${paddingX * scaleX}px`
this.textEditNode.style.marginTop = `-${paddingY * scaleY}px`
this.textEditNode.style.zIndex = this.mindMap.opt.nodeTextEditZIndex
this.textEditNode.style.zIndex = nodeTextEditZIndex
this.textEditNode.style.backgroundColor =
bgColor === 'transparent' ? '#fff' : bgColor
bgColor === 'transparent'
? isWhite(color)
? getVisibleColorFromTheme(this.mindMap.themeConfig)
: '#fff'
: bgColor
this.textEditNode.style.minWidth = originWidth + paddingX * 2 + 'px'
this.textEditNode.style.minHeight = originHeight + 'px'
this.textEditNode.style.left = rect.left + 'px'
this.textEditNode.style.top = rect.top + 'px'
this.textEditNode.style.display = 'block'
this.textEditNode.style.maxWidth =
this.mindMap.opt.textAutoWrapWidth + paddingX * 2 + 'px'
this.textEditNode.style.maxWidth = textAutoWrapWidth + paddingX * 2 + 'px'
this.textEditNode.style.transform = `scale(${scaleX}, ${scaleY})`
this.textEditNode.style.transformOrigin = 'left top'
if (richTextEditFakeInPlace) {
this.textEditNode.style.borderRadius =
(node.style.merge('borderRadius') || 5) + 'px'
if (node.style.merge('shape') == 'roundedRectangle') {
this.textEditNode.style.borderRadius = (node.height || 50) + 'px'
}
}
if (!node.nodeData.data.richText) {
// 还不是富文本的情况
let text = node.nodeData.data.text.split(/\n/gim).join('<br>')
@@ -200,7 +245,8 @@ class RichText {
this.initQuillEditor()
document.querySelector('.ql-editor').style.minHeight = originHeight + 'px'
this.showTextEdit = true
this.focus()
// 如果是刚创建的节点,那么默认全选,否则普通激活不全选
this.focus(isInserting ? 0 : null)
if (!node.nodeData.data.richText) {
// 如果是非富文本的情况,需要手动应用文本样式
this.setTextStyleIfNotRichText(node)
@@ -250,6 +296,7 @@ class RichText {
this.showTextEdit = false
this.mindMap.emit('rich_text_selection_change', false)
this.node = null
this.isInserting = false
}
// 初始化Quill富文本编辑器
@@ -264,6 +311,12 @@ class RichText {
handler: function () {
// 覆盖默认的回车键换行
}
},
tab: {
key: 9,
handler: function () {
// 覆盖默认的tab键
}
}
}
}
@@ -271,6 +324,8 @@ class RichText {
theme: 'snow'
})
this.quill.on('selection-change', range => {
// 刚创建的节点全选不需要显示操作条
if (this.isInserting) return
this.lastRange = this.range
this.range = null
if (range) {
@@ -338,9 +393,9 @@ class RichText {
}
// 聚焦
focus() {
focus(start) {
let len = this.quill.getLength()
this.quill.setSelection(len, len)
this.quill.setSelection(typeof start === 'number' ? start : len, len)
}
// 格式化当前选中的文本
@@ -485,11 +540,16 @@ class RichText {
}
}
walk(node)
let canvas = await html2canvas(el, {
backgroundColor: null
})
// 如果使用html2canvas
// let canvas = await html2canvas(el, {
// backgroundColor: null
// })
// return canvas.toDataURL()
const res = await domtoimage.toPng(el)
this.mindMap.el.removeChild(el)
return canvas.toDataURL()
return res
}
// 将所有节点转换成非富文本节点

View File

@@ -0,0 +1,172 @@
import { bfsWalk, getTextFromHtml, isUndef, replaceHtmlText } from '../utils/index'
// 搜索插件
class Search {
// 构造函数
constructor({ mindMap }) {
this.mindMap = mindMap
// 是否正在搜索
this.isSearching = false
// 搜索文本
this.searchText = ''
// 匹配的节点列表
this.matchNodeList = []
// 当前所在的节点列表索引
this.currentIndex = -1
// 不要复位搜索文本
this.notResetSearchText = false
// 是否自动跳转下一个匹配节点
this.isJumpNext = false
this.onDataChange = this.onDataChange.bind(this)
this.mindMap.on('data_change', this.onDataChange)
}
// 节点数据改变了,需要重新搜索
onDataChange() {
if (this.isJumpNext) {
this.isJumpNext = false
this.search(this.searchText)
return
}
if (this.notResetSearchText) {
this.notResetSearchText = false
return
}
this.searchText = ''
}
// 搜索
search(text, callback = () => {}) {
if (isUndef(text)) return this.endSearch()
text = String(text)
this.isSearching = true
if (this.searchText === text) {
// 和上一次搜索文本一样,那么搜索下一个
this.searchNext(callback)
} else {
// 和上次搜索文本不一样,那么重新开始
this.searchText = text
this.doSearch()
this.searchNext(callback)
}
this.emitEvent()
}
// 结束搜索
endSearch() {
if (!this.isSearching) return
this.searchText = ''
this.matchNodeList = []
this.currentIndex = -1
this.notResetSearchText = false
this.isSearching = false
this.emitEvent()
}
// 搜索匹配的节点
doSearch() {
this.matchNodeList = []
this.currentIndex = -1
bfsWalk(this.mindMap.renderer.root, node => {
let { richText, text } = node.nodeData.data
if (richText) {
text = getTextFromHtml(text)
}
if (text.includes(this.searchText)) {
this.matchNodeList.push(node)
}
})
}
// 搜索下一个,定位到下一个匹配节点
searchNext(callback) {
if (!this.isSearching || this.matchNodeList.length <= 0) return
if (this.currentIndex < this.matchNodeList.length - 1) {
this.currentIndex++
} else {
this.currentIndex = 0
}
let currentNode = this.matchNodeList[this.currentIndex]
this.notResetSearchText = true
this.mindMap.execCommand('GO_TARGET_NODE', currentNode, () => {
this.notResetSearchText = false
callback()
})
}
// 替换当前节点
replace(replaceText, jumpNext = false) {
if (
replaceText === null ||
replaceText === undefined ||
!this.isSearching ||
this.matchNodeList.length <= 0
)
return
// 自动跳转下一个匹配节点
this.isJumpNext = jumpNext
replaceText = String(replaceText)
let currentNode = this.matchNodeList[this.currentIndex]
if (!currentNode) return
let text = this.getReplacedText(currentNode, this.searchText, replaceText)
this.notResetSearchText = true
currentNode.setText(text, currentNode.nodeData.data.richText, true)
this.matchNodeList = this.matchNodeList.filter(node => {
return currentNode !== node
})
if (this.currentIndex > this.matchNodeList.length - 1) {
this.currentIndex = -1
} else {
this.currentIndex--
}
this.emitEvent()
}
// 替换所有
replaceAll(replaceText) {
if (
replaceText === null ||
replaceText === undefined ||
!this.isSearching ||
this.matchNodeList.length <= 0
)
return
replaceText = String(replaceText)
this.matchNodeList.forEach(node => {
let text = this.getReplacedText(node, this.searchText, replaceText)
this.mindMap.renderer.setNodeDataRender(
node,
{
text,
resetRichText: !!node.nodeData.data.richText
},
true
)
})
this.mindMap.render()
this.mindMap.command.addHistory()
this.endSearch()
}
// 获取某个节点替换后的文本
getReplacedText(node, searchText, replaceText) {
let { richText, text } = node.nodeData.data
if (richText) {
return replaceHtmlText(text, searchText, replaceText)
} else {
return text.replaceAll(searchText, replaceText)
}
}
// 发送事件
emitEvent() {
this.mindMap.emit('search_info_change', {
currentIndex: this.currentIndex,
total: this.matchNodeList.length
})
}
}
Search.instanceName = 'search'
export default Search

View File

@@ -1,7 +1,6 @@
import { bfsWalk, throttle } from '../utils'
// 选择节点类
// 节点选择插件
class Select {
// 构造函数
constructor({ mindMap }) {

View File

@@ -1,5 +1,4 @@
// 手势事件支持
// 手势事件支持插件
class TouchEvent {
// 构造函数
constructor({ mindMap }) {
@@ -7,7 +6,7 @@ class TouchEvent {
this.touchesNum = 0
this.singleTouchstartEvent = null
this.clickNum = 0
this.doubleTouchmoveDistance = 0
this.touchStartScaleView = null
this.bindEvent()
}
@@ -34,6 +33,7 @@ class TouchEvent {
// 手指按下事件
onTouchstart(e) {
this.touchesNum = e.touches.length
this.touchStartScaleView = null
if (this.touchesNum === 1) {
let touch = e.touches[0]
this.singleTouchstartEvent = touch
@@ -54,18 +54,46 @@ class TouchEvent {
let oy = touch1.clientY - touch2.clientY
let distance = Math.sqrt(Math.pow(ox, 2) + Math.pow(oy, 2))
// 以两指中心点进行缩放
let { x: touch1ClientX, y: touch1ClientY } = this.mindMap.toPos(touch1.clientX, touch1.clientY)
let { x: touch2ClientX, y: touch2ClientY } = this.mindMap.toPos(touch2.clientX, touch2.clientY)
let { x: touch1ClientX, y: touch1ClientY } = this.mindMap.toPos(
touch1.clientX,
touch1.clientY
)
let { x: touch2ClientX, y: touch2ClientY } = this.mindMap.toPos(
touch2.clientX,
touch2.clientY
)
let cx = (touch1ClientX + touch2ClientX) / 2
let cy = (touch1ClientY + touch2ClientY) / 2
if (distance > this.doubleTouchmoveDistance) {
// 放大
this.mindMap.view.enlarge(cx, cy)
} else {
// 缩小
this.mindMap.view.narrow(cx, cy)
// 手势缩放,基于最开始的位置进行缩放(基于前一个位置缩放不是线性关系); 缩放同时支持位置拖动
const view = this.mindMap.view
if (!this.touchStartScaleView) {
this.touchStartScaleView = {
distance: distance,
scale: view.scale,
x: view.x,
y: view.y,
cx: cx,
cy: cy
}
return
}
this.doubleTouchmoveDistance = distance
const viewBefore = this.touchStartScaleView
let scale = viewBefore.scale * (distance / viewBefore.distance)
if (Math.abs(distance - viewBefore.distance) <= 10) {
scale = viewBefore.scale
}
const ratio = 1 - scale / viewBefore.scale
view.scale = scale < 0.1 ? 0.1 : scale
view.x =
viewBefore.x +
(cx - viewBefore.x) * ratio +
(cx - viewBefore.cx) * scale
view.y =
viewBefore.y +
(cy - viewBefore.y) * ratio +
(cy - viewBefore.cy) * scale
view.transform()
this.mindMap.emit('scale', scale)
}
}
@@ -86,12 +114,13 @@ class TouchEvent {
this.clickNum = 0
this.dispatchMouseEvent('dblclick', ev.target, ev)
} else {
this.dispatchMouseEvent('click', ev.target, ev)
// 点击事件应该不用模拟
// this.dispatchMouseEvent('click', ev.target, ev)
}
}
this.touchesNum = 0
this.singleTouchstartEvent = null
this.doubleTouchmoveDistance = 0
this.touchStartScaleView = null
}
// 发送鼠标事件

View File

@@ -2,7 +2,7 @@ import { Text, G } from '@svgdotjs/svg.js'
import { degToRad, camelCaseToHyphen } from '../utils'
import merge from 'deepmerge'
// 水印
// 水印插件
class Watermark {
constructor(opt = {}) {
this.mindMap = opt.mindMap

View File

@@ -47,7 +47,8 @@ function showEditTextBox(g) {
this.textEditNode.addEventListener('click', e => {
e.stopPropagation()
})
document.body.appendChild(this.textEditNode)
const targetNode = this.mindMap.opt.customInnerElsAppendTo || document.body
targetNode.appendChild(this.textEditNode)
}
let {
associativeLineTextFontSize,

View File

@@ -4,7 +4,15 @@ const open = `<svg t="1618141562310" class="icon" viewBox="0 0 1024 1024" versio
// 收缩按钮
const close = `<svg t="1618141589243" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="13611" width="200" height="200"><path d="M512 105.472c225.28 0 407.04 181.76 407.04 407.04s-181.76 407.04-407.04 407.04-407.04-181.76-407.04-407.04 181.76-407.04 407.04-407.04z m0-74.24c-265.216 0-480.768 215.552-480.768 480.768s215.552 480.768 480.768 480.768 480.768-215.552 480.768-480.768-215.552-480.768-480.768-480.768z" p-id="13612"></path><path d="M252.928 474.624h518.144v74.24h-518.144z" p-id="13613"></path></svg>`
// 删除按钮
const remove = `<svg width="14px" height="14px" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="13611" width="200" height="200"><path fill="#ffffff" d="M512 105.472c225.28 0 407.04 181.76 407.04 407.04s-181.76 407.04-407.04 407.04-407.04-181.76-407.04-407.04 181.76-407.04 407.04-407.04z m0-74.24c-265.216 0-480.768 215.552-480.768 480.768s215.552 480.768 480.768 480.768 480.768-215.552 480.768-480.768-215.552-480.768-480.768-480.768z" p-id="13612"></path><path fill="#ffffff" d="M252.928 474.624h518.144v74.24h-518.144z" p-id="13613"></path></svg>`
// 图片调整按钮
const imgAdjust = `<svg width="12px" height="12px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M1008.128 614.4a25.6 25.6 0 0 0-27.648 5.632l-142.848 142.848L259.072 186.88 401.92 43.52A25.6 25.6 0 0 0 384 0h-358.4a25.6 25.6 0 0 0-25.6 25.6v358.4a25.6 25.6 0 0 0 43.52 17.92l143.36-142.848 578.048 578.048-142.848 142.848a25.6 25.6 0 0 0 17.92 43.52h358.4a25.6 25.6 0 0 0 25.6-25.6v-358.4a25.6 25.6 0 0 0-15.872-25.088z" /></svg>`
export default {
open,
close
close,
remove,
imgAdjust
}

View File

@@ -18,6 +18,8 @@ export default {
lineDasharray: 'none',
// 连线风格
lineStyle: 'straight', // 针对logicalStructure、mindMap两种结构。曲线curve、直线straight、直连direct
// 曲线连接时,根节点和其他节点的连接线样式保持统一,默认根节点为 ( 型,其他节点为 { 型设为true后都为 { 型
rootLineKeepSameInCurve: true,
// 概要连线的粗细
generalizationLineWidth: 1,
// 概要连线的颜色

View File

@@ -1,3 +1,5 @@
import { v4 as uuidv4 } from 'uuid'
// 深度优先遍历树
export const walk = (
root,
@@ -31,9 +33,11 @@ export const walk = (
// 广度优先遍历树
export const bfsWalk = (root, callback) => {
callback(root)
let stack = [root]
let isStop = false
if (callback(root, null) === 'stop') {
isStop = true
}
while (stack.length) {
if (isStop) {
break
@@ -41,8 +45,9 @@ export const bfsWalk = (root, callback) => {
let cur = stack.shift()
if (cur.children && cur.children.length) {
cur.children.forEach(item => {
if (isStop) return
stack.push(item)
if (callback(item) === 'stop') {
if (callback(item, cur) === 'stop') {
isStop = true
}
})
@@ -50,6 +55,26 @@ export const bfsWalk = (root, callback) => {
}
}
// 按原比例缩放图片
export const resizeImgSizeByOriginRatio = (
width,
height,
newWidth,
newHeight
) => {
let arr = []
let nRatio = width / height
let mRatio = newWidth / newHeight
if (nRatio > mRatio) {
// 固定高度
arr = [nRatio * newHeight, newHeight]
} else {
// 固定宽度
arr = [newWidth, newWidth / nRatio]
}
return arr
}
// 缩放图片尺寸
export const resizeImgSize = (width, height, maxWidth, maxHeight) => {
let nRatio = width / height
@@ -137,7 +162,12 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => {
}
// 复制节点树数据
export const copyNodeTree = (tree, root, removeActiveState = false, keepId = false) => {
export const copyNodeTree = (
tree,
root,
removeActiveState = false,
keepId = false
) => {
tree.data = simpleDeepClone(root.nodeData ? root.nodeData.data : root.data)
// 去除节点id因为节点id不能重复
if (tree.data.id && !keepId) delete tree.data.id
@@ -188,6 +218,18 @@ export const imgToDataUrl = src => {
})
}
// 解析dataUrl
export const parseDataUrl = data => {
if (!/^data:/.test(data)) return data
let [typeStr, base64] = data.split(',')
let res = /^data:[^/]+\/([^;]+);/.exec(typeStr)
let type = res[1]
return {
type,
base64
}
}
// 下载文件
export const downloadFile = (file, fileName) => {
let a = document.createElement('a')
@@ -236,8 +278,8 @@ export const degToRad = deg => {
return deg * (Math.PI / 180)
}
// 驼峰转连字符
export const camelCaseToHyphen = (str) => {
// 驼峰转连字符
export const camelCaseToHyphen = str => {
return str.replace(/([a-z])([A-Z])/g, (...args) => {
return args[1] + '-' + args[2].toLowerCase()
})
@@ -258,11 +300,8 @@ export const measureText = (text, { italic, bold, fontSize, fontFamily }) => {
}
measureTextContext.save()
measureTextContext.font = font
const {
width,
actualBoundingBoxAscent,
actualBoundingBoxDescent
} = measureTextContext.measureText(text)
const { width, actualBoundingBoxAscent, actualBoundingBoxDescent } =
measureTextContext.measureText(text)
measureTextContext.restore()
const height = actualBoundingBoxAscent + actualBoundingBoxDescent
return { width, height }
@@ -270,7 +309,9 @@ export const measureText = (text, { italic, bold, fontSize, fontFamily }) => {
// 拼接font字符串
export const joinFontStr = ({ italic, bold, fontSize, fontFamily }) => {
return `${italic ? 'italic ' : ''} ${bold ? 'bold ' : ''} ${fontSize}px ${fontFamily} `
return `${italic ? 'italic ' : ''} ${
bold ? 'bold ' : ''
} ${fontSize}px ${fontFamily} `
}
// 在下一个事件循环里执行任务
@@ -336,7 +377,7 @@ export const checkNodeOuter = (mindMap, node) => {
// 提取html字符串里的纯文本
let getTextFromHtmlEl = null
export const getTextFromHtml = (html) => {
export const getTextFromHtml = html => {
if (!getTextFromHtmlEl) {
getTextFromHtmlEl = document.createElement('div')
}
@@ -345,13 +386,13 @@ export const getTextFromHtml = (html) => {
}
// 将blob转成data:url
export const readBlob = (blob) => {
export const readBlob = blob => {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.onload = (evt) => {
reader.onload = evt => {
resolve(evt.target.result)
}
reader.onerror = (err) => {
reader.onerror = err => {
reject(err)
}
reader.readAsDataURL(blob)
@@ -360,11 +401,234 @@ export const readBlob = (blob) => {
// 将dom节点转换成html字符串
let nodeToHTMLWrapEl = null
export const nodeToHTML = (node) => {
export const nodeToHTML = node => {
if (!nodeToHTMLWrapEl) {
nodeToHTMLWrapEl = document.createElement('div')
}
nodeToHTMLWrapEl.innerHTML = ''
nodeToHTMLWrapEl.appendChild(node)
return nodeToHTMLWrapEl.innerHTML
}
}
// 获取图片大小
export const getImageSize = src => {
return new Promise(resolve => {
let img = new Image()
img.src = src
img.onload = () => {
resolve({
width: img.width,
height: img.height
})
}
img.onerror = () => {
resolve({
width: 0,
height: 0
})
}
})
}
// 创建节点唯一的id
export const createUid = () => {
return uuidv4()
}
// 加载图片文件
export const loadImage = imgFile => {
return new Promise((resolve, reject) => {
let fr = new FileReader()
fr.readAsDataURL(imgFile)
fr.onload = async e => {
let url = e.target.result
let size = await getImageSize(url)
resolve({
url,
size
})
}
fr.onerror = error => {
reject(error)
}
})
}
// 移除字符串中的html实体
export const removeHTMLEntities = str => {
;[['&nbsp;', '&#160;']].forEach(item => {
str = str.replaceAll(item[0], item[1])
})
return str
}
// 获取一个数据的类型
export const getType = data => {
return Object.prototype.toString.call(data).slice(7, -1)
}
// 判断一个数据是否是null和undefined和空字符串
export const isUndef = data => {
return data === null || data === undefined || data === ''
}
// 移除html字符串中节点的内联样式
export const removeHtmlStyle = html => {
return html.replaceAll(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2')
}
// 给html标签中指定的标签添加内联样式
export const addHtmlStyle = (html, tag, style) => {
const reg = new RegExp(`(<${tag}[^>]*)(>[^<>]*</${tag}>)`, 'g')
return html.replaceAll(reg, `$1 style="${style}"$2`)
}
// 检查一个字符串是否是富文本字符
let checkIsRichTextEl = null
export const checkIsRichText = str => {
if (!checkIsRichTextEl) {
checkIsRichTextEl = document.createElement('div')
}
checkIsRichTextEl.innerHTML = str
for (let c = checkIsRichTextEl.childNodes, i = c.length; i--; ) {
if (c[i].nodeType == 1) return true
}
return false
}
// 搜索和替换html字符串中指定的文本
let replaceHtmlTextEl = null
export const replaceHtmlText = (html, searchText, replaceText) => {
if (!replaceHtmlTextEl) {
replaceHtmlTextEl = document.createElement('div')
}
replaceHtmlTextEl.innerHTML = html
let walk = root => {
let childNodes = root.childNodes
childNodes.forEach(node => {
if (node.nodeType === 1) {
// 元素节点
walk(node)
} else if (node.nodeType === 3) {
// 文本节点
root.replaceChild(
document.createTextNode(
node.nodeValue.replaceAll(searchText, replaceText)
),
node
)
}
})
}
walk(replaceHtmlTextEl)
return replaceHtmlTextEl.innerHTML
}
// 判断一个颜色是否是白色
export const isWhite = color => {
color = String(color).replaceAll(/\s+/g, '')
return (
['#fff', '#ffffff', '#FFF', '#FFFFFF', 'rgb(255,255,255)'].includes(
color
) || /rgba\(255,255,255,[^)]+\)/.test(color)
)
}
// 判断一个颜色是否是透明
export const isTransparent = color => {
color = String(color).replaceAll(/\s+/g, '')
return (
['', 'transparent'].includes(color) || /rgba\(\d+,\d+,\d+,0\)/.test(color)
)
}
// 从当前主题里获取一个非透明非白色的颜色
export const getVisibleColorFromTheme = themeConfig => {
let { lineColor, root, second, node } = themeConfig
let list = [
lineColor,
root.fillColor,
root.color,
second.fillColor,
second.color,
node.fillColor,
node.color,
root.borderColor,
second.borderColor,
node.borderColor
]
for (let i = 0; i < list.length; i++) {
let color = list[i]
if (!isTransparent(color) && !isWhite(color)) {
return color
}
}
}
// 将<p><span></span><p>形式的节点富文本内容转换成\n换行的文本
let nodeRichTextToTextWithWrapEl = null
export const nodeRichTextToTextWithWrap = html => {
if (!nodeRichTextToTextWithWrapEl) {
nodeRichTextToTextWithWrapEl = document.createElement('div')
}
nodeRichTextToTextWithWrapEl.innerHTML = html
const childNodes = nodeRichTextToTextWithWrapEl.childNodes
let res = ''
for (let i = 0; i < childNodes.length; i++) {
const node = childNodes[i]
if (node.nodeType === 1) {
// 元素节点
if (node.tagName.toLowerCase() === 'p') {
res += node.textContent + '\n'
} else {
res += node.textContent
}
} else if (node.nodeType === 3) {
// 文本节点
res += node.nodeValue
}
}
return res.replace(/\n$/, '')
}
// 将<br>换行的文本转换成<p><span></span><p>形式的节点富文本内容
let textToNodeRichTextWithWrapEl = null
export const textToNodeRichTextWithWrap = html => {
if (!textToNodeRichTextWithWrapEl) {
textToNodeRichTextWithWrapEl = document.createElement('div')
}
textToNodeRichTextWithWrapEl.innerHTML = html
const childNodes = textToNodeRichTextWithWrapEl.childNodes
let list = []
let str = ''
for (let i = 0; i < childNodes.length; i++) {
const node = childNodes[i]
if (node.nodeType === 1) {
// 元素节点
if (node.tagName.toLowerCase() === 'br') {
list.push(str)
str = ''
} else {
str += node.textContent
}
} else if (node.nodeType === 3) {
// 文本节点
str += node.nodeValue
}
}
if (str) {
list.push(str)
}
return list
.map(item => {
return `<p><span>${item}</span></p>`
})
.join('')
}
// 判断是否是移动端环境
export const isMobile = () => {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
}

1
web/.env.library Normal file
View File

@@ -0,0 +1 @@
NODE_ENV=library

15
web/package-lock.json generated
View File

@@ -35,7 +35,8 @@
"prettier": "^1.19.1",
"vconsole": "^3.15.1",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.44.2"
"webpack": "^4.44.2",
"webpack-dynamic-public-path": "^1.0.8"
}
},
"node_modules/@achrinza/node-ipc": {
@@ -16224,6 +16225,12 @@
"decamelize": "^1.2.0"
}
},
"node_modules/webpack-dynamic-public-path": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/webpack-dynamic-public-path/-/webpack-dynamic-public-path-1.0.8.tgz",
"integrity": "sha512-AF6onorpvmiC+I/dQ19SOi+oN66oEy9h4deam7gPs1Qa1mOQ9i7IRsOahaukohKAciys7NfX+YFboRn4rmpuKw==",
"dev": true
},
"node_modules/webpack-log": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/webpack-log/-/webpack-log-2.0.0.tgz",
@@ -29476,6 +29483,12 @@
}
}
},
"webpack-dynamic-public-path": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/webpack-dynamic-public-path/-/webpack-dynamic-public-path-1.0.8.tgz",
"integrity": "sha512-AF6onorpvmiC+I/dQ19SOi+oN66oEy9h4deam7gPs1Qa1mOQ9i7IRsOahaukohKAciys7NfX+YFboRn4rmpuKw==",
"dev": true
},
"webpack-log": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/webpack-log/-/webpack-log-2.0.0.tgz",

View File

@@ -6,10 +6,11 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build && node ../copy.js",
"lint": "vue-cli-service lint",
"buildLibrary": "vue-cli-service build --target lib --name simpleMindMap ../simple-mind-map/full.js --dest ../simple-mind-map/dist && esbuild ../simple-mind-map/full.js --bundle --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.js",
"buildLibrary": "vue-cli-service build --mode library --target lib --name simpleMindMap ../simple-mind-map/full.js --dest ../simple-mind-map/dist && esbuild ../simple-mind-map/full.js --bundle --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.js && esbuild ../simple-mind-map/full.js --bundle --minify --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.min.js",
"format": "prettier --write src/* src/*/* src/*/*/* src/*/*/*/*",
"buildDoc": "node ./scripts/buildDoc.js",
"autoBuildDoc": "node ./scripts/autoBuildDoc.js"
"autoBuildDoc": "node ./scripts/autoBuildDoc.js",
"createNodeImageList": "node ./scripts/createNodeImageList.js"
},
"dependencies": {
"@toast-ui/editor": "^3.1.5",
@@ -39,7 +40,8 @@
"prettier": "^1.19.1",
"vconsole": "^3.15.1",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.44.2"
"webpack": "^4.44.2",
"webpack-dynamic-public-path": "^1.0.8"
},
"eslintConfig": {
"root": true,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 695 KiB

View File

@@ -4,8 +4,14 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<link rel="icon" href="./dist/logo.png">
<title>一个简单的web思维导图实现</title>
<link rel="icon" href="dist/logo.ico">
<title>思绪思维导图</title>
<script>
// 自定义静态资源的路径
window.externalPublicPath = './dist/'
// 接管应用
window.takeOverApp = false
</script>
</head>
<body>
<noscript>
@@ -13,5 +19,73 @@
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script>
const getDataFromBackend = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
mindMapData: {
root:{
"data": {
"text": "根节点"
},
"children": []
},
theme:{
"template":"avocado",
"config":{}
},
layout:"logicalStructure",
config: {},
view: null,
},
lang: 'zh',
localConfig: null
})
}, 200)
})
}
const setTakeOverAppMethods = (data) => {
window.takeOverAppMethods = {}
// 获取思维导图数据的函数
window.takeOverAppMethods.getMindMapData = () => {
return data.mindMapData
}
// 保存思维导图数据的函数
window.takeOverAppMethods.saveMindMapData = (data) => {
console.log(data)
}
// 获取语言的函数
window.takeOverAppMethods.getLanguage = () => {
return data.lang
}
// 保存语言的函数
window.takeOverAppMethods.saveLanguage = (lang) => {
console.log(lang)
}
// 获取本地配置的函数
window.takeOverAppMethods.getLocalConfig = () => {
return data.localConfig
}
// 保存本地配置的函数
window.takeOverAppMethods.saveLocalConfig = (config) => {
console.log(config)
}
}
window.onload = async () => {
if (!window.takeOverApp) return
// 请求数据
const data = await getDataFromBackend()
// 设置全局的方法
setTakeOverAppMethods(data)
// 思维导图实例创建完成事件
window.$bus.$on('app_inited', (mindMap) => {
console.log(mindMap)
})
// 可以通过window.$bus.$on()来监听应用的一些事件
// 实例化页面
window.initApp()
}
</script>
</body>
</html>

BIN
web/public/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1,50 @@
const path = require('path')
const fs = require('fs')
const fileDest = path.join(__dirname, '../src/assets/svg')
const targetDest = path.join(__dirname, '../src/config/image.js')
const run = (dir) => {
let dirs = fs.readdirSync(dir)
dirs.forEach(item => {
let cur = path.join(dir, item)
if (fs.statSync(cur).isDirectory()) {
walkDir(cur, item)
}
})
}
const list = []
const importList = []
const walkDir = (dir, item) => {
let files = fs.readdirSync(dir)
let name = files.find((file) => {
return !/\./.test(file)
})
let fileList = files.filter((file) => {
return /\.svg$/.test(file)
})
let itemList = []
fileList.forEach((file) => {
let fileName = item + '_' + file.replace(/\.svg$/, '').replaceAll('-', '')
importList.push(`import ${fileName} from '../assets/svg/${item}/${file}'`)
itemList.push({
url: fileName,
width: 100,
height: 100
})
})
list.push({
name,
list: itemList
})
const content = `
// 该文件请运行npm run createNodeImageList命令自动生成
${importList.join('\n')}
export default ${JSON.stringify(list, null, 2).replace(/(url":\s*)"([^"]+)"(,)/g, '$1$2$3')}
`
fs.writeFileSync(targetDest, content)
}
run(fileDest)
console.log('运行成功')

BIN
web/src/.DS_Store vendored

Binary file not shown.

View File

@@ -6,6 +6,8 @@ const SIMPLE_MIND_MAP_DATA = 'SIMPLE_MIND_MAP_DATA'
const SIMPLE_MIND_MAP_LANG = 'SIMPLE_MIND_MAP_LANG'
const SIMPLE_MIND_MAP_LOCAL_CONFIG = 'SIMPLE_MIND_MAP_LOCAL_CONFIG'
let mindMapData = null
/**
* @Author: 王林
* @Date: 2021-08-02 22:36:48
@@ -29,6 +31,10 @@ const copyMindMapTreeData = (tree, root) => {
* @Desc: 获取缓存的思维导图数据
*/
export const getData = () => {
if (window.takeOverApp) {
mindMapData = window.takeOverAppMethods.getMindMapData()
return mindMapData
}
let store = localStorage.getItem(SIMPLE_MIND_MAP_DATA)
if (store === null) {
return simpleDeepClone(exampleData)
@@ -48,8 +54,18 @@ export const getData = () => {
*/
export const storeData = data => {
try {
let originData = getData()
let originData = null
if (window.takeOverApp) {
originData = mindMapData
} else {
originData = getData()
}
originData.root = copyMindMapTreeData({}, data)
if (window.takeOverApp) {
mindMapData = originData
window.takeOverAppMethods.saveMindMapData(originData)
return
}
Vue.prototype.$bus.$emit('write_local_file', originData)
let dataStr = JSON.stringify(originData)
localStorage.setItem(SIMPLE_MIND_MAP_DATA, dataStr)
@@ -65,11 +81,21 @@ export const storeData = data => {
*/
export const storeConfig = config => {
try {
let originData = getData()
let originData = null
if (window.takeOverApp) {
originData = mindMapData
} else {
originData = getData()
}
originData = {
...originData,
...config
}
if (window.takeOverApp) {
mindMapData = originData
window.takeOverAppMethods.saveMindMapData(originData)
return
}
Vue.prototype.$bus.$emit('write_local_file', originData)
let dataStr = JSON.stringify(originData)
localStorage.setItem(SIMPLE_MIND_MAP_DATA, dataStr)
@@ -85,6 +111,10 @@ export const storeConfig = config => {
* @Desc: 存储语言
*/
export const storeLang = lang => {
if (window.takeOverApp) {
window.takeOverAppMethods.saveLanguage(lang)
return
}
localStorage.setItem(SIMPLE_MIND_MAP_LANG, lang)
}
@@ -95,6 +125,9 @@ export const storeLang = lang => {
* @Desc: 获取存储的语言
*/
export const getLang = () => {
if (window.takeOverApp) {
return window.takeOverAppMethods.getLanguage() || 'zh'
}
let lang = localStorage.getItem(SIMPLE_MIND_MAP_LANG)
if (lang) {
return lang
@@ -110,6 +143,9 @@ export const getLang = () => {
* @Desc: 存储本地配置
*/
export const storeLocalConfig = config => {
if (window.takeOverApp) {
return window.takeOverAppMethods.saveLocalConfig(config)
}
localStorage.setItem(SIMPLE_MIND_MAP_LOCAL_CONFIG, JSON.stringify(config))
}
@@ -120,6 +156,9 @@ export const storeLocalConfig = config => {
* @Desc: 获取本地配置
*/
export const getLocalConfig = () => {
if (window.takeOverApp) {
return window.takeOverAppMethods.getLocalConfig()
}
let config = localStorage.getItem(SIMPLE_MIND_MAP_LOCAL_CONFIG)
if (config) {
return JSON.parse(config)

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 2479351 */
src: url('iconfont.woff2?t=1686298427624') format('woff2'),
url('iconfont.woff?t=1686298427624') format('woff'),
url('iconfont.ttf?t=1686298427624') format('truetype');
src: url('iconfont.woff2?t=1691822758372') format('woff2'),
url('iconfont.woff?t=1691822758372') format('woff'),
url('iconfont.ttf?t=1691822758372') format('truetype');
}
.iconfont {
@@ -13,6 +13,74 @@
-moz-osx-font-smoothing: grayscale;
}
.icontouming:before {
content: "\e60c";
}
.iconlieri:before {
content: "\e60b";
}
.iconmoon_line:before {
content: "\e745";
}
.iconsousuo:before {
content: "\e693";
}
.iconjiantouyou:before {
content: "\e62d";
}
.iconbianji1:before {
content: "\e60a";
}
.icondaohang1:before {
content: "\e632";
}
.iconyanjing:before {
content: "\e8bf";
}
.iconwangzhan:before {
content: "\e628";
}
.iconcsdn:before {
content: "\e608";
}
.iconshejiaotubiao-10:before {
content: "\e644";
}
.iconstar:before {
content: "\e7df";
}
.iconfork:before {
content: "\e641";
}
.iconxiazai:before {
content: "\e613";
}
.iconteamwork:before {
content: "\e870";
}
.iconshuiyin:before {
content: "\e67a";
}
.iconxmind:before {
content: "\ea57";
}
.iconmouseR:before {
content: "\e6bd";
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Some files were not shown because too many files have changed in this diff Show More