Commit 651acd74 authored by techird's avatar techird

使用 Module 规范组织代码

parent b27e5394
{
"directory": "lib"
}
\ No newline at end of file
......@@ -4,8 +4,4 @@
*.sublime-workspace
dist/
node_modules/
_drafts/
native-support/archive/src/tmp/
native-support/archive/upload/
ui/theme/default/css/*.css
ui/theme/default/css/*.css.map
\ No newline at end of file
_drafts/
\ No newline at end of file
[submodule "lib/kity"]
path = lib/kity
url = https://github.com/fex-team/kity
\ No newline at end of file
url = https://github.com/fex-team/kity
[submodule "lib/promise"]
path = lib/promise
url = https://github.com/jakearchibald/es6-promise
......@@ -66,7 +66,7 @@
"disallowSpacesInsideParentheses": true,
// 行尾「MUST NOT」使用空格
"disallowTrailingWhitespace": false,
"disallowTrailingWhitespace": true,
// 每行「MUST NOT」超过 120 个字符
"maximumLineLength": 120,
......
......@@ -10,23 +10,7 @@
"browser": true,
"boss": true,
"predef" : [
"module",
"require",
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"keymap",
"Utils",
"utils",
"$",
"KM",
"keymap",
"browser"
"define",
"Promise"
]
}
\ No newline at end of file
/*-----------------------------------------------------
* livereload Default Setting
*-----------------------------------------------------*/
'use strict';
/* global require, module */
var path = require('path');
/*-----------------------------------------------------
* Module Setting
*-----------------------------------------------------*/
module.exports = function(grunt) {
'use strict';
// These plugins provide necessary tasks.
/* [Build plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-module-dependence');
grunt.loadNpmTasks('grunt-contrib-concat');
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' +
' * ====================================================\n' +
......@@ -32,161 +22,29 @@ module.exports = function(grunt) {
' * ====================================================\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.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
clean: ['dist', 'native-support/upload/', 'native-support/src/tmp/'],
concat: concatConfigs,
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
dependence: {
options: {
base: 'src',
entrance: 'kityminder'
},
mise: {
merge: {
files: [{
src: ['LICENSE', 'favicon.ico', 'README.md', 'CHANGELOG.md'],
dest: distPath
}]
}
},
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())
src: 'src/**/*.js',
dest: 'release/kityminder.all.js'
}]
}
},
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).
grunt.registerTask('default', ['clean', 'concat', 'uglify', 'less', 'autoprefixer', 'copy', 'replace']);
grunt.registerTask('dev', ['less', 'autoprefixer', 'watch']);
grunt.registerTask('default', ['dependence']);
};
\ 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 @@
<meta charset="utf-8">
<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">
<style type="text/css">
body {
......@@ -37,9 +30,33 @@
<body>
<div id="minder-view"></div>
</body>
<!-- *************************** Module 形式加载引入 **************************** -->
<script type="text/javascript" src="lib/seajs/dist/sea-debug.js"></script>
<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'
});
});
seajs.use('start');
</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>
\ 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 @@
"title": "kityminder",
"description": "Kity Minder",
"version": "1.3.5",
"homepage": "https://github.com/fex-team/kityminder",
"homepage": "https://github.com/fex-team/kityminder-core",
"author": {
"name": "f-cube @ FEX",
"url": "http://fex.baidu.com"
},
"repository": {
"type": "git",
"url": "https://github.com/fex-team/kityminder.git"
"url": "https://github.com/fex-team/kityminder-core.git"
},
"keywords": [
"kityminder",
......@@ -21,23 +21,20 @@
"javascript"
],
"bugs": {
"url": "https://github.com/fex-team/kityminder/issues"
"url": "https://github.com/fex-team/kityminder-core/issues"
},
"licenses": [ {
"type": "MIT",
"url": "https://github.com/fex-team/kityminder/blob/dev/LICENSE"
"url": "https://github.com/fex-team/kityminder-core/blob/dev/LICENSE"
} ],
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-module-dependence": "~0.1.4",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-text-replace": "~0.3.9",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-less": "~0.11.3",
"grunt-contrib-clean": "~0.6.0",
"grunt-autoprefixer": "~1.0.1"
"grunt-contrib-clean": "~0.5.0"
}
}
\ No newline at end of file
......@@ -7,38 +7,43 @@
* @copyright: Baidu FEX, 2014
*/
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');
});
define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
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(),
pBox = parent.getLayoutBox();
connect.register('arc', function(node, parent, connection, width, color) {
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
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);
end = side == 'left' ?
new kity.Point(box.right + 2, box.cy) :
new kity.Point(box.left - 2, box.cy);
node.getMinder().getPaper().addResource(connectMarker);
vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
start = new kity.Point(pBox.cx, pBox.cy);
end = side == 'left' ?
new kity.Point(box.right + 2, box.cy) :
new kity.Point(box.left - 2, box.cy);
connection.setMarker(connectMarker);
connectMarker.dot.fill(color);
vector = kity.Vector.fromPoints(start, end);
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 @@
* @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');
// 连线起点和终点
var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
connect.register('bezier', function(node, parent, connection) {
// 连线矢量和方向
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;
if (abs(v.x) > abs(v.y)) {
// 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);
}
var pathData = [];
pathData.push('M', r(po.x), r(po.y));
connection.setMarker(null);
connection.setPathData(pathData);
if (abs(v.x) > abs(v.y)) {
// 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 @@
* @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(),
pin = node.getLayoutVertexIn();
connect.register('fish-bone-master', function(node, parent, connection) {
var abs = Math.abs;
var pout = parent.getLayoutVertexOut(),
pin = node.getLayoutVertexIn();
var dy = abs(pout.y - pin.y),
dx = abs(pout.x - pin.x);
var abs = Math.abs;
var pathData = [];
var dy = abs(pout.y - pin.y),
dx = abs(pout.x - pin.x);
pathData.push('M', pout.x, pout.y);
pathData.push('h', dx - dy);
pathData.push('L', pin.x, pin.y);
var pathData = [];
connection.setMarker(null);
connection.setPathData(pathData);
pathData.push('M', pout.x, pout.y);
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 @@
* @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();
var pi = node.getLayoutVertexIn();
var vo = parent.getLayoutVectorOut();
connect.register('l', function(node, parent, connection) {
var pathData = [];
var r = Math.round,
abs = Math.abs;
var po = parent.getLayoutVertexOut();
var pi = node.getLayoutVertexIn();
var vo = parent.getLayoutVectorOut();
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);
var pathData = [];
var r = Math.round,
abs = Math.abs;
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 @@
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerConnectProvider('poly', function(node, parent, connection, width) {
// 连线起点和终点
var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
// 连线矢量和方向
var v = parent.getLayoutVectorOut().normalize();
var r = Math.round;
var abs = Math.abs;
var pathData = [];
pathData.push('M', r(po.x), r(po.y));
switch (true) {
case abs(v.x) > abs(v.y) && v.x < 0:
// left
pathData.push('h', -parent.getStyle('margin-left'));
pathData.push('v', pi.y - po.y);
pathData.push('H', pi.x);
break;
case abs(v.x) > abs(v.y) && v.x >= 0:
// right
pathData.push('h', parent.getStyle('margin-right'));
pathData.push('v', pi.y - po.y);
pathData.push('H', pi.x);
break;
case abs(v.x) <= abs(v.y) && v.y < 0:
// top
pathData.push('v', -parent.getStyle('margin-top'));
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y);
break;
case abs(v.x) <= abs(v.y) && v.y >= 0:
// bottom
pathData.push('v', parent.getStyle('margin-bottom'));
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y);
break;
}
connection.setMarker(null);
connection.setPathData(pathData);
define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('poly', function(node, parent, connection, width) {
// 连线起点和终点
var po = parent.getLayoutVertexOut(),
pi = node.getLayoutVertexIn();
// 连线矢量和方向
var v = parent.getLayoutVectorOut().normalize();
var r = Math.round;
var abs = Math.abs;
var pathData = [];
pathData.push('M', r(po.x), r(po.y));
switch (true) {
case abs(v.x) > abs(v.y) && v.x < 0:
// left
pathData.push('h', -parent.getStyle('margin-left'));
pathData.push('v', pi.y - po.y);
pathData.push('H', pi.x);
break;
case abs(v.x) > abs(v.y) && v.x >= 0:
// right
pathData.push('h', parent.getStyle('margin-right'));
pathData.push('v', pi.y - po.y);
pathData.push('H', pi.x);
break;
case abs(v.x) <= abs(v.y) && v.y < 0:
// top
pathData.push('v', -parent.getStyle('margin-top'));
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y);
break;
case abs(v.x) <= abs(v.y) && v.y >= 0:
// bottom
pathData.push('v', parent.getStyle('margin-bottom'));
pathData.push('h', pi.x - po.x);
pathData.push('V', pi.y);
break;
}
connection.setMarker(null);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,39 +7,44 @@
* @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(),
pBox = parent.getLayoutBox();
connect.register('under', function(node, parent, connection, width, color) {
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.x > pBox.x ? 'right' : 'left';
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
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') {
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);
}
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;
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);
pathData.push('C', mx, p1.y, mx, p2.y, p2);
pathData.push('L', p3);
mx = (p1.x + p2.x) / 2;
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;
KityMinder.COMMAND_STATE_DISABLED = -1;
KityMinder.COMMAND_STATE_ACTIVED = 1;
var Command = kity.createClass( "Command", {
constructor: function () {
this._isContentChange = true;
this._isSelectionChange = false;
},
execute: function ( minder, args ) {
},
setContentChanged: function ( val ) {
this._isContentChange = !! val;
},
isContentChanged: function () {
return this._isContentChange;
},
setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val;
},
isSelectionChanged: function () {
return this._isContentChange;
},
queryState: function ( km ) {
return KityMinder.COMMAND_STATE_NORMAL;
},
queryValue: function ( km ) {
return 0;
},
isNeedUndo: function () {
return true;
}
} );
kity.extendClass(KityMinder, {
_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", 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;
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
var MinderNode = require('./node');
var MinderEvent = require('./event');
var COMMAND_STATE_NORMAL = 0;
var COMMAND_STATE_DISABLED = -1;
var COMMAND_STATE_ACTIVED = 1;
/**
* @class Command
*
* 表示一个命令,包含命令的查询及执行
*/
var Command = kity.createClass('Command', {
constructor: function() {
this._isContentChange = true;
this._isSelectionChange = false;
},
execute: function(minder, args) {
throw new Error('Not Implement: Command.execute()');
},
setContentChanged: function(val) {
this._isContentChange = !!val;
},
isContentChanged: function() {
return this._isContentChange;
},
setSelectionChanged: function(val) {
this._isSelectionChange = !!val;
},
isSelectionChanged: function() {
return this._isContentChange;
},
queryState: function(km) {
return COMMAND_STATE_NORMAL;
},
queryValue: function(km) {
return 0;
},
isNeedUndo: function() {
return true;
}
});
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()) {
this._hasEnterExecCommand = true;
stoped = this._fire(new MinderEvent('beforeExecCommand', eventParams, true));
if (!this._hasEnterExecCommand && cmd.isNeedUndo()) {
this._hasEnterExecCommand = true;
stoped = this._fire(new MinderEvent('beforeExecCommand', eventParams, true));
if (!stoped) {
//保存场景
this._fire(new MinderEvent('saveScene'));
if (!stoped) {
//保存场景
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()) {
this._firePharse(new MinderEvent('contentchange'));
if (cmd.isContentChanged()) {
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) {
this._interactChange();
}
return result === undefined ? null : result;
}
});
return result === undefined ? null : result;
}
module.exports = Command;
});
\ No newline at end of file
Utils.extend(KityMinder, {
compatibility: function(json) {
define(function(require, exports, module) {
var utils = require('./utils');
var version = json.version || '1.1.3';
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;
function compatibility(json) {
// 升级优先级、进度图标
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;
});
}
var version = json.version || '1.1.3';
switch (version) {
case '1.1.3':
c_113_120(json);
/* falls through */
case '1.2.0':
case '1.2.1':
c_120_130(json);
/* falls through */
}
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 */
utils.extend(KityMinder, {
_connectProviders: {},
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
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([
'M', parent.getLayoutVertexOut(),
'L', node.getLayoutVertexIn()
]);
},
registerConnectProvider: function(name, provider) {
KityMinder._connectProviders[name] = provider;
},
getConnectProvider: function(name) {
return KityMinder._connectProviders[name] || KityMinder._defaultConnectProvider;
}
});
});
kity.extendClass(MinderNode, {
getConnectProvider: function() {
return KityMinder.getConnectProvider(this.getConnect());
},
kity.extendClass(MinderNode, {
getConnect: function() {
return this.data.connect || 'default';
},
getConnect: function() {
return null;
},
getConnectProvider: function() {
return _connectProviders[this.getConnect()] || _connectProviders['default'];
},
getConnection: function() {
return this._connection || null;
}
});
getConnection: function() {
return this._connection || null;
}
});
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
getConnectContainer: function() {
return this._connectContainer;
},
getConnectContainer: function() {
return this._connectContainer;
},
createConnect: function(node) {
if (node.isRoot()) return;
createConnect: function(node) {
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.updateConnect(node);
},
this._connectContainer.addShape(connection);
this.updateConnect(node);
},
removeConnect: function(node) {
var me = this;
node.traverse(function(node) {
me._connectContainer.removeShape(node._connection);
node._connection = null;
});
},
removeConnect: function(node) {
var me = this;
node.traverse(function(node) {
me._connectContainer.removeShape(node._connection);
node._connection = null;
});
},
updateConnect: function(node) {
updateConnect: function(node) {
var connection = node._connection;
var parent = node.parent;
var connection = node._connection;
var parent = node.parent;
if (!parent || !connection) return;
if (!parent || !connection) return;
if (parent.isCollapsed()) {
connection.setVisible(false);
return;
}
connection.setVisible(true);
if (parent.isCollapsed()) {
connection.setVisible(false);
return;
}
connection.setVisible(true);
var provider = node.getConnectProvider();
var provider = node.getConnectProvider();
var strokeColor = node.getStyle('connect-color') || 'white',
strokeWidth = node.getStyle('connect-width') || 2;
var strokeColor = node.getStyle('connect-color') || 'white',
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) {
connection.setTranslate(0.5, 0.5);
} else {
connection.setTranslate(0, 0);
if (strokeWidth % 2 === 0) {
connection.setTranslate(0.5, 0.5);
} else {
connection.setTranslate(0, 0);
}
}
}
});
KityMinder.registerModule('Connect', {
init: function() {
this._connectContainer = new kity.Group().setId(KityMinder.uuid('minder_connect_group'));
this.getRenderContainer().prependShape(this._connectContainer);
},
events: {
'nodeattach': function(e) {
this.createConnect(e.node);
},
'nodedetach': function(e) {
this.removeConnect(e.node);
});
Module.register('Connect', {
init: function() {
this._connectContainer = new kity.Group().setId(utils.uuid('minder_connect_group'));
this.getRenderContainer().prependShape(this._connectContainer);
},
'layoutapply layoutfinish noderender': function(e) {
this.updateConnect(e.node);
events: {
'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, {
_protocols: {},
registerProtocol: function(name, protocolDeal) {
KityMinder._protocols[name] = protocolDeal;
}
});
var DEFAULT_TEXT = {
'root': 'maintopic',
'main': 'topic',
'sub': 'topic'
};
KityMinder.registerInit(function() {
this._initProtocols();
});
// 导入导出
kity.extendClass(KityMinder, {
_initProtocols: function(options) {
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]));
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
var MinderNode = require('./node');
var MinderEvent = require('./event');
var compatibility = require('./compatibility');
// 导入导出
kity.extendClass(Minder, {
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.theme = this.getTheme();
json.version = KityMinder.version;
json.template = this.getTemplate();
json.theme = this.getTheme();
json.version = Minder.version;
return json;
},
return json;
},
importJson: function(json, params) {
importJson: function(json, params) {
function importNode(node, json, km) {
var data = json.data;
node.data = {};
for (var field in data) {
node.setData(field, data[field]);
}
function importNode(node, json, km) {
var data = json.data;
node.data = {};
for (var field in data) {
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 || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km);
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node);
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) {
protocol = this.getProtocol(protocolName);
if (!protocol || !protocol.encode) {
return Promise.reject(new Error('Not supported protocol:' + protocolName));
// 删除当前所有节点
while (this._root.getChildren().length) {
this.removeNode(this._root.getChildren()[0]);
}
}
// 导出前抛个事件
this._fire(new MinderEvent('beforeexport', {
json: json,
protocolName: protocolName,
protocol: protocol
}));
if (protocol) {
return Promise.resolve(protocol.encode(json, this, options));
} else {
return Promise.resolve(json);
}
},
json = Minder.compatibility(json);
importData: function(local, protocolName) {
importNode(this._root, json, this);
var json, protocol;
var minder = this;
this.setTemplate(json.template || 'default');
this.setTheme(json.theme || null);
this.refresh();
// 指定了协议进行导入,需要检测协议是否支持
if (protocolName) {
protocol = this.getProtocol(protocolName);
this.fire('import', params);
if (!protocol || !protocol.decode) {
return Promise.reject(new Error('Not supported protocol:' + protocolName));
}
this._firePharse({
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 @@
* @copyright: Baidu FEX, 2014
*/
/**
* 计算包含 meta 键的 keycode
*
* @param {String|KeyEvent} unknown
*/
function getMetaKeyCode(unknown) {
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;
}
define(function(require, exports, module) {
var kity = require('./kity.js');
var utils = require('./utils');
var keymap = require('./keymap');
var Minder = require('./minder');
var MinderEvent = require('./event');
return metaKeyCode;
}
kity.extendClass(MinderEvent, {
isShortcutKey: function(keyCombine) {
var keyEvent = this.originEvent;
if (!keyEvent) return false;
/**
* 计算包含 meta 键的 keycode
*
* @param {String|KeyEvent} unknown
*/
function getMetaKeyCode(unknown) {
var CTRL_MASK = 0x1000;
var ALT_MASK = 0x2000;
var SHIFT_MASK = 0x4000;
var metaKeyCode = 0;
return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent);
}
});
KityMinder.registerInit(function() {
this._initShortcutKey();
});
kity.extendClass(KityMinder, {
_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();
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;
}
});
},
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;
if (unknown.altKey) {
metaKeyCode |= ALT_MASK;
}
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;
if (unknown.shiftKey) {
metaKeyCode |= SHIFT_MASK;
}
metaKeyCode |= unknown.keyCode;
}
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() {
if (minder.queryCommandState(command) === 0) {
minder.execCommand(command);
kity.extendClass(Minder, {
_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) {
var binds = this._commandShortcutKeys;
return binds && binds[cmd] || null;
}
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;
});
},
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) {
var ret = {};
for (var key in origin) {
if (origin.hasOwnProperty(key)) {
ret[key] = origin[key];
ret[key.toLowerCase()] = origin[key];
define(function(require, exports, module) {
var 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
}
};
// 小写适配
for (var key in keymap) {
if (keymap.hasOwnProperty(key)) {
keymap[key.toLowerCase()] = keymap[key];
}
}
var aKeyCode = 65;
......@@ -11,118 +115,14 @@ var keymap = KityMinder.keymap = (function(origin) {
// letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
keymap[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
});
// numbers
var n = 9;
do {
ret[n.toString()] = n + 48;
keymap[n.toString()] = n + 48;
} while(--n);
return ret;
})({
'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
}
module.exports = keymap;
});
\ 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;
});
//模块注册&暴露模块接口
( function () {
var _modules;
KityMinder.registerModule = function ( name, module ) {
//初始化模块列表
if ( !_modules ) {
_modules = {};
}
_modules[ name ] = module;
};
KityMinder.getModules = function () {
return _modules;
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
/* 已注册的模块 */
var _modules = {};
exports.register = function(name, module) {
_modules[name] = module;
};
} )();
KityMinder.registerInit(function() {
this._initModules();
});
/* 模块初始化 */
Minder.registerInitHook(function() {
this._initModules();
});
// 模块声明周期维护
kity.extendClass(KityMinder, {
_initModules: function() {
var modulesPool = KityMinder.getModules();
var modulesToLoad = this._options.modules || Utils.keys(modulesPool);
// 模块声明周期维护
kity.extendClass(Minder, {
_initModules: function() {
var modulesPool = _modules;
var modulesToLoad = this._options.modules || utils.keys(modulesPool);
this._commands = {};
this._query = {};
this._modules = {};
this._rendererClasses = {};
this._commands = {};
this._query = {};
this._modules = {};
this._rendererClasses = {};
var i, name, type, module, moduleDeals,
dealCommands, dealEvents, dealRenderers;
var i, name, type, module, moduleDeals,
dealCommands, dealEvents, dealRenderers;
var me = this;
for (i = 0; i < modulesToLoad.length; i++) {
name = modulesToLoad[i];
var me = this;
for (i = 0; i < modulesToLoad.length; i++) {
name = modulesToLoad[i];
if (!modulesPool[name]) continue;
if (!modulesPool[name]) continue;
// 执行模块初始化,抛出后续处理对象
// 执行模块初始化,抛出后续处理对象
if (typeof(modulesPool[name]) == 'function') {
moduleDeals = modulesPool[name].call(me);
} else {
moduleDeals = modulesPool[name];
}
this._modules[name] = moduleDeals;
if (typeof(modulesPool[name]) == 'function') {
moduleDeals = modulesPool[name].call(me);
} else {
moduleDeals = modulesPool[name];
}
this._modules[name] = moduleDeals;
if (!moduleDeals) continue;
if (!moduleDeals) continue;
if (moduleDeals.init) {
moduleDeals.init.call(me, this._options);
}
if (moduleDeals.init) {
moduleDeals.init.call(me, this._options);
}
// command加入命令池子
dealCommands = moduleDeals.commands;
for (name in dealCommands) {
this._commands[name.toLowerCase()] = new dealCommands[name]();
}
// command加入命令池子
dealCommands = moduleDeals.commands;
for (name in dealCommands) {
this._commands[name.toLowerCase()] = new dealCommands[name]();
}
// 绑定事件
dealEvents = moduleDeals.events;
if (dealEvents) {
for (type in dealEvents) {
me.on(type, dealEvents[type]);
// 绑定事件
dealEvents = moduleDeals.events;
if (dealEvents) {
for (type in dealEvents) {
me.on(type, dealEvents[type]);
}
}
}
// 渲染器
dealRenderers = moduleDeals.renderers;
// 渲染器
dealRenderers = moduleDeals.renderers;
if (dealRenderers) {
if (dealRenderers) {
for (type in dealRenderers) {
this._rendererClasses[type] = this._rendererClasses[type] || [];
for (type in dealRenderers) {
this._rendererClasses[type] = this._rendererClasses[type] || [];
if (Utils.isArray(dealRenderers[type])) {
this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]);
} else {
this._rendererClasses[type].push(dealRenderers[type]);
if (utils.isArray(dealRenderers[type])) {
this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]);
} else {
this._rendererClasses[type].push(dealRenderers[type]);
}
}
}
}
}
},
//添加模块的快捷键
if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
}
_garbage: function() {
this.clearSelect();
}
},
while (this._root.getChildren().length) {
this._root.removeChild(0);
}
},
_garbage: function() {
this.clearSelect();
destroy: function() {
var modules = this._modules;
while (this._root.getChildren().length) {
this._root.removeChild(0);
}
},
this._resetEvents();
this._garbage();
destroy: function() {
var modules = this._modules;
for (var key in modules) {
if (!modules[key].destroy) continue;
modules[key].destroy.call(this);
}
},
this._resetEvents();
this._garbage();
reset: function() {
var modules = this._modules;
for (var key in modules) {
if (!modules[key].destroy) continue;
modules[key].destroy.call(this);
}
},
this._garbage();
reset: function() {
var modules = this._modules;
for (var key in modules) {
if (!modules[key].reset) continue;
modules[key].reset.call(this);
this._garbage();
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 @@
* @author: techird
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function() {
this._initPaper();
});
kity.extendClass(KityMinder, {
_initPaper: function() {
this._paper = new kity.Paper();
this._paper.getNode().setAttribute('contenteditable', true);
this._paper.getNode().ondragstart = function(e) {
e.preventDefault();
};
this._paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
this._addRenderContainer();
this.setRoot(this.createNode());
if (this._options.renderTo) {
this.renderTo(this._options.renderTo);
}
},
_addRenderContainer: function() {
this._rc = new kity.Group().setId(KityMinder.uuid('minder'));
this._paper.addShape(this._rc);
},
renderTo: function(target) {
if (typeof(target) == 'string') {
target = document.getElementById(target);
}
this._paper.renderTo(this._renderTarget = target);
this._bindEvents();
},
getRenderContainer: function() {
return this._rc;
},
getPaper: function() {
return this._paper;
},
getRenderTarget: function() {
return this._renderTarget;
},
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
Minder.registerInitHook(function() {
this._initPaper();
});
kity.extendClass(Minder, {
_initPaper: function() {
this._paper = new kity.Paper();
this._paper.getNode().ondragstart = function(e) {
e.preventDefault();
};
this._paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
this._addRenderContainer();
this.setRoot(this.createNode());
if (this._options.renderTo) {
this.renderTo(this._options.renderTo);
}
},
_addRenderContainer: function() {
this._rc = new kity.Group().setId(utils.uuid('minder'));
this._paper.addShape(this._rc);
},
renderTo: function(target) {
if (typeof(target) == 'string') {
target = document.getElementById(target);
}
if (target) {
this._paper.renderTo(this._renderTarget = target);
this._bindEvents();
this.fire('paperrender');
}
return this;
},
getRenderContainer: function() {
return this._rc;
},
getPaper: function() {
return this._paper;
},
getRenderTarget: function() {
return this._renderTarget;
},
});
});
\ No newline at end of file
/**
* @fileOverview
*
*
* 只读模式支持
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function(options) {
if (options.readOnly) {
this.setDisabled();
}
});
kity.extendClass(KityMinder, {
disable: function() {
var me = this;
//禁用命令
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);
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
Minder.registerInitHook(function(options) {
if (options.readOnly) {
this.setDisabled();
}
});
kity.extendClass(Minder, {
disable: function() {
var me = this;
//禁用命令
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;
};
me.queryCommandValue = function(type) {
var cmd = this._getCommand(type);
if (cmd && cmd.enableReadOnly) {
return me.bkqueryCommandValue.apply(me, arguments);
if (me.bkqueryCommandValue) {
me.queryCommandValue = me.bkqueryCommandValue;
delete me.bkqueryCommandValue;
}
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 @@
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function() {
this._initStatus();
});
define(function(require, exports, module) {
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() {
this._status = 'normal';
this._rollbackStatus = 'normal';
},
Minder.registerInitHook(function() {
this._initStatus();
});
setStatus: (function() {
var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
kity.extendClass(Minder, {
// 在 readonly 模式下,只有 force 为 true 才能切换回来
return function(status, force) {
_initStatus: function() {
this._status = 'normal';
this._rollbackStatus = 'normal';
},
setStatus: function(status, force) {
// 在 readonly 模式下,只有 force 为 true 才能切换回来
if (this._status == 'readonly' && !force) return this;
if (status != this._status) {
this._rollbackStatus = this._status;
......@@ -33,6 +36,7 @@ kity.extendClass(KityMinder, {
currentStatus: this._status
});
if (sf) {
/* global console: true */
console.log(window.event.type, this._rollbackStatus, '->', this._status);
if (tf) {
console.trace();
......@@ -40,16 +44,17 @@ kity.extendClass(KityMinder, {
}
}
return this;
};
})(),
rollbackStatus: function() {
this.setStatus(this._rollbackStatus);
},
getRollbackStatus:function(){
return this._rollbackStatus;
},
getStatus: function() {
return this._status;
}
},
rollbackStatus: function() {
this.setStatus(this._rollbackStatus);
},
getRollbackStatus:function(){
return this._rollbackStatus;
},
getStatus: function() {
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 @@
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('structure', {
template.register('structure', {
getLayout: function(node) {
return node.getData('layout') || 'bottom';
},
getLayout: function(node) {
return node.getData('layout') || 'bottom';
},
getConnect: function(node) {
return 'poly';
}
getConnect: function(node) {
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