From 1b7aad3de28fac2183bb8ec0a4fe5f0d1e43328f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 3 Apr 2025 09:50:01 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=94=AF=E6=8C=81=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E8=8A=82=E7=82=B9=E5=BD=A2=E7=8A=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 36 +++++++++++++++++++ simple-mind-map/src/core/render/node/Shape.js | 32 +++++++++++++++-- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 761b4909..39003ccc 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -82,6 +82,22 @@ class MindMap { // 该检查可以通过customCheckEnableShortcut选项来覆盖 this.editNodeClassList = [] + // 扩展的节点形状列表 + /* + { + createShape: (node) => { + return path + }, + getPadding: ({ node, width, height, paddingX, paddingY }) => { + return { + paddingX: 0, + paddingY: 0 + } + } + } + */ + this.extendShapeList = [] + // 画布 this.initContainer() @@ -675,6 +691,26 @@ class MindMap { } } + // 扩展节点形状 + addShape(shape) { + if (!shape) return + const exist = this.extendShapeList.find(item => { + return item.name === shape.name + }) + if (exist) return + this.extendShapeList.push(shape) + } + + // 删除扩展的形状 + removeShape(name) { + const index = this.extendShapeList.findIndex(item => { + return item.name === name + }) + if (index !== -1) { + this.extendShapeList.splice(index, 1) + } + } + // 添加插件 addPlugin(plugin, opt) { let index = MindMap.hasPlugin(plugin) diff --git a/simple-mind-map/src/core/render/node/Shape.js b/simple-mind-map/src/core/render/node/Shape.js index 85e52517..704f1129 100644 --- a/simple-mind-map/src/core/render/node/Shape.js +++ b/simple-mind-map/src/core/render/node/Shape.js @@ -52,14 +52,36 @@ export default class Shape { paddingX: actHeight > actWidth ? actOffset / 2 : 0, paddingY: actHeight < actWidth ? actOffset / 2 : 0 } - default: - return { + } + const extendShape = this.getShapeFromExtendList(shape) + if (extendShape) { + return ( + extendShape.getPadding({ + node: this.node, + width, + height, + paddingX, + paddingY + }) || { paddingX: 0, paddingY: 0 } + ) + } else { + return { + paddingX: 0, + paddingY: 0 + } } } + // 从形状扩展列表里获取指定名称的形状 + getShapeFromExtendList(shape) { + return this.mindMap.extendShapeList.find(item => { + return item.name === shape + }) + } + // 创建形状节点 createShape() { const shape = this.node.getShape() @@ -92,6 +114,12 @@ export default class Shape { // 圆 node = this.createCircle() } + if (!node) { + const extendShape = this.getShapeFromExtendList(shape) + if (extendShape) { + node = extendShape.createShape(this.node) + } + } return node }