Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
01df8e56
Commit
01df8e56
authored
Feb 12, 2014
by
campaign
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
88eaa1ba
d91df167
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
143 additions
and
16 deletions
+143
-16
.jshintrc
.jshintrc
+3
-1
Import Export.md
doc/Import Export.md
+95
-0
node.js
src/core/node.js
+7
-6
layout.default.js
src/module/layout.default.js
+35
-6
layout.js
src/module/layout.js
+3
-3
No files found.
.jshintrc
View file @
01df8e56
...
...
@@ -12,11 +12,13 @@
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"Utils"
"Utils",
"utils"
]
}
\ No newline at end of file
doc/Import Export.md
0 → 100644
View file @
01df8e56
# 导入导出功能设计
## 名词
*
本地格式
指一种公开的脑图编码格式,如 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 格式。
src/core/node.js
View file @
01df8e56
...
...
@@ -234,15 +234,15 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
if
(
parent
)
{
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
);
}
return
_tmp
;
}
return
function
()
{
return
cloneNode
(
null
,
this
);
}
};
}(),
equals
:
function
(
node
)
{
if
(
node
.
children
.
length
!=
this
.
children
.
length
)
{
...
...
@@ -252,7 +252,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
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
)
{
return
false
;
}
...
...
@@ -261,9 +262,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
},
getTextShape
:
function
()
{
return
this
.
getContRc
().
getShapesByType
(
'text'
)[
0
]
return
this
.
getContRc
().
getShapesByType
(
'text'
)[
0
]
;
},
isSelected
:
function
()
{
return
this
.
getData
(
'highlight'
)
===
true
return
this
.
getData
(
'highlight'
)
===
true
;
}
}
);
\ No newline at end of file
src/module/layout.default.js
View file @
01df8e56
...
...
@@ -501,7 +501,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
this
.
appendChildNode
(
parent
,
node
,
sibling
);
},
removeNode
:
function
(
nodes
)
{
console
.
log
(
nodes
);
while
(
nodes
.
length
!==
0
)
{
var
parent
=
nodes
[
0
].
getParent
();
var
nodeLayout
=
nodes
[
0
].
getData
(
"layout"
);
...
...
@@ -519,10 +518,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
_buffer
=
[
nodes
[
0
]
];
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
[
0
].
getRenderContainer
().
remove
();
var
Layout
=
_buffer
[
0
].
getData
(
"layout"
);
Layout
.
connect
.
remove
();
Layout
.
shicon
.
remove
();
try
{
_buffer
[
0
].
getRenderContainer
().
remove
();
var
Layout
=
_buffer
[
0
].
getData
(
"layout"
);
Layout
.
connect
.
remove
();
Layout
.
shicon
.
remove
();
}
catch
(
error
)
{
console
.
log
(
"isRemoved"
);
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var
idx
=
nodes
.
indexOf
(
_buffer
[
0
]
);
if
(
idx
!==
-
1
)
{
...
...
@@ -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
]
);
}
}
};
...
...
src/module/layout.js
View file @
01df8e56
...
...
@@ -44,9 +44,9 @@ KityMinder.registerModule( "LayoutModule", function () {
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
updateLayout
.
call
(
this
,
node
);
},
expandNode
:
function
(
node
)
{
expandNode
:
function
(
ico
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
expandNode
.
call
(
this
,
node
);
this
.
getLayoutStyle
(
curStyle
).
expandNode
.
call
(
this
,
ico
);
}
}
);
kity
.
extendClass
(
MinderNode
,
{
...
...
@@ -162,7 +162,7 @@ KityMinder.registerModule( "LayoutModule", function () {
"click"
:
function
(
e
)
{
var
ico
=
e
.
kityEvent
.
targetShape
.
container
;
if
(
ico
.
class
===
"shicon"
)
{
this
.
expandNode
(
ico
.
icon
.
_node
);
this
.
expandNode
(
ico
);
}
}
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment