Commit 651acd74 authored by techird's avatar techird

使用 Module 规范组织代码

parent b27e5394
{
"directory": "lib"
}
\ No newline at end of file
...@@ -4,8 +4,4 @@ ...@@ -4,8 +4,4 @@
*.sublime-workspace *.sublime-workspace
dist/ dist/
node_modules/ node_modules/
_drafts/ _drafts/
native-support/archive/src/tmp/ \ No newline at end of file
native-support/archive/upload/
ui/theme/default/css/*.css
ui/theme/default/css/*.css.map
\ No newline at end of file
[submodule "lib/kity"] [submodule "lib/kity"]
path = lib/kity path = lib/kity
url = https://github.com/fex-team/kity url = https://github.com/fex-team/kity
\ No newline at end of file [submodule "lib/promise"]
path = lib/promise
url = https://github.com/jakearchibald/es6-promise
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
"disallowSpacesInsideParentheses": true, "disallowSpacesInsideParentheses": true,
// 行尾「MUST NOT」使用空格 // 行尾「MUST NOT」使用空格
"disallowTrailingWhitespace": false, "disallowTrailingWhitespace": true,
// 每行「MUST NOT」超过 120 个字符 // 每行「MUST NOT」超过 120 个字符
"maximumLineLength": 120, "maximumLineLength": 120,
......
...@@ -10,23 +10,7 @@ ...@@ -10,23 +10,7 @@
"browser": true, "browser": true,
"boss": true, "boss": true,
"predef" : [ "predef" : [
"module", "define",
"require", "Promise"
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"keymap",
"Utils",
"utils",
"$",
"KM",
"keymap",
"browser"
] ]
} }
\ No newline at end of file
/*----------------------------------------------------- /* global require, module */
* livereload Default Setting
*-----------------------------------------------------*/
'use strict';
var path = require('path'); var path = require('path');
/*-----------------------------------------------------
* Module Setting
*-----------------------------------------------------*/
module.exports = function(grunt) { module.exports = function(grunt) {
'use strict';
// These plugins provide necessary tasks. // These plugins provide necessary tasks.
/* [Build plugin & task ] ------------------------------------*/ /* [Build plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-module-dependence');
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-autoprefixer');
var banner = '/*!\n' + var banner = '/*!\n' +
' * ====================================================\n' + ' * ====================================================\n' +
...@@ -32,161 +22,29 @@ module.exports = function(grunt) { ...@@ -32,161 +22,29 @@ module.exports = function(grunt) {
' * ====================================================\n' + ' * ====================================================\n' +
' */\n\n'; ' */\n\n';
var packs = ['index', 'edit', 'share', 'm-share'];
var sources = require('./import.js');
var srcPath = 'src/';
var distPath = 'dist/';
var distPages = ['index', 'edit', 'viewshare', 'm-share'].map(function(name) {
return distPath + name + '.html';
});
var concatConfigs = {};
packs.forEach(function(pack) {
concatConfigs[pack] = {
options: {
banner: banner + '(function(window) {\n\n',
footer: '\n\n})(window)',
sourceMap: true,
sourceMapStyle: 'link'
},
src: sources.filter(function(source) {
return source.pack == '*' || source.pack.split('|').indexOf(pack) !== -1;
}).map(function(source) {
return source.path;
}),
dest: distPath + 'kityminder.' + pack + '.js'
};
});
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
// Metadata. // Metadata.
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
clean: ['dist', 'native-support/upload/', 'native-support/src/tmp/'], dependence: {
options: {
concat: concatConfigs, base: 'src',
entrance: 'kityminder'
uglify: {
minimize: {
options: {
banner: banner,
sourceMap: true
},
files: (function() {
var files = {};
packs.forEach(function(pack) {
files[distPath + 'kityminder.' + pack + '.min.js'] = distPath + 'kityminder.' + pack + '.js';
});
return files;
})()
}
},
copy: {
dir: {
files: [{
src: [
'ui/theme/**/css/*.css',
'ui/theme/**/css/*.css.map',
'ui/theme/**/images/*',
'lang/**/*',
'static/**/*',
'native-support/**/*',
'lib/ZeroClipboard.swf',
'lib/inflate.js',
'lib/source-map.min.js',
'index.html',
'edit.html',
'viewshare.html',
'm-share.html',
'download.php'
],
dest: distPath
}]
},
km_config: {
expand: true,
src: 'kityminder.config.js',
dest: distPath
}, },
mise: { merge: {
files: [{ files: [{
src: ['LICENSE', 'favicon.ico', 'README.md', 'CHANGELOG.md'], src: 'src/**/*.js',
dest: distPath dest: 'release/kityminder.all.js'
}]
}
},
replace: {
online: {
src: distPages,
overwrite: true,
replacements: [{
from: /import\.js\?pack=([\w-]+)\"/,
to: 'kityminder.$1.min.js"'
}]
},
pageNoCache: {
src: distPages,
overwrite: true,
replacements: [{
from: /(src|href)=\"(.+?)\.(js|css)\"/ig,
to: '$1="$2.$3?_=' + (+new Date()) + '"'
}]
},
imageNoCache: {
src: 'dist/ui/theme/default/css/default.all.css',
overwrite: true,
replacements: [{
from: /\.png/ig,
to: '.png?_=' + (+new Date())
}] }]
} }
},
watch: {
less: {
files: ['ui/theme/**/*.less'],
tasks: ['less:compile', 'autoprefixer']
}
},
less: {
compile: {
files: {
'ui/theme/default/css/default.all.temp.css': [
'ui/theme/default/css/import.less'
]
},
options: {
sourceMap: true,
sourceMapFilename: 'ui/theme/default/css/default.all.temp.css.map',
sourceMapBasepath: 'ui/theme/default/css/'
}
}
},
autoprefixer: {
all: {
options: {
map: true
},
src: 'ui/theme/default/css/default.all.temp.css',
dest: 'ui/theme/default/css/default.all.css'
}
} }
}); });
// Build task(s). // Build task(s).
grunt.registerTask('default', ['clean', 'concat', 'uglify', 'less', 'autoprefixer', 'copy', 'replace']); grunt.registerTask('default', ['dependence']);
grunt.registerTask('dev', ['less', 'autoprefixer', 'watch']);
}; };
\ No newline at end of file
{
"name": "kityminder-core",
"title": "Kity Minder Core",
"description": "Powerful online mind graphic visualization and editor (command based)",
"version": "1.3.6",
"main": "src/kityminder.js",
"keywords": ["kityminder", "kity", "svg"],
"homepage": "https://github.com/fex-team/kityminder-core",
"devDependencies": {
"seajs": "~2.3.0"
},
"licenses": [{
"type": "BSD",
"url": "https://github.com/fex-team/kityminder-core/blob/dev/LICENSE"
}],
"bugs": {
"url": "https://github.com/fex-team/kityminder-core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/fex-team/kityminder-core.git"
},
"author": {
"name": "Baidu FEX",
"url": "http://fex.baidu.com"
}
}
\ No newline at end of file
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>KityMinder Example</title> <title>KityMinder Example</title>
<script type="text/javascript" src="lib/kity/dist/kity.js"></script>
<!--dev mode 引入-->
<script type="text/javascript" src="import.js"></script>
<!--dist mode 引入 -->
<!--<script type="text/javascript" src="../dist/kityminder.min.js">-->
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"> <link href="favicon.ico" type="image/x-icon" rel="shortcut icon">
<style type="text/css"> <style type="text/css">
body { body {
...@@ -37,9 +30,33 @@ ...@@ -37,9 +30,33 @@
<body> <body>
<div id="minder-view"></div> <div id="minder-view"></div>
</body> </body>
<!-- *************************** Module 形式加载引入 **************************** -->
<script type="text/javascript" src="lib/seajs/dist/sea-debug.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.km = new KityMinder({ /* global seajs */
seajs.config({
base: './src'
});
define('start', function(require) {
var Minder = require('kityminder').Minder;
// 创建 km 实例
var km = window.km = new Minder({
renderTo: 'minder-view' renderTo: 'minder-view'
}); });
});
seajs.use('start');
</script> </script>
<!-- *********************** 打包文件引入(需要先 grunt 发布) ************************* -->
<!--
<script type="text/javascript" src="../release/kityminder.all.min.js">
<script type="text/javascript">
// 创建 km 实例
window.km = new kityminder.Minder('minder-view');
</script>
-->
</html> </html>
\ No newline at end of file
This diff is collapsed.
{
"name": "seajs",
"version": "2.3.0",
"main": "./dist/sea.js",
"ignore": [
"**/.*",
"docs",
"lib",
"src",
"tests",
"CNAME",
"component.json",
"CONTRIBUTING.md",
"index.html",
"Makefile",
"package.json",
"README.md"
],
"homepage": "https://github.com/seajs/seajs",
"_release": "2.3.0",
"_resolution": {
"type": "version",
"tag": "2.3.0",
"commit": "9c6299636991fbca73a9aa7b2eb152c6e8614854"
},
"_source": "git://github.com/seajs/seajs.git",
"_target": "~2.3.0",
"_originalSource": "seajs"
}
\ No newline at end of file
MIT LICENSE
Copyright (c) 2009 - 2099 Frank Wang, http://seajs.org/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "seajs",
"version": "2.3.0",
"main": "./dist/sea.js",
"ignore": [
"**/.*",
"docs",
"lib",
"src",
"tests",
"CNAME",
"component.json",
"CONTRIBUTING.md",
"index.html",
"Makefile",
"package.json",
"README.md"
]
}
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
"title": "kityminder", "title": "kityminder",
"description": "Kity Minder", "description": "Kity Minder",
"version": "1.3.5", "version": "1.3.5",
"homepage": "https://github.com/fex-team/kityminder", "homepage": "https://github.com/fex-team/kityminder-core",
"author": { "author": {
"name": "f-cube @ FEX", "name": "f-cube @ FEX",
"url": "http://fex.baidu.com" "url": "http://fex.baidu.com"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/fex-team/kityminder.git" "url": "https://github.com/fex-team/kityminder-core.git"
}, },
"keywords": [ "keywords": [
"kityminder", "kityminder",
...@@ -21,23 +21,20 @@ ...@@ -21,23 +21,20 @@
"javascript" "javascript"
], ],
"bugs": { "bugs": {
"url": "https://github.com/fex-team/kityminder/issues" "url": "https://github.com/fex-team/kityminder-core/issues"
}, },
"licenses": [ { "licenses": [ {
"type": "MIT", "type": "MIT",
"url": "https://github.com/fex-team/kityminder/blob/dev/LICENSE" "url": "https://github.com/fex-team/kityminder-core/blob/dev/LICENSE"
} ], } ],
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-module-dependence": "~0.1.4",
"grunt-contrib-concat": "~0.5.0", "grunt-contrib-concat": "~0.5.0",
"grunt-contrib-uglify": "~0.4.0", "grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-copy": "~0.5.0", "grunt-contrib-copy": "~0.5.0",
"grunt-text-replace": "~0.3.9", "grunt-contrib-clean": "~0.5.0"
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-less": "~0.11.3",
"grunt-contrib-clean": "~0.6.0",
"grunt-autoprefixer": "~1.0.1"
} }
} }
\ No newline at end of file
...@@ -7,38 +7,43 @@ ...@@ -7,38 +7,43 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
var connectMarker = new kity.Marker().pipe(function() { define(function(require, exports, module) {
var r = 7; var kity = require('core/kity');
var dot = new kity.Circle(r - 1); var connect = require('core/connect');
this.addShape(dot);
this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
this.dot = dot;
this.node.setAttribute('markerUnits', 'userSpaceOnUse');
});
KityMinder.registerConnectProvider('arc', function(node, parent, connection, width, color) { var connectMarker = new kity.Marker().pipe(function() {
var r = 7;
var dot = new kity.Circle(r - 1);
this.addShape(dot);
this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
this.dot = dot;
this.node.setAttribute('markerUnits', 'userSpaceOnUse');
});
var box = node.getLayoutBox(), connect.register('arc', function(node, parent, connection, width, color) {
pBox = parent.getLayoutBox();
var start, end, vector; var box = node.getLayoutBox(),
var abs = Math.abs; pBox = parent.getLayoutBox();
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
node.getMinder().getPaper().addResource(connectMarker); var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
start = new kity.Point(pBox.cx, pBox.cy); node.getMinder().getPaper().addResource(connectMarker);
end = side == 'left' ?
new kity.Point(box.right + 2, box.cy) :
new kity.Point(box.left - 2, box.cy);
vector = kity.Vector.fromPoints(start, end); start = new kity.Point(pBox.cx, pBox.cy);
pathData.push('M', start); end = side == 'left' ?
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end); new kity.Point(box.right + 2, box.cy) :
new kity.Point(box.left - 2, box.cy);
connection.setMarker(connectMarker); vector = kity.Vector.fromPoints(start, end);
connectMarker.dot.fill(color); pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
connection.setPathData(pathData); connection.setMarker(connectMarker);
connectMarker.dot.fill(color);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,31 +7,36 @@ ...@@ -7,31 +7,36 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('bezier', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
// 连线起点和终点 connect.register('bezier', function(node, parent, connection) {
var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
// 连线矢量和方向 // 连线起点和终点
var v = parent.getLayoutVectorOut().normalize(); var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
var r = Math.round; // 连线矢量和方向
var abs = Math.abs; var v = parent.getLayoutVectorOut().normalize();
var pathData = []; var r = Math.round;
pathData.push('M', r(po.x), r(po.y)); var abs = Math.abs;
if (abs(v.x) > abs(v.y)) { var pathData = [];
// x - direction pathData.push('M', r(po.x), r(po.y));
var hx = (pi.x + po.x) / 2;
pathData.push('C', hx, po.y, hx, pi.y, pi.x, pi.y);
} else {
// y - direction
var hy = (pi.y + po.y) / 2;
pathData.push('C', po.x, hy, pi.x, hy, pi.x, pi.y);
}
connection.setMarker(null); if (abs(v.x) > abs(v.y)) {
connection.setPathData(pathData); // x - direction
var hx = (pi.x + po.x) / 2;
pathData.push('C', hx, po.y, hx, pi.y, pi.x, pi.y);
} else {
// y - direction
var hy = (pi.y + po.y) / 2;
pathData.push('C', po.x, hy, pi.x, hy, pi.x, pi.y);
}
connection.setMarker(null);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,22 +7,27 @@ ...@@ -7,22 +7,27 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
var pout = parent.getLayoutVertexOut(), connect.register('fish-bone-master', function(node, parent, connection) {
pin = node.getLayoutVertexIn();
var abs = Math.abs; var pout = parent.getLayoutVertexOut(),
pin = node.getLayoutVertexIn();
var dy = abs(pout.y - pin.y), var abs = Math.abs;
dx = abs(pout.x - pin.x);
var pathData = []; var dy = abs(pout.y - pin.y),
dx = abs(pout.x - pin.x);
pathData.push('M', pout.x, pout.y); var pathData = [];
pathData.push('h', dx - dy);
pathData.push('L', pin.x, pin.y);
connection.setMarker(null); pathData.push('M', pout.x, pout.y);
connection.setPathData(pathData); pathData.push('h', dx - dy);
pathData.push('L', pin.x, pin.y);
connection.setMarker(null);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,23 +7,28 @@ ...@@ -7,23 +7,28 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('l', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
var po = parent.getLayoutVertexOut(); connect.register('l', function(node, parent, connection) {
var pi = node.getLayoutVertexIn();
var vo = parent.getLayoutVectorOut();
var pathData = []; var po = parent.getLayoutVertexOut();
var r = Math.round, var pi = node.getLayoutVertexIn();
abs = Math.abs; var vo = parent.getLayoutVectorOut();
pathData.push('M', po.round()); var pathData = [];
if (abs(vo.x) > abs(vo.y)) { var r = Math.round,
pathData.push('H', r(pi.x)); abs = Math.abs;
} else {
pathData.push('V', pi.y);
}
pathData.push('L', pi);
connection.setPathData(pathData); pathData.push('M', po.round());
if (abs(vo.x) > abs(vo.y)) {
pathData.push('H', r(pi.x));
} else {
pathData.push('V', pi.y);
}
pathData.push('L', pi);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,52 +7,57 @@ ...@@ -7,52 +7,57 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('poly', function(node, parent, connection, width) { define(function(require, exports, module) {
var kity = require('core/kity');
// 连线起点和终点 var connect = require('core/connect');
var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn(); connect.register('poly', function(node, parent, connection, width) {
// 连线矢量和方向 // 连线起点和终点
var v = parent.getLayoutVectorOut().normalize(); var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
var r = Math.round;
var abs = Math.abs; // 连线矢量和方向
var v = parent.getLayoutVectorOut().normalize();
var pathData = [];
pathData.push('M', r(po.x), r(po.y)); var r = Math.round;
var abs = Math.abs;
switch (true) {
case abs(v.x) > abs(v.y) && v.x < 0: var pathData = [];
// left pathData.push('M', r(po.x), r(po.y));
pathData.push('h', -parent.getStyle('margin-left'));
pathData.push('v', pi.y - po.y); switch (true) {
pathData.push('H', pi.x); case abs(v.x) > abs(v.y) && v.x < 0:
break; // left
pathData.push('h', -parent.getStyle('margin-left'));
case abs(v.x) > abs(v.y) && v.x >= 0: pathData.push('v', pi.y - po.y);
// right pathData.push('H', pi.x);
pathData.push('h', parent.getStyle('margin-right')); break;
pathData.push('v', pi.y - po.y);
pathData.push('H', pi.x); case abs(v.x) > abs(v.y) && v.x >= 0:
break; // right
pathData.push('h', parent.getStyle('margin-right'));
case abs(v.x) <= abs(v.y) && v.y < 0: pathData.push('v', pi.y - po.y);
// top pathData.push('H', pi.x);
pathData.push('v', -parent.getStyle('margin-top')); break;
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y); case abs(v.x) <= abs(v.y) && v.y < 0:
break; // top
pathData.push('v', -parent.getStyle('margin-top'));
case abs(v.x) <= abs(v.y) && v.y >= 0: pathData.push('h', pi.x - po.x);
// bottom pathData.push('V', pi.y);
pathData.push('v', parent.getStyle('margin-bottom')); break;
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y); case abs(v.x) <= abs(v.y) && v.y >= 0:
break; // bottom
pathData.push('v', parent.getStyle('margin-bottom'));
} pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y);
connection.setMarker(null); break;
connection.setPathData(pathData);
}
connection.setMarker(null);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,39 +7,44 @@ ...@@ -7,39 +7,44 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('under', function(node, parent, connection, width, color) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
var box = node.getLayoutBox(), connect.register('under', function(node, parent, connection, width, color) {
pBox = parent.getLayoutBox();
var start, end, vector; var box = node.getLayoutBox(),
var abs = Math.abs; pBox = parent.getLayoutBox();
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
var radius = node.getStyle('connect-radius');
var underY = box.bottom + 3;
var startY = parent.getType() == 'sub' ? pBox.bottom + 3 : pBox.cy;
var p1, p2, p3, mx;
if (side == 'right') { var radius = node.getStyle('connect-radius');
p1 = new kity.Point(pBox.right, startY); var underY = box.bottom + 3;
p2 = new kity.Point(box.left - 10, underY); var startY = parent.getType() == 'sub' ? pBox.bottom + 3 : pBox.cy;
p3 = new kity.Point(box.right, underY); var p1, p2, p3, mx;
} else {
p1 = new kity.Point(pBox.left, startY);
p2 = new kity.Point(box.right + 10, underY);
p3 = new kity.Point(box.left, underY);
}
mx = (p1.x + p2.x) / 2; if (side == 'right') {
p1 = new kity.Point(pBox.right, startY);
p2 = new kity.Point(box.left - 10, underY);
p3 = new kity.Point(box.right, underY);
} else {
p1 = new kity.Point(pBox.left, startY);
p2 = new kity.Point(box.right + 10, underY);
p3 = new kity.Point(box.left, underY);
}
pathData.push('M', p1); mx = (p1.x + p2.x) / 2;
pathData.push('C', mx, p1.y, mx, p2.y, p2);
pathData.push('L', p3);
connection.setMarker(null); pathData.push('M', p1);
pathData.push('C', mx, p1.y, mx, p2.y, p2);
pathData.push('L', p3);
connection.setPathData(pathData); connection.setMarker(null);
connection.setPathData(pathData);
});
}); });
\ No newline at end of file
KityMinder.COMMAND_STATE_NORMAL = 0; define(function(require, exports, module) {
KityMinder.COMMAND_STATE_DISABLED = -1; var kity = require('./kity');
KityMinder.COMMAND_STATE_ACTIVED = 1; var utils = require('./utils');
var Minder = require('./minder');
var Command = kity.createClass( "Command", { var MinderNode = require('./node');
constructor: function () { var MinderEvent = require('./event');
this._isContentChange = true;
this._isSelectionChange = false; var COMMAND_STATE_NORMAL = 0;
}, var COMMAND_STATE_DISABLED = -1;
var COMMAND_STATE_ACTIVED = 1;
execute: function ( minder, args ) {
/**
}, * @class Command
*
setContentChanged: function ( val ) { * 表示一个命令,包含命令的查询及执行
this._isContentChange = !! val; */
}, var Command = kity.createClass('Command', {
constructor: function() {
isContentChanged: function () { this._isContentChange = true;
return this._isContentChange; this._isSelectionChange = false;
}, },
setSelectionChanged: function ( val ) { execute: function(minder, args) {
this._isSelectionChange = !! val; throw new Error('Not Implement: Command.execute()');
}, },
isSelectionChanged: function () { setContentChanged: function(val) {
return this._isContentChange; this._isContentChange = !!val;
}, },
queryState: function ( km ) { isContentChanged: function() {
return KityMinder.COMMAND_STATE_NORMAL; return this._isContentChange;
}, },
queryValue: function ( km ) { setSelectionChanged: function(val) {
return 0; this._isSelectionChange = !!val;
}, },
isNeedUndo: function () {
return true; isSelectionChanged: function() {
} return this._isContentChange;
} ); },
kity.extendClass(KityMinder, { queryState: function(km) {
_getCommand: function (name) { return COMMAND_STATE_NORMAL;
return this._commands[name.toLowerCase()]; },
},
queryValue: function(km) {
_queryCommand: function (name, type, args) { return 0;
var cmd = this._getCommand(name); },
if (cmd) {
var queryCmd = cmd['query' + type]; isNeedUndo: function() {
if (queryCmd) return true;
return queryCmd.apply(cmd, [this].concat(args));
}
return 0;
},
queryCommandState: function (name) {
return this._queryCommand(name, "State", Utils.argsToArray(1));
},
queryCommandValue: function (name) {
return this._queryCommand(name, "Value", Utils.argsToArray(1));
},
execCommand: function (name) {
name = name.toLowerCase();
var cmdArgs = Utils.argsToArray(arguments, 1),
cmd, stoped, result, eventParams;
var me = this;
cmd = this._getCommand(name);
eventParams = {
command: cmd,
commandName: name.toLowerCase(),
commandArgs: cmdArgs
};
if (!cmd || !~this.queryCommandState(name)) {
return false;
} }
});
Command.STATE_NORMAL = COMMAND_STATE_NORMAL;
Command.STATE_ACTIVE = COMMAND_STATE_ACTIVED;
Command.STATE_DISABLED = COMMAND_STATE_DISABLED;
kity.extendClass(Minder, {
_getCommand: function(name) {
return this._commands[name.toLowerCase()];
},
_queryCommand: function(name, type, args) {
var cmd = this._getCommand(name);
if (cmd) {
var queryCmd = cmd['query' + type];
if (queryCmd)
return queryCmd.apply(cmd, [this].concat(args));
}
return 0;
},
queryCommandState: function(name) {
return this._queryCommand(name, 'State', [].slice.call(arguments, 1));
},
queryCommandValue: function(name) {
return this._queryCommand(name, 'Value', [].slice.call(arguments, 1));
},
execCommand: function(name) {
name = name.toLowerCase();
var cmdArgs = [].slice.call(arguments, 1),
cmd, stoped, result, eventParams;
var me = this;
cmd = this._getCommand(name);
eventParams = {
command: cmd,
commandName: name.toLowerCase(),
commandArgs: cmdArgs
};
if (!cmd || !~this.queryCommandState(name)) {
return false;
}
if (!this._hasEnterExecCommand && cmd.isNeedUndo()) { if (!this._hasEnterExecCommand && cmd.isNeedUndo()) {
this._hasEnterExecCommand = true; this._hasEnterExecCommand = true;
stoped = this._fire(new MinderEvent('beforeExecCommand', eventParams, true)); stoped = this._fire(new MinderEvent('beforeExecCommand', eventParams, true));
if (!stoped) { if (!stoped) {
//保存场景 //保存场景
this._fire(new MinderEvent('saveScene')); this._fire(new MinderEvent('saveScene'));
this._fire(new MinderEvent("preExecCommand", eventParams, false)); this._fire(new MinderEvent('preExecCommand', eventParams, false));
result = cmd.execute.apply(cmd, [me].concat(cmdArgs)); result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
this._fire(new MinderEvent('execCommand', eventParams, false)); this._fire(new MinderEvent('execCommand', eventParams, false));
//保存场景 //保存场景
this._fire(new MinderEvent('saveScene')); this._fire(new MinderEvent('saveScene'));
if (cmd.isContentChanged()) { if (cmd.isContentChanged()) {
this._firePharse(new MinderEvent('contentchange')); this._firePharse(new MinderEvent('contentchange'));
}
this._interactChange();
} }
this._hasEnterExecCommand = false;
} else {
result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
this._interactChange(); if (!this._hasEnterExecCommand) {
this._interactChange();
}
} }
this._hasEnterExecCommand = false;
} else {
result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
if (!this._hasEnterExecCommand) { return result === undefined ? null : result;
this._interactChange();
}
} }
});
return result === undefined ? null : result; module.exports = Command;
}
}); });
\ No newline at end of file
Utils.extend(KityMinder, { define(function(require, exports, module) {
var utils = require('./utils');
compatibility: function(json) {
var version = json.version || '1.1.3'; function compatibility(json) {
function traverse(node, fn) {
fn(node);
if (node.children) node.children.forEach(function(child) {
traverse(child, fn);
});
}
/* 脑图数据升级 */
function c_120_130(json) {
traverse(json, function(node) {
var data = node.data;
delete data.layout_bottom_offset;
delete data.layout_default_offset;
delete data.layout_filetree_offset;
});
}
/**
* 脑图数据升级
* v1.1.3 => v1.2.0
* */
function c_113_120(json) {
// 原本的布局风格
var ocs = json.data.currentstyle;
delete json.data.currentstyle;
// 为 1.2 选择模板,同时保留老版本文件的皮肤
if (ocs == 'bottom') {
json.template = 'structure';
json.theme = 'snow';
} else if (ocs == 'default') {
json.template = 'default';
json.theme = 'classic';
}
traverse(json, function(node) {
var data = node.data;
// 升级优先级、进度图标 var version = json.version || '1.1.3';
if ('PriorityIcon' in data) {
data.priority = data.PriorityIcon;
delete data.PriorityIcon;
}
if ('ProgressIcon' in data) {
data.progress = 1 + ((data.ProgressIcon - 1) << 1);
delete data.ProgressIcon;
}
// 删除过时属性
delete data.point;
delete data.layout;
});
}
switch (version) { switch (version) {
case '1.1.3': case '1.1.3':
c_113_120(json); c_113_120(json);
/* falls through */
case '1.2.0': case '1.2.0':
case '1.2.1': case '1.2.1':
c_120_130(json); c_120_130(json);
/* falls through */
} }
return json; return json;
} }
function traverse(node, fn) {
fn(node);
if (node.children) node.children.forEach(function(child) {
traverse(child, fn);
});
}
/* 脑图数据升级 */
function c_120_130(json) {
traverse(json, function(node) {
var data = node.data;
delete data.layout_bottom_offset;
delete data.layout_default_offset;
delete data.layout_filetree_offset;
});
}
/**
* 脑图数据升级
* v1.1.3 => v1.2.0
* */
function c_113_120(json) {
// 原本的布局风格
var ocs = json.data.currentstyle;
delete json.data.currentstyle;
// 为 1.2 选择模板,同时保留老版本文件的皮肤
if (ocs == 'bottom') {
json.template = 'structure';
json.theme = 'snow';
} else if (ocs == 'default') {
json.template = 'default';
json.theme = 'classic';
}
traverse(json, function(node) {
var data = node.data;
// 升级优先级、进度图标
if ('PriorityIcon' in data) {
data.priority = data.PriorityIcon;
delete data.PriorityIcon;
}
if ('ProgressIcon' in data) {
data.progress = 1 + ((data.ProgressIcon - 1) << 1);
delete data.ProgressIcon;
}
// 删除过时属性
delete data.point;
delete data.layout;
});
}
module.exports = compatibility;
}); });
\ No newline at end of file
/* global Renderer: true */ define(function(require, exports, module) {
var kity = require('./kity');
utils.extend(KityMinder, { var utils = require('./utils');
_connectProviders: {}, var Module = require('./module');
var Minder = require('./minder');
var MinderNode = require('./node');
// 连线提供方
var _connectProviders = {};
function register(name, provider) {
_connectProviders[name] = provider;
}
_defaultConnectProvider: function(node, parent, connection) { register('default', function(node, parent, connection) {
connection.setPathData([ connection.setPathData([
'M', parent.getLayoutVertexOut(), 'M', parent.getLayoutVertexOut(),
'L', node.getLayoutVertexIn() 'L', node.getLayoutVertexIn()
]); ]);
}, });
registerConnectProvider: function(name, provider) {
KityMinder._connectProviders[name] = provider;
},
getConnectProvider: function(name) {
return KityMinder._connectProviders[name] || KityMinder._defaultConnectProvider;
}
});
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
getConnectProvider: function() { getConnect: function() {
return KityMinder.getConnectProvider(this.getConnect()); return this.data.connect || 'default';
}, },
getConnect: function() { getConnectProvider: function() {
return null; return _connectProviders[this.getConnect()] || _connectProviders['default'];
}, },
getConnection: function() { getConnection: function() {
return this._connection || null; return this._connection || null;
} }
}); });
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
getConnectContainer: function() { getConnectContainer: function() {
return this._connectContainer; return this._connectContainer;
}, },
createConnect: function(node) { createConnect: function(node) {
if (node.isRoot()) return; if (node.isRoot()) return;
var connection = new kity.Path(); var connection = new kity.Path();
node._connection = connection; node._connection = connection;
this._connectContainer.addShape(connection); this._connectContainer.addShape(connection);
this.updateConnect(node); this.updateConnect(node);
}, },
removeConnect: function(node) { removeConnect: function(node) {
var me = this; var me = this;
node.traverse(function(node) { node.traverse(function(node) {
me._connectContainer.removeShape(node._connection); me._connectContainer.removeShape(node._connection);
node._connection = null; node._connection = null;
}); });
}, },
updateConnect: function(node) { updateConnect: function(node) {
var connection = node._connection; var connection = node._connection;
var parent = node.parent; var parent = node.parent;
if (!parent || !connection) return; if (!parent || !connection) return;
if (parent.isCollapsed()) { if (parent.isCollapsed()) {
connection.setVisible(false); connection.setVisible(false);
return; return;
} }
connection.setVisible(true); connection.setVisible(true);
var provider = node.getConnectProvider(); var provider = node.getConnectProvider();
var strokeColor = node.getStyle('connect-color') || 'white', var strokeColor = node.getStyle('connect-color') || 'white',
strokeWidth = node.getStyle('connect-width') || 2; strokeWidth = node.getStyle('connect-width') || 2;
connection.stroke(strokeColor, strokeWidth); connection.stroke(strokeColor, strokeWidth);
provider(node, parent, connection, strokeWidth, strokeColor); provider(node, parent, connection, strokeWidth, strokeColor);
if (strokeWidth % 2 === 0) { if (strokeWidth % 2 === 0) {
connection.setTranslate(0.5, 0.5); connection.setTranslate(0.5, 0.5);
} else { } else {
connection.setTranslate(0, 0); connection.setTranslate(0, 0);
}
} }
} });
});
Module.register('Connect', {
KityMinder.registerModule('Connect', { init: function() {
init: function() { this._connectContainer = new kity.Group().setId(utils.uuid('minder_connect_group'));
this._connectContainer = new kity.Group().setId(KityMinder.uuid('minder_connect_group')); this.getRenderContainer().prependShape(this._connectContainer);
this.getRenderContainer().prependShape(this._connectContainer);
},
events: {
'nodeattach': function(e) {
this.createConnect(e.node);
},
'nodedetach': function(e) {
this.removeConnect(e.node);
}, },
'layoutapply layoutfinish noderender': function(e) { events: {
this.updateConnect(e.node); 'nodeattach': function(e) {
this.createConnect(e.node);
},
'nodedetach': function(e) {
this.removeConnect(e.node);
},
'layoutapply layoutfinish noderender': function(e) {
this.updateConnect(e.node);
}
} }
} });
exports.register = register;
}); });
\ No newline at end of file
Utils.extend(KityMinder, { define(function(require, exports, module) {
_protocols: {}, var kity = require('./kity');
registerProtocol: function(name, protocolDeal) { var utils = require('./utils');
KityMinder._protocols[name] = protocolDeal; var Minder = require('./minder');
} var MinderNode = require('./node');
}); var MinderEvent = require('./event');
var compatibility = require('./compatibility');
var DEFAULT_TEXT = {
'root': 'maintopic', // 导入导出
'main': 'topic', kity.extendClass(Minder, {
'sub': 'topic'
}; exportJson: function() {
/* 导出 node 上整棵树的数据为 JSON */
KityMinder.registerInit(function() { function exportNode(node) {
this._initProtocols(); var exported = {};
}); exported.data = node.getData();
var childNodes = node.getChildren();
// 导入导出 if (childNodes.length) {
kity.extendClass(KityMinder, { exported.children = [];
for (var i = 0; i < childNodes.length; i++) {
_initProtocols: function(options) { exported.children.push(exportNode(childNodes[i]));
var protocols = this._protocols = {}; }
var pool = KityMinder._protocols;
for (var name in pool) {
if (pool.hasOwnProperty(name))
protocols[name] = pool[name](this);
protocols[name].name = name;
}
},
getProtocol: function(name) {
return this._protocols[name] || null;
},
getSupportedProtocols: function() {
var protocols = this._protocols;
return Utils.keys(protocols).map(function(name) {
return protocols[name];
});
},
exportJson: function() {
/* 导出 node 上整棵树的数据为 JSON */
function exportNode(node) {
var exported = {};
exported.data = node.getData();
var childNodes = node.getChildren();
if (childNodes.length) {
exported.children = [];
for (var i = 0; i < childNodes.length; i++) {
exported.children.push(exportNode(childNodes[i]));
} }
return exported;
} }
return exported;
}
var json = exportNode(this.getRoot()); var json = exportNode(this.getRoot());
json.template = this.getTemplate(); json.template = this.getTemplate();
json.theme = this.getTheme(); json.theme = this.getTheme();
json.version = KityMinder.version; json.version = Minder.version;
return json; return json;
}, },
importJson: function(json, params) { importJson: function(json, params) {
function importNode(node, json, km) { function importNode(node, json, km) {
var data = json.data; var data = json.data;
node.data = {}; node.data = {};
for (var field in data) { for (var field in data) {
node.setData(field, data[field]); node.setData(field, data[field]);
} }
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()])); node.setData('text', data.text);
var childrenTreeData = json.children || []; var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) { for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node); var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km); importNode(childNode, childrenTreeData[i], km);
}
return node;
} }
return node;
}
if (!json) return;
this._fire(new MinderEvent('preimport', params, false));
// 删除当前所有节点
while (this._root.getChildren().length) {
this.removeNode(this._root.getChildren()[0]);
}
json = KityMinder.compatibility(json);
importNode(this._root, json, this);
this.setTemplate(json.template || 'default');
this.setTheme(json.theme || null);
this.refresh();
this.fire('import', params);
this._firePharse({
type: 'contentchange'
});
this._interactChange();
},
exportData: function(protocolName, options) {
var json, protocol; if (!json) return;
json = this.exportJson(); this._fire(new MinderEvent('preimport', params, false));
// 指定了协议进行导出,需要检测协议是否支持 // 删除当前所有节点
if (protocolName) { while (this._root.getChildren().length) {
protocol = this.getProtocol(protocolName); this.removeNode(this._root.getChildren()[0]);
if (!protocol || !protocol.encode) {
return Promise.reject(new Error('Not supported protocol:' + protocolName));
} }
}
// 导出前抛个事件
this._fire(new MinderEvent('beforeexport', {
json: json,
protocolName: protocolName,
protocol: protocol
}));
if (protocol) { json = Minder.compatibility(json);
return Promise.resolve(protocol.encode(json, this, options));
} else {
return Promise.resolve(json);
}
},
importData: function(local, protocolName) { importNode(this._root, json, this);
var json, protocol; this.setTemplate(json.template || 'default');
var minder = this; this.setTheme(json.theme || null);
this.refresh();
// 指定了协议进行导入,需要检测协议是否支持 this.fire('import', params);
if (protocolName) {
protocol = this.getProtocol(protocolName);
if (!protocol || !protocol.decode) { this._firePharse({
return Promise.reject(new Error('Not supported protocol:' + protocolName)); type: 'contentchange'
} });
this._interactChange();
} }
});
var params = {
local: local,
protocolName: protocolName,
protocol: protocol
};
// 导入前抛事件
this._fire(new MinderEvent('beforeimport', params));
return new Promise(function(resolve, reject) {
resolve(protocol ? protocol.decode(local) : local);
}).then(function(json) {
minder.importJson(json, params);
return json;
});
}
}); });
\ No newline at end of file
This diff is collapsed.
...@@ -7,126 +7,134 @@ ...@@ -7,126 +7,134 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
/** define(function(require, exports, module) {
* 计算包含 meta 键的 keycode var kity = require('./kity.js');
* var utils = require('./utils');
* @param {String|KeyEvent} unknown var keymap = require('./keymap');
*/ var Minder = require('./minder');
function getMetaKeyCode(unknown) { var MinderEvent = require('./event');
var CTRL_MASK = 0x1000;
var ALT_MASK = 0x2000;
var SHIFT_MASK = 0x4000;
var metaKeyCode = 0;
if (typeof(unknown) == 'string') {
// unknown as string
unknown.toLowerCase().split(/\+\s*/).forEach(function(name) {
switch(name) {
case 'ctrl':
case 'cmd':
metaKeyCode |= CTRL_MASK;
break;
case 'alt':
metaKeyCode |= ALT_MASK;
break;
case 'shift':
metaKeyCode |= SHIFT_MASK;
break;
default:
metaKeyCode |= keymap[name];
}
});
} else {
// unknown as key event
if (unknown.ctrlKey || unknown.metaKey) {
metaKeyCode |= CTRL_MASK;
}
if (unknown.altKey) {
metaKeyCode |= ALT_MASK;
}
if (unknown.shiftKey) {
metaKeyCode |= SHIFT_MASK;
}
metaKeyCode |= unknown.keyCode;
}
return metaKeyCode; /**
} * 计算包含 meta 键的 keycode
kity.extendClass(MinderEvent, { *
isShortcutKey: function(keyCombine) { * @param {String|KeyEvent} unknown
var keyEvent = this.originEvent; */
if (!keyEvent) return false; function getMetaKeyCode(unknown) {
var CTRL_MASK = 0x1000;
var ALT_MASK = 0x2000;
var SHIFT_MASK = 0x4000;
var metaKeyCode = 0;
return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent); if (typeof(unknown) == 'string') {
} // unknown as string
}); unknown.toLowerCase().split(/\+\s*/).forEach(function(name) {
switch(name) {
KityMinder.registerInit(function() { case 'ctrl':
this._initShortcutKey(); case 'cmd':
}); metaKeyCode |= CTRL_MASK;
break;
kity.extendClass(KityMinder, { case 'alt':
metaKeyCode |= ALT_MASK;
_initShortcutKey: function() { break;
this._bindShortcutKeys(); case 'shift':
}, metaKeyCode |= SHIFT_MASK;
break;
_bindShortcutKeys: function() { default:
var map = this._shortcutKeys = {}; metaKeyCode |= keymap[name];
var has = 'hasOwnProperty';
this.on('keydown', function(e) {
for (var keys in map) {
if (!map[has](keys)) continue;
if (e.isShortcutKey(keys)) {
var fn = map[keys];
if (fn.__statusCondition && fn.__statusCondition != this.getStatus()) return;
fn();
e.preventDefault();
} }
});
} else {
// unknown as key event
if (unknown.ctrlKey || unknown.metaKey) {
metaKeyCode |= CTRL_MASK;
} }
}); if (unknown.altKey) {
}, metaKeyCode |= ALT_MASK;
addShortcut: function(keys, fn) {
var binds = this._shortcutKeys;
keys.split(/\|\s*/).forEach(function(combine) {
var parts = combine.split('::');
var status;
if (parts.length > 1) {
combine = parts[1];
status = parts[0];
fn.__statusCondition = status;
} }
binds[combine] = fn; if (unknown.shiftKey) {
}); metaKeyCode |= SHIFT_MASK;
}, }
metaKeyCode |= unknown.keyCode;
addCommandShortcutKeys: function(cmd, keys) {
var binds = this._commandShortcutKeys || (this._commandShortcutKeys = {});
var obj = {},
km = this;
if (keys) {
obj[cmd] = keys;
} else {
obj = cmd;
} }
var minder = this; return metaKeyCode;
}
kity.extendClass(MinderEvent, {
isShortcutKey: function(keyCombine) {
var keyEvent = this.originEvent;
if (!keyEvent) return false;
utils.each(obj, function(command, keys) { return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent);
}
});
binds[command] = keys; Minder.registerInitHook(function() {
this._initShortcutKey();
});
minder.addShortcut(keys, function execCommandByShortcut() { kity.extendClass(Minder, {
if (minder.queryCommandState(command) === 0) {
minder.execCommand(command); _initShortcutKey: function() {
this._bindShortcutKeys();
},
_bindShortcutKeys: function() {
var map = this._shortcutKeys = {};
var has = 'hasOwnProperty';
this.on('keydown', function(e) {
for (var keys in map) {
if (!map[has](keys)) continue;
if (e.isShortcutKey(keys)) {
var fn = map[keys];
if (fn.__statusCondition && fn.__statusCondition != this.getStatus()) return;
fn();
e.preventDefault();
}
} }
}); });
}); },
},
getCommandShortcutKey: function(cmd) { addShortcut: function(keys, fn) {
var binds = this._commandShortcutKeys; var binds = this._shortcutKeys;
return binds && binds[cmd] || null; keys.split(/\|\s*/).forEach(function(combine) {
} var parts = combine.split('::');
var status;
if (parts.length > 1) {
combine = parts[1];
status = parts[0];
fn.__statusCondition = status;
}
binds[combine] = fn;
});
},
addCommandShortcutKeys: function(cmd, keys) {
var binds = this._commandShortcutKeys || (this._commandShortcutKeys = {});
var obj = {},
km = this;
if (keys) {
obj[cmd] = keys;
} else {
obj = cmd;
}
var minder = this;
utils.each(obj, function(keys, command) {
binds[command] = keys;
minder.addShortcut(keys, function execCommandByShortcut() {
if (minder.queryCommandState(command) === 0) {
minder.execCommand(command);
}
});
});
},
getCommandShortcutKey: function(cmd) {
var binds = this._commandShortcutKeys;
return binds && binds[cmd] || null;
}
});
}); });
\ No newline at end of file
var keymap = KityMinder.keymap = (function(origin) { define(function(require, exports, module) {
var ret = {}; var keymap = {
for (var key in origin) { 'Backspace': 8,
if (origin.hasOwnProperty(key)) { 'Tab': 9,
ret[key] = origin[key]; 'Enter': 13,
ret[key.toLowerCase()] = origin[key];
'Shift': 16,
'Control': 17,
'Alt': 18,
'CapsLock': 20,
'Esc': 27,
'Spacebar': 32,
'PageUp': 33,
'PageDown': 34,
'End': 35,
'Home': 36,
'Insert': 45,
'Left': 37,
'Up': 38,
'Right': 39,
'Down': 40,
'direction': {
37: 1,
38: 1,
39: 1,
40: 1
},
'Del': 46,
'NumLock': 144,
'Cmd': 91,
'CmdFF': 224,
'F1': 112,
'F2': 113,
'F3': 114,
'F4': 115,
'F5': 116,
'F6': 117,
'F7': 118,
'F8': 119,
'F9': 120,
'F10': 121,
'F11': 122,
'F12': 123,
'`': 192,
'=': 187,
'-': 189,
'/': 191,
'.': 190,
controlKeys: {
16: 1,
17: 1,
18: 1,
20: 1,
91: 1,
224: 1
},
'notContentChange': {
13: 1,
9: 1,
33: 1,
34: 1,
35: 1,
36: 1,
16: 1,
17: 1,
18: 1,
20: 1,
91: 1,
//上下左右
37: 1,
38: 1,
39: 1,
40: 1,
113: 1,
114: 1,
115: 1,
144: 1,
27: 1
},
'isSelectedNodeKey': {
//上下左右
37: 1,
38: 1,
39: 1,
40: 1,
13: 1,
9: 1
}
};
// 小写适配
for (var key in keymap) {
if (keymap.hasOwnProperty(key)) {
keymap[key.toLowerCase()] = keymap[key];
} }
} }
var aKeyCode = 65; var aKeyCode = 65;
...@@ -11,118 +115,14 @@ var keymap = KityMinder.keymap = (function(origin) { ...@@ -11,118 +115,14 @@ var keymap = KityMinder.keymap = (function(origin) {
// letters // letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) { 'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode); keymap[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
}); });
// numbers // numbers
var n = 9; var n = 9;
do { do {
ret[n.toString()] = n + 48; keymap[n.toString()] = n + 48;
} while(--n); } while(--n);
return ret; module.exports = keymap;
})({
'Backspace': 8,
'Tab': 9,
'Enter': 13,
'Shift': 16,
'Control': 17,
'Alt': 18,
'CapsLock': 20,
'Esc': 27,
'Spacebar': 32,
'PageUp': 33,
'PageDown': 34,
'End': 35,
'Home': 36,
'Insert': 45,
'Left': 37,
'Up': 38,
'Right': 39,
'Down': 40,
'direction': {
37: 1,
38: 1,
39: 1,
40: 1
},
'Del': 46,
'NumLock': 144,
'Cmd': 91,
'CmdFF': 224,
'F1': 112,
'F2': 113,
'F3': 114,
'F4': 115,
'F5': 116,
'F6': 117,
'F7': 118,
'F8': 119,
'F9': 120,
'F10': 121,
'F11': 122,
'F12': 123,
'`': 192,
'=': 187,
'-': 189,
'/': 191,
'.': 190,
controlKeys: {
16: 1,
17: 1,
18: 1,
20: 1,
91: 1,
224: 1
},
'notContentChange': {
13: 1,
9: 1,
33: 1,
34: 1,
35: 1,
36: 1,
16: 1,
17: 1,
18: 1,
20: 1,
91: 1,
//上下左右
37: 1,
38: 1,
39: 1,
40: 1,
113: 1,
114: 1,
115: 1,
144: 1,
27: 1
},
'isSelectedNodeKey': {
//上下左右
37: 1,
38: 1,
39: 1,
40: 1,
13: 1,
9: 1
}
}); });
\ No newline at end of file
/**
* @fileOverview
*
* Kity 引入
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
module.exports = require('../../lib/kity/src/kity.js');
});
\ No newline at end of file
/**
* @fileOverview
*
* KityMinder 类,暴露在 window 上的唯一变量
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
/* jshint -W079 */
var _initFnQueue = [];
var _uuidMap = {};
var KityMinder = kity.createClass('KityMinder', {
constructor: function(options) {
this._options = Utils.extend({}, options);
var initQueue = _initFnQueue.slice();
// @see option.js
// @see event.js
// @see status.js
// @see paper.js
// @see select.js
// @see key.js
// @see contextmenu.js
// @see module.js
// @see data.js
// @see readonly.js
// @see layout.js
// @see theme.js
while (initQueue.length) initQueue.shift().call(this, options);
this.fire('ready');
}
});
KityMinder.version = '1.0.0';
KityMinder.registerInit = function(fn) {
_initFnQueue.push(fn);
};
KityMinder.uuid = function(name) {
name = name || 'unknown';
_uuidMap[name] = _uuidMap[name] || 0;
++_uuidMap[name];
return name + '_' + _uuidMap[name];
};
// expose
if (typeof(module) != 'undefined') {
module.exports = KityMinder;
} else {
window.KityMinder = KityMinder;
}
This diff is collapsed.
/**
* @fileOverview
*
* KityMinder 类,暴露在 window 上的唯一变量
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var _initHooks = [];
var Minder = kity.createClass('Minder', {
constructor: function(options) {
this._options = utils.extend({}, options);
var initHooks = _initHooks.slice();
var initHook;
while (initHooks.length) {
initHook = initHooks.shift();
if (typeof(initHook) == 'function') {
initHook.call(this, this._options);
}
}
this.fire('ready');
}
});
Minder.version = '1.3.6';
Minder.registerInitHook = function(hook) {
_initHooks.push(hook);
};
module.exports = Minder;
});
//模块注册&暴露模块接口 define(function(require, exports, module) {
( function () { var kity = require('./kity');
var _modules; var utils = require('./utils');
KityMinder.registerModule = function ( name, module ) { var Minder = require('./minder');
//初始化模块列表
if ( !_modules ) { /* 已注册的模块 */
_modules = {}; var _modules = {};
}
_modules[ name ] = module; exports.register = function(name, module) {
}; _modules[name] = module;
KityMinder.getModules = function () {
return _modules;
}; };
} )();
KityMinder.registerInit(function() { /* 模块初始化 */
this._initModules(); Minder.registerInitHook(function() {
}); this._initModules();
});
// 模块声明周期维护 // 模块声明周期维护
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
_initModules: function() { _initModules: function() {
var modulesPool = KityMinder.getModules(); var modulesPool = _modules;
var modulesToLoad = this._options.modules || Utils.keys(modulesPool); var modulesToLoad = this._options.modules || utils.keys(modulesPool);
this._commands = {}; this._commands = {};
this._query = {}; this._query = {};
this._modules = {}; this._modules = {};
this._rendererClasses = {}; this._rendererClasses = {};
var i, name, type, module, moduleDeals, var i, name, type, module, moduleDeals,
dealCommands, dealEvents, dealRenderers; dealCommands, dealEvents, dealRenderers;
var me = this; var me = this;
for (i = 0; i < modulesToLoad.length; i++) { for (i = 0; i < modulesToLoad.length; i++) {
name = modulesToLoad[i]; name = modulesToLoad[i];
if (!modulesPool[name]) continue; if (!modulesPool[name]) continue;
// 执行模块初始化,抛出后续处理对象 // 执行模块初始化,抛出后续处理对象
if (typeof(modulesPool[name]) == 'function') { if (typeof(modulesPool[name]) == 'function') {
moduleDeals = modulesPool[name].call(me); moduleDeals = modulesPool[name].call(me);
} else { } else {
moduleDeals = modulesPool[name]; moduleDeals = modulesPool[name];
} }
this._modules[name] = moduleDeals; this._modules[name] = moduleDeals;
if (!moduleDeals) continue; if (!moduleDeals) continue;
if (moduleDeals.init) { if (moduleDeals.init) {
moduleDeals.init.call(me, this._options); moduleDeals.init.call(me, this._options);
} }
// command加入命令池子 // command加入命令池子
dealCommands = moduleDeals.commands; dealCommands = moduleDeals.commands;
for (name in dealCommands) { for (name in dealCommands) {
this._commands[name.toLowerCase()] = new dealCommands[name](); this._commands[name.toLowerCase()] = new dealCommands[name]();
} }
// 绑定事件 // 绑定事件
dealEvents = moduleDeals.events; dealEvents = moduleDeals.events;
if (dealEvents) { if (dealEvents) {
for (type in dealEvents) { for (type in dealEvents) {
me.on(type, dealEvents[type]); me.on(type, dealEvents[type]);
}
} }
}
// 渲染器 // 渲染器
dealRenderers = moduleDeals.renderers; dealRenderers = moduleDeals.renderers;
if (dealRenderers) { if (dealRenderers) {
for (type in dealRenderers) { for (type in dealRenderers) {
this._rendererClasses[type] = this._rendererClasses[type] || []; this._rendererClasses[type] = this._rendererClasses[type] || [];
if (Utils.isArray(dealRenderers[type])) { if (utils.isArray(dealRenderers[type])) {
this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]); this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]);
} else { } else {
this._rendererClasses[type].push(dealRenderers[type]); this._rendererClasses[type].push(dealRenderers[type]);
}
} }
} }
}
} //添加模块的快捷键
}, if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
}
_garbage: function() { }
this.clearSelect(); },
while (this._root.getChildren().length) { _garbage: function() {
this._root.removeChild(0); this.clearSelect();
}
},
destroy: function() { while (this._root.getChildren().length) {
var modules = this._modules; this._root.removeChild(0);
}
},
this._resetEvents(); destroy: function() {
this._garbage(); var modules = this._modules;
for (var key in modules) { this._resetEvents();
if (!modules[key].destroy) continue; this._garbage();
modules[key].destroy.call(this);
}
},
reset: function() { for (var key in modules) {
var modules = this._modules; if (!modules[key].destroy) continue;
modules[key].destroy.call(this);
}
},
this._garbage(); reset: function() {
var modules = this._modules;
for (var key in modules) { this._garbage();
if (!modules[key].reset) continue;
modules[key].reset.call(this); for (var key in modules) {
if (!modules[key].reset) continue;
modules[key].reset.call(this);
}
} }
} });
}); });
\ No newline at end of file
This diff is collapsed.
/**
* @fileOverview
*
* 提供脑图选项支持
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
kity.extendClass(Minder, {
getOption: function(key) {
if (key) {
return this._options[key];
} else {
return this._options;
}
}
});
});
\ No newline at end of file
/**
* @fileOverview
*
* 提供脑图选项支持
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
kity.extendClass(KityMinder, {
getOptions: function(key) {
if (key) {
return this._options[key];
} else {
return this._options;
}
}
});
\ No newline at end of file
...@@ -6,51 +6,61 @@ ...@@ -6,51 +6,61 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerInit(function() { define(function(require, exports, module) {
this._initPaper(); var kity = require('./kity');
}); var utils = require('./utils');
kity.extendClass(KityMinder, { var Minder = require('./minder');
_initPaper: function() { Minder.registerInitHook(function() {
this._initPaper();
this._paper = new kity.Paper(); });
this._paper.getNode().setAttribute('contenteditable', true);
this._paper.getNode().ondragstart = function(e) { kity.extendClass(Minder, {
e.preventDefault();
}; _initPaper: function() {
this._paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
this._paper = new kity.Paper();
this._addRenderContainer(); this._paper.getNode().ondragstart = function(e) {
e.preventDefault();
this.setRoot(this.createNode()); };
this._paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
if (this._options.renderTo) {
this.renderTo(this._options.renderTo); this._addRenderContainer();
}
}, this.setRoot(this.createNode());
_addRenderContainer: function() { if (this._options.renderTo) {
this._rc = new kity.Group().setId(KityMinder.uuid('minder')); this.renderTo(this._options.renderTo);
this._paper.addShape(this._rc); }
}, },
renderTo: function(target) { _addRenderContainer: function() {
if (typeof(target) == 'string') { this._rc = new kity.Group().setId(utils.uuid('minder'));
target = document.getElementById(target); this._paper.addShape(this._rc);
} },
this._paper.renderTo(this._renderTarget = target);
this._bindEvents(); renderTo: function(target) {
}, if (typeof(target) == 'string') {
target = document.getElementById(target);
getRenderContainer: function() { }
return this._rc; if (target) {
}, this._paper.renderTo(this._renderTarget = target);
this._bindEvents();
getPaper: function() { this.fire('paperrender');
return this._paper; }
}, return this;
},
getRenderTarget: function() {
return this._renderTarget; getRenderContainer: function() {
}, return this._rc;
},
getPaper: function() {
return this._paper;
},
getRenderTarget: function() {
return this._renderTarget;
},
});
}); });
\ No newline at end of file
/** /**
* @fileOverview * @fileOverview
* *
* * 只读模式支持
* *
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerInit(function(options) {
if (options.readOnly) { define(function(require, exports, module) {
this.setDisabled(); var kity = require('./kity');
} var Minder = require('./minder');
});
kity.extendClass(KityMinder, { Minder.registerInitHook(function(options) {
if (options.readOnly) {
disable: function() { this.setDisabled();
var me = this; }
//禁用命令 });
me.bkqueryCommandState = me.queryCommandState;
me.bkqueryCommandValue = me.queryCommandValue; kity.extendClass(Minder, {
me.queryCommandState = function(type) {
var cmd = this._getCommand(type); disable: function() {
if (cmd && cmd.enableReadOnly) { var me = this;
return me.bkqueryCommandState.apply(me, arguments); //禁用命令
me.bkqueryCommandState = me.queryCommandState;
me.bkqueryCommandValue = me.queryCommandValue;
me.queryCommandState = function(type) {
var cmd = this._getCommand(type);
if (cmd && cmd.enableReadOnly) {
return me.bkqueryCommandState.apply(me, arguments);
}
return -1;
};
me.queryCommandValue = function(type) {
var cmd = this._getCommand(type);
if (cmd && cmd.enableReadOnly) {
return me.bkqueryCommandValue.apply(me, arguments);
}
return null;
};
this.setStatus('readonly');
me._interactChange();
},
enable: function() {
var me = this;
if (me.bkqueryCommandState) {
me.queryCommandState = me.bkqueryCommandState;
delete me.bkqueryCommandState;
} }
return -1; if (me.bkqueryCommandValue) {
}; me.queryCommandValue = me.bkqueryCommandValue;
me.queryCommandValue = function(type) { delete me.bkqueryCommandValue;
var cmd = this._getCommand(type);
if (cmd && cmd.enableReadOnly) {
return me.bkqueryCommandValue.apply(me, arguments);
} }
return null;
};
this.setStatus('readonly');
me._interactChange();
},
enable: function() {
var me = this;
if (me.bkqueryCommandState) {
me.queryCommandState = me.bkqueryCommandState;
delete me.bkqueryCommandState;
}
if (me.bkqueryCommandValue) {
me.queryCommandValue = me.bkqueryCommandValue;
delete me.bkqueryCommandValue;
}
this.setStatus('normal'); this.setStatus('normal');
me._interactChange(); me._interactChange();
} }
});
}); });
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -7,23 +7,26 @@ ...@@ -7,23 +7,26 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerInit(function() { define(function(require, exports, module) {
this._initStatus(); var kity = require('./kity');
}); var Minder = require('./minder');
kity.extendClass(KityMinder, { var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
_initStatus: function() { Minder.registerInitHook(function() {
this._status = 'normal'; this._initStatus();
this._rollbackStatus = 'normal'; });
},
setStatus: (function() { kity.extendClass(Minder, {
var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
// 在 readonly 模式下,只有 force 为 true 才能切换回来 _initStatus: function() {
return function(status, force) { this._status = 'normal';
this._rollbackStatus = 'normal';
},
setStatus: function(status, force) {
// 在 readonly 模式下,只有 force 为 true 才能切换回来
if (this._status == 'readonly' && !force) return this; if (this._status == 'readonly' && !force) return this;
if (status != this._status) { if (status != this._status) {
this._rollbackStatus = this._status; this._rollbackStatus = this._status;
...@@ -33,6 +36,7 @@ kity.extendClass(KityMinder, { ...@@ -33,6 +36,7 @@ kity.extendClass(KityMinder, {
currentStatus: this._status currentStatus: this._status
}); });
if (sf) { if (sf) {
/* global console: true */
console.log(window.event.type, this._rollbackStatus, '->', this._status); console.log(window.event.type, this._rollbackStatus, '->', this._status);
if (tf) { if (tf) {
console.trace(); console.trace();
...@@ -40,16 +44,17 @@ kity.extendClass(KityMinder, { ...@@ -40,16 +44,17 @@ kity.extendClass(KityMinder, {
} }
} }
return this; return this;
}; },
})(),
rollbackStatus: function() {
rollbackStatus: function() { this.setStatus(this._rollbackStatus);
this.setStatus(this._rollbackStatus); },
}, getRollbackStatus:function(){
getRollbackStatus:function(){ return this._rollbackStatus;
return this._rollbackStatus; },
}, getStatus: function() {
getStatus: function() { return this._status;
return this._status; }
} });
}); });
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* @fileOverview
*
* 默认导出(全部模块)
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var kityminder = {
version: require('core/minder').version
};
// 核心导出,大写的部分导出类,小写的部分简单 require 一下
require('core/kity');
require('core/utils');
kityminder.Minder = require('core/minder');
kityminder.Command = require('core/command');
kityminder.Node = require('core/node');
require('core/option');
kityminder.Event = require('core/event');
kityminder.KeyMap = require('core/keymap');
require('core/key');
require('core/status');
require('core/paper');
require('core/select');
kityminder.Module = require('core/module');
kityminder.Data = require('core/data');
require('core/compatibility');
require('core/readonly');
kityminder.Render = require('core/render');
kityminder.Connect = require('core/connect');
kityminder.Layout = require('core/layout');
kityminder.Theme = require('core/theme');
kityminder.Template = require('core/template');
// 模块依赖
require('module/arrange');
require('module/basestyle');
require('module/clipboard');
require('module/dragtree');
require('module/expand');
require('module/font');
require('module/history');
require('module/hyperlink');
require('module/image');
require('module/keynav');
require('module/layout');
require('module/node');
require('module/note');
require('module/outline');
require('module/priority');
require('module/progress');
require('module/resource');
require('module/select');
require('module/style');
require('module/text');
require('module/view');
require('module/zoom');
require('layout/mind');
require('layout/btree');
require('layout/filetree');
require('layout/fish-bone-master');
require('layout/fish-bone-slave');
require('theme/default');
require('theme/snow');
require('theme/fresh');
require('theme/fish');
require('theme/snow');
require('connect/arc');
require('connect/bezier');
require('connect/fish-bone-master');
require('connect/l');
require('connect/poly');
require('connect/under');
require('template/default');
require('template/structure');
require('template/filetree');
require('template/right');
require('template/fish-bone');
module.exports = kityminder;
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('structure', { template.register('structure', {
getLayout: function(node) { getLayout: function(node) {
return node.getData('layout') || 'bottom'; return node.getData('layout') || 'bottom';
}, },
getConnect: function(node) { getConnect: function(node) {
return 'poly'; return 'poly';
} }
});
}); });
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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