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
a876ca99
Commit
a876ca99
authored
Feb 22, 2014
by
techird
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of github.com:kitygraph/kityminder into dev
parents
df63a21c
b88ee449
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
557 additions
and
200 deletions
+557
-200
configure.js
configure.js
+15
-15
dev.php
dist/dev.php
+2
-0
zh-cn.js
lang/zh-cn/zh-cn.js
+7
-6
combobox.js
src/adapter/combobox.js
+2
-24
layout.js
src/adapter/layout.js
+46
-0
node.js
src/adapter/node.js
+16
-17
saveto.js
src/adapter/saveto.js
+47
-0
minder.js
src/core/minder.js
+7
-0
dragtree.js
src/module/dragtree.js
+1
-1
editor.js
src/module/editor.js
+40
-9
editor.range.js
src/module/editor.range.js
+6
-1
editor.receiver.js
src/module/editor.receiver.js
+8
-3
editor.selection.js
src/module/editor.selection.js
+15
-8
layout.bottom.js
src/module/layout.bottom.js
+207
-86
layout.js
src/module/layout.js
+13
-15
select.js
src/module/select.js
+6
-4
png.js
src/protocal/png.js
+102
-0
combobox.js
src/ui/combobox.js
+17
-11
No files found.
configure.js
View file @
a876ca99
(
function
()
{
function
getKMBasePath
(
docUrl
,
confUrl
)
{
(
function
()
{
function
getKMBasePath
(
docUrl
,
confUrl
)
{
return
getBasePath
(
docUrl
||
self
.
document
.
URL
||
self
.
location
.
href
,
confUrl
||
getConfigFilePath
()
);
}
function
getConfigFilePath
()
{
function
getConfigFilePath
()
{
var
configPath
=
document
.
getElementsByTagName
(
'script'
);
var
configPath
=
document
.
getElementsByTagName
(
'script'
);
return
configPath
[
configPath
.
length
-
1
].
src
;
return
configPath
[
configPath
.
length
-
1
].
src
;
}
function
getBasePath
(
docUrl
,
confUrl
)
{
function
getBasePath
(
docUrl
,
confUrl
)
{
var
basePath
=
confUrl
;
if
(
/^
(\/
|
\\\\)
/
.
test
(
confUrl
))
{
if
(
/^
(\/
|
\\\\)
/
.
test
(
confUrl
)
)
{
basePath
=
/^.+
?\w(\/
|
\\\\)
/
.
exec
(
docUrl
)[
0
]
+
confUrl
.
replace
(
/^
(\/
|
\\\\)
/
,
''
);
basePath
=
/^.+
?\w(\/
|
\\\\)
/
.
exec
(
docUrl
)[
0
]
+
confUrl
.
replace
(
/^
(\/
|
\\\\)
/
,
''
);
}
else
if
(
!
/^
[
a-z
]
+:/i
.
test
(
confUrl
)
)
{
}
else
if
(
!
/^
[
a-z
]
+:/i
.
test
(
confUrl
)
)
{
docUrl
=
docUrl
.
split
(
"#"
)[
0
].
split
(
"?"
)[
0
].
replace
(
/
[^\\\/]
+$/
,
''
);
docUrl
=
docUrl
.
split
(
"#"
)[
0
].
split
(
"?"
)[
0
].
replace
(
/
[^\\\/]
+$/
,
''
);
basePath
=
docUrl
+
""
+
confUrl
;
...
...
@@ -34,15 +34,15 @@
}
function
optimizationPath
(
path
)
{
function
optimizationPath
(
path
)
{
var
protocol
=
/^
[
a-z
]
+:
\/\/
/
.
exec
(
path
)[
0
],
tmp
=
null
,
res
=
[];
path
=
path
.
replace
(
protocol
,
""
).
split
(
"?"
)[
0
].
split
(
"#"
)[
0
];
path
=
path
.
replace
(
protocol
,
""
).
split
(
"?"
)[
0
].
split
(
"#"
)[
0
];
path
=
path
.
replace
(
/
\\
/g
,
'/'
).
split
(
/
\/
/
);
path
=
path
.
replace
(
/
\\
/g
,
'/'
).
split
(
/
\/
/
);
path
[
path
.
length
-
1
]
=
""
;
...
...
@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL'
:
getKMBasePath
(),
//定义工具栏
toolbars
:
[
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node'
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node
| switchlayout
'
]
//设置主题
...
...
@@ -79,4 +79,4 @@
//设置km整体的z-index大小
//,zIndex : 1000
};
})()
}
)()
\ No newline at end of file
dist/dev.php
View file @
a876ca99
...
...
@@ -62,9 +62,11 @@ $dependency = Array(
,
'src/adapter/view.js'
,
'src/adapter/dialog.js'
,
'src/adapter/tooltips.js'
,
'src/adapter/layout.js'
,
'src/adapter/node.js'
,
'src/protocal/plain.js'
,
'src/protocal/json.js'
,
'src/protocal/png.js'
);
$content
=
""
;
...
...
lang/zh-cn/zh-cn.js
View file @
a876ca99
...
...
@@ -10,12 +10,13 @@ KityMinder.LANG[ 'zh-cn' ] = {
'fontfamily'
:
'字体'
,
'fontsize'
:
'字号'
,
'layoutstyle'
:
'主题'
,
'node'
:
'节点操作'
,
'node'
:
'节点操作'
,
'saveto'
:
'导出'
,
'hand'
:
'允许拖拽'
,
'zoom-in'
:
'放大'
,
'zoom-out'
:
'缩小'
,
'markers'
:
'添加标签'
'markers'
:
'添加标签'
,
'switchlayout'
:
'切换主题'
},
'popupcolor'
:
{
'clearColor'
:
'清空颜色'
,
...
...
@@ -40,10 +41,10 @@ KityMinder.LANG[ 'zh-cn' ] = {
}
}
},
'node'
:{
'appendsiblingnode'
:
'插入兄弟节点'
,
'appendchildnode'
:
'插入孩子节点'
,
'removenode'
:
'删除节点'
'node'
:
{
'appendsiblingnode'
:
'插入兄弟节点'
,
'appendchildnode'
:
'插入孩子节点'
,
'removenode'
:
'删除节点'
}
};
\ No newline at end of file
src/adapter/combobox.js
View file @
a876ca99
KM
.
registerToolbarUI
(
'
layoutstyle fontfamily fontsize inserttopic
'
,
function
(
name
)
{
KM
.
registerToolbarUI
(
'
fontfamily fontsize
'
,
function
(
name
)
{
var
me
=
this
,
label
=
me
.
getLang
(
'tooltips.'
+
name
),
...
...
@@ -19,9 +19,7 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
}
switch
(
name
)
{
case
'layoutstyle'
:
options
=
transForLayoutstyle
(
options
);
break
;
case
'fontfamily'
:
options
=
transForFontfamily
(
options
);
...
...
@@ -31,8 +29,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
options
=
transForFontsize
(
options
);
break
;
case
'inserttopic'
:
optons
}
//实例化
...
...
@@ -64,24 +60,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
return
comboboxWidget
.
button
().
addClass
(
'kmui-combobox'
);
function
transForLayoutstyle
(
options
)
{
var
tempItems
=
[];
utils
.
each
(
options
.
items
,
function
(
k
,
v
)
{
options
.
value
.
push
(
k
);
tempItems
.
push
(
k
);
options
.
autowidthitem
.
push
(
$
.
wordCountAdaptive
(
tempItems
[
tempItems
.
length
-
1
]
)
);
}
);
options
.
items
=
tempItems
;
return
options
;
}
//字体参数转换
function
transForFontfamily
(
options
)
{
...
...
src/adapter/layout.js
0 → 100644
View file @
a876ca99
KM
.
registerToolbarUI
(
'switchlayout'
,
function
(
name
)
{
var
me
=
this
,
label
=
me
.
getLang
(
'tooltips.'
+
name
),
options
=
{
label
:
label
,
title
:
label
,
comboboxName
:
name
,
items
:
me
.
getLayoutStyleItems
()
||
[],
itemStyles
:
[],
value
:
me
.
getLayoutStyleItems
(),
autowidthitem
:
[],
enabledRecord
:
false
},
$combox
=
null
;
if
(
options
.
items
.
length
==
0
)
{
return
null
;
}
//实例化
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
me
.
execCommand
(
name
,
res
.
value
);
}
).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
}
}
);
//状态反射
me
.
on
(
'interactchange'
,
function
()
{
var
state
=
this
.
queryCommandState
(
name
),
value
=
this
.
queryCommandValue
(
name
);
//设置按钮状态
comboboxWidget
.
button
().
kmui
().
disabled
(
state
==
-
1
).
active
(
state
==
1
);
if
(
value
)
{
//设置label
value
=
value
.
replace
(
/
[
'"
]
/g
,
''
).
toLowerCase
().
split
(
/
[
'|"
]?\s
*,
\s
*
[\1]?
/
);
comboboxWidget
.
selectItemByLabel
(
value
);
}
}
);
return
comboboxWidget
.
button
().
addClass
(
'kmui-combobox'
);
}
);
\ No newline at end of file
src/adapter/node.js
View file @
a876ca99
KM
.
registerToolbarUI
(
'node'
,
function
(
name
)
{
var
shortcutKeys
=
{
var
shortcutKeys
=
{
"appendsiblingnode"
:
"enter"
,
"appendchildnode"
:
"tab"
,
"removenode"
:
"del|backspace"
"removenode"
:
"del|backspace"
};
var
me
=
this
,
msg
=
me
.
getLang
(
'node'
),
msg
=
me
.
getLang
(
'node'
),
label
=
me
.
getLang
(
'tooltips.'
+
name
),
options
=
{
label
:
label
,
...
...
@@ -15,10 +15,10 @@ KM.registerToolbarUI( 'node', function ( name ) {
items
:
me
.
getOptions
(
name
)
||
[],
itemStyles
:
[],
value
:
[],
autowidthitem
:
[]
autowidthitem
:
[],
enabledRecord
:
false
},
$combox
=
null
;
if
(
options
.
items
.
length
==
0
)
{
return
null
;
}
...
...
@@ -28,21 +28,21 @@ KM.registerToolbarUI( 'node', function ( name ) {
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
me
.
execCommand
(
res
.
value
);
}).
on
(
"beforeshow"
,
function
()
{
me
.
execCommand
(
res
.
value
,
new
MinderNode
(
me
.
getLang
().
topic
)
);
}
).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
}
var
combox
=
$combox
.
kmui
();
combox
.
traverseItems
(
function
(
label
,
value
)
{
if
(
me
.
queryCommandState
(
value
)
==
-
1
)
{
combox
.
disableItemByLabel
(
label
)
}
else
{
combox
.
enableItemByLabel
(
label
)
combox
.
traverseItems
(
function
(
label
,
value
)
{
if
(
me
.
queryCommandState
(
value
)
==
-
1
)
{
combox
.
disableItemByLabel
(
label
)
}
else
{
combox
.
enableItemByLabel
(
label
)
}
})
});
}
)
}
);
return
comboboxWidget
.
button
().
addClass
(
'kmui-combobox'
);
...
...
@@ -55,7 +55,7 @@ KM.registerToolbarUI( 'node', function ( name ) {
utils
.
each
(
options
.
items
,
function
(
k
,
v
)
{
options
.
value
.
push
(
v
);
tempItems
.
push
(
(
msg
[
k
]
||
k
)
+
'('
+
shortcutKeys
[
v
].
toUpperCase
()
+
')'
);
tempItems
.
push
(
(
msg
[
k
]
||
k
)
+
'('
+
shortcutKeys
[
v
].
toUpperCase
()
+
')'
);
options
.
autowidthitem
.
push
(
$
.
wordCountAdaptive
(
tempItems
[
tempItems
.
length
-
1
]
)
);
}
);
...
...
@@ -64,5 +64,4 @@ KM.registerToolbarUI( 'node', function ( name ) {
}
});
}
);
\ No newline at end of file
src/adapter/saveto.js
View file @
a876ca99
...
...
@@ -30,6 +30,53 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
if
(
res
.
value
===
"png"
)
{
var
svghtml
=
$
(
"#kityminder .kmui-editor-body"
).
html
();
var
rootBox
=
me
.
getRoot
().
getRenderContainer
().
getRenderBox
();
var
svg
=
$
(
svghtml
).
attr
(
{
width
:
rootBox
.
x
+
me
.
getRenderContainer
().
getWidth
()
+
20
,
height
:
rootBox
.
y
+
me
.
getRenderContainer
().
getHeight
()
+
20
,
viewBox
:
null
}
);
var
div
=
$
(
"<div></div>"
).
append
(
svg
);
svghtml
=
div
.
html
();
var
canvas
=
$
(
'<canvas style="border:2px solid black;" width="'
+
svg
.
attr
(
"width"
)
+
'" height="'
+
svg
.
attr
(
"height"
)
+
'"></canvas>'
);
var
ctx
=
canvas
[
0
].
getContext
(
"2d"
);
var
DOMURL
=
self
.
URL
||
self
.
webkitURL
||
self
;
var
img
=
new
Image
();
var
svg
=
new
Blob
(
[
svghtml
],
{
type
:
"image/svg+xml;charset=utf-8"
}
);
var
url
=
DOMURL
.
createObjectURL
(
svg
);
img
.
onload
=
function
()
{
ctx
.
drawImage
(
img
,
0
,
0
);
DOMURL
.
revokeObjectURL
(
url
);
var
type
=
'png'
;
var
imgData
=
canvas
[
0
].
toDataURL
(
type
);
var
_fixType
=
function
(
type
)
{
type
=
type
.
toLowerCase
().
replace
(
/jpg/i
,
'jpeg'
);
var
r
=
type
.
match
(
/png|jpeg|bmp|gif/
)[
0
];
return
'image/'
+
r
;
};
imgData
=
imgData
.
replace
(
_fixType
(
type
),
'image/octet-stream'
);
var
saveFile
=
function
(
data
,
filename
)
{
var
save_link
=
document
.
createElementNS
(
'http://www.w3.org/1999/xhtml'
,
'a'
);
save_link
.
href
=
data
;
save_link
.
download
=
filename
;
var
event
=
document
.
createEvent
(
'MouseEvents'
);
event
.
initMouseEvent
(
'click'
,
true
,
false
,
window
,
0
,
0
,
0
,
0
,
0
,
false
,
false
,
false
,
false
,
0
,
null
);
save_link
.
dispatchEvent
(
event
);
};
// 下载后的问题名
var
filename
=
'kityminder_'
+
(
new
Date
()
).
getTime
()
+
'.'
+
type
;
// download
saveFile
(
imgData
,
filename
);
};
img
.
src
=
url
;
return
"png"
;
}
var
data
=
me
.
exportData
(
res
.
value
);
var
p
=
KityMinder
.
findProtocal
(
res
.
value
);
var
a
=
downloadLink
;
...
...
src/core/minder.js
View file @
a876ca99
...
...
@@ -69,6 +69,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this
.
_shortcutkeys
=
{};
this
.
_bindshortcutKeys
();
},
isTextEditStatus
:
function
(){
return
false
;
},
addShortcutKeys
:
function
(
cmd
,
keys
)
{
var
obj
=
{},
km
=
this
;
if
(
keys
)
{
...
...
@@ -122,6 +125,10 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
current
++
;
}
});
//todo 暂时通过receiver判断
if
(
me
.
isTextEditStatus
()){
return
;
}
if
(
current
==
keys
.
length
){
if
(
me
.
queryCommandState
(
i
)
!=
-
1
)
me
.
execCommand
(
i
);
...
...
src/module/dragtree.js
View file @
a876ca99
...
...
@@ -32,7 +32,7 @@ var MoveToParentCommand = kity.createClass( 'MoveToParentCommand', {
function
boxMapper
(
node
)
{
return
node
.
getRenderContainer
().
getRenderBox
();
return
node
.
getRenderContainer
().
getRenderBox
(
'top'
);
}
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
...
...
src/module/editor.js
View file @
a876ca99
...
...
@@ -14,6 +14,12 @@ KityMinder.registerModule( "TextEditModule", function () {
km
.
isTextEditStatus
=
function
(){
return
km
.
receiver
.
isTextEditStatus
();
};
var
selectionByClick
=
false
;
return
{
//插入光标
"init"
:
function
(){
...
...
@@ -23,12 +29,19 @@ KityMinder.registerModule( "TextEditModule", function () {
'beforemousedown'
:
function
(
e
){
sel
.
setHide
();
var
node
=
e
.
getTargetNode
();
if
(
!
node
){
var
selectionShape
=
e
.
kityEvent
.
targetShape
;
if
(
selectionShape
&&
selectionShape
.
getType
()
==
'Selection'
){
selectionByClick
=
true
;
node
=
selectionShape
.
getData
(
'relatedNode'
);
e
.
stopPropagationImmediately
();
}
}
if
(
node
){
var
textShape
=
node
.
getTextShape
();
textShape
.
setStyle
(
'cursor'
,
'default'
);
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
()
&&
e
.
kityEvent
.
targetShape
.
getType
().
toLowerCase
()
==
'text'
)
{
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
())
{
// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel
.
collapse
();
node
.
getTextShape
().
setStyle
(
'cursor'
,
'text'
);
receiver
.
setTextEditStatus
(
true
)
...
...
@@ -42,27 +55,44 @@ KityMinder.registerModule( "TextEditModule", function () {
.
setCurrentIndex
(
e
.
getPosition
())
.
updateSelection
()
.
setRange
(
range
);
sel
.
setData
(
'relatedNode'
,
node
);
mouseDownStatus
=
true
;
lastEvtPosition
=
e
.
getPosition
();
if
(
selectionByClick
){
sel
.
setShow
();
selectionByClick
=
false
;
}
}
}
},
'mouseup'
:
function
(
e
){
if
(
!
sel
.
collapsed
&&
mouseDownStatus
){
receiver
.
updateRange
(
range
)
if
(
mouseDownStatus
){
if
(
!
sel
.
collapsed
){
receiver
.
updateRange
(
range
)
}
else
sel
.
setShow
()
}
mouseDownStatus
=
false
;
oneTime
=
0
;
},
'beforemousemove'
:
function
(
e
){
if
(
mouseDownStatus
){
e
.
stopPropagationImmediately
();
var
offset
=
e
.
getPosition
();
if
(
Math
.
abs
(
offset
.
y
-
lastEvtPosition
.
y
)
>
2
&&
Math
.
abs
(
lastEvtPosition
.
x
-
offset
.
x
)
<
1
){
sel
.
setHide
();
mouseDownStatus
=
false
;
return
;
}
dir
=
offset
.
x
>
lastEvtPosition
.
x
?
1
:
(
offset
.
x
<
lastEvtPosition
.
x
?
-
1
:
dir
);
receiver
.
updateSelectionByMousePosition
(
offset
,
dir
)
.
updateSelectionShow
(
dir
);
sel
.
stroke
(
'none'
,
0
);
lastEvtPosition
=
e
.
getPosition
();
}
},
'dblclick'
:
function
(
e
){
...
...
@@ -73,8 +103,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel
.
setStartOffset
(
0
);
sel
.
setEndOffset
(
text
.
getContent
().
length
);
sel
.
setShow
();
receiver
.
updateSelectionShow
(
1
)
.
updateRange
(
range
)
;
receiver
.
setContainerTxt
(
text
.
getContent
()).
updateSelectionShow
(
1
)
.
updateRange
(
range
)
.
setTextEditStatus
(
true
)
}
},
...
...
@@ -117,7 +147,7 @@ KityMinder.registerModule( "TextEditModule", function () {
receiver
.
updateSelectionShow
(
1
)
.
updateRange
(
range
);
return
;
}
...
...
@@ -130,10 +160,11 @@ KityMinder.registerModule( "TextEditModule", function () {
}
else
{
receiver
.
updateSelectionShow
(
1
)
}
return
;
}
receiver
.
clear
().
setTextEditStatus
(
false
);
},
'selectionclear'
:
function
(){
receiver
.
setTextEditStatus
(
false
).
clear
()
...
...
src/module/editor.range.js
View file @
a876ca99
...
...
@@ -16,7 +16,12 @@ Minder.Range = kity.createClass('Range',{
return
this
;
},
setStart
:
function
(
node
,
index
){
this
.
nativeRange
.
setStart
(
node
,
index
);
try
{
this
.
nativeRange
.
setStart
(
node
,
index
);
}
catch
(
e
){
console
.
log
(
e
)
}
return
this
;
},
setEnd
:
function
(
node
,
index
){
...
...
src/module/editor.receiver.js
View file @
a876ca99
...
...
@@ -223,16 +223,17 @@ Minder.Receiver = kity.createClass('Receiver',{
return
false
;
}
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
){
if
(
me
.
index
==
i
){
if
(
i
==
0
){
me
.
selection
.
setStartOffset
(
i
)
}
me
.
selection
.
setEndOffset
(
i
+
(
dir
==
1
?
1
:
0
))
}
else
if
(
i
>
me
.
index
){
me
.
selection
.
setStartOffset
(
me
.
index
);
me
.
selection
.
setEndOffset
(
i
+
(
dir
==
1
?
1
:
0
))
}
else
{
me
.
selection
.
setStartOffset
(
i
+
(
dir
==
1
?
1
:
0
))
me
.
selection
.
setStartOffset
(
i
+
(
dir
==
1
?
1
:
0
));
me
.
selection
.
setEndOffset
(
me
.
index
)
}
return
false
;
...
...
@@ -246,7 +247,7 @@ Minder.Receiver = kity.createClass('Receiver',{
width
=
0
;
if
(
this
.
selection
.
collapsed
){
this
.
selection
.
updateShow
(
startOffset
,
0
);
this
.
selection
.
updateShow
(
startOffset
||
this
.
textData
[
this
.
textData
.
length
-
1
]
,
0
);
return
this
;
}
if
(
!
endOffset
){
...
...
@@ -269,5 +270,9 @@ Minder.Receiver = kity.createClass('Receiver',{
setIndex
:
function
(
index
){
this
.
index
=
index
;
return
this
},
setContainerTxt
:
function
(
txt
){
this
.
container
.
textContent
=
txt
;
return
this
;
}
});
\ No newline at end of file
src/module/editor.selection.js
View file @
a876ca99
...
...
@@ -5,18 +5,20 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
callBase
();
this
.
height
=
height
||
20
;
this
.
stroke
(
color
||
'
blue
'
,
width
||
1
);
this
.
width
=
1
;
this
.
fill
(
'
#99C8FF
'
);
this
.
stroke
(
color
||
'
rgb(27,171,255)
'
,
width
||
1
);
this
.
width
=
0
;
this
.
fill
(
'
rgb(27,171,255)
'
);
this
.
setHide
();
this
.
timer
=
null
;
this
.
collapsed
=
true
;
this
.
startOffset
=
this
.
endOffset
=
0
;
this
.
setOpacity
(
0.5
)
this
.
setOpacity
(
0.5
);
this
.
setStyle
(
'cursor'
,
'text'
);
},
collapse
:
function
(
toEnd
){
this
.
stroke
(
'blue'
,
1
);
this
.
stroke
(
'rgb(27,171,255)'
,
1
);
this
.
setOpacity
(
1
);
this
.
width
=
1
;
this
.
collapsed
=
true
;
if
(
toEnd
){
...
...
@@ -37,7 +39,8 @@ Minder.Selection = kity.createClass( 'Selection', {
return
this
;
}
this
.
collapsed
=
false
;
this
.
stroke
(
'none'
);
this
.
stroke
(
'none'
,
0
);
this
.
setOpacity
(
0.5
);
return
this
;
},
setEndOffset
:
function
(
offset
){
...
...
@@ -51,10 +54,14 @@ Minder.Selection = kity.createClass( 'Selection', {
return
this
;
}
this
.
collapsed
=
false
;
this
.
stroke
(
'none'
);
this
.
stroke
(
'none'
,
0
);
this
.
setOpacity
(
0.5
);
return
this
;
},
updateShow
:
function
(
offset
,
width
){
if
(
width
){
this
.
setShowHold
();
}
this
.
setPosition
(
offset
).
setWidth
(
width
);
return
this
;
},
...
...
@@ -64,7 +71,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
y
=
offset
.
y
;
}
catch
(
e
)
{
console
.
log
(
e
)
debugger
}
return
this
.
update
();
...
...
src/module/layout.bottom.js
View file @
a876ca99
...
...
@@ -17,21 +17,24 @@ KityMinder.registerModule( "LayoutBottom", function () {
var
iconShape
=
this
.
shape
=
new
kity
.
Group
();
iconShape
.
class
=
"shicon"
;
iconShape
.
icon
=
this
;
var
circle
=
this
.
_circle
=
new
kity
.
Circle
().
fill
(
"white"
).
stroke
(
"gray"
).
setRadius
(
5
);
var
rect
=
this
.
_rect
=
new
kity
.
Rect
().
fill
(
"white"
).
stroke
(
"gray"
).
setRadius
(
2
).
setWidth
(
10
).
setHeight
(
10
);
var
plus
=
this
.
_plus
=
new
kity
.
Path
();
plus
.
getDrawer
()
.
moveTo
(
-
3
,
0
)
.
lineTo
(
3
,
0
)
.
moveTo
(
0
,
-
3
)
.
lineTo
(
0
,
3
);
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
)
.
moveTo
(
5
,
2
)
.
lineTo
(
5
,
8
);
plus
.
stroke
(
"gray"
);
var
dec
=
this
.
_dec
=
new
kity
.
Path
();
dec
.
getDrawer
()
.
moveTo
(
-
3
,
0
)
.
lineTo
(
3
,
0
);
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
);
dec
.
stroke
(
"gray"
);
minder
.
getRenderContainer
().
addShape
(
iconShape
);
iconShape
.
addShapes
(
[
circle
,
plus
,
dec
]
);
if
(
node
.
getType
()
===
"main"
)
minder
.
getRenderContainer
().
addShape
(
iconShape
);
else
{
node
.
getLayout
().
subgroup
.
addShape
(
iconShape
);
}
iconShape
.
addShapes
(
[
rect
,
plus
,
dec
]
);
this
.
update
();
this
.
switchState
();
},
...
...
@@ -51,7 +54,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
var
node
=
this
.
_node
;
var
Layout
=
node
.
getLayout
();
var
nodeShape
=
node
.
getRenderContainer
();
var
nodeX
=
nodeShape
.
getRenderBox
().
closurePoints
[
1
].
x
+
10
;
var
nodeType
=
node
.
getType
();
var
nodeX
=
nodeShape
.
getRenderBox
().
closurePoints
[
1
].
x
+
5
;
var
nodeY
=
nodeShape
.
getRenderBox
().
closurePoints
[
0
].
y
;
this
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
nodeX
,
nodeY
)
);
},
...
...
@@ -60,16 +64,6 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
};
}
)()
);
//求并集
var
uSet
=
function
(
a
,
b
)
{
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
var
idx
=
b
.
indexOf
(
a
[
i
]
);
if
(
idx
!==
-
1
)
{
b
.
splice
(
idx
,
1
);
}
}
return
a
.
concat
(
b
);
};
//样式的配置(包括颜色、字号等)
var
nodeStyles
=
{
"root"
:
{
...
...
@@ -77,8 +71,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
fill
:
'#e9df98'
,
fontSize
:
24
,
padding
:
[
15.5
,
25.5
,
15.5
,
25.5
],
margin
:
[
0
,
0
,
0
,
0
],
radius
:
1
0
,
margin
:
[
0
,
0
,
2
0
,
0
],
radius
:
0
,
highlight
:
'rgb(254, 219, 0)'
},
"main"
:
{
...
...
@@ -87,17 +81,18 @@ KityMinder.registerModule( "LayoutBottom", function () {
color
:
"#333"
,
padding
:
[
6.5
,
20
,
6.5
,
20
],
fontSize
:
16
,
margin
:
[
20
,
1
0
,
10
,
10
],
radius
:
5
,
margin
:
[
20
,
2
0
,
10
,
10
],
radius
:
0
,
highlight
:
'rgb(254, 219, 0)'
},
"sub"
:
{
stroke
:
new
kity
.
Pen
(
"white"
,
2
).
setLineCap
(
"round"
).
setLineJoin
(
"round"
),
color
:
"
white
"
,
color
:
"
#333
"
,
fontSize
:
12
,
margin
:
[
10
,
10
,
20
,
6
],
margin
:
[
10
,
10
,
10
,
30
],
padding
:
[
5
,
10
,
5.5
,
10
],
highlight
:
'rgb(254, 219, 0)'
highlight
:
'rgb(254, 219, 0)'
,
fill
:
'rgb(231, 243, 255)'
}
};
//更新背景
...
...
@@ -115,9 +110,9 @@ KityMinder.registerModule( "LayoutBottom", function () {
Layout
.
bgShadow
.
fill
(
'black'
).
setOpacity
(
0.2
).
setRadius
(
nodeStyle
.
radius
).
translate
(
3
,
5
);
break
;
case
"sub"
:
var
underline
=
Layout
.
underline
=
new
kity
.
Path
();
var
highlightshape
=
Layout
.
highlightshape
=
new
kity
.
Rect
().
setRadius
(
4
);
node
.
getBgRc
().
clear
().
addShapes
(
[
Layout
.
bgRect
=
new
kity
.
Rect
().
setRadius
(
4
),
highlightshape
,
underline
]
);
var
bgRc
=
node
.
getBgRc
().
clear
();
bgRc
.
addShape
(
Layout
.
bgRect
=
new
kity
.
Rect
()
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
break
;
default
:
break
;
...
...
@@ -152,18 +147,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
Layout
.
bgShadow
.
setWidth
(
width
).
setHeight
(
height
);
break
;
case
"sub"
:
var
_contWidth
=
contRc
.
getWidth
();
var
_contHeight
=
contRc
.
getHeight
();
width
=
_contWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
];
height
=
_contHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
underline
.
getDrawer
()
.
clear
()
.
moveTo
(
0
,
_contHeight
+
nodeStyle
.
padding
[
2
]
+
nodeStyle
.
padding
[
0
]
)
.
lineTo
(
_contWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
],
_contHeight
+
nodeStyle
.
padding
[
2
]
+
nodeStyle
.
padding
[
0
]
);
Layout
.
underline
.
stroke
(
nodeStyle
.
stroke
);
Layout
.
highlightshape
.
setWidth
(
_contWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
]
)
.
setHeight
(
_contHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
]
);
width
=
_contRCWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
];
height
=
_contRCHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
bgRect
.
setWidth
(
width
).
setHeight
(
height
);
break
;
default
:
...
...
@@ -171,21 +156,35 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
contRc
.
setTransform
(
new
kity
.
Matrix
().
translate
(
nodeStyle
.
padding
[
3
],
nodeStyle
.
padding
[
0
]
+
node
.
getTextShape
().
getHeight
()
)
);
};
var
updateLayoutAll
=
function
(
node
,
parent
,
action
)
{
var
effectSet
=
[];
var
nodeType
=
node
.
getType
();
var
Layout
=
node
.
getLayout
();
var
updateLayoutMain
=
function
()
{
var
_root
=
minder
.
getRoot
();
var
mainnodes
=
_root
.
getChildren
();
var
countMainWidth
=
function
(
node
)
{
var
nLayout
=
node
.
getLayout
();
var
selfwidth
=
node
.
getRenderContainer
().
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
main
.
margin
[
3
];
var
childwidth
=
Layout
.
subgroup
.
getWidth
()
+
nodeStyles
.
sub
.
margin
[
3
];
var
childwidth
=
nLayout
.
subgroup
.
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
sub
.
margin
[
3
];
var
branchwidth
=
nLayout
.
branchwidth
=
(
selfwidth
>
childwidth
?
selfwidth
:
childwidth
);
return
branchwidth
;
};
var
updateMain
=
function
(
node
)
{
};
var
rootLayout
=
_root
.
getLayout
();
var
rootbranchwidth
=
0
;
for
(
var
j
=
0
;
j
<
mainnodes
.
length
;
j
++
)
{
rootbranchwidth
+=
countMainWidth
(
mainnodes
[
j
]
);
}
var
sX
=
rootLayout
.
x
-
rootbranchwidth
/
2
;
for
(
var
k
=
0
;
k
<
mainnodes
.
length
;
k
++
)
{
var
mLayout
=
mainnodes
[
k
].
getLayout
();
mLayout
.
x
=
sX
;
sX
+=
mLayout
.
branchwidth
;
}
return
mainnodes
;
};
var
updateLayoutAll
=
function
(
node
,
parent
,
action
)
{
var
effectSet
=
[];
var
nodeType
=
node
.
getType
();
var
Layout
=
node
.
getLayout
();
var
_root
=
minder
.
getRoot
();
var
rootLayout
=
_root
.
getLayout
();
if
(
nodeType
===
"root"
)
{
Layout
.
x
=
getMinderSize
().
width
/
2
;
Layout
.
y
=
100
;
...
...
@@ -194,42 +193,32 @@ KityMinder.registerModule( "LayoutBottom", function () {
var
children
=
node
.
getChildren
();
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
childLayout
=
children
[
i
].
getLayout
();
childLayout
.
y
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
main
.
margin
[
0
];
childLayout
.
y
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
}
effectSet
=
effectSet
.
concat
(
children
);
}
else
if
(
nodeType
===
"main"
)
{
Layout
.
align
=
"center"
;
var
mainnodes
=
_root
.
getChildren
();
var
rootLayout
=
_root
.
getLayout
();
var
rootbranchwidth
=
0
;
for
(
var
j
=
0
;
j
<
mainnodes
.
length
;
j
++
)
{
rootbranchwidth
+=
countMainWidth
(
mainnodes
[
j
]
);
}
var
sX
=
rootLayout
.
x
-
rootbranchwidth
/
2
;
for
(
var
k
=
0
;
k
<
mainnodes
.
length
;
k
++
)
{
var
mLayout
=
mainnodes
[
k
].
getLayout
();
var
mWidth
=
mainnodes
[
k
].
getRenderContainer
().
getWidth
();
mLayout
.
x
=
sX
+
nodeStyles
.
main
.
margin
[
3
]
+
mWidth
/
2
;
sX
+=
(
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
main
.
margin
[
3
]
+
mWidth
);
}
if
(
action
===
"append"
)
{
Layout
.
y
=
rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
main
.
margin
[
0
];
Layout
.
align
=
"left"
;
if
(
action
===
"append"
||
action
===
"contract"
)
{
Layout
.
y
=
rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
}
effectSet
=
mainnodes
;
effectSet
=
updateLayoutMain
()
;
}
else
{
Layout
.
align
=
"left"
;
var
parentLayout
=
parent
.
getLayout
();
if
(
action
===
"append"
)
{
if
(
parent
.
getType
()
===
"main"
)
{
Layout
.
x
=
10
;
Layout
.
x
=
nodeStyles
.
sub
.
margin
[
3
]
;
}
else
{
Layout
.
x
=
parentLayout
.
x
+
10
;
Layout
.
x
=
parentLayout
.
x
+
nodeStyles
.
sub
.
margin
[
3
]
;
}
}
if
(
action
===
"append"
||
action
===
"c
hange
"
)
{
if
(
action
===
"append"
||
action
===
"c
ontract
"
)
{
Layout
.
branchheight
=
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
sub
.
margin
[
0
]
+
nodeStyles
.
sub
.
margin
[
2
];
}
var
prt
=
parent
;
if
(
action
===
"change"
)
{
prt
=
node
;
}
//自底向上更新branchheight
while
(
prt
.
getType
()
!==
"main"
)
{
var
c
=
prt
.
getChildren
();
...
...
@@ -242,8 +231,24 @@ KityMinder.registerModule( "LayoutBottom", function () {
prt
=
prt
.
getParent
();
}
//自顶向下更新y
var
idx
=
prt
.
getIndex
();
effectSet
=
[
node
];
var
_buffer
=
[
prt
];
while
(
_buffer
.
length
!==
0
)
{
var
childrenC
=
_buffer
[
0
].
getChildren
();
_buffer
=
_buffer
.
concat
(
childrenC
);
var
_buffer0Layout
=
_buffer
[
0
].
getLayout
();
var
_buffer0Style
=
nodeStyles
[
_buffer
[
0
].
getType
()
];
var
sY
;
if
(
_buffer
[
0
].
getType
()
===
"main"
)
sY
=
0
;
else
sY
=
_buffer0Layout
.
y
+
_buffer
[
0
].
getRenderContainer
().
getHeight
()
+
_buffer0Style
.
margin
[
2
];
for
(
var
s
=
0
;
s
<
childrenC
.
length
;
s
++
)
{
var
childLayoutC
=
childrenC
[
s
].
getLayout
();
var
childStyleC
=
nodeStyles
[
childrenC
[
s
].
getType
()
];
childLayoutC
.
y
=
sY
+
childStyleC
.
margin
[
0
];
sY
+=
childLayoutC
.
branchheight
;
}
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
}
return
effectSet
;
};
...
...
@@ -265,7 +270,7 @@ KityMinder.registerModule( "LayoutBottom", function () {
break
;
}
if
(
node
.
getType
()
===
"main"
)
{
Layout
.
subgroup
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
-
node
.
getRenderContainer
().
getWidth
()
/
2
+
10
,
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
)
);
Layout
.
subgroup
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
,
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
)
);
}
node
.
setPoint
(
Layout
.
x
,
Layout
.
y
);
};
...
...
@@ -274,9 +279,50 @@ KityMinder.registerModule( "LayoutBottom", function () {
var
Layout
=
node
.
getLayout
();
var
nodeStyle
=
nodeStyles
[
node
.
getType
()
];
var
connect
;
var
_root
=
minder
.
getRoot
();
var
_rootLayout
=
_root
.
getLayout
();
//更新连线
if
(
nodeType
===
"main"
)
{
if
(
!
Layout
.
connect
)
{
connect
=
Layout
.
connect
=
new
kity
.
Path
();
minder
.
getRenderContainer
().
addShape
(
connect
);
}
connect
=
Layout
.
connect
;
var
sX
=
_rootLayout
.
x
;
var
sY
=
_rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
();
var
transX
=
Layout
.
x
+
node
.
getRenderContainer
().
getWidth
()
/
2
;
var
transY
=
sY
+
nodeStyles
.
root
.
margin
[
2
];
connect
.
getDrawer
().
clear
()
.
moveTo
(
sX
,
sY
)
.
lineTo
(
sX
,
transY
)
.
lineTo
(
transX
,
transY
)
.
lineTo
(
transX
,
Layout
.
y
);
connect
.
stroke
(
nodeStyles
.
main
.
stroke
);
}
else
if
(
nodeType
===
"sub"
)
{
var
parent
=
node
.
getParent
();
var
parentLayout
=
parent
.
getLayout
();
if
(
!
Layout
.
connect
)
{
connect
=
Layout
.
connect
=
new
kity
.
Path
();
Layout
.
subgroup
.
addShape
(
connect
);
}
connect
=
Layout
.
connect
;
var
ssX
,
ssY
;
if
(
parent
.
getType
()
===
"main"
)
{
ssX
=
10
;
ssY
=
0
;
}
else
{
ssX
=
parentLayout
.
x
+
10
;
ssY
=
parentLayout
.
y
+
parent
.
getRenderContainer
().
getHeight
()
+
10
;
}
var
transsY
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
/
2
;
connect
.
getDrawer
().
clear
()
.
moveTo
(
ssX
,
ssY
)
.
lineTo
(
ssX
,
transsY
)
.
lineTo
(
Layout
.
x
,
transsY
);
connect
.
stroke
(
nodeStyles
.
sub
.
stroke
);
}
//更新收放icon
if
(
nodeType
!==
"root"
)
{
if
(
nodeType
!==
"root"
&&
node
.
getChildren
().
length
!==
0
)
{
if
(
!
Layout
.
shicon
)
{
Layout
.
shicon
=
new
ShIcon
(
node
);
}
...
...
@@ -292,21 +338,13 @@ KityMinder.registerModule( "LayoutBottom", function () {
switch
(
nodeType
)
{
case
"root"
:
case
"main"
:
case
"sub"
:
if
(
highlight
)
{
Layout
.
bgRect
.
fill
(
nodeStyle
.
highlight
);
}
else
{
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
}
break
;
case
"sub"
:
if
(
highlight
)
{
Layout
.
highlightshape
.
fill
(
nodeStyle
.
highlight
).
setOpacity
(
1
);
node
.
getTextShape
().
fill
(
'black'
);
}
else
{
Layout
.
highlightshape
.
setOpacity
(
0
);
node
.
getTextShape
().
fill
(
'white'
);
}
break
;
default
:
break
;
}
...
...
@@ -320,11 +358,18 @@ KityMinder.registerModule( "LayoutBottom", function () {
},
false
)
);
updateShapeByCont
(
node
);
var
set
=
updateLayoutAll
(
node
);
var
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"change"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
if
(
node
.
getType
()
===
"sub"
)
{
var
set1
=
updateLayoutMain
();
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
}
}
},
initStyle
:
function
()
{
var
_root
=
minder
.
getRoot
();
...
...
@@ -393,16 +438,92 @@ KityMinder.registerModule( "LayoutBottom", function () {
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
if
(
node
.
getType
()
===
"sub"
)
{
var
set1
=
updateLayoutMain
();
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
}
}
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
this
.
appendChildNode
(
parent
,
node
,
sibling
);
},
removeNode
:
function
(
nodes
)
{
while
(
nodes
.
length
!==
0
)
{
var
parent
=
nodes
[
0
].
getParent
();
if
(
!
parent
)
{
nodes
.
splice
(
0
,
1
);
return
false
;
}
var
nodeLayout
=
nodes
[
0
].
getLayout
();
parent
.
removeChild
(
nodes
[
0
]
);
var
set
=
updateLayoutAll
(
nodes
[
0
],
parent
,
"remove"
);
for
(
var
j
=
0
;
j
<
set
.
length
;
j
++
)
{
translateNode
(
set
[
j
]
);
updateConnectAndshIcon
(
set
[
j
]
);
}
var
set1
=
updateLayoutMain
();
for
(
var
k
=
0
;
k
<
set1
.
length
;
k
++
)
{
translateNode
(
set1
[
k
]
);
updateConnectAndshIcon
(
set1
[
k
]
);
}
var
_buffer
=
[
nodes
[
0
]
];
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
try
{
_buffer
[
0
].
getRenderContainer
().
remove
();
var
Layout
=
_buffer
[
0
].
getLayout
();
Layout
.
connect
.
remove
();
Layout
.
shicon
.
remove
();
}
catch
(
error
)
{
console
.
log
(
"isRemoved"
);
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var
idx
=
nodes
.
indexOf
(
_buffer
[
0
]
);
if
(
idx
!==
-
1
)
{
nodes
.
splice
(
idx
,
1
);
}
_buffer
.
shift
();
}
}
},
expandNode
:
function
(
ico
)
{
var
isExpand
=
ico
.
icon
.
switchState
();
var
node
=
ico
.
icon
.
_node
;
var
_buffer
=
node
.
getChildren
();
var
_cleanbuffer
=
[];
while
(
_buffer
.
length
!==
0
)
{
var
Layout
=
_buffer
[
0
].
getLayout
();
if
(
isExpand
)
{
var
parent
=
_buffer
[
0
].
getParent
();
Layout
.
parent
=
parent
;
_cleanbuffer
.
push
(
_buffer
[
0
]
);
Layout
.
connect
=
null
;
Layout
.
shicon
=
null
;
}
else
{
_buffer
[
0
].
getRenderContainer
().
remove
();
Layout
.
connect
.
remove
();
if
(
Layout
.
shicon
)
Layout
.
shicon
.
remove
();
}
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
.
shift
();
}
if
(
isExpand
)
{
node
.
clearChildren
();
for
(
var
j
=
0
;
j
<
_cleanbuffer
.
length
;
j
++
)
{
_cleanbuffer
[
j
].
clearChildren
();
minder
.
appendChildNode
(
_cleanbuffer
[
j
].
getLayout
().
parent
,
_cleanbuffer
[
j
]
);
}
}
var
set
=
[];
if
(
!
isExpand
)
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"contract"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
}
};
this
.
addLayoutStyle
(
"bottom"
,
_style
);
...
...
src/module/layout.js
View file @
a876ca99
...
...
@@ -8,7 +8,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return
this
.
_layoutStyles
[
name
];
},
getLayoutStyleItems
:
function
()
{
return
this
.
_layoutStyles
;
var
items
=
[];
for
(
var
key
in
this
.
_layoutStyles
)
{
items
.
push
(
key
);
}
return
items
;
},
getCurrentStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
...
...
@@ -90,7 +94,10 @@ KityMinder.registerModule( "LayoutModule", function () {
var
SwitchLayoutCommand
=
kity
.
createClass
(
"SwitchLayoutCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
switchLayout
execute
:
switchLayout
,
queryValue
:
function
(
km
)
{
return
km
.
getCurrentStyle
();
}
};
}
)()
);
var
AppendChildNodeCommand
=
kity
.
createClass
(
"AppendChildNodeCommand"
,
(
function
()
{
...
...
@@ -98,9 +105,6 @@ KityMinder.registerModule( "LayoutModule", function () {
base
:
Command
,
execute
:
function
(
km
,
node
)
{
var
parent
=
km
.
getSelectedNode
();
if
(
!
parent
)
{
return
false
;
}
km
.
appendChildNode
(
parent
,
node
);
km
.
select
(
node
,
true
);
return
node
;
...
...
@@ -120,9 +124,6 @@ KityMinder.registerModule( "LayoutModule", function () {
base
:
Command
,
execute
:
function
(
km
,
node
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
return
false
;
}
if
(
selectedNode
.
isRoot
()
)
{
node
.
setType
(
"main"
);
km
.
appendChildNode
(
selectedNode
,
node
);
...
...
@@ -134,8 +135,9 @@ KityMinder.registerModule( "LayoutModule", function () {
return
node
;
},
queryState
:
function
(
km
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
||
selectedNode
===
km
.
getRoot
()
)
{
var
selectedNodes
=
km
.
getSelectedNodes
();
//没选中节点和单选root的时候返回不可执行
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
()
)
)
{
return
-
1
;
}
else
{
return
0
;
...
...
@@ -149,10 +151,6 @@ KityMinder.registerModule( "LayoutModule", function () {
execute
:
function
(
km
)
{
var
selectedNodes
=
km
.
getSelectedNodes
();
var
_root
=
km
.
getRoot
();
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
!
selectedNodes
[
0
].
getParent
()
)
)
{
km
.
select
(
_root
);
return
false
;
}
var
_buffer
=
[];
for
(
var
i
=
0
;
i
<
selectedNodes
.
length
;
i
++
)
{
_buffer
.
push
(
selectedNodes
[
i
]
);
...
...
@@ -167,7 +165,7 @@ KityMinder.registerModule( "LayoutModule", function () {
},
queryState
:
function
(
km
)
{
var
selectedNodes
=
km
.
getSelectedNodes
();
if
(
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
()
)
||
selectedNodes
.
length
===
0
)
{
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
()
)
)
{
return
-
1
;
}
else
{
return
0
;
...
...
src/module/select.js
View file @
a876ca99
...
...
@@ -29,9 +29,11 @@ KityMinder.registerModule( "Select", function () {
startPosition
=
g
.
snapToSharp
(
e
.
getPosition
()
);
},
selectMove
:
function
(
e
)
{
if
(
minder
.
isTextEditStatus
()
)
{
return
;
}
if
(
!
startPosition
)
return
;
var
p1
=
startPosition
,
p2
=
e
.
getPosition
();
...
...
@@ -65,7 +67,7 @@ KityMinder.registerModule( "Select", function () {
// 计算选中范围
minder
.
getRoot
().
traverse
(
function
(
node
)
{
var
renderBox
=
node
.
getRenderContainer
().
getRenderBox
();
var
renderBox
=
node
.
getRenderContainer
().
getRenderBox
(
"top"
);
if
(
g
.
isBoxIntersect
(
renderBox
,
marquee
)
)
{
selectedNodes
.
push
(
node
);
}
...
...
@@ -80,7 +82,7 @@ KityMinder.registerModule( "Select", function () {
}
if
(
marqueeMode
)
{
marqueeShape
.
fadeOut
(
200
,
'ease'
,
0
,
function
()
{
if
(
marqueeShape
.
remove
)
marqueeShape
.
remove
();
if
(
marqueeShape
.
remove
)
marqueeShape
.
remove
();
}
);
marqueeMode
=
false
;
}
...
...
src/protocal/png.js
0 → 100644
View file @
a876ca99
KityMinder
.
registerProtocal
(
"png"
,
function
()
{
var
LINE_ENDING
=
'
\
n'
,
TAB_CHAR
=
'
\
t'
;
function
repeat
(
s
,
n
)
{
var
result
=
""
;
while
(
n
--
)
result
+=
s
;
return
result
;
}
function
encode
(
json
,
level
)
{
var
local
=
""
;
level
=
level
||
0
;
local
+=
repeat
(
TAB_CHAR
,
level
);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
if
(
json
.
children
)
{
json
.
children
.
forEach
(
function
(
child
)
{
local
+=
encode
(
child
,
level
+
1
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
return
!
/
\S
/
.
test
(
line
);
}
function
getLevel
(
line
)
{
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
return
level
;
}
function
getNode
(
line
)
{
return
{
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
var
json
,
parentMap
=
{},
lines
=
local
.
split
(
LINE_ENDING
),
line
,
level
,
node
;
function
addChild
(
parent
,
child
)
{
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
children
.
push
(
child
);
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
line
=
lines
[
i
];
if
(
isEmpty
(
line
)
)
continue
;
level
=
getLevel
(
line
);
node
=
getNode
(
line
);
if
(
level
===
0
)
{
if
(
json
)
{
throw
new
Error
(
'Invalid local format'
);
}
json
=
node
;
}
else
{
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
}
addChild
(
parentMap
[
level
-
1
],
node
);
}
parentMap
[
level
]
=
node
;
}
return
json
;
}
var
lastTry
,
lastResult
;
function
recognize
(
local
)
{
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
fileDescription
:
'png'
,
fileExtension
:
'.png'
,
encode
:
function
(
json
)
{
return
encode
(
json
,
0
);
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
return
decode
(
local
);
},
recognize
:
recognize
,
recognizePriority
:
-
1
};
}
);
\ No newline at end of file
src/ui/combobox.js
View file @
a876ca99
...
...
@@ -51,7 +51,8 @@
//自动记录
autoRecord
:
true
,
//最多记录条数
recordCount
:
5
recordCount
:
5
,
enabledRecord
:
true
},
init
:
function
(
options
){
...
...
@@ -133,6 +134,7 @@
*/
select
:
function
(
index
){
var
options
=
this
.
data
(
'options'
),
itemCount
=
options
.
itemCount
,
items
=
options
.
autowidthitem
;
...
...
@@ -162,6 +164,7 @@
this
.
trigger
(
'changebefore'
,
items
[
index
]
);
this
.
_update
(
index
);
this
.
trigger
(
'changeafter'
,
items
[
index
]
);
...
...
@@ -330,22 +333,25 @@
var
options
=
this
.
data
(
"options"
),
newStack
=
[];
$
.
each
(
options
.
recordStack
,
function
(
i
,
item
){
if
(
this
.
data
(
'options'
).
enabledRecord
){
$
.
each
(
options
.
recordStack
,
function
(
i
,
item
){
if
(
item
!=
index
)
{
newStack
.
push
(
item
);
}
if
(
item
!=
index
)
{
newStack
.
push
(
item
);
}
}
);
}
);
//压入最新的记录
newStack
.
unshift
(
index
);
//压入最新的记录
newStack
.
unshift
(
index
);
if
(
newStack
.
length
>
options
.
recordCount
)
{
newStack
.
length
=
options
.
recordCount
;
}
if
(
newStack
.
length
>
options
.
recordCount
)
{
newStack
.
length
=
options
.
recordCount
;
options
.
recordStack
=
newStack
;
}
options
.
recordStack
=
newStack
;
options
.
selected
=
index
;
this
.
_repaint
();
...
...
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