Commit 01df8e56 authored by campaign's avatar campaign

Merge remote-tracking branch 'origin/dev' into dev

parents 88eaa1ba d91df167
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
"console", "console",
"kity", "kity",
"KityMinder", "KityMinder",
"KM",
"Minder", "Minder",
"MinderNode", "MinderNode",
"MinderEvent", "MinderEvent",
"Command", "Command",
"KITYMINDER_CONFIG", "KITYMINDER_CONFIG",
"Utils" "Utils",
"utils"
] ]
} }
\ No newline at end of file
# 导入导出功能设计
## 名词
* 本地格式
指一种公开的脑图编码格式,如 XMind、FreeMind、MinderManager、PDF等。下文代码中,local 表示本地格式字符串或二进制流(Blob)。
* Json格式
指 KityMinder 自身使用的 JS 内存对象,是带数据的树结构。数据结构如下:
```js
// A <MinderNode> is:
{
"data" : {...},
"children" : [<MinderNode>, <MinderNode>, ...]
}
```
下文代码中,json 表示 json 格式字符串。
* 编码
把 Json 格式转换为一种本地格式的过程
* 解码
把一种本地格式解析回 Json 格式的过程
* 协议
协议包含名称(作为标识)、编码方法(encode)、解码方法(decode)、识别判断(recognize)。解码方法是可选项,因为对于某些协议可以只支持导出而不需支持导入(如 PDF )。识别判断也是可选的,识别判断用于快速判断一个字符串或 Blob 是否改协议的本地数据,这个方法用于自动识别未知格式的协议。如果不提供这个方法,那么将不能把未知格式识别为该协议的格式,所以建议提供。
## 协议注册
使用 `KityMinder` 上的静态方法 `registerProtocal()` 来注册协议。
```js
KityMinder.registerProtocal( "xmind", function() {
return {
encode: function( json ) {
// return local;
},
decode: function( local ) {
// return json;
},
recognize: function( local ) {
// return bool;
}
}
});
```
## 协议使用
使用 `KityMinder` 上的静态方法 `findProtocal()` 来获取协议。
```js
var pXMind = KityMinder.findProtocal( "xmind" );
if (pXMind && pXMind.encode) {
local = pXMind.encode( json );
}
```
## 协议枚举
使用 `KityMinder` 上的静态方法 `getSupportedProtocals()` 来获取支持的协议列表。
```js
var supported = KityMinder.getSupportedProtocals();
// supported == [ 'xmind', 'txt', 'pdf', ... ]
```
## 导入导出接口
导入导出接口名称与原来架构的保持一致,只是参数有所调整。
### 导入
```js
minder.importData( local [, protocalName] );
```
导入数据需要提供读取到的本地数据,如果指明协议,则直接用指明的协议来解析;否则尝试去识别本地数据的协议格式。
### 导出
```js
var exported = minder.exportData( [protocalName] );
```
使用指定的协议来导出数据,如果不指定,则导出成 Json 格式。
...@@ -234,15 +234,15 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -234,15 +234,15 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
if ( parent ) { if ( parent ) {
parent.children.push( _tmp ); parent.children.push( _tmp );
} }
for ( var i = 0, ci; ci = isClonedNode.children[ i++ ]; ) { for ( var i = 0, ci;
( ci = isClonedNode.children[ i++ ] ); ) {
cloneNode( _tmp, ci ); cloneNode( _tmp, ci );
} }
return _tmp; return _tmp;
} }
return function () { return function () {
return cloneNode( null, this ); return cloneNode( null, this );
};
}
}(), }(),
equals: function ( node ) { equals: function ( node ) {
if ( node.children.length != this.children.length ) { if ( node.children.length != this.children.length ) {
...@@ -252,7 +252,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -252,7 +252,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return false; return false;
} }
for ( var i = 0, ci; ci = this.children[ i++ ]; ) { for ( var i = 0, ci;
( ci = this.children[ i++ ] ); ) {
if ( ci.equals( node ) === false ) { if ( ci.equals( node ) === false ) {
return false; return false;
} }
...@@ -261,9 +262,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -261,9 +262,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}, },
getTextShape: function () { getTextShape: function () {
return this.getContRc().getShapesByType( 'text' )[ 0 ] return this.getContRc().getShapesByType( 'text' )[ 0 ];
}, },
isSelected: function () { isSelected: function () {
return this.getData( 'highlight' ) === true return this.getData( 'highlight' ) === true;
} }
} ); } );
\ No newline at end of file
...@@ -501,7 +501,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -501,7 +501,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
this.appendChildNode( parent, node, sibling ); this.appendChildNode( parent, node, sibling );
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
console.log( nodes );
while ( nodes.length !== 0 ) { while ( nodes.length !== 0 ) {
var parent = nodes[ 0 ].getParent(); var parent = nodes[ 0 ].getParent();
var nodeLayout = nodes[ 0 ].getData( "layout" ); var nodeLayout = nodes[ 0 ].getData( "layout" );
...@@ -519,10 +518,14 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -519,10 +518,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
var _buffer = [ nodes[ 0 ] ]; var _buffer = [ nodes[ 0 ] ];
while ( _buffer.length !== 0 ) { while ( _buffer.length !== 0 ) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer[ 0 ].getRenderContainer().remove(); try {
var Layout = _buffer[ 0 ].getData( "layout" ); _buffer[ 0 ].getRenderContainer().remove();
Layout.connect.remove(); var Layout = _buffer[ 0 ].getData( "layout" );
Layout.shicon.remove(); Layout.connect.remove();
Layout.shicon.remove();
} catch ( error ) {
console.log( "isRemoved" );
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除 //检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf( _buffer[ 0 ] ); var idx = nodes.indexOf( _buffer[ 0 ] );
if ( idx !== -1 ) { if ( idx !== -1 ) {
...@@ -532,7 +535,33 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -532,7 +535,33 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
} }
}, },
expandNode: function ( node ) { expandNode: function ( ico ) {
var isExpand = ico.icon.switchState();
var node = ico.icon._node;
var _buffer = node.getChildren();
while ( _buffer.length !== 0 ) {
var Layout = _buffer[ 0 ].getData( "layout" );
if ( isExpand ) {
var parent = _buffer[ 0 ].getParent();
minder.appendChildNode( parent, _buffer[ 0 ] );
Layout.connect = null;
Layout.shicon = null;
} else {
_buffer[ 0 ].getRenderContainer().remove();
Layout.connect.remove();
Layout.shicon.remove();
}
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift();
}
var set;
if ( isExpand ) set = updateLayoutVertical( node, node.getParent(), "expand" );
else set = updateLayoutVertical( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
}
} }
}; };
......
...@@ -44,9 +44,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -44,9 +44,9 @@ KityMinder.registerModule( "LayoutModule", function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).updateLayout.call( this, node ); this.getLayoutStyle( curStyle ).updateLayout.call( this, node );
}, },
expandNode: function ( node ) { expandNode: function ( ico ) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).expandNode.call( this, node ); this.getLayoutStyle( curStyle ).expandNode.call( this, ico );
} }
} ); } );
kity.extendClass( MinderNode, { kity.extendClass( MinderNode, {
...@@ -162,7 +162,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -162,7 +162,7 @@ KityMinder.registerModule( "LayoutModule", function () {
"click": function ( e ) { "click": function ( e ) {
var ico = e.kityEvent.targetShape.container; var ico = e.kityEvent.targetShape.container;
if ( ico.class === "shicon" ) { if ( ico.class === "shicon" ) {
this.expandNode( ico.icon._node ); this.expandNode( ico );
} }
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment