Commit 651acd74 authored by techird's avatar techird

使用 Module 规范组织代码

parent b27e5394
{
"directory": "lib"
}
\ No newline at end of file
......@@ -5,7 +5,3 @@
dist/
node_modules/
_drafts/
\ No newline at end of file
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
[submodule "lib/kity"]
path = lib/kity
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,153 +22,22 @@ 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: {
dependence: {
options: {
banner: banner,
sourceMap: true
base: 'src',
entrance: 'kityminder'
},
files: (function() {
var files = {};
packs.forEach(function(pack) {
files[distPath + 'kityminder.' + pack + '.min.js'] = distPath + 'kityminder.' + pack + '.js';
});
return files;
})()
}
},
copy: {
dir: {
merge: {
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
src: 'src/**/*.js',
dest: 'release/kityminder.all.js'
}]
},
km_config: {
expand: true,
src: 'kityminder.config.js',
dest: distPath
},
mise: {
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())
}]
}
},
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'
}
}
......@@ -186,7 +45,6 @@ module.exports = function(grunt) {
// 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,16 +7,20 @@
* @copyright: Baidu FEX, 2014
*/
var connectMarker = new kity.Marker().pipe(function() {
define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
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');
});
});
KityMinder.registerConnectProvider('arc', function(node, parent, connection, width, color) {
connect.register('arc', function(node, parent, connection, width, color) {
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
......@@ -41,4 +45,5 @@ KityMinder.registerConnectProvider('arc', function(node, parent, connection, wid
connectMarker.dot.fill(color);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,7 +7,11 @@
* @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(),
......@@ -34,4 +38,5 @@ KityMinder.registerConnectProvider('bezier', function(node, parent, connection)
connection.setMarker(null);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,7 +7,11 @@
* @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');
connect.register('fish-bone-master', function(node, parent, connection) {
var pout = parent.getLayoutVertexOut(),
pin = node.getLayoutVertexIn();
......@@ -25,4 +29,5 @@ KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, co
connection.setMarker(null);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,7 +7,11 @@
* @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');
connect.register('l', function(node, parent, connection) {
var po = parent.getLayoutVertexOut();
var pi = node.getLayoutVertexIn();
......@@ -26,4 +30,5 @@ KityMinder.registerConnectProvider('l', function(node, parent, connection) {
pathData.push('L', pi);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,7 +7,11 @@
* @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');
connect.register('poly', function(node, parent, connection, width) {
// 连线起点和终点
var po = parent.getLayoutVertexOut(),
......@@ -55,4 +59,5 @@ KityMinder.registerConnectProvider('poly', function(node, parent, connection, wi
connection.setMarker(null);
connection.setPathData(pathData);
});
});
\ No newline at end of file
......@@ -7,7 +7,11 @@
* @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');
connect.register('under', function(node, parent, connection, width, color) {
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
......@@ -42,4 +46,5 @@ KityMinder.registerConnectProvider('under', function(node, parent, connection, w
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 () {
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 ) {
execute: function(minder, args) {
throw new Error('Not Implement: Command.execute()');
},
setContentChanged: function ( val ) {
this._isContentChange = !! val;
setContentChanged: function(val) {
this._isContentChange = !!val;
},
isContentChanged: function () {
isContentChanged: function() {
return this._isContentChange;
},
setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val;
setSelectionChanged: function(val) {
this._isSelectionChange = !!val;
},
isSelectionChanged: function () {
isSelectionChanged: function() {
return this._isContentChange;
},
queryState: function ( km ) {
return KityMinder.COMMAND_STATE_NORMAL;
queryState: function(km) {
return COMMAND_STATE_NORMAL;
},
queryValue: function ( km ) {
queryValue: function(km) {
return 0;
},
isNeedUndo: function () {
isNeedUndo: function() {
return true;
}
} );
});
kity.extendClass(KityMinder, {
_getCommand: function (name) {
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) {
_queryCommand: function(name, type, args) {
var cmd = this._getCommand(name);
if (cmd) {
var queryCmd = cmd['query' + type];
......@@ -55,18 +72,18 @@ kity.extendClass(KityMinder, {
return 0;
},
queryCommandState: function (name) {
return this._queryCommand(name, "State", Utils.argsToArray(1));
queryCommandState: function(name) {
return this._queryCommand(name, 'State', [].slice.call(arguments, 1));
},
queryCommandValue: function (name) {
return this._queryCommand(name, "Value", Utils.argsToArray(1));
queryCommandValue: function(name) {
return this._queryCommand(name, 'Value', [].slice.call(arguments, 1));
},
execCommand: function (name) {
execCommand: function(name) {
name = name.toLowerCase();
var cmdArgs = Utils.argsToArray(arguments, 1),
var cmdArgs = [].slice.call(arguments, 1),
cmd, stoped, result, eventParams;
var me = this;
cmd = this._getCommand(name);
......@@ -88,7 +105,7 @@ kity.extendClass(KityMinder, {
//保存场景
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));
......@@ -114,4 +131,7 @@ kity.extendClass(KityMinder, {
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) {
function compatibility(json) {
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) {
......@@ -58,14 +71,5 @@ Utils.extend(KityMinder, {
});
}
switch (version) {
case '1.1.3':
c_113_120(json);
case '1.2.0':
case '1.2.1':
c_120_130(json);
}
return json;
}
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;
kity.extendClass(MinderNode, {
getConnect: function() {
return this.data.connect || 'default';
},
getConnectProvider: function(name) {
return KityMinder._connectProviders[name] || KityMinder._defaultConnectProvider;
}
});
kity.extendClass(MinderNode, {
getConnectProvider: function() {
return KityMinder.getConnectProvider(this.getConnect());
},
getConnect: function() {
return null;
return _connectProviders[this.getConnect()] || _connectProviders['default'];
},
getConnection: function() {
return this._connection || null;
}
});
});
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
getConnectContainer: function() {
return this._connectContainer;
......@@ -86,11 +86,11 @@ kity.extendClass(KityMinder, {
connection.setTranslate(0, 0);
}
}
});
});
KityMinder.registerModule('Connect', {
Module.register('Connect', {
init: function() {
this._connectContainer = new kity.Group().setId(KityMinder.uuid('minder_connect_group'));
this._connectContainer = new kity.Group().setId(utils.uuid('minder_connect_group'));
this.getRenderContainer().prependShape(this._connectContainer);
},
events: {
......@@ -104,4 +104,7 @@ KityMinder.registerModule('Connect', {
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'
};
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');
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];
});
},
// 导入导出
kity.extendClass(Minder, {
exportJson: function() {
/* 导出 node 上整棵树的数据为 JSON */
......@@ -58,7 +28,7 @@ kity.extendClass(KityMinder, {
json.template = this.getTemplate();
json.theme = this.getTheme();
json.version = KityMinder.version;
json.version = Minder.version;
return json;
},
......@@ -72,7 +42,7 @@ kity.extendClass(KityMinder, {
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++) {
......@@ -91,7 +61,7 @@ kity.extendClass(KityMinder, {
this.removeNode(this._root.getChildren()[0]);
}
json = KityMinder.compatibility(json);
json = Minder.compatibility(json);
importNode(this._root, json, this);
......@@ -105,72 +75,6 @@ kity.extendClass(KityMinder, {
type: 'contentchange'
});
this._interactChange();
},
exportData: function(protocolName, options) {
var json, protocol;
json = this.exportJson();
// 指定了协议进行导出,需要检测协议是否支持
if (protocolName) {
protocol = this.getProtocol(protocolName);
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) {
return Promise.resolve(protocol.encode(json, this, options));
} else {
return Promise.resolve(json);
}
},
importData: function(local, protocolName) {
var json, protocol;
var minder = this;
// 指定了协议进行导入,需要检测协议是否支持
if (protocolName) {
protocol = this.getProtocol(protocolName);
if (!protocol || !protocol.decode) {
return Promise.reject(new Error('Not supported protocol:' + protocolName));
}
}
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
var MinderEvent = kity.createClass('MindEvent', {
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
function listen(element, type, handler) {
var types = utils.isArray(type) ? type : utils.trim(type).split(' '),
k = types.length;
types.forEach(function(name) {
element.addEventListener(name, handler, false);
});
}
var MinderEvent = kity.createClass('MindEvent', {
constructor: function(type, params, canstop) {
params = params || {};
if (params.getType && params.getType() == 'ShapeEvent') {
......@@ -49,9 +62,9 @@ var MinderEvent = kity.createClass('MindEvent', {
if (!this.originEvent) {
return false;
}
if ("which" in this.originEvent)
if ('which' in this.originEvent)
isRightMB = this.originEvent.which == 3;
else if ("button" in this.originEvent)
else if ('button' in this.originEvent)
isRightMB = this.originEvent.button == 2;
return isRightMB;
},
......@@ -59,39 +72,44 @@ var MinderEvent = kity.createClass('MindEvent', {
var evt = this.originEvent;
return evt.keyCode || evt.which;
}
});
});
KityMinder.registerInit(function() {
Minder.registerInitHook(function() {
this._initEvents();
});
});
kity.extendClass(Minder, {
// 事件机制
kity.extendClass(KityMinder, {
_initEvents: function() {
this._eventCallbacks = {};
},
_bindEvents: function() {
this._bindPaperEvents();
this._bindKeyboardEvents();
},
_resetEvents: function() {
this._initEvents();
this._bindEvents();
},
// TODO: mousemove lazy bind
_bindPaperEvents: function() {
/* jscs:disable maximumLineLength */
this._paper.on('click dblclick mousedown contextmenu mouseup mousemove mouseover mousewheel DOMMouseScroll touchstart touchmove touchend dragenter dragleave drop', this._firePharse.bind(this));
if (window) {
window.addEventListener('resize', this._firePharse.bind(this));
window.addEventListener('blur', this._firePharse.bind(this));
}
},
_bindKeyboardEvents: function() {
if ((navigator.userAgent.indexOf('iPhone') == -1) && (navigator.userAgent.indexOf('iPod') == -1) && (navigator.userAgent.indexOf('iPad') == -1)) {
//只能在这里做,要不无法触发
Utils.listen(document.body, 'keydown keyup keypress paste', this._firePharse.bind(this));
listen(document.body, 'keydown keyup keypress paste', this._firePharse.bind(this));
}
},
_firePharse: function(e) {
// //只读模式下强了所有的事件操作
// if(this.readOnly === true){
......@@ -117,6 +135,7 @@ kity.extendClass(KityMinder, {
this._fire(executeEvent))
this._fire(new MinderEvent('after' + e.type, e, false));
},
_interactChange: function(e) {
var me = this;
if (me._interactScheduled) return;
......@@ -126,31 +145,26 @@ kity.extendClass(KityMinder, {
}, 100);
me._interactScheduled = true;
},
_listen: function(type, callback) {
var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []);
callbacks.push(callback);
},
_fire: function(e) {
_fire: function(e) {
var status = this.getStatus();
var callbacks = this._eventCallbacks[e.type.toLowerCase()] || [];
if (status) {
callbacks = callbacks.concat(this._eventCallbacks[status + '.' + e.type.toLowerCase()] || []);
}
if (callbacks.length === 0) {
return;
}
var lastStatus = this.getStatus();
var lastStatus = this.getStatus();
for (var i = 0; i < callbacks.length; i++) {
callbacks[i].call(this, e);
/* this.getStatus() != lastStatus ||*/
......@@ -158,15 +172,18 @@ kity.extendClass(KityMinder, {
break;
}
}
return e.shouldStopPropagation();
},
on: function(name, callback) {
var km = this;
utils.each(name.split(/\s+/), function(i, n) {
name.split(/\s+/).forEach(function(n) {
km._listen(n.toLowerCase(), callback);
});
return this;
},
off: function(name, callback) {
var types = name.split(/\s+/);
......@@ -187,9 +204,13 @@ kity.extendClass(KityMinder, {
}
}
},
fire: function(type, params) {
var e = new MinderEvent(type, params);
this._fire(e);
return this;
}
});
module.exports = MinderEvent;
});
......@@ -7,12 +7,19 @@
* @copyright: Baidu FEX, 2014
*/
/**
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');
/**
* 计算包含 meta 键的 keycode
*
* @param {String|KeyEvent} unknown
*/
function getMetaKeyCode(unknown) {
function getMetaKeyCode(unknown) {
var CTRL_MASK = 0x1000;
var ALT_MASK = 0x2000;
var SHIFT_MASK = 0x4000;
......@@ -51,21 +58,21 @@ function getMetaKeyCode(unknown) {
}
return metaKeyCode;
}
kity.extendClass(MinderEvent, {
}
kity.extendClass(MinderEvent, {
isShortcutKey: function(keyCombine) {
var keyEvent = this.originEvent;
if (!keyEvent) return false;
return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent);
}
});
});
KityMinder.registerInit(function() {
Minder.registerInitHook(function() {
this._initShortcutKey();
});
});
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
_initShortcutKey: function() {
this._bindShortcutKeys();
......@@ -113,7 +120,7 @@ kity.extendClass(KityMinder, {
var minder = this;
utils.each(obj, function(command, keys) {
utils.each(obj, function(keys, command) {
binds[command] = keys;
......@@ -129,4 +136,5 @@ kity.extendClass(KityMinder, {
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];
}
}
var aKeyCode = 65;
var aCharCode = 'a'.charCodeAt(0);
// letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
});
// numbers
var n = 9;
do {
ret[n.toString()] = n + 48;
} while(--n);
return ret;
})({
define(function(require, exports, module) {
var keymap = {
'Backspace': 8,
'Tab': 9,
'Enter': 13,
......@@ -124,5 +102,27 @@ var keymap = KityMinder.keymap = (function(origin) {
13: 1,
9: 1
}
};
// 小写适配
for (var key in keymap) {
if (keymap.hasOwnProperty(key)) {
keymap[key.toLowerCase()] = keymap[key];
}
}
var aKeyCode = 65;
var aCharCode = 'a'.charCodeAt(0);
// letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
keymap[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
});
// numbers
var n = 9;
do {
keymap[n.toString()] = n + 48;
} while(--n);
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() {
/* 模块初始化 */
Minder.registerInitHook(function() {
this._initModules();
});
});
// 模块声明周期维护
kity.extendClass(KityMinder, {
// 模块声明周期维护
kity.extendClass(Minder, {
_initModules: function() {
var modulesPool = KityMinder.getModules();
var modulesToLoad = this._options.modules || Utils.keys(modulesPool);
var modulesPool = _modules;
var modulesToLoad = this._options.modules || utils.keys(modulesPool);
this._commands = {};
this._query = {};
......@@ -74,7 +72,7 @@ kity.extendClass(KityMinder, {
for (type in dealRenderers) {
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]);
} else {
this._rendererClasses[type].push(dealRenderers[type]);
......@@ -82,6 +80,11 @@ kity.extendClass(KityMinder, {
}
}
//添加模块的快捷键
if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
}
}
},
......@@ -115,4 +118,5 @@ kity.extendClass(KityMinder, {
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,15 +6,20 @@
* @author: techird
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function() {
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
Minder.registerInitHook(function() {
this._initPaper();
});
kity.extendClass(KityMinder, {
});
kity.extendClass(Minder, {
_initPaper: function() {
this._paper = new kity.Paper();
this._paper.getNode().setAttribute('contenteditable', true);
this._paper.getNode().ondragstart = function(e) {
e.preventDefault();
};
......@@ -30,7 +35,7 @@ kity.extendClass(KityMinder, {
},
_addRenderContainer: function() {
this._rc = new kity.Group().setId(KityMinder.uuid('minder'));
this._rc = new kity.Group().setId(utils.uuid('minder'));
this._paper.addShape(this._rc);
},
......@@ -38,8 +43,12 @@ kity.extendClass(KityMinder, {
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() {
......@@ -53,4 +62,5 @@ kity.extendClass(KityMinder, {
getRenderTarget: function() {
return this._renderTarget;
},
});
});
\ No newline at end of file
/**
* @fileOverview
*
*
* 只读模式支持
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function(options) {
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
Minder.registerInitHook(function(options) {
if (options.readOnly) {
this.setDisabled();
}
});
kity.extendClass(KityMinder, {
});
kity.extendClass(Minder, {
disable: function() {
var me = this;
......@@ -52,4 +58,5 @@ kity.extendClass(KityMinder, {
me._interactChange();
}
});
});
\ No newline at end of file
var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
var MinderNode = require('./node');
var Renderer = kity.createClass('Renderer', {
constructor: function(node) {
this.node = node;
},
......@@ -49,9 +55,9 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
setRenderShape: function(shape) {
this._renderShape = shape;
}
});
});
kity.extendClass(KityMinder, (function() {
function createMinderExtension() {
function createRendererForNode(node, registered) {
var renderers = [];
......@@ -77,7 +83,6 @@ kity.extendClass(KityMinder, (function() {
}
return {
renderNodeBatch: function(nodes) {
var rendererClasses = this._rendererClasses;
var lastBoxes = [];
......@@ -158,7 +163,6 @@ kity.extendClass(KityMinder, (function() {
renderNode: function(node) {
var rendererClasses = this._rendererClasses;
var g = KityMinder.Geometry;
var i, latestBox, renderer;
if (!node._renderers) {
......@@ -212,9 +216,11 @@ kity.extendClass(KityMinder, (function() {
});
}
};
})());
}
kity.extendClass(Minder, createMinderExtension());
kity.extendClass(MinderNode, {
kity.extendClass(MinderNode, {
render: function() {
if (!this.attached) return;
this.getMinder().renderNode(this);
......@@ -240,4 +246,7 @@ kity.extendClass(MinderNode, {
//if (!this._contentBox) this.render();
return this.parent && this.parent.isCollapsed() ? new kity.Box() : (this._contentBox || new kity.Box());
}
});
module.exports = Renderer;
});
\ No newline at end of file
KityMinder.registerInit(function() {
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
var MinderNode = require('./node');
Minder.registerInitHook(function() {
this._initSelection();
});
});
// 选区管理
kity.extendClass(KityMinder, {
// 选区管理
kity.extendClass(Minder, {
_initSelection: function() {
this._selectedNodes = [];
},
renderChangedSelection: function(last) {
var current = this.getSelectedNodes();
var changed = [];
var i = 0;
current.forEach(function(node) {
if (last.indexOf(node) == -1) {
changed.push(node);
node.setTmpData('selected', true);
}
});
last.forEach(function(node) {
if (current.indexOf(node) == -1) {
changed.push(node);
node.setTmpData('selected', false);
}
});
......@@ -31,7 +34,9 @@ kity.extendClass(KityMinder, {
this._interactChange();
this.fire('selectionchange');
}
while (i < changed.length) changed[i++].render();
while (changed.length) {
changed.shift().render();
}
},
getSelectedNodes: function() {
//不能克隆返回,会对当前选区操作,从而影响querycommand
......@@ -50,12 +55,14 @@ kity.extendClass(KityMinder, {
removeSelectedNodes: function(nodes) {
var me = this;
var last = this._selectedNodes.slice(0);
nodes = Utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
nodes = utils.isArray(nodes) ? nodes : [nodes];
nodes.forEach(function(node) {
var index;
if ((index = me._selectedNodes.indexOf(n)) === -1) return;
if ((index = me._selectedNodes.indexOf(node)) === -1) return;
me._selectedNodes.splice(index, 1);
});
this.renderChangedSelection(last);
return this;
},
......@@ -65,10 +72,10 @@ kity.extendClass(KityMinder, {
this._selectedNodes = [];
}
var me = this;
nodes = Utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
if (me._selectedNodes.indexOf(n) !== -1) return;
me._selectedNodes.push(n);
nodes = utils.isArray(nodes) ? nodes : [nodes];
nodes.forEach(function(node) {
if (me._selectedNodes.indexOf(node) !== -1) return;
me._selectedNodes.push(node);
});
this.renderChangedSelection(lastSelect);
return this;
......@@ -77,7 +84,7 @@ kity.extendClass(KityMinder, {
//当前选区中的节点在给定的节点范围内的保留选中状态,
//没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect: function(node) {
if (Utils.isArray(node)) {
if (utils.isArray(node)) {
node.forEach(this.toggleSelect.bind(this));
} else {
if (node.isSelected()) this.removeSelectedNodes(node);
......@@ -123,16 +130,12 @@ kity.extendClass(KityMinder, {
return ancestors;
}
});
});
kity.extendClass(MinderNode, {
kity.extendClass(MinderNode, {
isSelected: function() {
return this.getTmpData('selected');
},
clearSelectedFlag:function(){
this.setTmpData('selected');
},
setSelectedFlag:function(){
this.setTmpData('selected',true);
return this.getMinder().getSelectedNodes().indexOf(this) != -1;
}
});
});
\ No newline at end of file
......@@ -7,23 +7,26 @@
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerInit(function() {
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
Minder.registerInitHook(function() {
this._initStatus();
});
});
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
_initStatus: function() {
this._status = 'normal';
this._rollbackStatus = 'normal';
},
setStatus: (function() {
var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
setStatus: function(status, force) {
// 在 readonly 模式下,只有 force 为 true 才能切换回来
return function(status, force) {
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,8 +44,7 @@ kity.extendClass(KityMinder, {
}
}
return this;
};
})(),
},
rollbackStatus: function() {
this.setStatus(this._rollbackStatus);
......@@ -52,4 +55,6 @@ kity.extendClass(KityMinder, {
getStatus: function() {
return this._status;
}
});
});
\ No newline at end of file
utils.extend(KityMinder, {
_templates: {},
registerTemplate: function(name, supports) {
KityMinder._templates[name] = supports;
},
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
var Command = require('./command');
var MinderNode = require('./node');
var Module = require('./module');
var _templates = {};
function register(name, supports) {
_templates[name] = supports;
}
exports.register = register;
utils.extend(Minder, {
getTemplateList: function() {
return KityMinder._templates;
return _templates;
}
});
});
kity.extendClass(KityMinder, (function() {
var originGetTheme = KityMinder.prototype.getTheme;
kity.extendClass(Minder, (function() {
var originGetTheme = Minder.prototype.getTheme;
return {
useTemplate: function(name, duration) {
this.setTemplate(name);
......@@ -25,7 +36,7 @@ kity.extendClass(KityMinder, (function() {
},
getTemplateSupport: function(method) {
var supports = KityMinder._templates[this.getTemplate()];
var supports = _templates[this.getTemplate()];
return supports && supports[method];
},
......@@ -34,10 +45,10 @@ kity.extendClass(KityMinder, (function() {
return support.call(this, node);
}
};
})());
})());
kity.extendClass(MinderNode, (function() {
kity.extendClass(MinderNode, (function() {
var originGetLayout = MinderNode.prototype.getLayout;
var originGetConnect = MinderNode.prototype.getConnect;
return {
......@@ -51,9 +62,9 @@ kity.extendClass(MinderNode, (function() {
return support.call(this, this);
}
};
})());
})());
KityMinder.registerModule('TemplateModule', {
Module.register('TemplateModule', {
commands: {
'template': kity.createClass('TemplateCommand', {
base: Command,
......@@ -68,4 +79,5 @@ KityMinder.registerModule('TemplateModule', {
}
})
}
});
});
\ No newline at end of file
var cssLikeValueMatcher = {
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
var MinderNode = require('./node');
var Module = require('./module');
var Command = require('./command');
var cssLikeValueMatcher = {
left: function(value) {
return 3 in value && value[3] ||
1 in value && value[1] ||
......@@ -13,10 +21,9 @@ var cssLikeValueMatcher = {
bottom: function(value) {
return 2 in value && value[2] || value[0];
}
};
};
Utils.extend(KityMinder, {
_themes: {},
var _themes = {};
/**
* 注册一个主题
......@@ -25,22 +32,24 @@ Utils.extend(KityMinder, {
* @param {Plain} theme 主题的样式描述
*
* @example
* KityMinder.registerTheme('default', {
* Minder.registerTheme('default', {
* 'root-color': 'red',
* 'root-stroke': 'none',
* 'root-padding': [10, 20]
* });
*/
registerTheme: function(name, theme) {
KityMinder._themes[name] = theme;
},
function register(name, theme) {
_themes[name] = theme;
}
exports.register = register;
utils.extend(Minder, {
getThemeList: function() {
return KityMinder._themes;
return _themes;
}
});
});
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
/**
* 切换脑图实例上的主题
......@@ -67,12 +76,12 @@ kity.extendClass(KityMinder, {
* @return {[type]} [description]
*/
getTheme: function(node) {
return this._theme || this.getOptions('defaultTheme') || 'fresh-blue';
return this._theme || this.getOption('defaultTheme') || 'fresh-blue';
},
getThemeItems: function(node) {
var theme = this.getTheme(node);
return KityMinder._themes[this.getTheme(node)];
return _themes[this.getTheme(node)];
},
/**
......@@ -96,7 +105,7 @@ kity.extendClass(KityMinder, {
if (item in items) {
value = items[item];
if (Utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
if (utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
return matcher(value);
}
if (!isNaN(value)) return value;
......@@ -113,15 +122,15 @@ kity.extendClass(KityMinder, {
var value = this.getStyle(node.getType() + '-' + name, node);
return value !== null ? value : this.getStyle(name, node);
}
});
});
kity.extendClass(MinderNode, {
kity.extendClass(MinderNode, {
getStyle: function(name) {
return this.getMinder().getNodeStyle(this, name);
}
});
});
KityMinder.registerModule('Theme', {
Module.register('Theme', {
defaultOptions: {
defaultTheme: 'fresh-blue'
},
......@@ -138,8 +147,10 @@ KityMinder.registerModule('Theme', {
}
})
}
});
});
KityMinder.registerInit(function() {
Minder.registerInitHook(function() {
this.setTheme();
});
});
\ No newline at end of file
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
/* global Layout:true */
define(function(require, exports, module) {
var kity = require('core/kity');
var Layout = require('core/layout');
var layouts = ['left', 'right', 'top', 'bottom'];
['left', 'right', 'top', 'bottom'].forEach(registerLayoutForDirection);
layouts.forEach(function(name) {
function registerLayoutForDirection(name) {
var axis = (name == 'left' || name == 'right') ? 'x' : 'y';
var dir = (name == 'left' || name == 'top') ? -1 : 1;
......@@ -73,7 +75,7 @@ layouts.forEach(function(name) {
return hint;
}
KityMinder.registerLayout(name, kity.createClass({
Layout.register(name, kity.createClass({
base: Layout,
......@@ -137,4 +139,5 @@ layouts.forEach(function(name) {
getOrderHint: getOrderHint
}));
}
});
\ No newline at end of file
/* global Layout:true */
define(function(require, exports, module) {
var kity = require('core/kity');
var Layout = require('core/layout');
[-1, 1].forEach(function (dir) {
[-1, 1].forEach(registerLayoutForDir);
function registerLayoutForDir(dir) {
var name = 'filetree-' + (dir > 0 ? 'down' : 'up');
KityMinder.registerLayout(name, kity.createClass({
Layout.register(name, kity.createClass({
base: Layout,
doLayout: function(parent, children, round) {
......@@ -80,4 +84,6 @@
}
}));
}
});
\ No newline at end of file
......@@ -6,8 +6,12 @@
* @author: techird
* @copyright: Baidu FEX, 2014
*/
/* global Layout:true */
KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
define(function(require, exports, module) {
var kity = require('core/kity');
var Layout = require('core/layout');
Layout.register('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
base: Layout,
doLayout: function(parent, children, round) {
......@@ -58,16 +62,7 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa
this.move(upPart, xAdjust, yAdjustUp);
this.move(downPart, xAdjust + cMarginLeft, yAdjustDown);
// children.forEach(function(child, index) {
// var matrix = child.getLayoutTransform();
// var dx, dy;
// dx = matrix.getMatrix().e;
// dy = matrix.getMatrix().f;
// matrix.translate(-dx, -dy);
// matrix.rotate(index % 2 ? 45 : -45);
// matrix.translate(dx, dy);
// });
}
}));
\ No newline at end of file
}));
});
\ No newline at end of file
......@@ -7,8 +7,11 @@
* @copyright: Baidu FEX, 2014
*/
/* global Layout: true */
KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayout', {
define(function(require, exports, module) {
var kity = require('core/kity');
var Layout = require('core/layout');
Layout.register('fish-bone-slave', kity.createClass('FishBoneSlaveLayout', {
base: Layout,
doLayout: function (parent, children, round) {
......@@ -39,8 +42,8 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo
this.stack(children, 'y');
this.align(children, 'left');
var xAdjust = 0, yAdjust = 0;
var xAdjust = 0, yAdjust = 0;
xAdjust += pout.x;
if (parent.getLayoutVectorOut().y < 0) {
......@@ -65,4 +68,5 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo
});
}
}
}));
\ No newline at end of file
}));
});
\ No newline at end of file
/* global Layout:true */
KityMinder.registerLayout('mind', kity.createClass({
define(function(require, exports, module) {
var kity = require('core/kity');
var Layout = require('core/layout');
var Minder = require('core/minder');
Layout.register('mind', kity.createClass({
base: Layout,
doLayout: function(node, children) {
......@@ -13,8 +17,8 @@ KityMinder.registerLayout('mind', kity.createClass({
else left.push(child);
});
var leftLayout = KityMinder.getLayoutInstance('left');
var rightLayout = KityMinder.getLayoutInstance('right');
var leftLayout = Minder.getLayoutInstance('left');
var rightLayout = Minder.getLayoutInstance('right');
leftLayout.doLayout(node, left);
rightLayout.doLayout(node, right);
......@@ -54,4 +58,5 @@ KityMinder.registerLayout('mind', kity.createClass({
});
return hint;
}
}));
\ No newline at end of file
}));
});
\ No newline at end of file
kity.extendClass(MinderNode, {
define(function(require, exports, module) {
var kity = require('core/kity');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
kity.extendClass(MinderNode, {
arrange: function(index) {
var parent = this.parent;
if (!parent) return;
......@@ -9,21 +16,21 @@ kity.extendClass(MinderNode, {
sibling.splice(index, 0, this);
return this;
}
});
});
function asc(nodeA, nodeB) {
function asc(nodeA, nodeB) {
return nodeA.getIndex() - nodeB.getIndex();
}
function desc(nodeA, nodeB) {
}
function desc(nodeA, nodeB) {
return -asc(nodeA, nodeB);
}
}
function canArrange(km) {
function canArrange(km) {
var selected = km.getSelectedNode();
return selected && selected.parent && selected.parent.children.length > 1;
}
}
var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', {
var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', {
base: Command,
execute: function(km) {
......@@ -42,9 +49,9 @@ var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', {
var selected = km.getSelectedNode();
return selected ? 0 : -1;
}
});
});
var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', {
var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', {
base: Command,
execute: function(km) {
......@@ -63,9 +70,9 @@ var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', {
var selected = km.getSelectedNode();
return selected ? 0 : -1;
}
});
});
var ArrangeCommand = kity.createClass('ArrangeCommand', {
var ArrangeCommand = kity.createClass('ArrangeCommand', {
base: Command,
execute: function(km, nodes, index) {
......@@ -101,9 +108,9 @@ var ArrangeCommand = kity.createClass('ArrangeCommand', {
var selected = km.getSelectedNode();
return selected ? 0 : -1;
}
});
});
KityMinder.registerModule('ArrangeModule', {
Module.register('ArrangeModule', {
commands: {
'arrangeup': ArrangeUpCommand,
'arrangedown': ArrangeDownCommand,
......@@ -120,4 +127,5 @@ KityMinder.registerModule('ArrangeModule', {
'arrangeup': 'normal::alt+Up',
'arrangedown': 'normal::alt+Down'
}
});
});
\ No newline at end of file
KityMinder.registerModule('basestylemodule', function() {
define(function(require, exports, module) {
var kity = require('core/kity');
var utils = require('core/utils');
var Minder = require('core/minder');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
var TextRenderer = require('./text');
Module.register('basestylemodule', function() {
var km = this;
function getNodeDataOrStyle(node, name) {
return node.getData(name) || node.getStyle(name);
}
KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) {
TextRenderer.registerStyleHook(function(node, textGroup) {
var fontWeight = getNodeDataOrStyle(node,'font-weight');
var fontStyle = getNodeDataOrStyle(node, 'font-style');
var styleHash = [fontWeight, fontStyle].join('/');
textGroup.eachItem(function(index,item){
textGroup.eachItem(function(index,item) {
item.setFont({
'weight': fontWeight,
'style': fontStyle
......@@ -28,11 +40,11 @@ KityMinder.registerModule('basestylemodule', function() {
var nodes = km.getSelectedNodes();
if (this.queryState('bold') == 1) {
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
n.setData('font-weight').render();
});
} else {
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
n.setData('font-weight', 'bold').render();
});
}
......@@ -44,7 +56,7 @@ KityMinder.registerModule('basestylemodule', function() {
if (nodes.length === 0) {
return -1;
}
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
if (n && n.getData('font-weight')) {
result = 1;
return false;
......@@ -60,11 +72,11 @@ KityMinder.registerModule('basestylemodule', function() {
var nodes = km.getSelectedNodes();
if (this.queryState('italic') == 1) {
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
n.setData('font-style').render();
});
} else {
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
n.setData('font-style', 'italic').render();
});
}
......@@ -77,7 +89,7 @@ KityMinder.registerModule('basestylemodule', function() {
if (nodes.length === 0) {
return -1;
}
utils.each(nodes, function(i, n) {
nodes.forEach(function(n) {
if (n && n.getData('font-style')) {
result = 1;
return false;
......@@ -92,4 +104,5 @@ KityMinder.registerModule('basestylemodule', function() {
'italic': 'ctrl+i' //italic
}
};
});
});
\ No newline at end of file
KityMinder.registerModule( "ClipboardModule", function () {
define(function(require, exports, module) {
var kity = require('core/kity');
var utils = require('core/utils');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
Module.register('ClipboardModule', function() {
var km = this,
_clipboardNodes = [],
......@@ -11,7 +18,8 @@ KityMinder.registerModule( "ClipboardModule", function () {
child.render();
child.setLayoutOffset(null);
var children = utils.cloneArr(child.children);
for (var i = 0, ci; (ci = children[i]); i++) {
for (var i = 0, ci;
(ci = children[i]); i++) {
appendChildNode(child, ci);
}
}
......@@ -60,7 +68,8 @@ KityMinder.registerModule( "ClipboardModule", function () {
var node = km.getSelectedNode();
if (!node) return;
for(var i= 0, ni; (ni = _clipboardNodes[i]); i++) {
for (var i = 0, ni;
(ni = _clipboardNodes[i]); i++) {
appendChildNode(node, ni.clone());
}
......@@ -88,4 +97,5 @@ KityMinder.registerModule( "ClipboardModule", function () {
'paste': 'normal::ctrl+v'
}
};
} );
\ No newline at end of file
});
});
\ No newline at end of file
var GM = KityMinder.Geometry;
define(function(require, exports, module) {
var kity = require('core/kity');
var utils = require('core/utils');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
// 矩形的变形动画定义
// 矩形的变形动画定义
var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
base: Command,
execute: function(minder, nodes, parent) {
var node;
......@@ -17,9 +22,9 @@ var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
parent.expand();
minder.select(nodes, true);
}
});
});
var DropHinter = kity.createClass('DropHinter', {
var DropHinter = kity.createClass('DropHinter', {
base: kity.Group,
constructor: function() {
......@@ -41,9 +46,9 @@ var DropHinter = kity.createClass('DropHinter', {
this.bringTop();
}
}
});
});
var OrderHinter = kity.createClass('OrderHinter', {
var OrderHinter = kity.createClass('OrderHinter', {
base: kity.Group,
constructor: function() {
......@@ -64,12 +69,12 @@ var OrderHinter = kity.createClass('OrderHinter', {
hint.node.getStyle('order-hint-path-width') || 1);
}
}
});
});
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
// 1. 从节点列表计算出拖动部分
// 2. 计算可以 drop 的节点,产生 drop 交互提示
var TreeDragger = kity.createClass('TreeDragger', {
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
// 1. 从节点列表计算出拖动部分
// 2. 计算可以 drop 的节点,产生 drop 交互提示
var TreeDragger = kity.createClass('TreeDragger', {
constructor: function(minder) {
this._minder = minder;
......@@ -97,7 +102,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
if (!this._dragMode) {
// 判断拖放模式是否该启动
if (GM.getDistance(this._dragPosition, this._startPosition) < DRAG_MOVE_THRESHOLD) {
if (kity.Vector.fromPoints(this._dragPosition, this._startPosition).length() < DRAG_MOVE_THRESHOLD) {
return;
}
if (!this._enterDragMode()) {
......@@ -296,7 +301,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
for (j = 0; j < sourceBoxes.length; j++) {
sourceBox = sourceBoxes[j];
var intersectBox = GM.getIntersectBox(sourceBox, targetBox);
var intersectBox = sourceBox.intersect(targetBox);
if (judge(intersectBox, sourceBox, targetBox)) {
return target;
}
......@@ -342,9 +347,9 @@ var TreeDragger = kity.createClass('TreeDragger', {
preventDragMove: function() {
this._startPosition = null;
}
});
});
KityMinder.registerModule('DragTree', function() {
Module.register('DragTree', function() {
var dragger;
return {
......@@ -380,4 +385,5 @@ KityMinder.registerModule('DragTree', function() {
'movetoparent': MoveToParentCommand
}
};
});
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
KityMinder.Range = kity.createClass('Range',function(){
function getOffset(rng,dir){
var node = rng[dir + 'Container'],
offset = rng[dir + 'Offset'],
rOffset = 0;
if(node.nodeType == 1){
//默认不会出现得不到子节点的情况
node = node.childNodes[offset];
if(!node && rng.startContainer && rng.startContainer.nodeName == 'DIV' ) {
rng.startContainer.innerHTML = '<p></p>';
offset = 0;
}else if(node.nodeType == 3){
offset = 0;
}
}
utils.each(rng.container.childNodes,function(index,n){
if(n === node){
if(n.nodeType == 1){
return false;
}else{
rOffset += offset;
return false;
}
}
rOffset += (n.nodeType == 1 ? 1 : utils.clearWhitespace(n.nodeValue).length);
});
return rOffset;
}
function setBoundary(rng,offset,dir){
var rOffset = 0,cont = rng.container;
utils.each(cont.childNodes,function(index,node){
if(node.nodeType == 1){
if(rOffset == offset){
rng['set' + dir](cont,index);
return false;
}
rOffset++;
return;
}
var currentLength = utils.clearWhitespace(node.nodeValue).length;
if(rOffset + currentLength >= offset){
rng['set' + dir](node,offset - rOffset);
return false;
}
rOffset += currentLength;
});
}
return {
constructor : function(container){
this.nativeRange = document.createRange();
this.nativeSel = window.getSelection();
this.startContainer =
this.endContainer =
this.startOffset =
this.endOffset = null;
this.collapsed = false;
this.container = container || null;
},
hasNativeRange : function(){
return this.nativeSel.rangeCount !== 0 ;
},
deleteContents : function(){
this.nativeRange.deleteContents();
return this._updateBoundary();
},
select:function(){
var start = this.nativeRange.startContainer;
if(start.nodeType == 1 && start.childNodes.length === 0){
var char = document.createTextNode('\u200b');
start.appendChild(char);
this.nativeRange.setStart(char,1);
this.nativeRange.collapse(true);
}else if(this.collapsed && start.nodeType == 1){
start = start.childNodes[this.startOffset];
if(start && start.nodeType == 3 && start.nodeValue.length === 0){
this.nativeRange.setStart(start,1);
this.nativeRange.collapse(true);
}
}
try{
this.nativeSel.removeAllRanges();
}catch(e){
}
this.nativeSel.addRange(this.nativeRange);
return this;
},
_updateBoundary : function(){
var nRange = this.nativeRange;
this.startContainer = nRange.startContainer;
this.startContainer = nRange.startContainer;
this.endContainer = nRange.endContainer;
this.startOffset = nRange.startOffset;
this.endOffset = nRange.endOffset;
this.collapsed = nRange.collapsed;
return this;
},
setStartOffset:function(offset){
setBoundary(this,offset,'Start');
return this;
},
setEndOffset:function(offset){
setBoundary(this,offset,'End');
return this;
},
setStart:function(node,offset){
this.nativeRange.setStart(node,offset);
this._updateBoundary();
return this;
},
setStartAfter:function(node){
return this.setStart(node.parentNode,utils.getNodeIndex(node) + 1);
},
setStartBefore:function(node){
return this.setStart(node.parentNode,utils.getNodeIndex(node));
},
setEnd:function(node,offset){
this.nativeRange.setEnd(node,offset);
this._updateBoundary();
return this;
},
update:function(){
this.updateNativeRange()
._updateBoundary();
return this;
},
getStart:function(){
this.update();
return {
startContainer:this.startContainer,
startOffset:this.startOffset
};
},
getStartOffset:function(){
return getOffset(this,'start');
},
getEndOffset:function(){
return getOffset(this,'end');
},
collapse:function(toStart){
this.nativeRange.collapse(toStart === true);
this._updateBoundary();
return this;
},
isCollapsed:function(){
this._updateBoundary();
return this.collapsed;
},
insertNode:function(node){
this.nativeRange.insertNode(node);
return this._updateBoundary();
},
updateNativeRange:function(){
this.nativeRange = this.nativeSel.getRangeAt(0);
return this;
},
clear : function(){
this.nativeSel.removeAllRanges();
return this;
}
};
}());
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/* global Renderer: true */
KityMinder.registerModule('Expand', function() {
define(function(require, exports, module) {
var kity = require('core/kity');
var utils = require('core/utils');
var keymap = require('core/keymap');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
var Renderer = require('core/render');
Module.register('Expand', function() {
var minder = this;
var EXPAND_STATE_DATA = 'expandState',
STATE_EXPAND = 'expand',
......@@ -86,7 +93,7 @@ KityMinder.registerModule('Expand', function() {
this.sign = new kity.Path().stroke('gray');
this.addShapes([this.outline, this.sign]);
this.initEvent(node);
this.setId(KityMinder.uuid('node_expander'));
this.setId(utils.uuid('node_expander'));
this.setStyle('cursor', 'pointer');
},
......@@ -236,4 +243,5 @@ KityMinder.registerModule('Expand', function() {
divider: true
}]
};
});
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
KityMinder.registerModule('KeyboardModule', function() {
define(function(require, exports, module) {
var kity = require('core/kity');
var utils = require('core/utils');
var keymap = require('core/keymap');
var Minder = require('core/minder');
var MinderNode = require('core/node');
var Command = require('core/command');
var Module = require('core/module');
var Renderer = require('core/render');
Module.register('KeyboardModule', function() {
var min = Math.min,
max = Math.max,
abs = Math.abs,
......@@ -171,9 +182,8 @@ KityMinder.registerModule('KeyboardModule', function() {
},
'normal.keyup': function(e) {
if (kity.Browser.ipad) {
var keys = KityMinder.keymap;
var keys = keymap;
var node = e.getTargetNode();
var lang = this.getLang();
if (this.receiver) this.receiver.keydownNode = node;
......@@ -183,7 +193,7 @@ KityMinder.registerModule('KeyboardModule', function() {
switch (keyEvent.keyCode) {
case keys.Enter:
this.execCommand('AppendSiblingNode', lang.topic);
this.execCommand('AppendSiblingNode');
e.preventDefault();
break;
......@@ -199,4 +209,5 @@ KityMinder.registerModule('KeyboardModule', function() {
}
}
};
});
});
\ 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.
......@@ -6,8 +6,10 @@
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('default', {
template.register('default', {
getLayout: function(node) {
......@@ -32,4 +34,5 @@ KityMinder.registerTemplate('default', {
if (node.getLevel() == 1) return 'arc';
return 'under';
}
});
});
\ 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.
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