Compare commits

...

4 Commits
0.4.0 ... 0.4.1

28 changed files with 236 additions and 33 deletions

View File

@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="./dist/logo.png"><title>一个简单的web思维导图实现</title><link href="dist/js/chunk-2d0a3179.3b27bed0.js" rel="prefetch"><link href="dist/js/chunk-2d0aa579.82a73ddc.js" rel="prefetch"><link href="dist/js/chunk-2d0aa978.84fc06da.js" rel="prefetch"><link href="dist/js/chunk-2d0ab10b.a0694d8e.js" rel="prefetch"><link href="dist/js/chunk-2d0abe0f.a9abff6a.js" rel="prefetch"><link href="dist/js/chunk-2d0b361e.d657e190.js" rel="prefetch"><link href="dist/js/chunk-2d0b91e5.433fdc5c.js" rel="prefetch"><link href="dist/js/chunk-2d0b92c3.9d7f8382.js" rel="prefetch"><link href="dist/js/chunk-2d0ba309.3542b9be.js" rel="prefetch"><link href="dist/js/chunk-2d0bd54e.906e86ec.js" rel="prefetch"><link href="dist/js/chunk-2d0be174.0cf53d60.js" rel="prefetch"><link href="dist/js/chunk-2d0c0a44.bdfd7cfb.js" rel="prefetch"><link href="dist/js/chunk-2d0c14fc.7163274e.js" rel="prefetch"><link href="dist/js/chunk-2d0c18d8.8456c878.js" rel="prefetch"><link href="dist/js/chunk-2d0c191e.f425dd57.js" rel="prefetch"><link href="dist/js/chunk-2d0c1a01.e37b19a2.js" rel="prefetch"><link href="dist/js/chunk-2d0c20be.76666437.js" rel="prefetch"><link href="dist/js/chunk-2d0d9fbc.22793f14.js" rel="prefetch"><link href="dist/js/chunk-2d0da701.80759043.js" rel="prefetch"><link href="dist/js/chunk-2d0dad5f.2e4d6938.js" rel="prefetch"><link href="dist/js/chunk-2d0db0f2.b5ce4946.js" rel="prefetch"><link href="dist/js/chunk-2d0dddce.3eea98de.js" rel="prefetch"><link href="dist/js/chunk-2d0ddf37.6ecb5986.js" rel="prefetch"><link href="dist/js/chunk-2d0de01b.a2a047cf.js" rel="prefetch"><link href="dist/js/chunk-2d0e2326.cfbc28b0.js" rel="prefetch"><link href="dist/js/chunk-2d0e268c.eba27ee7.js" rel="prefetch"><link href="dist/js/chunk-2d0e5089.10135360.js" rel="prefetch"><link href="dist/js/chunk-2d0e9742.9abceada.js" rel="prefetch"><link href="dist/js/chunk-2d0f026c.5f73597d.js" rel="prefetch"><link href="dist/js/chunk-2d2082b9.f52387a2.js" rel="prefetch"><link href="dist/js/chunk-2d208ffa.7f14d671.js" rel="prefetch"><link href="dist/js/chunk-2d20ec02.917aff76.js" rel="prefetch"><link href="dist/js/chunk-2d20f68f.ff46a11f.js" rel="prefetch"><link href="dist/js/chunk-2d210a7a.6a4911c4.js" rel="prefetch"><link href="dist/js/chunk-2d216004.1c1e194c.js" rel="prefetch"><link href="dist/js/chunk-2d217907.32a00939.js" rel="prefetch"><link href="dist/js/chunk-2d226d0a.6b1238d2.js" rel="prefetch"><link href="dist/js/chunk-2d2299c3.8f3151dd.js" rel="prefetch"><link href="dist/js/chunk-2d22bd06.29ee05f7.js" rel="prefetch"><link href="dist/js/chunk-2d2308b0.2797f6b4.js" rel="prefetch"><link href="dist/js/chunk-2d238428.7c9ae7c7.js" rel="prefetch"><link href="dist/js/chunk-3a2f3e67.13278516.js" rel="prefetch"><link href="dist/css/app.10014a3e.css" rel="preload" as="style"><link href="dist/css/chunk-vendors.c097b26d.css" rel="preload" as="style"><link href="dist/js/app.4d5a4cb3.js" rel="preload" as="script"><link href="dist/js/chunk-vendors.524ee6e1.js" rel="preload" as="script"><link href="dist/css/chunk-vendors.c097b26d.css" rel="stylesheet"><link href="dist/css/app.10014a3e.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="dist/js/chunk-vendors.524ee6e1.js"></script><script src="dist/js/app.4d5a4cb3.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="./dist/logo.png"><title>一个简单的web思维导图实现</title><link href="dist/js/chunk-2d0a3179.05d77cdf.js" rel="prefetch"><link href="dist/js/chunk-2d0aa579.61258a02.js" rel="prefetch"><link href="dist/js/chunk-2d0aa978.040c6f5c.js" rel="prefetch"><link href="dist/js/chunk-2d0ab10b.87f48f42.js" rel="prefetch"><link href="dist/js/chunk-2d0abe0f.ae972b36.js" rel="prefetch"><link href="dist/js/chunk-2d0b361e.b094b87c.js" rel="prefetch"><link href="dist/js/chunk-2d0b91e5.34207f33.js" rel="prefetch"><link href="dist/js/chunk-2d0b92c3.ade5a7e0.js" rel="prefetch"><link href="dist/js/chunk-2d0ba309.c9a9ab22.js" rel="prefetch"><link href="dist/js/chunk-2d0bd54e.db6065c6.js" rel="prefetch"><link href="dist/js/chunk-2d0be174.1ffa155d.js" rel="prefetch"><link href="dist/js/chunk-2d0c0a44.a872e86f.js" rel="prefetch"><link href="dist/js/chunk-2d0c14fc.17d4f60a.js" rel="prefetch"><link href="dist/js/chunk-2d0c18d8.b6a4f7bb.js" rel="prefetch"><link href="dist/js/chunk-2d0c191e.2803233f.js" rel="prefetch"><link href="dist/js/chunk-2d0c1a01.77611624.js" rel="prefetch"><link href="dist/js/chunk-2d0c20be.57f5b62e.js" rel="prefetch"><link href="dist/js/chunk-2d0d9fbc.5f7a8ef7.js" rel="prefetch"><link href="dist/js/chunk-2d0da701.6c0d2c1e.js" rel="prefetch"><link href="dist/js/chunk-2d0dad5f.3ab82f4a.js" rel="prefetch"><link href="dist/js/chunk-2d0db0f2.32d1bf7e.js" rel="prefetch"><link href="dist/js/chunk-2d0dddce.836132f8.js" rel="prefetch"><link href="dist/js/chunk-2d0ddf37.7b4a470a.js" rel="prefetch"><link href="dist/js/chunk-2d0de01b.00dad103.js" rel="prefetch"><link href="dist/js/chunk-2d0e2326.8750dc1f.js" rel="prefetch"><link href="dist/js/chunk-2d0e268c.2d4b7022.js" rel="prefetch"><link href="dist/js/chunk-2d0e5089.a4640577.js" rel="prefetch"><link href="dist/js/chunk-2d0e9742.bd5197f5.js" rel="prefetch"><link href="dist/js/chunk-2d0f026c.67054456.js" rel="prefetch"><link href="dist/js/chunk-2d2082b9.c7c6517f.js" rel="prefetch"><link href="dist/js/chunk-2d208ffa.f4b779ed.js" rel="prefetch"><link href="dist/js/chunk-2d20ec02.917aff76.js" rel="prefetch"><link href="dist/js/chunk-2d20f68f.4cf834ac.js" rel="prefetch"><link href="dist/js/chunk-2d210a7a.e60ccf9b.js" rel="prefetch"><link href="dist/js/chunk-2d216004.41f8f60d.js" rel="prefetch"><link href="dist/js/chunk-2d217907.3772894a.js" rel="prefetch"><link href="dist/js/chunk-2d226d0a.5947204c.js" rel="prefetch"><link href="dist/js/chunk-2d2299c3.0bdd83ab.js" rel="prefetch"><link href="dist/js/chunk-2d22bd06.1447b6d2.js" rel="prefetch"><link href="dist/js/chunk-2d2308b0.4fa18681.js" rel="prefetch"><link href="dist/js/chunk-2d238428.61fffbf5.js" rel="prefetch"><link href="dist/js/chunk-3a2f3e67.13278516.js" rel="prefetch"><link href="dist/css/app.0db5f6e3.css" rel="preload" as="style"><link href="dist/css/chunk-vendors.c097b26d.css" rel="preload" as="style"><link href="dist/js/app.ef341b88.js" rel="preload" as="script"><link href="dist/js/chunk-vendors.524ee6e1.js" rel="preload" as="script"><link href="dist/css/chunk-vendors.c097b26d.css" rel="stylesheet"><link href="dist/css/app.0db5f6e3.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="dist/js/chunk-vendors.524ee6e1.js"></script><script src="dist/js/app.ef341b88.js"></script></body></html>

View File

@@ -900,6 +900,17 @@ const data5 = {
}
}
// 富文本数据v0.4.0+需要使用RichText插件才支持富文本编辑
const richTextData = {
"root": {
"data": {
"text": "<a href='http://lxqnsys.com/' target='_blank'>理想去年实验室</a>",
"richText": true
},
"children": []
}
}
const rootData = {
"root": {
"data": {

View File

@@ -31,6 +31,12 @@
"isActive": false
},
"children": []
}, {
"data": {
"text": "<a href='http://lxqnsys.com/' target='_blank'>理想去年实验室</a>",
"richText": true
},
"children": []
}]
}]
},

View File

@@ -1,6 +1,6 @@
{
"name": "simple-mind-map",
"version": "0.4.0",
"version": "0.4.1",
"description": "一个简单的web在线思维导图",
"authors": [
{

View File

@@ -43,12 +43,7 @@ class Event extends EventEmitter {
this.mindMap.svg.on('mousedown', this.onSvgMousedown)
window.addEventListener('mousemove', this.onMousemove)
window.addEventListener('mouseup', this.onMouseup)
// 兼容火狐浏览器
if (window.navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
this.mindMap.el.addEventListener('DOMMouseScroll', this.onMousewheel)
} else {
this.mindMap.el.addEventListener('mousewheel', this.onMousewheel)
}
this.mindMap.el.addEventListener('wheel', this.onMousewheel)
this.mindMap.svg.on('contextmenu', this.onContextmenu)
window.addEventListener('keyup', this.onKeyup)
}
@@ -59,7 +54,7 @@ class Event extends EventEmitter {
this.mindMap.el.removeEventListener('mousedown', this.onMousedown)
window.removeEventListener('mousemove', this.onMousemove)
window.removeEventListener('mouseup', this.onMouseup)
this.mindMap.el.removeEventListener('mousewheel', this.onMousewheel)
this.mindMap.el.removeEventListener('wheel', this.onMousewheel)
this.mindMap.svg.off('contextmenu', this.onContextmenu)
window.removeEventListener('keyup', this.onKeyup)
}
@@ -110,10 +105,16 @@ class Event extends EventEmitter {
e.stopPropagation()
e.preventDefault()
let dir
if ((e.wheelDeltaY || e.detail) > 0) {
dir = 'up'
// 解决mac触控板双指缩放方向相反的问题
if (e.ctrlKey) {
if (e.deltaY > 0) dir = 'up'
if (e.deltaY < 0) dir = 'down'
} else {
dir = 'down'
if ((e.wheelDeltaY || e.detail) > 0) {
dir = 'up'
} else {
dir = 'down'
}
}
this.emit('mousewheel', e, dir, this)
}

View File

@@ -191,7 +191,9 @@ class Node {
'dblclick',
'contextmenu',
'mousedown',
'mouseup'
'mouseup',
'mouseenter',
'mouseleave'
])
}
}
@@ -677,6 +679,12 @@ class Node {
e.stopPropagation()
this.mindMap.emit('node_mouseup', this, e)
})
this.group.on('mouseenter', e => {
this.mindMap.emit('node_mouseenter', this, e)
})
this.group.on('mouseleave', e => {
this.mindMap.emit('node_mouseleave', this, e)
})
// 双击事件
this.group.on('dblclick', e => {
if (this.mindMap.opt.readonly) {

View File

@@ -229,17 +229,22 @@ class RichText {
}
// 格式化当前选中的文本
formatText(config = {}) {
formatText(config = {}, clear = false) {
if (!this.range && !this.lastRange) return
this.syncFormatToNodeConfig(config)
this.syncFormatToNodeConfig(config, clear)
let rangeLost = !this.range
let range = rangeLost ? this.lastRange : this.range
this.quill.formatText(range.index, range.length, config)
clear ? this.quill.removeFormat(range.index, range.length) : this.quill.formatText(range.index, range.length, config)
if (rangeLost) {
this.quill.setSelection(this.lastRange.index, this.lastRange.length)
}
}
// 清除当前选中文本的样式
removeFormat() {
this.formatText({}, true)
}
// 格式化指定范围的文本
formatRangeText(range, config = {}) {
if (!range) return
@@ -254,10 +259,17 @@ class RichText {
}
// 同步格式化到节点样式配置
syncFormatToNodeConfig(config) {
syncFormatToNodeConfig(config, clear) {
if (!this.node) return
let data = this.richTextStyleToNormalStyle(config)
this.mindMap.renderer.setNodeData(this.node, data)
if (clear) {
// 清除文本样式
['fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'textDecoration', 'color'].forEach((prop) => {
delete this.node.nodeData.data[prop]
})
} else {
let data = this.richTextStyleToNormalStyle(config)
this.mindMap.renderer.setNodeData(this.node, data)
}
}
// 将普通节点样式对象转换成富文本样式对象
@@ -372,10 +384,13 @@ class RichText {
let canvas = await html2canvas(clone, {
backgroundColor: null
})
// 优先使用原始宽高因为当设备的window.devicePixelRatio不为1时html2canvas输出的图片会更大
let imgNodeWidth = parent.attr('data-width') || canvas.width
let imgNodeHeight = parent.attr('data-height') || canvas.height
this.mindMap.el.removeChild(div)
let imgNode = new SvgImage()
.load(canvas.toDataURL())
.size(canvas.width, canvas.height)
.size(imgNodeWidth, imgNodeHeight)
.x((parent ? parent.attr('data-offsetx') : 0) || 0)
item.replace(imgNode)
if (index <= len - 1) {

View File

@@ -6,4 +6,5 @@
.ql-container {
height: auto;
font-size: inherit;
}

View File

@@ -54,6 +54,18 @@
<div class="content unicode" style="display: block;">
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont">&#xe6f8;</span>
<div class="name">背景颜色</div>
<div class="code-name">&amp;#xe6f8;</div>
</li>
<li class="dib">
<span class="icon iconfont">&#xe605;</span>
<div class="name">清除</div>
<div class="code-name">&amp;#xe605;</div>
</li>
<li class="dib">
<span class="icon iconfont">&#xe6c6;</span>
<div class="name">case</div>
@@ -390,9 +402,9 @@
<pre><code class="language-css"
>@font-face {
font-family: 'iconfont';
src: url('iconfont.woff2?t=1677058133223') format('woff2'),
url('iconfont.woff?t=1677058133223') format('woff'),
url('iconfont.ttf?t=1677058133223') format('truetype');
src: url('iconfont.woff2?t=1677478278322') format('woff2'),
url('iconfont.woff?t=1677478278322') format('woff'),
url('iconfont.ttf?t=1677478278322') format('truetype');
}
</code></pre>
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
@@ -418,6 +430,24 @@
<div class="content font-class">
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont iconbeijingyanse"></span>
<div class="name">
背景颜色
</div>
<div class="code-name">.iconbeijingyanse
</div>
</li>
<li class="dib">
<span class="icon iconfont iconqingchu"></span>
<div class="name">
清除
</div>
<div class="code-name">.iconqingchu
</div>
</li>
<li class="dib">
<span class="icon iconfont iconcase"></span>
<div class="name">
@@ -922,6 +952,22 @@
<div class="content symbol">
<ul class="icon_lists dib-box">
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconbeijingyanse"></use>
</svg>
<div class="name">背景颜色</div>
<div class="code-name">#iconbeijingyanse</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconqingchu"></use>
</svg>
<div class="name">清除</div>
<div class="code-name">#iconqingchu</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconcase"></use>

View File

@@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 2479351 */
src: url('iconfont.woff2?t=1677058133223') format('woff2'),
url('iconfont.woff?t=1677058133223') format('woff'),
url('iconfont.ttf?t=1677058133223') format('truetype');
src: url('iconfont.woff2?t=1677478278322') format('woff2'),
url('iconfont.woff?t=1677478278322') format('woff'),
url('iconfont.ttf?t=1677478278322') format('truetype');
}
.iconfont {
@@ -13,6 +13,14 @@
-moz-osx-font-smoothing: grayscale;
}
.iconbeijingyanse:before {
content: "\e6f8";
}
.iconqingchu:before {
content: "\e605";
}
.iconcase:before {
content: "\e6c6";
}

File diff suppressed because one or more lines are too long

View File

@@ -5,6 +5,20 @@
"css_prefix_text": "icon",
"description": "思维导图",
"glyphs": [
{
"icon_id": "1790495",
"name": "背景颜色",
"font_class": "beijingyanse",
"unicode": "e6f8",
"unicode_decimal": 59128
},
{
"icon_id": "11321310",
"name": "清除",
"font_class": "qingchu",
"unicode": "e605",
"unicode_decimal": 58885
},
{
"icon_id": "586787",
"name": "case",

View File

@@ -1,12 +1,18 @@
# Changelog
## 0.4.1
New: 1.Add and throw node mouseenter and mouseleave events; 2.Node rich text supports setting background color; 3.Node rich text supports clear style.
Fix: 1.Mac system touchpad scaling is the opposite problem; 2.When the device window.devicePixelRatio is not 1, the size of the rich text node in the exported image will become larger when there are rich text nodes.
## 0.4.0
New: The node supports rich text editing.
## 0.3.4
NewAutomatic line wrapping function is added to node text.
New: Automatic line wrapping function is added to node text.
Fix: 1.Fix the problem of deletion exceptions if there are root nodes in the batch deleted nodes. 2.Fix the problem that high node height will overlap with other nodes in the case of bottom edge style.

View File

@@ -1,10 +1,13 @@
<template>
<div>
<h1>Changelog</h1>
<h2>0.4.1</h2>
<p>New: 1.Add and throw node mouseenter and mouseleave events; 2.Node rich text supports setting background color; 3.Node rich text supports clear style.</p>
<p>Fix: 1.Mac system touchpad scaling is the opposite problem; 2.When the device window.devicePixelRatio is not 1, the size of the rich text node in the exported image will become larger when there are rich text nodes.</p>
<h2>0.4.0</h2>
<p>New: The node supports rich text editing.</p>
<h2>0.3.4</h2>
<p>NewAutomatic line wrapping function is added to node text.</p>
<p>New: Automatic line wrapping function is added to node text.</p>
<p>Fix: 1.Fix the problem of deletion exceptions if there are root nodes in the batch deleted nodes. 2.Fix the problem that high node height will overlap with other nodes in the case of bottom edge style.</p>
<h2>0.3.3</h2>
<p>Fix: The root node text cannot wrap.</p>

View File

@@ -178,6 +178,8 @@ Listen to an event. Event list:
| node_mouseup | Node mouseup event | this (node instance), e (event object) |
| node_dblclick | Node double-click event | this (node instance), e (event object) |
| node_contextmenu | Node right-click menu event | e (event object), this (node instance) |
| node_mouseenterv0.4.1+ | Node mouseenter event | this (node instance), e (event object) |
| node_mouseleavev0.4.1+ | Node mouseleave event | this (node instance), e (event object) |
| before_node_active | Event before node activation | this (node instance), activeNodeList (current list of active nodes) |
| node_active | Node activation event | this (node instance), activeNodeList (current list of active nodes) |
| expand_btn_click | Node expand or collapse event | this (node instance) |

View File

@@ -367,6 +367,16 @@ poor performance and should be used sparingly.</p>
<td>e (event object), this (node instance)</td>
</tr>
<tr>
<td>node_mouseenterv0.4.1+</td>
<td>Node mouseenter event</td>
<td>this (node instance), e (event object)</td>
</tr>
<tr>
<td>node_mouseleavev0.4.1+</td>
<td>Node mouseleave event</td>
<td>this (node instance), e (event object)</td>
</tr>
<tr>
<td>before_node_active</td>
<td>Event before node activation</td>
<td>this (node instance), activeNodeList (current list of active nodes)</td>

View File

@@ -6,7 +6,7 @@
This plugin provides the ability to edit rich text of nodes, and takes effect after registration.
By default, node editing can only uniformly apply styles to all text in the node. This plugin can support rich text editing effects. Currently, it supports bold, italic, underline, strikethrough, font, font size, and color. Underline and line height are not supported.
By default, node editing can only uniformly apply styles to all text in the node. This plugin can support rich text editing effects. Currently, it supports bold, italic, underline, strikethrough, font, font size, color, and backgroundColor. Underline and line height are not supported.
The principle of this plugin is to use [Quill](https://github.com/quilljs/quill) editor implements rich text editing, and then uses the edited `DOM` node directly as the text data of the node, and embeds the `DOM` node through the `svg` `foreignObject` tag during rendering.
@@ -104,6 +104,12 @@ Formats the text of the specified range.
Formats all text of the current edit node.
### removeFormat()
> v0.4.1+
Clears the style of the currently selected text.
### normalStyleToRichTextStyle(style)
Converts a normal node style object to a rich text style object. Because there are differences between node style attributes and rich text style attributes during non-rich text editing, a conversion operation is required. For example:

View File

@@ -8,7 +8,7 @@
<p>Note: This is a testing nature and imperfect function</p>
</blockquote>
<p>This plugin provides the ability to edit rich text of nodes, and takes effect after registration.</p>
<p>By default, node editing can only uniformly apply styles to all text in the node. This plugin can support rich text editing effects. Currently, it supports bold, italic, underline, strikethrough, font, font size, and color. Underline and line height are not supported.</p>
<p>By default, node editing can only uniformly apply styles to all text in the node. This plugin can support rich text editing effects. Currently, it supports bold, italic, underline, strikethrough, font, font size, color, and backgroundColor. Underline and line height are not supported.</p>
<p>The principle of this plugin is to use <a href="https://github.com/quilljs/quill">Quill</a> editor implements rich text editing, and then uses the edited <code>DOM</code> node directly as the text data of the node, and embeds the <code>DOM</code> node through the <code>svg</code> <code>foreignObject</code> tag during rendering.</p>
<p>This also caused a problem, that is, the function of exporting as a picture was affected, The original principle of exporting <code>svg</code> as an image is very simple, Get the <code>svg</code> string, and then create the <code>blob</code> data of the <code>type=image/svg+xml</code> type. Then use the <code>URL.createObjectURL</code> method to generate the <code>data:url</code> data. Then create a <code>Image</code> tag, use the <code>data:url</code> as the <code>src</code> of the image, and finally draw the image on the <code>canvas</code> object for export, However, after testing, when the <code>DOM</code> node is embedded in the <code>svg</code>, this method of export will cause errors, and after trying many ways, the perfect export effect cannot be achieved, The current method is to traverse the <code>foreignObject</code> node in <code>svg</code>, using <a href="https://github.com/niklasvh/html2canvas">html2canvas</a> Convert the <code>DOM</code> node in the <code>foreignObject</code> node into an image and then replace the <code>foreignObject</code> node. This method can work, but it is very time-consuming. Because the <code>html2canvas</code> conversion takes a long time, it takes about 2 seconds to convert a node. This leads to the more nodes, the slower the conversion time. Therefore, it is recommended not to use this plugin if you cannot tolerate the long time of export.</p>
<p>If you have a better way, please leave a message.</p>
@@ -83,6 +83,11 @@ MindMap.usePlugin(RichText, opt?)
<li><code>config</code>Same as <code>formatText</code> method</li>
</ul>
<p>Formats all text of the current edit node.</p>
<h3>removeFormat()</h3>
<blockquote>
<p>v0.4.1+</p>
</blockquote>
<p>Clears the style of the currently selected text.</p>
<h3>normalStyleToRichTextStyle(style)</h3>
<p>Converts a normal node style object to a rich text style object. Because there are differences between node style attributes and rich text style attributes during non-rich text editing, a conversion operation is required. For example:</p>
<pre class="hljs"><code>{

View File

@@ -1,5 +1,11 @@
# Changelog
## 0.4.1
新增1.新增抛出节点鼠标移入和移除事件2.节点富文本支持设置背景颜色3.节点富文本支持清除样式。
修复1.Mac系统触控板缩放相反的问题2.设备window.devicePixelRatio不为1时当存在富文本节点时导出的图片中富文本节点尺寸会变大的问题。
## 0.4.0
新增:节点支持富文本编辑。

View File

@@ -1,6 +1,9 @@
<template>
<div>
<h1>Changelog</h1>
<h2>0.4.1</h2>
<p>新增1.新增抛出节点鼠标移入和移除事件2.节点富文本支持设置背景颜色3.节点富文本支持清除样式</p>
<p>修复1.Mac系统触控板缩放相反的问题2.设备window.devicePixelRatio不为1时当存在富文本节点时导出的图片中富文本节点尺寸会变大的问题</p>
<h2>0.4.0</h2>
<p>新增节点支持富文本编辑</p>
<h2>0.3.4</h2>

View File

@@ -175,6 +175,8 @@ mindMap.setTheme('主题名称')
| node_mouseup | 节点的鼠标松开事件 | this节点实例、e事件对象 |
| node_dblclick | 节点的双击事件 | this节点实例、e事件对象 |
| node_contextmenu | 节点的右键菜单事件 | e事件对象、this节点实例 |
| node_mouseenterv0.4.1+ | 节点的鼠标移入事件 | this节点实例、e事件对象 |
| node_mouseleavev0.4.1+ | 节点的鼠标移出事件 | this节点实例、e事件对象 |
| before_node_active | 节点激活前事件 | this节点实例、activeNodeList当前激活的所有节点列表 |
| node_active | 节点激活事件 | this节点实例、activeNodeList当前激活的所有节点列表 |
| expand_btn_click | 节点展开或收缩事件 | this节点实例 |

View File

@@ -360,6 +360,16 @@ mindMap.setTheme(<span class="hljs-string">&#x27;主题名称&#x27;</span>)
<td>e事件对象this节点实例</td>
</tr>
<tr>
<td>node_mouseenterv0.4.1+</td>
<td>节点的鼠标移入事件</td>
<td>this节点实例e事件对象</td>
</tr>
<tr>
<td>node_mouseleavev0.4.1+</td>
<td>节点的鼠标移出事件</td>
<td>this节点实例e事件对象</td>
</tr>
<tr>
<td>before_node_active</td>
<td>节点激活前事件</td>
<td>this节点实例activeNodeList当前激活的所有节点列表</td>

View File

@@ -6,7 +6,7 @@
该插件提供节点富文本编辑的能力,注册了即可生效。
默认节点编辑只能对节点内所有文本统一应用样式,通过该插件可以支持富文本编辑的效果,目前支持:加粗、斜体、下划线、删除线、字体、字号、颜色。不支持上划线、行高。
默认节点编辑只能对节点内所有文本统一应用样式,通过该插件可以支持富文本编辑的效果,目前支持:加粗、斜体、下划线、删除线、字体、字号、颜色、背景颜色。不支持上划线、行高。
该插件的原理是使用[Quill](https://github.com/quilljs/quill)编辑器实现富文本编辑,然后把编辑后生成的`DOM`节点直接作为节点的文本数据,并且在渲染的时候通过`svg``foreignObject`标签嵌入`DOM`节点。
@@ -104,6 +104,12 @@ MindMap.usePlugin(RichText, opt?)
格式化当前编辑节点的所有文本。
### removeFormat()
> v0.4.1+
清除当前选中文本的样式。
### normalStyleToRichTextStyle(style)
将普通节点样式对象转换成富文本样式对象。因为非富文本编辑时的节点样式属性和富文本样式属性是存在差异的,所以需要一个转换操作。比如:

View File

@@ -8,7 +8,7 @@
<p>注意这是一个测试性质和不完善的功能</p>
</blockquote>
<p>该插件提供节点富文本编辑的能力注册了即可生效</p>
<p>默认节点编辑只能对节点内所有文本统一应用样式通过该插件可以支持富文本编辑的效果目前支持加粗斜体下划线删除线字体字号颜色不支持上划线行高</p>
<p>默认节点编辑只能对节点内所有文本统一应用样式通过该插件可以支持富文本编辑的效果目前支持加粗斜体下划线删除线字体字号颜色背景颜色不支持上划线行高</p>
<p>该插件的原理是使用<a href="https://github.com/quilljs/quill">Quill</a>编辑器实现富文本编辑然后把编辑后生成的<code>DOM</code>节点直接作为节点的文本数据并且在渲染的时候通过<code>svg</code><code>foreignObject</code>标签嵌入<code>DOM</code>节点</p>
<p>这样也造成了一个问题就是导出为图片的功能受到了影响原本将<code>svg</code>导出为图片的原理很简单获取到<code>svg</code>字符串然后创建为<code>type=image/svg+xml</code>类型的<code>blob</code>数据再使用<code>URL.createObjectURL</code>方法生成<code>data:url</code>数据再创建一个<code>Image</code>标签<code>data:url</code>作为该图片的<code>src</code>最后再将这个图片绘制到<code>canvas</code>对象上进行导出但是经过测试<code>svg</code>中嵌入了<code>DOM</code>节点这种方式导出会出错并且尝试了多种方式后都无法实现完美的导出效果目前的方式是遍历<code>svg</code>中的<code>foreignObject</code>节点使用<a href="https://github.com/niklasvh/html2canvas">html2canvas</a><code>foreignObject</code>节点内的<code>DOM</code>节点转换为图片再替换掉<code>foreignObject</code>节点这种方式可以工作但是非常耗时因为<code>html2canvas</code>转换一次的时间很长导致转换一个节点都需要耗时差不多2秒这样导致节点越多转换时间越慢所以如果无法忍受长时间的导出的话推荐不要使用该插件</p>
<p>如果你有更好的方式也欢迎留言</p>
@@ -83,6 +83,11 @@ MindMap.usePlugin(RichText, opt?)
<li><code>config</code><code>formatText</code>方法</li>
</ul>
<p>格式化当前编辑节点的所有文本</p>
<h3>removeFormat()</h3>
<blockquote>
<p>v0.4.1+</p>
</blockquote>
<p>清除当前选中文本的样式</p>
<h3>normalStyleToRichTextStyle(style)</h3>
<p>将普通节点样式对象转换成富文本样式对象因为非富文本编辑时的节点样式属性和富文本样式属性是存在差异的所以需要一个转换操作比如</p>
<pre class="hljs"><code>{

View File

@@ -90,6 +90,23 @@
</div>
</el-popover>
</el-tooltip>
<el-tooltip content="背景颜色" placement="top">
<el-popover placement="bottom" trigger="hover">
<Color :color="fontBackgroundColor" @change="changeFontBackgroundColor"></Color>
<div class="btn" slot="reference">
<span class="icon iconfont iconbeijingyanse"></span>
</div>
</el-popover>
</el-tooltip>
<el-tooltip content="清除样式" placement="top">
<div
class="btn" @click="removeFormat"
>
<span class="icon iconfont iconqingchu"></span>
</div>
</el-tooltip>
</div>
</template>
@@ -116,6 +133,7 @@ export default {
top: 0
},
fontColor: '',
fontBackgroundColor: '',
formatInfo: {}
}
},
@@ -190,6 +208,17 @@ export default {
this.mindMap.richText.formatText({
color
})
},
changeFontBackgroundColor(background) {
this.formatInfo.background = background
this.mindMap.richText.formatText({
background
})
},
removeFormat() {
this.mindMap.richText.removeFormat()
}
}
}