Commit 651acd74 authored by techird's avatar techird

使用 Module 规范组织代码

parent b27e5394
{
"directory": "lib"
}
\ No newline at end of file
...@@ -5,7 +5,3 @@ ...@@ -5,7 +5,3 @@
dist/ dist/
node_modules/ node_modules/
_drafts/ _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
[submodule "lib/kity"] [submodule "lib/kity"]
path = lib/kity path = lib/kity
url = https://github.com/fex-team/kity url = https://github.com/fex-team/kity
[submodule "lib/promise"]
path = lib/promise
url = https://github.com/jakearchibald/es6-promise
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
"disallowSpacesInsideParentheses": true, "disallowSpacesInsideParentheses": true,
// 行尾「MUST NOT」使用空格 // 行尾「MUST NOT」使用空格
"disallowTrailingWhitespace": false, "disallowTrailingWhitespace": true,
// 每行「MUST NOT」超过 120 个字符 // 每行「MUST NOT」超过 120 个字符
"maximumLineLength": 120, "maximumLineLength": 120,
......
...@@ -10,23 +10,7 @@ ...@@ -10,23 +10,7 @@
"browser": true, "browser": true,
"boss": true, "boss": true,
"predef" : [ "predef" : [
"module", "define",
"require", "Promise"
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"keymap",
"Utils",
"utils",
"$",
"KM",
"keymap",
"browser"
] ]
} }
\ No newline at end of file
/*----------------------------------------------------- /* global require, module */
* livereload Default Setting
*-----------------------------------------------------*/
'use strict';
var path = require('path'); var path = require('path');
/*-----------------------------------------------------
* Module Setting
*-----------------------------------------------------*/
module.exports = function(grunt) { module.exports = function(grunt) {
'use strict';
// These plugins provide necessary tasks. // These plugins provide necessary tasks.
/* [Build plugin & task ] ------------------------------------*/ /* [Build plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-module-dependence');
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-autoprefixer');
var banner = '/*!\n' + var banner = '/*!\n' +
' * ====================================================\n' + ' * ====================================================\n' +
...@@ -32,153 +22,22 @@ module.exports = function(grunt) { ...@@ -32,153 +22,22 @@ module.exports = function(grunt) {
' * ====================================================\n' + ' * ====================================================\n' +
' */\n\n'; ' */\n\n';
var packs = ['index', 'edit', 'share', 'm-share'];
var sources = require('./import.js');
var srcPath = 'src/';
var distPath = 'dist/';
var distPages = ['index', 'edit', 'viewshare', 'm-share'].map(function(name) {
return distPath + name + '.html';
});
var concatConfigs = {};
packs.forEach(function(pack) {
concatConfigs[pack] = {
options: {
banner: banner + '(function(window) {\n\n',
footer: '\n\n})(window)',
sourceMap: true,
sourceMapStyle: 'link'
},
src: sources.filter(function(source) {
return source.pack == '*' || source.pack.split('|').indexOf(pack) !== -1;
}).map(function(source) {
return source.path;
}),
dest: distPath + 'kityminder.' + pack + '.js'
};
});
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
// Metadata. // Metadata.
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
clean: ['dist', 'native-support/upload/', 'native-support/src/tmp/'], dependence: {
concat: concatConfigs,
uglify: {
minimize: {
options: { options: {
banner: banner, base: 'src',
sourceMap: true entrance: 'kityminder'
}, },
files: (function() { merge: {
var files = {};
packs.forEach(function(pack) {
files[distPath + 'kityminder.' + pack + '.min.js'] = distPath + 'kityminder.' + pack + '.js';
});
return files;
})()
}
},
copy: {
dir: {
files: [{ files: [{
src: [ src: 'src/**/*.js',
'ui/theme/**/css/*.css', dest: 'release/kityminder.all.js'
'ui/theme/**/css/*.css.map',
'ui/theme/**/images/*',
'lang/**/*',
'static/**/*',
'native-support/**/*',
'lib/ZeroClipboard.swf',
'lib/inflate.js',
'lib/source-map.min.js',
'index.html',
'edit.html',
'viewshare.html',
'm-share.html',
'download.php'
],
dest: distPath
}] }]
},
km_config: {
expand: true,
src: 'kityminder.config.js',
dest: distPath
},
mise: {
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) { ...@@ -186,7 +45,6 @@ module.exports = function(grunt) {
// Build task(s). // Build task(s).
grunt.registerTask('default', ['clean', 'concat', 'uglify', 'less', 'autoprefixer', 'copy', 'replace']); grunt.registerTask('default', ['dependence']);
grunt.registerTask('dev', ['less', 'autoprefixer', 'watch']);
}; };
\ No newline at end of file
{
"name": "kityminder-core",
"title": "Kity Minder Core",
"description": "Powerful online mind graphic visualization and editor (command based)",
"version": "1.3.6",
"main": "src/kityminder.js",
"keywords": ["kityminder", "kity", "svg"],
"homepage": "https://github.com/fex-team/kityminder-core",
"devDependencies": {
"seajs": "~2.3.0"
},
"licenses": [{
"type": "BSD",
"url": "https://github.com/fex-team/kityminder-core/blob/dev/LICENSE"
}],
"bugs": {
"url": "https://github.com/fex-team/kityminder-core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/fex-team/kityminder-core.git"
},
"author": {
"name": "Baidu FEX",
"url": "http://fex.baidu.com"
}
}
\ No newline at end of file
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>KityMinder Example</title> <title>KityMinder Example</title>
<script type="text/javascript" src="lib/kity/dist/kity.js"></script>
<!--dev mode 引入-->
<script type="text/javascript" src="import.js"></script>
<!--dist mode 引入 -->
<!--<script type="text/javascript" src="../dist/kityminder.min.js">-->
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"> <link href="favicon.ico" type="image/x-icon" rel="shortcut icon">
<style type="text/css"> <style type="text/css">
body { body {
...@@ -37,9 +30,33 @@ ...@@ -37,9 +30,33 @@
<body> <body>
<div id="minder-view"></div> <div id="minder-view"></div>
</body> </body>
<!-- *************************** Module 形式加载引入 **************************** -->
<script type="text/javascript" src="lib/seajs/dist/sea-debug.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.km = new KityMinder({ /* global seajs */
seajs.config({
base: './src'
});
define('start', function(require) {
var Minder = require('kityminder').Minder;
// 创建 km 实例
var km = window.km = new Minder({
renderTo: 'minder-view' renderTo: 'minder-view'
}); });
});
seajs.use('start');
</script> </script>
<!-- *********************** 打包文件引入(需要先 grunt 发布) ************************* -->
<!--
<script type="text/javascript" src="../release/kityminder.all.min.js">
<script type="text/javascript">
// 创建 km 实例
window.km = new kityminder.Minder('minder-view');
</script>
-->
</html> </html>
\ No newline at end of file
(function() {
var define, requireModule, require, requirejs;
(function() {
var registry = {}, seen = {};
define = function(name, deps, callback) {
registry[name] = { deps: deps, callback: callback };
};
requirejs = require = requireModule = function(name) {
requirejs._eak_seen = registry;
if (seen[name]) { return seen[name]; }
seen[name] = {};
if (!registry[name]) {
throw new Error("Could not find module " + name);
}
var mod = registry[name],
deps = mod.deps,
callback = mod.callback,
reified = [],
exports;
for (var i=0, l=deps.length; i<l; i++) {
if (deps[i] === 'exports') {
reified.push(exports = {});
} else {
reified.push(requireModule(resolve(deps[i])));
}
}
var value = callback.apply(this, reified);
return seen[name] = exports || value;
function resolve(child) {
if (child.charAt(0) !== '.') { return child; }
var parts = child.split("/");
var parentBase = name.split("/").slice(0, -1);
for (var i=0, l=parts.length; i<l; i++) {
var part = parts[i];
if (part === '..') { parentBase.pop(); }
else if (part === '.') { continue; }
else { parentBase.push(part); }
}
return parentBase.join("/");
}
};
})();
define("promise/all",
["./utils","exports"],
function(__dependency1__, __exports__) {
"use strict";
/* global toString */
var isArray = __dependency1__.isArray;
var isFunction = __dependency1__.isFunction;
/**
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
*/
function all(promises) {
/*jshint validthis:true */
var Promise = this;
if (!isArray(promises)) {
throw new TypeError('You must pass an array to all.');
}
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length,
promise;
if (remaining === 0) {
resolve([]);
}
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && isFunction(promise.then)) {
promise.then(resolver(i), reject);
} else {
resolveAll(i, promise);
}
}
});
}
__exports__.all = all;
});
define("promise/asap",
["exports"],
function(__exports__) {
"use strict";
var browserGlobal = (typeof window !== 'undefined') ? window : {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var local = (typeof global !== 'undefined') ? global : (this === undefined? window:this);
// node
function useNextTick() {
return function() {
process.nextTick(flush);
};
}
function useMutationObserver() {
var iterations = 0;
var observer = new BrowserMutationObserver(flush);
var node = document.createTextNode('');
observer.observe(node, { characterData: true });
return function() {
node.data = (iterations = ++iterations % 2);
};
}
function useSetTimeout() {
return function() {
local.setTimeout(flush, 1);
};
}
var queue = [];
function flush() {
for (var i = 0; i < queue.length; i++) {
var tuple = queue[i];
var callback = tuple[0], arg = tuple[1];
callback(arg);
}
queue = [];
}
var scheduleFlush;
// Decide what async method to use to triggering processing of queued callbacks:
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
scheduleFlush = useNextTick();
} else if (BrowserMutationObserver) {
scheduleFlush = useMutationObserver();
} else {
scheduleFlush = useSetTimeout();
}
function asap(callback, arg) {
var length = queue.push([callback, arg]);
if (length === 1) {
// If length is 1, that means that we need to schedule an async flush.
// If additional callbacks are queued before the queue is flushed, they
// will be processed by this flush that we are scheduling.
scheduleFlush();
}
}
__exports__.asap = asap;
});
define("promise/config",
["exports"],
function(__exports__) {
"use strict";
var config = {
instrument: false
};
function configure(name, value) {
if (arguments.length === 2) {
config[name] = value;
} else {
return config[name];
}
}
__exports__.config = config;
__exports__.configure = configure;
});
define("promise/polyfill",
["./promise","./utils","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
/*global self*/
var RSVPPromise = __dependency1__.Promise;
var isFunction = __dependency2__.isFunction;
function polyfill() {
var local;
if (typeof global !== 'undefined') {
local = global;
} else if (typeof window !== 'undefined' && window.document) {
local = window;
} else {
local = self;
}
var es6PromiseSupport =
"Promise" in local &&
// Some of these methods are missing from
// Firefox/Chrome experimental implementations
"resolve" in local.Promise &&
"reject" in local.Promise &&
"all" in local.Promise &&
"race" in local.Promise &&
// Older version of the spec had a resolver object
// as the arg rather than a function
(function() {
var resolve;
new local.Promise(function(r) { resolve = r; });
return isFunction(resolve);
}());
// !es6PromiseSupport || ~window.location.href.indexOf('rsvpromise')
if (true) {
local.Promise = RSVPPromise;
}
}
__exports__.polyfill = polyfill;
});
define("promise/promise",
["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __exports__) {
"use strict";
var config = __dependency1__.config;
var configure = __dependency1__.configure;
var objectOrFunction = __dependency2__.objectOrFunction;
var isFunction = __dependency2__.isFunction;
var now = __dependency2__.now;
var all = __dependency3__.all;
var race = __dependency4__.race;
var staticResolve = __dependency5__.resolve;
var staticReject = __dependency6__.reject;
var asap = __dependency7__.asap;
var counter = 0;
config.async = asap; // default async is asap;
function Promise(resolver) {
if (!isFunction(resolver)) {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
if (!(this instanceof Promise)) {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}
this._subscribers = [];
invokeResolver(resolver, this);
}
function invokeResolver(resolver, promise) {
function resolvePromise(value) {
resolve(promise, value);
}
function rejectPromise(reason) {
reject(promise, reason);
}
try {
resolver(resolvePromise, rejectPromise);
} catch(e) {
rejectPromise(e);
}
}
function invokeCallback(settled, promise, callback, detail) {
var hasCallback = isFunction(callback),
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = detail;
succeeded = true;
}
if (handleThenable(promise, value)) {
return;
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (settled === FULFILLED) {
resolve(promise, value);
} else if (settled === REJECTED) {
reject(promise, value);
}
}
var PENDING = void 0;
var SEALED = 0;
var FULFILLED = 1;
var REJECTED = 2;
function subscribe(parent, child, onFulfillment, onRejection) {
var subscribers = parent._subscribers;
var length = subscribers.length;
subscribers[length] = child;
subscribers[length + FULFILLED] = onFulfillment;
subscribers[length + REJECTED] = onRejection;
}
function publish(promise, settled) {
var child, callback, subscribers = promise._subscribers, detail = promise._detail;
for (var i = 0; i < subscribers.length; i += 3) {
child = subscribers[i];
callback = subscribers[i + settled];
invokeCallback(settled, child, callback, detail);
}
promise._subscribers = null;
}
Promise.prototype = {
constructor: Promise,
_state: undefined,
_detail: undefined,
_subscribers: undefined,
then: function(onFulfillment, onRejection) {
var promise = this;
var thenPromise = new this.constructor(function() {});
if (this._state) {
var callbacks = arguments;
config.async(function invokePromiseCallback() {
invokeCallback(promise._state, thenPromise, callbacks[promise._state - 1], promise._detail);
});
} else {
subscribe(this, thenPromise, onFulfillment, onRejection);
}
return thenPromise;
},
'catch': function(onRejection) {
return this.then(null, onRejection);
}
};
Promise.all = all;
Promise.race = race;
Promise.resolve = staticResolve;
Promise.reject = staticReject;
function handleThenable(promise, value) {
var then = null,
resolved;
try {
if (promise === value) {
throw new TypeError("A promises callback cannot return that same promise.");
}
if (objectOrFunction(value)) {
then = value.then;
if (isFunction(then)) {
then.call(value, function(val) {
if (resolved) { return true; }
resolved = true;
if (value !== val) {
resolve(promise, val);
} else {
fulfill(promise, val);
}
}, function(val) {
if (resolved) { return true; }
resolved = true;
reject(promise, val);
});
return true;
}
}
} catch (error) {
if (resolved) { return true; }
reject(promise, error);
return true;
}
return false;
}
function resolve(promise, value) {
if (promise === value) {
fulfill(promise, value);
} else if (!handleThenable(promise, value)) {
fulfill(promise, value);
}
}
function fulfill(promise, value) {
if (promise._state !== PENDING) { return; }
promise._state = SEALED;
promise._detail = value;
config.async(publishFulfillment, promise);
}
function reject(promise, reason) {
if (promise._state !== PENDING) { return; }
promise._state = SEALED;
promise._detail = reason;
config.async(publishRejection, promise);
}
function publishFulfillment(promise) {
publish(promise, promise._state = FULFILLED);
}
function publishRejection(promise) {
publish(promise, promise._state = REJECTED);
}
__exports__.Promise = Promise;
});
define("promise/race",
["./utils","exports"],
function(__dependency1__, __exports__) {
"use strict";
/* global toString */
var isArray = __dependency1__.isArray;
/**
`RSVP.race` allows you to watch a series of promises and act as soon as the
first promise given to the `promises` argument fulfills or rejects.
Example:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 2");
}, 100);
});
RSVP.race([promise1, promise2]).then(function(result){
// result === "promise 2" because it was resolved before promise1
// was resolved.
});
```
`RSVP.race` is deterministic in that only the state of the first completed
promise matters. For example, even if other promises given to the `promises`
array argument are resolved, but the first completed promise has become
rejected before the other promises became fulfilled, the returned promise
will become rejected:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
reject(new Error("promise 2"));
}, 100);
});
RSVP.race([promise1, promise2]).then(function(result){
// Code here never runs because there are rejected promises!
}, function(reason){
// reason.message === "promise2" because promise 2 became rejected before
// promise 1 became fulfilled
});
```
@method race
@for RSVP
@param {Array} promises array of promises to observe
@param {String} label optional string for describing the promise returned.
Useful for tooling.
@return {Promise} a promise that becomes fulfilled with the value the first
completed promises is resolved with if the first completed promise was
fulfilled, or rejected with the reason that the first completed promise
was rejected with.
*/
function race(promises) {
/*jshint validthis:true */
var Promise = this;
if (!isArray(promises)) {
throw new TypeError('You must pass an array to race.');
}
return new Promise(function(resolve, reject) {
var results = [], promise;
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && typeof promise.then === 'function') {
promise.then(resolve, reject);
} else {
resolve(promise);
}
}
});
}
__exports__.race = race;
});
define("promise/reject",
["exports"],
function(__exports__) {
"use strict";
/**
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
*/
function reject(reason) {
/*jshint validthis:true */
var Promise = this;
return new Promise(function (resolve, reject) {
reject(reason);
});
}
__exports__.reject = reject;
});
define("promise/resolve",
["exports"],
function(__exports__) {
"use strict";
function resolve(value) {
/*jshint validthis:true */
if (value && typeof value === 'object' && value.constructor === this) {
return value;
}
var Promise = this;
return new Promise(function(resolve) {
resolve(value);
});
}
__exports__.resolve = resolve;
});
define("promise/utils",
["exports"],
function(__exports__) {
"use strict";
function objectOrFunction(x) {
return isFunction(x) || (typeof x === "object" && x !== null);
}
function isFunction(x) {
return typeof x === "function";
}
function isArray(x) {
return Object.prototype.toString.call(x) === "[object Array]";
}
// Date.now is not available in browsers < IE9
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
var now = Date.now || function() { return new Date().getTime(); };
__exports__.objectOrFunction = objectOrFunction;
__exports__.isFunction = isFunction;
__exports__.isArray = isArray;
__exports__.now = now;
});
requireModule('promise/polyfill').polyfill();
}());
\ No newline at end of file
{
"name": "seajs",
"version": "2.3.0",
"main": "./dist/sea.js",
"ignore": [
"**/.*",
"docs",
"lib",
"src",
"tests",
"CNAME",
"component.json",
"CONTRIBUTING.md",
"index.html",
"Makefile",
"package.json",
"README.md"
],
"homepage": "https://github.com/seajs/seajs",
"_release": "2.3.0",
"_resolution": {
"type": "version",
"tag": "2.3.0",
"commit": "9c6299636991fbca73a9aa7b2eb152c6e8614854"
},
"_source": "git://github.com/seajs/seajs.git",
"_target": "~2.3.0",
"_originalSource": "seajs"
}
\ No newline at end of file
MIT LICENSE
Copyright (c) 2009 - 2099 Frank Wang, http://seajs.org/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "seajs",
"version": "2.3.0",
"main": "./dist/sea.js",
"ignore": [
"**/.*",
"docs",
"lib",
"src",
"tests",
"CNAME",
"component.json",
"CONTRIBUTING.md",
"index.html",
"Makefile",
"package.json",
"README.md"
]
}
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
"title": "kityminder", "title": "kityminder",
"description": "Kity Minder", "description": "Kity Minder",
"version": "1.3.5", "version": "1.3.5",
"homepage": "https://github.com/fex-team/kityminder", "homepage": "https://github.com/fex-team/kityminder-core",
"author": { "author": {
"name": "f-cube @ FEX", "name": "f-cube @ FEX",
"url": "http://fex.baidu.com" "url": "http://fex.baidu.com"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/fex-team/kityminder.git" "url": "https://github.com/fex-team/kityminder-core.git"
}, },
"keywords": [ "keywords": [
"kityminder", "kityminder",
...@@ -21,23 +21,20 @@ ...@@ -21,23 +21,20 @@
"javascript" "javascript"
], ],
"bugs": { "bugs": {
"url": "https://github.com/fex-team/kityminder/issues" "url": "https://github.com/fex-team/kityminder-core/issues"
}, },
"licenses": [ { "licenses": [ {
"type": "MIT", "type": "MIT",
"url": "https://github.com/fex-team/kityminder/blob/dev/LICENSE" "url": "https://github.com/fex-team/kityminder-core/blob/dev/LICENSE"
} ], } ],
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-module-dependence": "~0.1.4",
"grunt-contrib-concat": "~0.5.0", "grunt-contrib-concat": "~0.5.0",
"grunt-contrib-uglify": "~0.4.0", "grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-copy": "~0.5.0", "grunt-contrib-copy": "~0.5.0",
"grunt-text-replace": "~0.3.9", "grunt-contrib-clean": "~0.5.0"
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-less": "~0.11.3",
"grunt-contrib-clean": "~0.6.0",
"grunt-autoprefixer": "~1.0.1"
} }
} }
\ No newline at end of file
...@@ -7,16 +7,20 @@ ...@@ -7,16 +7,20 @@
* @copyright: Baidu FEX, 2014 * @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 r = 7;
var dot = new kity.Circle(r - 1); var dot = new kity.Circle(r - 1);
this.addShape(dot); this.addShape(dot);
this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r); this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
this.dot = dot; this.dot = dot;
this.node.setAttribute('markerUnits', 'userSpaceOnUse'); 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(), var box = node.getLayoutBox(),
pBox = parent.getLayoutBox(); pBox = parent.getLayoutBox();
...@@ -41,4 +45,5 @@ KityMinder.registerConnectProvider('arc', function(node, parent, connection, wid ...@@ -41,4 +45,5 @@ KityMinder.registerConnectProvider('arc', function(node, parent, connection, wid
connectMarker.dot.fill(color); connectMarker.dot.fill(color);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('bezier', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('bezier', function(node, parent, connection) {
// 连线起点和终点 // 连线起点和终点
var po = parent.getLayoutVertexOut(), var po = parent.getLayoutVertexOut(),
...@@ -34,4 +38,5 @@ KityMinder.registerConnectProvider('bezier', function(node, parent, connection) ...@@ -34,4 +38,5 @@ KityMinder.registerConnectProvider('bezier', function(node, parent, connection)
connection.setMarker(null); connection.setMarker(null);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('fish-bone-master', function(node, parent, connection) {
var pout = parent.getLayoutVertexOut(), var pout = parent.getLayoutVertexOut(),
pin = node.getLayoutVertexIn(); pin = node.getLayoutVertexIn();
...@@ -25,4 +29,5 @@ KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, co ...@@ -25,4 +29,5 @@ KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, co
connection.setMarker(null); connection.setMarker(null);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('l', function(node, parent, connection) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('l', function(node, parent, connection) {
var po = parent.getLayoutVertexOut(); var po = parent.getLayoutVertexOut();
var pi = node.getLayoutVertexIn(); var pi = node.getLayoutVertexIn();
...@@ -26,4 +30,5 @@ KityMinder.registerConnectProvider('l', function(node, parent, connection) { ...@@ -26,4 +30,5 @@ KityMinder.registerConnectProvider('l', function(node, parent, connection) {
pathData.push('L', pi); pathData.push('L', pi);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('poly', function(node, parent, connection, width) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('poly', function(node, parent, connection, width) {
// 连线起点和终点 // 连线起点和终点
var po = parent.getLayoutVertexOut(), var po = parent.getLayoutVertexOut(),
...@@ -55,4 +59,5 @@ KityMinder.registerConnectProvider('poly', function(node, parent, connection, wi ...@@ -55,4 +59,5 @@ KityMinder.registerConnectProvider('poly', function(node, parent, connection, wi
connection.setMarker(null); connection.setMarker(null);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerConnectProvider('under', function(node, parent, connection, width, color) { define(function(require, exports, module) {
var kity = require('core/kity');
var connect = require('core/connect');
connect.register('under', function(node, parent, connection, width, color) {
var box = node.getLayoutBox(), var box = node.getLayoutBox(),
pBox = parent.getLayoutBox(); pBox = parent.getLayoutBox();
...@@ -42,4 +46,5 @@ KityMinder.registerConnectProvider('under', function(node, parent, connection, w ...@@ -42,4 +46,5 @@ KityMinder.registerConnectProvider('under', function(node, parent, connection, w
connection.setMarker(null); connection.setMarker(null);
connection.setPathData(pathData); connection.setPathData(pathData);
});
}); });
\ No newline at end of file
KityMinder.COMMAND_STATE_NORMAL = 0; define(function(require, exports, module) {
KityMinder.COMMAND_STATE_DISABLED = -1; var kity = require('./kity');
KityMinder.COMMAND_STATE_ACTIVED = 1; var utils = require('./utils');
var Minder = require('./minder');
var Command = kity.createClass( "Command", { var MinderNode = require('./node');
constructor: function () { var MinderEvent = require('./event');
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._isContentChange = true;
this._isSelectionChange = false; this._isSelectionChange = false;
}, },
execute: function ( minder, args ) { execute: function(minder, args) {
throw new Error('Not Implement: Command.execute()');
}, },
setContentChanged: function ( val ) { setContentChanged: function(val) {
this._isContentChange = !! val; this._isContentChange = !!val;
}, },
isContentChanged: function () { isContentChanged: function() {
return this._isContentChange; return this._isContentChange;
}, },
setSelectionChanged: function ( val ) { setSelectionChanged: function(val) {
this._isSelectionChange = !! val; this._isSelectionChange = !!val;
}, },
isSelectionChanged: function () { isSelectionChanged: function() {
return this._isContentChange; return this._isContentChange;
}, },
queryState: function ( km ) { queryState: function(km) {
return KityMinder.COMMAND_STATE_NORMAL; return COMMAND_STATE_NORMAL;
}, },
queryValue: function ( km ) { queryValue: function(km) {
return 0; return 0;
}, },
isNeedUndo: function () {
isNeedUndo: function() {
return true; return true;
} }
} ); });
kity.extendClass(KityMinder, { Command.STATE_NORMAL = COMMAND_STATE_NORMAL;
_getCommand: function (name) { Command.STATE_ACTIVE = COMMAND_STATE_ACTIVED;
Command.STATE_DISABLED = COMMAND_STATE_DISABLED;
kity.extendClass(Minder, {
_getCommand: function(name) {
return this._commands[name.toLowerCase()]; return this._commands[name.toLowerCase()];
}, },
_queryCommand: function (name, type, args) { _queryCommand: function(name, type, args) {
var cmd = this._getCommand(name); var cmd = this._getCommand(name);
if (cmd) { if (cmd) {
var queryCmd = cmd['query' + type]; var queryCmd = cmd['query' + type];
...@@ -55,18 +72,18 @@ kity.extendClass(KityMinder, { ...@@ -55,18 +72,18 @@ kity.extendClass(KityMinder, {
return 0; return 0;
}, },
queryCommandState: function (name) { queryCommandState: function(name) {
return this._queryCommand(name, "State", Utils.argsToArray(1)); return this._queryCommand(name, 'State', [].slice.call(arguments, 1));
}, },
queryCommandValue: function (name) { queryCommandValue: function(name) {
return this._queryCommand(name, "Value", Utils.argsToArray(1)); return this._queryCommand(name, 'Value', [].slice.call(arguments, 1));
}, },
execCommand: function (name) { execCommand: function(name) {
name = name.toLowerCase(); name = name.toLowerCase();
var cmdArgs = Utils.argsToArray(arguments, 1), var cmdArgs = [].slice.call(arguments, 1),
cmd, stoped, result, eventParams; cmd, stoped, result, eventParams;
var me = this; var me = this;
cmd = this._getCommand(name); cmd = this._getCommand(name);
...@@ -88,7 +105,7 @@ kity.extendClass(KityMinder, { ...@@ -88,7 +105,7 @@ kity.extendClass(KityMinder, {
//保存场景 //保存场景
this._fire(new MinderEvent('saveScene')); this._fire(new MinderEvent('saveScene'));
this._fire(new MinderEvent("preExecCommand", eventParams, false)); this._fire(new MinderEvent('preExecCommand', eventParams, false));
result = cmd.execute.apply(cmd, [me].concat(cmdArgs)); result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
...@@ -114,4 +131,7 @@ kity.extendClass(KityMinder, { ...@@ -114,4 +131,7 @@ kity.extendClass(KityMinder, {
return result === undefined ? null : result; 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'; 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) { function traverse(node, fn) {
fn(node); fn(node);
if (node.children) node.children.forEach(function(child) { if (node.children) node.children.forEach(function(child) {
...@@ -58,14 +71,5 @@ Utils.extend(KityMinder, { ...@@ -58,14 +71,5 @@ Utils.extend(KityMinder, {
}); });
} }
switch (version) { module.exports = compatibility;
case '1.1.3':
c_113_120(json);
case '1.2.0':
case '1.2.1':
c_120_130(json);
}
return json;
}
}); });
\ No newline at end of file
/* global Renderer: true */ define(function(require, exports, module) {
var kity = require('./kity');
utils.extend(KityMinder, { var utils = require('./utils');
_connectProviders: {}, var Module = require('./module');
var Minder = require('./minder');
var MinderNode = require('./node');
// 连线提供方
var _connectProviders = {};
function register(name, provider) {
_connectProviders[name] = provider;
}
_defaultConnectProvider: function(node, parent, connection) { register('default', function(node, parent, connection) {
connection.setPathData([ connection.setPathData([
'M', parent.getLayoutVertexOut(), 'M', parent.getLayoutVertexOut(),
'L', node.getLayoutVertexIn() 'L', node.getLayoutVertexIn()
]); ]);
}, });
registerConnectProvider: function(name, provider) { kity.extendClass(MinderNode, {
KityMinder._connectProviders[name] = provider; getConnect: function() {
return this.data.connect || 'default';
}, },
getConnectProvider: function(name) {
return KityMinder._connectProviders[name] || KityMinder._defaultConnectProvider;
}
});
kity.extendClass(MinderNode, {
getConnectProvider: function() { getConnectProvider: function() {
return KityMinder.getConnectProvider(this.getConnect()); return _connectProviders[this.getConnect()] || _connectProviders['default'];
},
getConnect: function() {
return null;
}, },
getConnection: function() { getConnection: function() {
return this._connection || null; return this._connection || null;
} }
}); });
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
getConnectContainer: function() { getConnectContainer: function() {
return this._connectContainer; return this._connectContainer;
...@@ -86,11 +86,11 @@ kity.extendClass(KityMinder, { ...@@ -86,11 +86,11 @@ kity.extendClass(KityMinder, {
connection.setTranslate(0, 0); connection.setTranslate(0, 0);
} }
} }
}); });
KityMinder.registerModule('Connect', { Module.register('Connect', {
init: function() { 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); this.getRenderContainer().prependShape(this._connectContainer);
}, },
events: { events: {
...@@ -104,4 +104,7 @@ KityMinder.registerModule('Connect', { ...@@ -104,4 +104,7 @@ KityMinder.registerModule('Connect', {
this.updateConnect(e.node); this.updateConnect(e.node);
} }
} }
});
exports.register = register;
}); });
\ No newline at end of file
Utils.extend(KityMinder, { define(function(require, exports, module) {
_protocols: {}, var kity = require('./kity');
registerProtocol: function(name, protocolDeal) { var utils = require('./utils');
KityMinder._protocols[name] = protocolDeal; var Minder = require('./minder');
} var MinderNode = require('./node');
}); var MinderEvent = require('./event');
var compatibility = require('./compatibility');
var DEFAULT_TEXT = {
'root': 'maintopic',
'main': 'topic',
'sub': 'topic'
};
KityMinder.registerInit(function() { // 导入导出
this._initProtocols(); kity.extendClass(Minder, {
});
// 导入导出
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() { exportJson: function() {
/* 导出 node 上整棵树的数据为 JSON */ /* 导出 node 上整棵树的数据为 JSON */
...@@ -58,7 +28,7 @@ kity.extendClass(KityMinder, { ...@@ -58,7 +28,7 @@ kity.extendClass(KityMinder, {
json.template = this.getTemplate(); json.template = this.getTemplate();
json.theme = this.getTheme(); json.theme = this.getTheme();
json.version = KityMinder.version; json.version = Minder.version;
return json; return json;
}, },
...@@ -72,7 +42,7 @@ kity.extendClass(KityMinder, { ...@@ -72,7 +42,7 @@ kity.extendClass(KityMinder, {
node.setData(field, data[field]); node.setData(field, data[field]);
} }
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()])); node.setData('text', data.text);
var childrenTreeData = json.children || []; var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) { for (var i = 0; i < childrenTreeData.length; i++) {
...@@ -91,7 +61,7 @@ kity.extendClass(KityMinder, { ...@@ -91,7 +61,7 @@ kity.extendClass(KityMinder, {
this.removeNode(this._root.getChildren()[0]); this.removeNode(this._root.getChildren()[0]);
} }
json = KityMinder.compatibility(json); json = Minder.compatibility(json);
importNode(this._root, json, this); importNode(this._root, json, this);
...@@ -105,72 +75,6 @@ kity.extendClass(KityMinder, { ...@@ -105,72 +75,6 @@ kity.extendClass(KityMinder, {
type: 'contentchange' type: 'contentchange'
}); });
this._interactChange(); 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) { constructor: function(type, params, canstop) {
params = params || {}; params = params || {};
if (params.getType && params.getType() == 'ShapeEvent') { if (params.getType && params.getType() == 'ShapeEvent') {
...@@ -49,9 +62,9 @@ var MinderEvent = kity.createClass('MindEvent', { ...@@ -49,9 +62,9 @@ var MinderEvent = kity.createClass('MindEvent', {
if (!this.originEvent) { if (!this.originEvent) {
return false; return false;
} }
if ("which" in this.originEvent) if ('which' in this.originEvent)
isRightMB = this.originEvent.which == 3; isRightMB = this.originEvent.which == 3;
else if ("button" in this.originEvent) else if ('button' in this.originEvent)
isRightMB = this.originEvent.button == 2; isRightMB = this.originEvent.button == 2;
return isRightMB; return isRightMB;
}, },
...@@ -59,39 +72,44 @@ var MinderEvent = kity.createClass('MindEvent', { ...@@ -59,39 +72,44 @@ var MinderEvent = kity.createClass('MindEvent', {
var evt = this.originEvent; var evt = this.originEvent;
return evt.keyCode || evt.which; return evt.keyCode || evt.which;
} }
}); });
KityMinder.registerInit(function() { Minder.registerInitHook(function() {
this._initEvents(); this._initEvents();
}); });
kity.extendClass(Minder, {
// 事件机制
kity.extendClass(KityMinder, {
_initEvents: function() { _initEvents: function() {
this._eventCallbacks = {}; this._eventCallbacks = {};
}, },
_bindEvents: function() { _bindEvents: function() {
this._bindPaperEvents(); this._bindPaperEvents();
this._bindKeyboardEvents(); this._bindKeyboardEvents();
}, },
_resetEvents: function() { _resetEvents: function() {
this._initEvents(); this._initEvents();
this._bindEvents(); this._bindEvents();
}, },
// TODO: mousemove lazy bind
_bindPaperEvents: function() { _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)); this._paper.on('click dblclick mousedown contextmenu mouseup mousemove mouseover mousewheel DOMMouseScroll touchstart touchmove touchend dragenter dragleave drop', this._firePharse.bind(this));
if (window) { if (window) {
window.addEventListener('resize', this._firePharse.bind(this)); window.addEventListener('resize', this._firePharse.bind(this));
window.addEventListener('blur', this._firePharse.bind(this)); window.addEventListener('blur', this._firePharse.bind(this));
} }
}, },
_bindKeyboardEvents: function() { _bindKeyboardEvents: function() {
if ((navigator.userAgent.indexOf('iPhone') == -1) && (navigator.userAgent.indexOf('iPod') == -1) && (navigator.userAgent.indexOf('iPad') == -1)) { 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) { _firePharse: function(e) {
// //只读模式下强了所有的事件操作 // //只读模式下强了所有的事件操作
// if(this.readOnly === true){ // if(this.readOnly === true){
...@@ -117,6 +135,7 @@ kity.extendClass(KityMinder, { ...@@ -117,6 +135,7 @@ kity.extendClass(KityMinder, {
this._fire(executeEvent)) this._fire(executeEvent))
this._fire(new MinderEvent('after' + e.type, e, false)); this._fire(new MinderEvent('after' + e.type, e, false));
}, },
_interactChange: function(e) { _interactChange: function(e) {
var me = this; var me = this;
if (me._interactScheduled) return; if (me._interactScheduled) return;
...@@ -126,31 +145,26 @@ kity.extendClass(KityMinder, { ...@@ -126,31 +145,26 @@ kity.extendClass(KityMinder, {
}, 100); }, 100);
me._interactScheduled = true; me._interactScheduled = true;
}, },
_listen: function(type, callback) { _listen: function(type, callback) {
var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []); var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []);
callbacks.push(callback); callbacks.push(callback);
}, },
_fire: function(e) {
_fire: function(e) {
var status = this.getStatus(); var status = this.getStatus();
var callbacks = this._eventCallbacks[e.type.toLowerCase()] || []; var callbacks = this._eventCallbacks[e.type.toLowerCase()] || [];
if (status) { if (status) {
callbacks = callbacks.concat(this._eventCallbacks[status + '.' + e.type.toLowerCase()] || []); callbacks = callbacks.concat(this._eventCallbacks[status + '.' + e.type.toLowerCase()] || []);
} }
if (callbacks.length === 0) { if (callbacks.length === 0) {
return; return;
} }
var lastStatus = this.getStatus();
var lastStatus = this.getStatus();
for (var i = 0; i < callbacks.length; i++) { for (var i = 0; i < callbacks.length; i++) {
callbacks[i].call(this, e); callbacks[i].call(this, e);
/* this.getStatus() != lastStatus ||*/ /* this.getStatus() != lastStatus ||*/
...@@ -158,15 +172,18 @@ kity.extendClass(KityMinder, { ...@@ -158,15 +172,18 @@ kity.extendClass(KityMinder, {
break; break;
} }
} }
return e.shouldStopPropagation(); return e.shouldStopPropagation();
}, },
on: function(name, callback) { on: function(name, callback) {
var km = this; var km = this;
utils.each(name.split(/\s+/), function(i, n) { name.split(/\s+/).forEach(function(n) {
km._listen(n.toLowerCase(), callback); km._listen(n.toLowerCase(), callback);
}); });
return this; return this;
}, },
off: function(name, callback) { off: function(name, callback) {
var types = name.split(/\s+/); var types = name.split(/\s+/);
...@@ -187,9 +204,13 @@ kity.extendClass(KityMinder, { ...@@ -187,9 +204,13 @@ kity.extendClass(KityMinder, {
} }
} }
}, },
fire: function(type, params) { fire: function(type, params) {
var e = new MinderEvent(type, params); var e = new MinderEvent(type, params);
this._fire(e); this._fire(e);
return this; return this;
} }
});
module.exports = MinderEvent;
}); });
...@@ -7,12 +7,19 @@ ...@@ -7,12 +7,19 @@
* @copyright: Baidu FEX, 2014 * @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 * 计算包含 meta 键的 keycode
* *
* @param {String|KeyEvent} unknown * @param {String|KeyEvent} unknown
*/ */
function getMetaKeyCode(unknown) { function getMetaKeyCode(unknown) {
var CTRL_MASK = 0x1000; var CTRL_MASK = 0x1000;
var ALT_MASK = 0x2000; var ALT_MASK = 0x2000;
var SHIFT_MASK = 0x4000; var SHIFT_MASK = 0x4000;
...@@ -51,21 +58,21 @@ function getMetaKeyCode(unknown) { ...@@ -51,21 +58,21 @@ function getMetaKeyCode(unknown) {
} }
return metaKeyCode; return metaKeyCode;
} }
kity.extendClass(MinderEvent, { kity.extendClass(MinderEvent, {
isShortcutKey: function(keyCombine) { isShortcutKey: function(keyCombine) {
var keyEvent = this.originEvent; var keyEvent = this.originEvent;
if (!keyEvent) return false; if (!keyEvent) return false;
return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent); return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent);
} }
}); });
KityMinder.registerInit(function() { Minder.registerInitHook(function() {
this._initShortcutKey(); this._initShortcutKey();
}); });
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
_initShortcutKey: function() { _initShortcutKey: function() {
this._bindShortcutKeys(); this._bindShortcutKeys();
...@@ -113,7 +120,7 @@ kity.extendClass(KityMinder, { ...@@ -113,7 +120,7 @@ kity.extendClass(KityMinder, {
var minder = this; var minder = this;
utils.each(obj, function(command, keys) { utils.each(obj, function(keys, command) {
binds[command] = keys; binds[command] = keys;
...@@ -129,4 +136,5 @@ kity.extendClass(KityMinder, { ...@@ -129,4 +136,5 @@ kity.extendClass(KityMinder, {
var binds = this._commandShortcutKeys; var binds = this._commandShortcutKeys;
return binds && binds[cmd] || null; return binds && binds[cmd] || null;
} }
});
}); });
\ No newline at end of file
var keymap = KityMinder.keymap = (function(origin) { define(function(require, exports, module) {
var ret = {}; var keymap = {
for (var key in origin) {
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;
})({
'Backspace': 8, 'Backspace': 8,
'Tab': 9, 'Tab': 9,
'Enter': 13, 'Enter': 13,
...@@ -124,5 +102,27 @@ var keymap = KityMinder.keymap = (function(origin) { ...@@ -124,5 +102,27 @@ var keymap = KityMinder.keymap = (function(origin) {
13: 1, 13: 1,
9: 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;
}
/** 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 = require('./command');
var _layouts = {};
var _defaultLayout;
function register(name, layout) {
_layouts[name] = layout;
_defaultLayout = _defaultLayout || name;
}
/**
* @class Layout 布局基类,具体布局需要从该类派生
*/
var Layout = kity.createClass('Layout', {
/**
* @abstract
*
* 子类需要实现的布局算法,该算法输入一个节点,排布该节点的子节点(相对父节点的变换)
*
* @param {MinderNode} node 需要布局的节点
*
* @example
*
* doLayout: function(node) {
* var children = node.getChildren();
* // layout calculation
* children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
* }
*/ */
Utils.extend(KityMinder, { doLayout: function(node) {
_layout: {}, throw new Error('Not Implement: Layout.doLayout()');
},
registerLayout: function(name, layout) { /**
KityMinder._layout[name] = layout; * 对齐指定的节点
if (!KityMinder._defaultLayout) { *
KityMinder._defaultLayout = name; * @param {Array<MinderNode>} nodes 要对齐的节点
* @param {string} border 对齐边界,允许取值 left, right, top, bottom
*
*/
align: function(nodes, border, offset) {
var me = this;
offset = offset || 0;
nodes.forEach(function(node) {
var tbox = me.getTreeBox([node]);
var matrix = node.getLayoutTransform();
switch (border) {
case 'left':
return matrix.translate(offset - tbox.left, 0);
case 'right':
return matrix.translate(offset - tbox.right, 0);
case 'top':
return matrix.translate(0, offset - tbox.top);
case 'bottom':
return matrix.translate(0, offset - tbox.bottom);
} }
});
}, },
stack: function(nodes, axis, distance) {
var me = this;
var position = 0;
distance = distance || function(node, next, axis) {
return node.getStyle({
x: 'margin-right',
y: 'margin-bottom'
}[axis]) + next.getStyle({
x: 'margin-left',
y: 'margin-top'
}[axis]);
};
nodes.forEach(function(node, index, nodes) {
var tbox = me.getTreeBox([node]);
var size = {
x: tbox.width,
y: tbox.height
}[axis];
var offset = {
x: tbox.left,
y: tbox.top
}[axis];
var matrix = node.getLayoutTransform();
if (axis == 'x') {
matrix.translate(position - offset, 0);
} else {
matrix.translate(0, position - offset);
}
position += size;
if (nodes[index + 1])
position += distance(node, nodes[index + 1], axis);
});
return position;
},
move: function(nodes, dx, dy) {
nodes.forEach(function(node) {
node.getLayoutTransform().translate(dx, dy);
});
},
/**
* 工具方法:获取给点的节点所占的布局区域
*
* @param {MinderNode[]} nodes 需要计算的节点
*
* @return {Box} 计算结果
*/
getBranchBox: function(nodes) {
var box = new kity.Box();
var i, node, matrix, contentBox;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
contentBox = node.getContentBox();
box = box.merge(matrix.transformBox(contentBox));
}
return box;
},
/**
* 工具方法:计算给定的节点的子树所占的布局区域
*
* @param {MinderNode} nodes 需要计算的节点
*
* @return {Box} 计算的结果
*/
getTreeBox: function(nodes) {
var i, node, matrix, treeBox;
var box = new kity.Box();
if (!(nodes instanceof Array)) nodes = [nodes];
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
treeBox = node.getContentBox();
if (node.isExpanded() && node.children.length) {
treeBox = treeBox.merge(this.getTreeBox(node.children));
}
box = box.merge(matrix.transformBox(treeBox));
}
return box;
},
getOrderHint: function(node) {
return [];
}
});
Layout.register = register;
Minder.registerInitHook(function(options) {
this.refresh();
});
/**
* 布局支持池子管理
*/
utils.extend(Minder, {
getLayoutList: function() { getLayoutList: function() {
return this._layout; return _layouts;
}, },
getLayoutInstance: function(name) { getLayoutInstance: function(name) {
var LayoutClass = KityMinder._layout[name]; var LayoutClass = _layouts[name];
if (!LayoutClass) throw new Error('Missing Layout: ' + name); if (!LayoutClass) throw new Error('Missing Layout: ' + name);
var layout = new LayoutClass(); var layout = new LayoutClass();
return layout; return layout;
} }
}); });
/** /**
* MinderNode 上的布局支持 * MinderNode 上的布局支持
*/ */
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
/** /**
* 获得当前节点的布局名称 * 获得当前节点的布局名称
...@@ -36,7 +203,7 @@ kity.extendClass(MinderNode, { ...@@ -36,7 +203,7 @@ kity.extendClass(MinderNode, {
getLayout: function() { getLayout: function() {
var layout = this.getData('layout'); var layout = this.getData('layout');
layout = layout || (this.isRoot() ? KityMinder._defaultLayout : this.parent.getLayout()); layout = layout || (this.isRoot() ? _defaultLayout : this.parent.getLayout());
return layout; return layout;
}, },
...@@ -60,7 +227,7 @@ kity.extendClass(MinderNode, { ...@@ -60,7 +227,7 @@ kity.extendClass(MinderNode, {
}, },
getLayoutInstance: function() { getLayoutInstance: function() {
return KityMinder.getLayoutInstance(this.getLayout()); return Minder.getLayoutInstance(this.getLayout());
}, },
getOrderHint: function(refer) { getOrderHint: function(refer) {
...@@ -224,13 +391,12 @@ kity.extendClass(MinderNode, { ...@@ -224,13 +391,12 @@ kity.extendClass(MinderNode, {
isLayoutRoot: function() { isLayoutRoot: function() {
return this.getData('layout') || this.isRoot(); return this.getData('layout') || this.isRoot();
} }
}); });
KityMinder.registerInit(function(options) {
this.refresh();
});
kity.extendClass(KityMinder, { /**
* Minder 上的布局支持
*/
kity.extendClass(Minder, {
layout: function(duration) { layout: function(duration) {
...@@ -265,7 +431,7 @@ kity.extendClass(KityMinder, { ...@@ -265,7 +431,7 @@ kity.extendClass(KityMinder, {
duration = duration ? 300 : 0; duration = duration ? 300 : 0;
var minder = this; var minder = this;
this.applyLayoutResult(this.getRoot(), duration).then(function() { this.applyLayoutResult(this.getRoot(), duration, function() {
minder.fire('layoutallfinish'); minder.fire('layoutallfinish');
}); });
...@@ -278,21 +444,17 @@ kity.extendClass(KityMinder, { ...@@ -278,21 +444,17 @@ kity.extendClass(KityMinder, {
return this; return this;
}, },
applyLayoutResult: function(root, duration) { applyLayoutResult: function(root, duration, callback) {
root = root || this.getRoot(); root = root || this.getRoot();
var me = this; var me = this;
var deffered = {};
var promise = new Promise(function(resolve, reject) {
deffered.resolve = resolve;
deffered.reject = reject;
});
var complex = root.getComplex(); var complex = root.getComplex();
function consume() { function consume() {
if (!--complex) { if (!--complex) {
deffered.resolve(); if (callback) {
callback();
}
} }
} }
...@@ -358,227 +520,9 @@ kity.extendClass(KityMinder, { ...@@ -358,227 +520,9 @@ kity.extendClass(KityMinder, {
} }
apply(root, root.parent ? root.parent.getGlobalLayoutTransform() : new kity.Matrix()); apply(root, root.parent ? root.parent.getGlobalLayoutTransform() : new kity.Matrix());
return promise; return this;
},
});
/**
* @class Layout 布局基类,具体布局需要从该类派生
*/
var Layout = kity.createClass('Layout', {
/**
* @abstract
*
* 子类需要实现的布局算法,该算法输入一个节点,排布该节点的子节点(相对父节点的变换)
*
* @param {MinderNode} node 需要布局的节点
*
* @example
*
* doLayout: function(node) {
* var children = node.getChildren();
* // layout calculation
* children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
* }
*/
doLayout: function(node) {
throw new Error('Not Implement: Layout.doLayout()');
},
/**
* 对齐指定的节点
*
* @param {Array<MinderNode>} nodes 要对齐的节点
* @param {string} border 对齐边界,允许取值 left, right, top, bottom
*
*/
align: function(nodes, border, offset) {
var me = this;
offset = offset || 0;
nodes.forEach(function(node) {
var tbox = me.getTreeBox([node]);
var matrix = node.getLayoutTransform();
switch (border) {
case 'left':
return matrix.translate(offset - tbox.left, 0);
case 'right':
return matrix.translate(offset - tbox.right, 0);
case 'top':
return matrix.translate(0, offset - tbox.top);
case 'bottom':
return matrix.translate(0, offset - tbox.bottom);
}
});
},
stack: function(nodes, axis, distance) {
var me = this;
var position = 0;
distance = distance || function(node, next, axis) {
return node.getStyle({
x: 'margin-right',
y: 'margin-bottom'
}[axis]) + next.getStyle({
x: 'margin-left',
y: 'margin-top'
}[axis]);
};
nodes.forEach(function(node, index, nodes) {
var tbox = me.getTreeBox([node]);
var size = {
x: tbox.width,
y: tbox.height
}[axis];
var offset = {
x: tbox.left,
y: tbox.top
}[axis];
var matrix = node.getLayoutTransform();
if (axis == 'x') {
matrix.translate(position - offset, 0);
} else {
matrix.translate(0, position - offset);
}
position += size;
if (nodes[index + 1])
position += distance(node, nodes[index + 1], axis);
});
return position;
},
move: function(nodes, dx, dy) {
nodes.forEach(function(node) {
node.getLayoutTransform().translate(dx, dy);
});
},
/**
* 工具方法:获取给点的节点所占的布局区域
*
* @param {MinderNode[]} nodes 需要计算的节点
*
* @return {Box} 计算结果
*/
getBranchBox: function(nodes) {
var box = new kity.Box();
var i, node, matrix, contentBox;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
contentBox = node.getContentBox();
box = box.merge(matrix.transformBox(contentBox));
}
return box;
},
/**
* 工具方法:计算给定的节点的子树所占的布局区域
*
* @param {MinderNode} nodes 需要计算的节点
*
* @return {Box} 计算的结果
*/
getTreeBox: function(nodes) {
var i, node, matrix, treeBox;
var g = KityMinder.Geometry;
var box = {
x: 0,
y: 0,
height: 0,
width: 0
};
if (!(nodes instanceof Array)) nodes = [nodes];
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
treeBox = node.getContentBox();
if (node.isExpanded() && node.children.length) {
treeBox = g.mergeBox(treeBox, this.getTreeBox(node.children));
}
box = g.mergeBox(box, matrix.transformBox(treeBox));
}
return box;
},
getOrderHint: function(node) {
return [];
}
});
var LayoutCommand = kity.createClass('LayoutCommand', {
base: Command,
execute: function(minder, name) {
var nodes = minder.getSelectedNodes();
nodes.forEach(function(node) {
node.layout(name);
});
},
queryValue: function(minder) {
var node = minder.getSelectedNode();
if (node) {
return node.getData('layout');
}
}, },
queryState: function(minder) {
return minder.getSelectedNode() ? 0 : -1;
}
});
var ResetLayoutCommand = kity.createClass('ResetLayoutCommand', {
base: Command,
execute: function(minder, name) {
var nodes = minder.getSelectedNodes();
if (!nodes.length) nodes = [minder.getRoot()];
nodes.forEach(function(node) {
node.traverse(function(child) {
child.resetLayoutOffset();
if (!child.isRoot()) {
child.setData('layout', null);
}
}); });
});
minder.layout(300);
},
enableReadOnly: true module.exports = Layout;
});
KityMinder.registerModule('LayoutModule', {
commands: {
'layout': LayoutCommand,
'resetlayout': ResetLayoutCommand
},
contextmenu: [{
command: 'resetlayout'
}, {
divider: true
}],
commandShortcutKeys: {
'resetlayout': 'Ctrl+Shift+L'
}
}); });
\ No newline at end of file
/**
* @fileOverview
*
* KityMinder 类,暴露在 window 上的唯一变量
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var _initHooks = [];
var Minder = kity.createClass('Minder', {
constructor: function(options) {
this._options = utils.extend({}, options);
var initHooks = _initHooks.slice();
var initHook;
while (initHooks.length) {
initHook = initHooks.shift();
if (typeof(initHook) == 'function') {
initHook.call(this, this._options);
}
}
this.fire('ready');
}
});
Minder.version = '1.3.6';
Minder.registerInitHook = function(hook) {
_initHooks.push(hook);
};
module.exports = Minder;
});
//模块注册&暴露模块接口 define(function(require, exports, module) {
( function () { var kity = require('./kity');
var _modules; var utils = require('./utils');
KityMinder.registerModule = function ( name, module ) { var Minder = require('./minder');
//初始化模块列表
if ( !_modules ) { /* 已注册的模块 */
_modules = {}; var _modules = {};
}
_modules[ name ] = module; exports.register = function(name, module) {
}; _modules[name] = module;
KityMinder.getModules = function () {
return _modules;
}; };
} )();
KityMinder.registerInit(function() { /* 模块初始化 */
Minder.registerInitHook(function() {
this._initModules(); this._initModules();
}); });
// 模块声明周期维护 // 模块声明周期维护
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
_initModules: function() { _initModules: function() {
var modulesPool = KityMinder.getModules(); var modulesPool = _modules;
var modulesToLoad = this._options.modules || Utils.keys(modulesPool); var modulesToLoad = this._options.modules || utils.keys(modulesPool);
this._commands = {}; this._commands = {};
this._query = {}; this._query = {};
...@@ -74,7 +72,7 @@ kity.extendClass(KityMinder, { ...@@ -74,7 +72,7 @@ kity.extendClass(KityMinder, {
for (type in dealRenderers) { for (type in dealRenderers) {
this._rendererClasses[type] = this._rendererClasses[type] || []; this._rendererClasses[type] = this._rendererClasses[type] || [];
if (Utils.isArray(dealRenderers[type])) { if (utils.isArray(dealRenderers[type])) {
this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]); this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]);
} else { } else {
this._rendererClasses[type].push(dealRenderers[type]); this._rendererClasses[type].push(dealRenderers[type]);
...@@ -82,6 +80,11 @@ kity.extendClass(KityMinder, { ...@@ -82,6 +80,11 @@ kity.extendClass(KityMinder, {
} }
} }
//添加模块的快捷键
if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
}
} }
}, },
...@@ -115,4 +118,5 @@ kity.extendClass(KityMinder, { ...@@ -115,4 +118,5 @@ kity.extendClass(KityMinder, {
modules[key].reset.call(this); modules[key].reset.call(this);
} }
} }
});
}); });
\ No newline at end of file
var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { define(function(require, exports, module) {
var kity = require('./kity');
var utils = require('./utils');
var Minder = require('./minder');
/** /**
* 创建一个节点 * @class MinderNode
* *
* @param {KityMinder} minder * 表示一个脑图节点
* 节点绑定的脑图的实例 */
var MinderNode = kity.createClass('MinderNode', {
/**
* 创建一个游离的脑图节点
* *
* @param {String|Object} unknown * @param {String|Object} textOrData
* 节点的初始数据或文本 * 节点的初始数据或文本
*/ */
constructor: function(unknown) { constructor: function(textOrData) {
// 指针
this.parent = null; this.parent = null;
this.root = this; this.root = this;
this.children = []; this.children = [];
this.data = {};
this.tmpData = {};
// 数据
this.data = {
id: utils.guid(),
created: +new Date()
};
// 绘图容器
this.initContainers(); this.initContainers();
if (Utils.isString(unknown)) { if (utils.isString(textOrData)) {
this.setText(unknown); this.setText(textOrData);
} else { } else if (utils.isObject(textOrData)) {
this.setData(unknown); utils.extend(this.data, textOrData);
} }
}, },
initContainers: function() { initContainers: function() {
this.rc = new kity.Group().setId(KityMinder.uuid('minder_node')); this.rc = new kity.Group().setId(utils.uuid('minder_node'));
this.rc.minderNode = this; this.rc.minderNode = this;
}, },
...@@ -63,10 +77,10 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -63,10 +77,10 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
*/ */
getLevel: function() { getLevel: function() {
var level = 0, var level = 0,
parent = this.parent; ancestor = this.parent;
while (parent) { while (ancestor) {
level++; level++;
parent = parent.parent; ancestor = ancestor.parent;
} }
return level; return level;
}, },
...@@ -95,39 +109,36 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -95,39 +109,36 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
* @param {MinderNode} test 被测试的节点 * @param {MinderNode} test 被测试的节点
*/ */
isAncestorOf: function(test) { isAncestorOf: function(test) {
var p = test.parent; var ancestor = test.parent;
while (p) { while (ancestor) {
if (p == this) return true; if (ancestor == this) return true;
p = p.parent; ancestor = ancestor.parent;
} }
return false; return false;
}, },
getData: function(key) {
return this.data[key];
},
setData: function(key, value) {
this.data[key] = value;
},
/** /**
* 设置节点的文本数据 * 设置节点的文本数据
* @param {String} text 文本数据 * @param {String} text 文本数据
*/ */
setText: function(text) { setText: function(text) {
if(utils.isArray(text)){ return this.data.text = text;
text = text.join('\n');
}
return this.setData('text', text);
}, },
/** /**
* 获取节点的文本数据 * 获取节点的文本数据
* @return {String} * @return {String}
*/ */
getText: function(str2arr) { getText: function() {
var text = this.getData('text') || ''; return this.data.text || '';
text = text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;');
if(str2arr){
text = text.split('\n');
}
return text;
}, },
/** /**
...@@ -200,40 +211,12 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -200,40 +211,12 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
} }
}, },
getChild: function(index) { clearChildren: function() {
return this.children[index]; this.children = [];
},
getFirstChild: function() {
return this.children[0];
},
getLastChild: function() {
return this.children[this.children.length - 1];
},
getData: function(name) {
if (name === undefined) {
return this.data;
}
return this.data[name];
}, },
setData: function(name, value) { getChild: function(index) {
if (name === undefined) { return this.children[index];
this.data = {};
} else if (utils.isObject(name)) {
Utils.extend(this.data, name);
} else {
if (value === undefined) {
this.data[name] = null;
delete this.data[name];
} else {
this.data[name] = value;
}
}
return this;
}, },
getRenderContainer: function() { getRenderContainer: function() {
...@@ -241,7 +224,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -241,7 +224,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
}, },
getCommonAncestor: function(node) { getCommonAncestor: function(node) {
return Utils.getNodeCommonAncestor(this, node); return MinderNode.getNodeCommonAncestor(this, node);
}, },
contains: function(node) { contains: function(node) {
...@@ -249,106 +232,38 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -249,106 +232,38 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
}, },
clone: function() { clone: function() {
function cloneNode(parent, isClonedNode) { var cloned = new MinderNode();
var cloned = new KityMinder.MinderNode();
cloned.data = Utils.clonePlainObject(isClonedNode.getData()); cloned.data = utils.clone(this.data);
cloned.tmpData = Utils.clonePlainObject(isClonedNode.getTmpData());
this.children.forEach(function(child) {
cloned.appendChild(child.clone());
});
if (parent) {
parent.appendChild(cloned);
}
for (var i = 0, ci;
(ci = isClonedNode.children[i++]);) {
cloneNode(cloned, ci);
}
return cloned; return cloned;
}
return cloneNode(null, this);
}, },
equals: function(node,ignoreSelected) { compareTo: function(node) {
var me = this;
function restoreSelected(){
if(isSelectedA){
me.setSelectedFlag();
}
if(isSelectedB){
node.setSelectedFlag();
}
}
if(ignoreSelected){
var isSelectedA = false;
var isSelectedB = false;
if(me.isSelected()){
isSelectedA = true;
me.clearSelectedFlag();
}
if(node.isSelected()){
isSelectedB = true;
node.clearSelectedFlag();
}
}
if (node.children.length != this.children.length) {
restoreSelected();
return false;
}
if (utils.compareObject(node.getData(), me.getData()) === false) {
restoreSelected();
return false;
}
if (utils.compareObject(node.getTmpData(), me.getTmpData()) === false) {
restoreSelected();
return false;
}
for (var i = 0, ci;
(ci = me.children[i]); i++) {
if (ci.equals(node.children[i],ignoreSelected) === false) {
restoreSelected();
return false;
}
}
restoreSelected();
return true;
}, if (!utils.comparePlainObject(this.data, node.data)) return false;
if (!utils.comparePlainObject(this.temp, node.temp)) return false;
clearChildren: function() { if (this.children.length != node.children.length) return false;
this.children = [];
},
setTmpData: function(a, v) { var i = 0;
var me = this; while (this.children[i]) {
if (utils.isObject(a)) { if (!this.children[i].compareTo(node.children[i])) return false;
utils.each(a, function(key, val) { i++;
me.setTmpData(key, val);
});
}
if (v === undefined || v === null || v === '') {
delete this.tmpData[a];
} else {
this.tmpData[a] = v;
} }
},
getTmpData: function(a) { return true;
if (a === undefined) {
return this.tmpData;
}
return this.tmpData[a];
}, },
setValue: function(node) { getMinder: function() {
this.data = {}; return this.getRoot().minder;
this.setData(utils.clonePlainObject(node.getData()));
this.tmpData = {};
this.setTmpData(utils.clonePlainObject(node.getTmpData()));
return this;
} }
}); });
MinderNode.getCommonAncestor = function(nodeA, nodeB) { MinderNode.getCommonAncestor = function(nodeA, nodeB) {
if (nodeA instanceof Array) { if (nodeA instanceof Array) {
return MinderNode.getCommonAncestor.apply(this, nodeA); return MinderNode.getCommonAncestor.apply(this, nodeA);
} }
...@@ -370,13 +285,16 @@ MinderNode.getCommonAncestor = function(nodeA, nodeB) { ...@@ -370,13 +285,16 @@ MinderNode.getCommonAncestor = function(nodeA, nodeB) {
return ancestor; return ancestor;
default: default:
return Array.prototype.reduce.call(arguments, function(prev, current) { return Array.prototype.reduce.call(arguments,
function(prev, current) {
return MinderNode.getCommonAncestor(prev, current); return MinderNode.getCommonAncestor(prev, current);
}, nodeA); },
nodeA
);
} }
}; };
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
getRoot: function() { getRoot: function() {
return this._root; return this._root;
...@@ -387,9 +305,13 @@ kity.extendClass(KityMinder, { ...@@ -387,9 +305,13 @@ kity.extendClass(KityMinder, {
root.minder = this; root.minder = this;
}, },
createNode: function(unknown, parent, index) { createNode: function(textOrData, parent, index) {
var node = new MinderNode(unknown); var node = new MinderNode(textOrData);
this.fire('nodecreate', { node: node, parent: parent, index: index }); this.fire('nodecreate', {
node: node,
parent: parent,
index: index
});
this.appendNode(node, parent, index); this.appendNode(node, parent, index);
return node; return node;
}, },
...@@ -404,12 +326,14 @@ kity.extendClass(KityMinder, { ...@@ -404,12 +326,14 @@ kity.extendClass(KityMinder, {
if (node.parent) { if (node.parent) {
node.parent.removeChild(node); node.parent.removeChild(node);
this.detachNode(node); this.detachNode(node);
this.fire('noderemove', { node: node }); this.fire('noderemove', {
node: node
});
} }
}, },
attachNode: function(node) { attachNode: function(node) {
var rc = this._rc; var rc = this.getRenderContainer();
node.traverse(function(current) { node.traverse(function(current) {
current.attached = true; current.attached = true;
rc.addShape(current.getRenderContainer()); rc.addShape(current.getRenderContainer());
...@@ -421,7 +345,7 @@ kity.extendClass(KityMinder, { ...@@ -421,7 +345,7 @@ kity.extendClass(KityMinder, {
}, },
detachNode: function(node) { detachNode: function(node) {
var rc = this._rc; var rc = this.getRenderContainer();
node.traverse(function(current) { node.traverse(function(current) {
current.attached = false; current.attached = false;
rc.removeShape(current.getRenderContainer()); rc.removeShape(current.getRenderContainer());
...@@ -435,10 +359,7 @@ kity.extendClass(KityMinder, { ...@@ -435,10 +359,7 @@ kity.extendClass(KityMinder, {
return this.getRoot().getText(); return this.getRoot().getText();
} }
}); });
kity.extendClass(MinderNode, { module.exports = MinderNode;
getMinder: function() {
return this.getRoot().minder;
}
}); });
\ No newline at end of file
/**
* @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 @@ ...@@ -6,15 +6,20 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @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(); this._initPaper();
}); });
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
_initPaper: function() { _initPaper: function() {
this._paper = new kity.Paper(); this._paper = new kity.Paper();
this._paper.getNode().setAttribute('contenteditable', true);
this._paper.getNode().ondragstart = function(e) { this._paper.getNode().ondragstart = function(e) {
e.preventDefault(); e.preventDefault();
}; };
...@@ -30,7 +35,7 @@ kity.extendClass(KityMinder, { ...@@ -30,7 +35,7 @@ kity.extendClass(KityMinder, {
}, },
_addRenderContainer: function() { _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); this._paper.addShape(this._rc);
}, },
...@@ -38,8 +43,12 @@ kity.extendClass(KityMinder, { ...@@ -38,8 +43,12 @@ kity.extendClass(KityMinder, {
if (typeof(target) == 'string') { if (typeof(target) == 'string') {
target = document.getElementById(target); target = document.getElementById(target);
} }
if (target) {
this._paper.renderTo(this._renderTarget = target); this._paper.renderTo(this._renderTarget = target);
this._bindEvents(); this._bindEvents();
this.fire('paperrender');
}
return this;
}, },
getRenderContainer: function() { getRenderContainer: function() {
...@@ -53,4 +62,5 @@ kity.extendClass(KityMinder, { ...@@ -53,4 +62,5 @@ kity.extendClass(KityMinder, {
getRenderTarget: function() { getRenderTarget: function() {
return this._renderTarget; return this._renderTarget;
}, },
});
}); });
\ No newline at end of file
/** /**
* @fileOverview * @fileOverview
* *
* * 只读模式支持
* *
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerInit(function(options) {
define(function(require, exports, module) {
var kity = require('./kity');
var Minder = require('./minder');
Minder.registerInitHook(function(options) {
if (options.readOnly) { if (options.readOnly) {
this.setDisabled(); this.setDisabled();
} }
}); });
kity.extendClass(KityMinder, {
kity.extendClass(Minder, {
disable: function() { disable: function() {
var me = this; var me = this;
...@@ -52,4 +58,5 @@ kity.extendClass(KityMinder, { ...@@ -52,4 +58,5 @@ kity.extendClass(KityMinder, {
me._interactChange(); 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) { constructor: function(node) {
this.node = node; this.node = node;
}, },
...@@ -49,9 +55,9 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', { ...@@ -49,9 +55,9 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
setRenderShape: function(shape) { setRenderShape: function(shape) {
this._renderShape = shape; this._renderShape = shape;
} }
}); });
kity.extendClass(KityMinder, (function() { function createMinderExtension() {
function createRendererForNode(node, registered) { function createRendererForNode(node, registered) {
var renderers = []; var renderers = [];
...@@ -77,7 +83,6 @@ kity.extendClass(KityMinder, (function() { ...@@ -77,7 +83,6 @@ kity.extendClass(KityMinder, (function() {
} }
return { return {
renderNodeBatch: function(nodes) { renderNodeBatch: function(nodes) {
var rendererClasses = this._rendererClasses; var rendererClasses = this._rendererClasses;
var lastBoxes = []; var lastBoxes = [];
...@@ -158,7 +163,6 @@ kity.extendClass(KityMinder, (function() { ...@@ -158,7 +163,6 @@ kity.extendClass(KityMinder, (function() {
renderNode: function(node) { renderNode: function(node) {
var rendererClasses = this._rendererClasses; var rendererClasses = this._rendererClasses;
var g = KityMinder.Geometry;
var i, latestBox, renderer; var i, latestBox, renderer;
if (!node._renderers) { if (!node._renderers) {
...@@ -212,9 +216,11 @@ kity.extendClass(KityMinder, (function() { ...@@ -212,9 +216,11 @@ kity.extendClass(KityMinder, (function() {
}); });
} }
}; };
})()); }
kity.extendClass(Minder, createMinderExtension());
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
render: function() { render: function() {
if (!this.attached) return; if (!this.attached) return;
this.getMinder().renderNode(this); this.getMinder().renderNode(this);
...@@ -240,4 +246,7 @@ kity.extendClass(MinderNode, { ...@@ -240,4 +246,7 @@ kity.extendClass(MinderNode, {
//if (!this._contentBox) this.render(); //if (!this._contentBox) this.render();
return this.parent && this.parent.isCollapsed() ? new kity.Box() : (this._contentBox || new kity.Box()); 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(); this._initSelection();
}); });
// 选区管理 // 选区管理
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
_initSelection: function() { _initSelection: function() {
this._selectedNodes = []; this._selectedNodes = [];
}, },
renderChangedSelection: function(last) { renderChangedSelection: function(last) {
var current = this.getSelectedNodes(); var current = this.getSelectedNodes();
var changed = []; var changed = [];
var i = 0;
current.forEach(function(node) { current.forEach(function(node) {
if (last.indexOf(node) == -1) { if (last.indexOf(node) == -1) {
changed.push(node); changed.push(node);
node.setTmpData('selected', true);
} }
}); });
last.forEach(function(node) { last.forEach(function(node) {
if (current.indexOf(node) == -1) { if (current.indexOf(node) == -1) {
changed.push(node); changed.push(node);
node.setTmpData('selected', false);
} }
}); });
...@@ -31,7 +34,9 @@ kity.extendClass(KityMinder, { ...@@ -31,7 +34,9 @@ kity.extendClass(KityMinder, {
this._interactChange(); this._interactChange();
this.fire('selectionchange'); this.fire('selectionchange');
} }
while (i < changed.length) changed[i++].render(); while (changed.length) {
changed.shift().render();
}
}, },
getSelectedNodes: function() { getSelectedNodes: function() {
//不能克隆返回,会对当前选区操作,从而影响querycommand //不能克隆返回,会对当前选区操作,从而影响querycommand
...@@ -50,12 +55,14 @@ kity.extendClass(KityMinder, { ...@@ -50,12 +55,14 @@ kity.extendClass(KityMinder, {
removeSelectedNodes: function(nodes) { removeSelectedNodes: function(nodes) {
var me = this; var me = this;
var last = this._selectedNodes.slice(0); var last = this._selectedNodes.slice(0);
nodes = Utils.isArray(nodes) ? nodes : [nodes]; nodes = utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
nodes.forEach(function(node) {
var index; var index;
if ((index = me._selectedNodes.indexOf(n)) === -1) return; if ((index = me._selectedNodes.indexOf(node)) === -1) return;
me._selectedNodes.splice(index, 1); me._selectedNodes.splice(index, 1);
}); });
this.renderChangedSelection(last); this.renderChangedSelection(last);
return this; return this;
}, },
...@@ -65,10 +72,10 @@ kity.extendClass(KityMinder, { ...@@ -65,10 +72,10 @@ kity.extendClass(KityMinder, {
this._selectedNodes = []; this._selectedNodes = [];
} }
var me = this; var me = this;
nodes = Utils.isArray(nodes) ? nodes : [nodes]; nodes = utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) { nodes.forEach(function(node) {
if (me._selectedNodes.indexOf(n) !== -1) return; if (me._selectedNodes.indexOf(node) !== -1) return;
me._selectedNodes.push(n); me._selectedNodes.push(node);
}); });
this.renderChangedSelection(lastSelect); this.renderChangedSelection(lastSelect);
return this; return this;
...@@ -77,7 +84,7 @@ kity.extendClass(KityMinder, { ...@@ -77,7 +84,7 @@ kity.extendClass(KityMinder, {
//当前选区中的节点在给定的节点范围内的保留选中状态, //当前选区中的节点在给定的节点范围内的保留选中状态,
//没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果 //没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect: function(node) { toggleSelect: function(node) {
if (Utils.isArray(node)) { if (utils.isArray(node)) {
node.forEach(this.toggleSelect.bind(this)); node.forEach(this.toggleSelect.bind(this));
} else { } else {
if (node.isSelected()) this.removeSelectedNodes(node); if (node.isSelected()) this.removeSelectedNodes(node);
...@@ -123,16 +130,12 @@ kity.extendClass(KityMinder, { ...@@ -123,16 +130,12 @@ kity.extendClass(KityMinder, {
return ancestors; return ancestors;
} }
}); });
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
isSelected: function() { isSelected: function() {
return this.getTmpData('selected'); return this.getMinder().getSelectedNodes().indexOf(this) != -1;
},
clearSelectedFlag:function(){
this.setTmpData('selected');
},
setSelectedFlag:function(){
this.setTmpData('selected',true);
} }
});
}); });
\ No newline at end of file
...@@ -7,23 +7,26 @@ ...@@ -7,23 +7,26 @@
* @copyright: Baidu FEX, 2014 * @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(); this._initStatus();
}); });
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
_initStatus: function() { _initStatus: function() {
this._status = 'normal'; this._status = 'normal';
this._rollbackStatus = 'normal'; this._rollbackStatus = 'normal';
}, },
setStatus: (function() { setStatus: function(status, force) {
var sf = ~window.location.href.indexOf('status');
var tf = ~window.location.href.indexOf('trace');
// 在 readonly 模式下,只有 force 为 true 才能切换回来 // 在 readonly 模式下,只有 force 为 true 才能切换回来
return function(status, force) {
if (this._status == 'readonly' && !force) return this; if (this._status == 'readonly' && !force) return this;
if (status != this._status) { if (status != this._status) {
this._rollbackStatus = this._status; this._rollbackStatus = this._status;
...@@ -33,6 +36,7 @@ kity.extendClass(KityMinder, { ...@@ -33,6 +36,7 @@ kity.extendClass(KityMinder, {
currentStatus: this._status currentStatus: this._status
}); });
if (sf) { if (sf) {
/* global console: true */
console.log(window.event.type, this._rollbackStatus, '->', this._status); console.log(window.event.type, this._rollbackStatus, '->', this._status);
if (tf) { if (tf) {
console.trace(); console.trace();
...@@ -40,8 +44,7 @@ kity.extendClass(KityMinder, { ...@@ -40,8 +44,7 @@ kity.extendClass(KityMinder, {
} }
} }
return this; return this;
}; },
})(),
rollbackStatus: function() { rollbackStatus: function() {
this.setStatus(this._rollbackStatus); this.setStatus(this._rollbackStatus);
...@@ -52,4 +55,6 @@ kity.extendClass(KityMinder, { ...@@ -52,4 +55,6 @@ kity.extendClass(KityMinder, {
getStatus: function() { getStatus: function() {
return this._status; return this._status;
} }
});
}); });
\ No newline at end of file
utils.extend(KityMinder, { define(function(require, exports, module) {
_templates: {}, var kity = require('./kity');
registerTemplate: function(name, supports) { var utils = require('./utils');
KityMinder._templates[name] = supports; 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() { getTemplateList: function() {
return KityMinder._templates; return _templates;
} }
}); });
kity.extendClass(KityMinder, (function() { kity.extendClass(Minder, (function() {
var originGetTheme = KityMinder.prototype.getTheme; var originGetTheme = Minder.prototype.getTheme;
return { return {
useTemplate: function(name, duration) { useTemplate: function(name, duration) {
this.setTemplate(name); this.setTemplate(name);
...@@ -25,7 +36,7 @@ kity.extendClass(KityMinder, (function() { ...@@ -25,7 +36,7 @@ kity.extendClass(KityMinder, (function() {
}, },
getTemplateSupport: function(method) { getTemplateSupport: function(method) {
var supports = KityMinder._templates[this.getTemplate()]; var supports = _templates[this.getTemplate()];
return supports && supports[method]; return supports && supports[method];
}, },
...@@ -34,10 +45,10 @@ kity.extendClass(KityMinder, (function() { ...@@ -34,10 +45,10 @@ kity.extendClass(KityMinder, (function() {
return support.call(this, node); return support.call(this, node);
} }
}; };
})()); })());
kity.extendClass(MinderNode, (function() { kity.extendClass(MinderNode, (function() {
var originGetLayout = MinderNode.prototype.getLayout; var originGetLayout = MinderNode.prototype.getLayout;
var originGetConnect = MinderNode.prototype.getConnect; var originGetConnect = MinderNode.prototype.getConnect;
return { return {
...@@ -51,9 +62,9 @@ kity.extendClass(MinderNode, (function() { ...@@ -51,9 +62,9 @@ kity.extendClass(MinderNode, (function() {
return support.call(this, this); return support.call(this, this);
} }
}; };
})()); })());
KityMinder.registerModule('TemplateModule', { Module.register('TemplateModule', {
commands: { commands: {
'template': kity.createClass('TemplateCommand', { 'template': kity.createClass('TemplateCommand', {
base: Command, base: Command,
...@@ -68,4 +79,5 @@ KityMinder.registerModule('TemplateModule', { ...@@ -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) { left: function(value) {
return 3 in value && value[3] || return 3 in value && value[3] ||
1 in value && value[1] || 1 in value && value[1] ||
...@@ -13,10 +21,9 @@ var cssLikeValueMatcher = { ...@@ -13,10 +21,9 @@ var cssLikeValueMatcher = {
bottom: function(value) { bottom: function(value) {
return 2 in value && value[2] || value[0]; return 2 in value && value[2] || value[0];
} }
}; };
Utils.extend(KityMinder, { var _themes = {};
_themes: {},
/** /**
* 注册一个主题 * 注册一个主题
...@@ -25,22 +32,24 @@ Utils.extend(KityMinder, { ...@@ -25,22 +32,24 @@ Utils.extend(KityMinder, {
* @param {Plain} theme 主题的样式描述 * @param {Plain} theme 主题的样式描述
* *
* @example * @example
* KityMinder.registerTheme('default', { * Minder.registerTheme('default', {
* 'root-color': 'red', * 'root-color': 'red',
* 'root-stroke': 'none', * 'root-stroke': 'none',
* 'root-padding': [10, 20] * 'root-padding': [10, 20]
* }); * });
*/ */
registerTheme: function(name, theme) { function register(name, theme) {
KityMinder._themes[name] = theme; _themes[name] = theme;
}, }
exports.register = register;
utils.extend(Minder, {
getThemeList: function() { getThemeList: function() {
return KityMinder._themes; return _themes;
} }
}); });
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
/** /**
* 切换脑图实例上的主题 * 切换脑图实例上的主题
...@@ -67,12 +76,12 @@ kity.extendClass(KityMinder, { ...@@ -67,12 +76,12 @@ kity.extendClass(KityMinder, {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
getTheme: function(node) { getTheme: function(node) {
return this._theme || this.getOptions('defaultTheme') || 'fresh-blue'; return this._theme || this.getOption('defaultTheme') || 'fresh-blue';
}, },
getThemeItems: function(node) { getThemeItems: function(node) {
var theme = this.getTheme(node); var theme = this.getTheme(node);
return KityMinder._themes[this.getTheme(node)]; return _themes[this.getTheme(node)];
}, },
/** /**
...@@ -96,7 +105,7 @@ kity.extendClass(KityMinder, { ...@@ -96,7 +105,7 @@ kity.extendClass(KityMinder, {
if (item in items) { if (item in items) {
value = items[item]; value = items[item];
if (Utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) { if (utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
return matcher(value); return matcher(value);
} }
if (!isNaN(value)) return value; if (!isNaN(value)) return value;
...@@ -113,15 +122,15 @@ kity.extendClass(KityMinder, { ...@@ -113,15 +122,15 @@ kity.extendClass(KityMinder, {
var value = this.getStyle(node.getType() + '-' + name, node); var value = this.getStyle(node.getType() + '-' + name, node);
return value !== null ? value : this.getStyle(name, node); return value !== null ? value : this.getStyle(name, node);
} }
}); });
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
getStyle: function(name) { getStyle: function(name) {
return this.getMinder().getNodeStyle(this, name); return this.getMinder().getNodeStyle(this, name);
} }
}); });
KityMinder.registerModule('Theme', { Module.register('Theme', {
defaultOptions: { defaultOptions: {
defaultTheme: 'fresh-blue' defaultTheme: 'fresh-blue'
}, },
...@@ -138,8 +147,10 @@ KityMinder.registerModule('Theme', { ...@@ -138,8 +147,10 @@ KityMinder.registerModule('Theme', {
} }
}) })
} }
}); });
KityMinder.registerInit(function() { Minder.registerInitHook(function() {
this.setTheme(); this.setTheme();
});
}); });
\ No newline at end of file
var utils = Utils = KityMinder.Utils = { define(function(require, exports) {
extend: kity.Utils.extend.bind(kity.Utils), var kity = require('../../lib/kity/src/kity.js');
var uuidMap = {};
listen: function(element, type, handler) { exports.extend = kity.Utils.extend.bind(kity.Utils);
var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/), exports.each = kity.Utils.each.bind(kity.Utils);
k = types.length;
if (k) exports.uuid = function(group) {
while (k--) { return uuidMap[group] = uuidMap[group] ? uuidMap[group] + 1 : 1;
type = types[k];
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else {
if (!handler._d) {
handler._d = {
els: []
}; };
}
var key = type + handler.toString(), exports.guid = function() {
index = utils.indexOf(handler._d.els, element); return (+new Date() * 1e6 + Math.floor(Math.random() * 1e6)).toString(36);
if (!handler._d[key] || index == -1) {
if (index == -1) {
handler._d.els.push(element);
}
if (!handler._d[key]) {
handler._d[key] = function(evt) {
return handler.call(evt.srcElement, evt || window.event);
}; };
}
element.attachEvent('on' + type, handler._d[key]);
}
}
}
element = null;
},
trim: function(str) {
return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
},
each: function(obj, iterator, context) {
if (obj == null) return;
if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (iterator.call(context, i, obj[i], obj) === false)
return false;
}
} else {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (iterator.call(context, key, obj[key], obj) === false)
return false;
}
}
}
},
addCssRule: function(key, style, doc) {
var head, node;
if (style === undefined || style && style.nodeType && style.nodeType == 9) {
//获取样式
doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
node = doc.getElementById(key);
return node ? node.innerHTML : undefined;
}
doc = doc || document;
node = doc.getElementById(key);
//清除样式 exports.trim = function(str) {
if (style === '') { return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
if (node) { };
node.parentNode.removeChild(node);
return true
}
return false;
}
//添加样式 exports.keys = function(plain) {
if (node) {
node.innerHTML = style;
} else {
node = doc.createElement('style');
node.id = key;
node.innerHTML = style;
doc.getElementsByTagName('head')[0].appendChild(node);
}
},
keys: function(plain) {
var keys = []; var keys = [];
for (var key in plain) { for (var key in plain) {
if (plain.hasOwnProperty(key)) { if (plain.hasOwnProperty(key)) {
...@@ -89,172 +25,17 @@ var utils = Utils = KityMinder.Utils = { ...@@ -89,172 +25,17 @@ var utils = Utils = KityMinder.Utils = {
} }
} }
return keys; return keys;
},
proxy: function(fn, context) {
return function() {
return fn.apply(context, arguments);
}; };
},
indexOf: function(array, item, start) {
var index = -1;
start = this.isNumber(start) ? start : 0;
this.each(array, function(v, i) {
if (i >= start && v === item) {
index = i;
return false;
}
});
return index;
},
argsToArray: function(args, index) {
return Array.prototype.slice.call(args, index || 0);
},
clonePlainObject: function(source, target) {
var tmp;
target = target || {};
for (var i in source) {
if (source.hasOwnProperty(i)) {
tmp = source[i];
if (utils.isObject(tmp) || utils.isArray(tmp)) {
target[i] = utils.isArray(tmp) ? [] : {};
utils.clonePlainObject(source[i], target[i])
} else {
target[i] = tmp;
}
}
}
return target;
},
compareObject: function(source, target) {
var tmp;
if (this.isEmptyObject(source) !== this.isEmptyObject(target)) {
return false
}
if (this.getObjectLength(source) != this.getObjectLength(target)) {
return false;
}
for (var p in source) {
if (source.hasOwnProperty(p)) {
tmp = source[p];
if (target[p] === undefined) {
return false;
}
if (this.isObject(tmp) || this.isArray(tmp)) {
if (this.isObject(target[p]) !== this.isObject(tmp)) {
return false;
}
if (this.isArray(tmp) !== this.isArray(target[p])) {
return false;
}
if (this.compareObject(tmp, target[p]) === false) {
return false
}
} else {
if (tmp != target[p]) {
return false
}
}
}
}
return true;
},
getObjectLength: function(obj) {
if (this.isArray(obj) || this.isString(obj)) return obj.length;
var count = 0;
for (var key in obj)
if (obj.hasOwnProperty(key)) count++;
return count;
},
isEmptyObject: function(obj) {
if (obj == null) return true;
if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
for (var key in obj)
if (obj.hasOwnProperty(key)) return false;
return true;
},
loadFile: function() {
var tmpList = [];
function getItem(doc, obj) { exports.clone = function(source) {
try { return JSON.parse(JSON.stringify(source));
for (var i = 0, ci; ci = tmpList[i++];) { };
if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
return ci;
}
}
} catch (e) {
return null;
}
}
return function(doc, obj, fn) { exports.comparePlainObject = function(a, b) {
var item = getItem(doc, obj); return JSON.stringify(a) == JSON.stringify(b);
if (item) {
if (item.ready) {
fn && fn();
} else {
item.funs.push(fn)
}
return;
}
tmpList.push({
doc: doc,
url: obj.src || obj.href,
funs: [fn]
});
if (!doc.body) {
var html = [];
for (var p in obj) {
if (p == 'tag') continue;
html.push(p + '="' + obj[p] + '"')
}
doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
return;
}
if (obj.id && doc.getElementById(obj.id)) {
return;
}
var element = doc.createElement(obj.tag);
delete obj.tag;
for (var p in obj) {
element.setAttribute(p, obj[p]);
}
element.onload = element.onreadystatechange = function() {
if (!this.readyState || /loaded|complete/.test(this.readyState)) {
item = getItem(doc, obj);
if (item.funs.length > 0) {
item.ready = 1;
for (var fi; fi = item.funs.pop();) {
fi();
}
}
element.onload = element.onreadystatechange = null;
}
}; };
// element.onerror = function () {
// throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file ') exports.encodeHtml = function(str, reg) {
// };
doc.getElementsByTagName("head")[0].appendChild(element);
}
}(),
clone: function(source, target) {
var tmp;
target = target || {};
for (var i in source) {
if (source.hasOwnProperty(i)) {
tmp = source[i];
if (typeof tmp == 'object') {
target[i] = utils.isArray(tmp) ? [] : {};
utils.clone(source[i], target[i])
} else {
target[i] = tmp;
}
}
}
return target;
},
unhtml: function(str, reg) {
return str ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp);)?/g, function(a, b) { return str ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp);)?/g, function(a, b) {
if (b) { if (b) {
return a; return a;
...@@ -264,64 +45,20 @@ var utils = Utils = KityMinder.Utils = { ...@@ -264,64 +45,20 @@ var utils = Utils = KityMinder.Utils = {
'&': '&amp;', '&': '&amp;',
'"': '&quot;', '"': '&quot;',
'>': '&gt;', '>': '&gt;',
"'": '&#39;' '\'': '&#39;'
}[a] }[a];
} }
}) : ''; }) : '';
}, };
cloneArr:function(arr){
return [].concat(arr);
},
clearWhitespace:function(str){
return str.replace(/[\u200b\t\r\n]/g, '');
},
getValueByIndex:function(data,index){
var initIndex = 0,result = 0;
utils.each(data,function(i,arr){
if(initIndex + arr.length >= index){
if(index - initIndex == arr.length){ exports.clearWhiteSpace = function(str) {
if(arr.length == 1 && arr[0].width === 0){ return str.replace(/[\u200b\t\r\n]/g, '');
initIndex++;
return;
}
result = {
x: arr[arr.length - 1].x + arr[arr.length - 1].width,
y: arr[arr.length - 1].y
}; };
}else{
result = arr[index - initIndex];
}
return false; exports.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object'], function(v) {
}else{ var toString = Object.prototype.toString;
initIndex += arr.length + (arr.length == 1 && arr[0].width === 0 ? 0 : 1); exports['is' + v] = function(obj) {
} return toString.apply(obj) == '[object ' + v + ']';
};
}); });
return result;
},
getNodeIndex:function (node, ignoreTextNode) {
var preNode = node,
i = 0;
while (preNode = preNode.previousSibling) {
if (ignoreTextNode && preNode.nodeType == 3) {
if(preNode.nodeType != preNode.nextSibling.nodeType ){
i++;
}
continue;
}
i++;
}
return i;
}
};
Utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object'], function(i, v) {
KityMinder.Utils['is' + v] = function(obj) {
return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
}
}); });
/**
* @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 axis = (name == 'left' || name == 'right') ? 'x' : 'y';
var dir = (name == 'left' || name == 'top') ? -1 : 1; var dir = (name == 'left' || name == 'top') ? -1 : 1;
...@@ -73,7 +75,7 @@ layouts.forEach(function(name) { ...@@ -73,7 +75,7 @@ layouts.forEach(function(name) {
return hint; return hint;
} }
KityMinder.registerLayout(name, kity.createClass({ Layout.register(name, kity.createClass({
base: Layout, base: Layout,
...@@ -137,4 +139,5 @@ layouts.forEach(function(name) { ...@@ -137,4 +139,5 @@ layouts.forEach(function(name) {
getOrderHint: getOrderHint 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'); var name = 'filetree-' + (dir > 0 ? 'down' : 'up');
KityMinder.registerLayout(name, kity.createClass({ Layout.register(name, kity.createClass({
base: Layout, base: Layout,
doLayout: function(parent, children, round) { doLayout: function(parent, children, round) {
...@@ -80,4 +84,6 @@ ...@@ -80,4 +84,6 @@
} }
})); }));
}
}); });
\ No newline at end of file
...@@ -6,8 +6,12 @@ ...@@ -6,8 +6,12 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @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, base: Layout,
doLayout: function(parent, children, round) { doLayout: function(parent, children, round) {
...@@ -58,16 +62,7 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa ...@@ -58,16 +62,7 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa
this.move(upPart, xAdjust, yAdjustUp); this.move(upPart, xAdjust, yAdjustUp);
this.move(downPart, xAdjust + cMarginLeft, yAdjustDown); 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 @@ ...@@ -7,8 +7,11 @@
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
/* global Layout: true */ define(function(require, exports, module) {
KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayout', { var kity = require('core/kity');
var Layout = require('core/layout');
Layout.register('fish-bone-slave', kity.createClass('FishBoneSlaveLayout', {
base: Layout, base: Layout,
doLayout: function (parent, children, round) { doLayout: function (parent, children, round) {
...@@ -39,8 +42,8 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo ...@@ -39,8 +42,8 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo
this.stack(children, 'y'); this.stack(children, 'y');
this.align(children, 'left'); this.align(children, 'left');
var xAdjust = 0, yAdjust = 0;
var xAdjust = 0, yAdjust = 0;
xAdjust += pout.x; xAdjust += pout.x;
if (parent.getLayoutVectorOut().y < 0) { if (parent.getLayoutVectorOut().y < 0) {
...@@ -65,4 +68,5 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo ...@@ -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 */ define(function(require, exports, module) {
KityMinder.registerLayout('mind', kity.createClass({ var kity = require('core/kity');
var Layout = require('core/layout');
var Minder = require('core/minder');
Layout.register('mind', kity.createClass({
base: Layout, base: Layout,
doLayout: function(node, children) { doLayout: function(node, children) {
...@@ -13,8 +17,8 @@ KityMinder.registerLayout('mind', kity.createClass({ ...@@ -13,8 +17,8 @@ KityMinder.registerLayout('mind', kity.createClass({
else left.push(child); else left.push(child);
}); });
var leftLayout = KityMinder.getLayoutInstance('left'); var leftLayout = Minder.getLayoutInstance('left');
var rightLayout = KityMinder.getLayoutInstance('right'); var rightLayout = Minder.getLayoutInstance('right');
leftLayout.doLayout(node, left); leftLayout.doLayout(node, left);
rightLayout.doLayout(node, right); rightLayout.doLayout(node, right);
...@@ -54,4 +58,5 @@ KityMinder.registerLayout('mind', kity.createClass({ ...@@ -54,4 +58,5 @@ KityMinder.registerLayout('mind', kity.createClass({
}); });
return hint; 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) { arrange: function(index) {
var parent = this.parent; var parent = this.parent;
if (!parent) return; if (!parent) return;
...@@ -9,21 +16,21 @@ kity.extendClass(MinderNode, { ...@@ -9,21 +16,21 @@ kity.extendClass(MinderNode, {
sibling.splice(index, 0, this); sibling.splice(index, 0, this);
return this; return this;
} }
}); });
function asc(nodeA, nodeB) { function asc(nodeA, nodeB) {
return nodeA.getIndex() - nodeB.getIndex(); return nodeA.getIndex() - nodeB.getIndex();
} }
function desc(nodeA, nodeB) { function desc(nodeA, nodeB) {
return -asc(nodeA, nodeB); return -asc(nodeA, nodeB);
} }
function canArrange(km) { function canArrange(km) {
var selected = km.getSelectedNode(); var selected = km.getSelectedNode();
return selected && selected.parent && selected.parent.children.length > 1; return selected && selected.parent && selected.parent.children.length > 1;
} }
var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', { var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', {
base: Command, base: Command,
execute: function(km) { execute: function(km) {
...@@ -42,9 +49,9 @@ var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', { ...@@ -42,9 +49,9 @@ var ArrangeUpCommand = kity.createClass('ArrangeUpCommand', {
var selected = km.getSelectedNode(); var selected = km.getSelectedNode();
return selected ? 0 : -1; return selected ? 0 : -1;
} }
}); });
var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', { var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', {
base: Command, base: Command,
execute: function(km) { execute: function(km) {
...@@ -63,9 +70,9 @@ var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', { ...@@ -63,9 +70,9 @@ var ArrangeDownCommand = kity.createClass('ArrangeUpCommand', {
var selected = km.getSelectedNode(); var selected = km.getSelectedNode();
return selected ? 0 : -1; return selected ? 0 : -1;
} }
}); });
var ArrangeCommand = kity.createClass('ArrangeCommand', { var ArrangeCommand = kity.createClass('ArrangeCommand', {
base: Command, base: Command,
execute: function(km, nodes, index) { execute: function(km, nodes, index) {
...@@ -101,9 +108,9 @@ var ArrangeCommand = kity.createClass('ArrangeCommand', { ...@@ -101,9 +108,9 @@ var ArrangeCommand = kity.createClass('ArrangeCommand', {
var selected = km.getSelectedNode(); var selected = km.getSelectedNode();
return selected ? 0 : -1; return selected ? 0 : -1;
} }
}); });
KityMinder.registerModule('ArrangeModule', { Module.register('ArrangeModule', {
commands: { commands: {
'arrangeup': ArrangeUpCommand, 'arrangeup': ArrangeUpCommand,
'arrangedown': ArrangeDownCommand, 'arrangedown': ArrangeDownCommand,
...@@ -120,4 +127,5 @@ KityMinder.registerModule('ArrangeModule', { ...@@ -120,4 +127,5 @@ KityMinder.registerModule('ArrangeModule', {
'arrangeup': 'normal::alt+Up', 'arrangeup': 'normal::alt+Up',
'arrangedown': 'normal::alt+Down' '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; var km = this;
function getNodeDataOrStyle(node, name) { function getNodeDataOrStyle(node, name) {
return node.getData(name) || node.getStyle(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 fontWeight = getNodeDataOrStyle(node,'font-weight');
var fontStyle = getNodeDataOrStyle(node, 'font-style'); var fontStyle = getNodeDataOrStyle(node, 'font-style');
var styleHash = [fontWeight, fontStyle].join('/'); var styleHash = [fontWeight, fontStyle].join('/');
textGroup.eachItem(function(index,item){ textGroup.eachItem(function(index,item) {
item.setFont({ item.setFont({
'weight': fontWeight, 'weight': fontWeight,
'style': fontStyle 'style': fontStyle
...@@ -28,11 +40,11 @@ KityMinder.registerModule('basestylemodule', function() { ...@@ -28,11 +40,11 @@ KityMinder.registerModule('basestylemodule', function() {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
if (this.queryState('bold') == 1) { if (this.queryState('bold') == 1) {
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-weight').render(); n.setData('font-weight').render();
}); });
} else { } else {
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-weight', 'bold').render(); n.setData('font-weight', 'bold').render();
}); });
} }
...@@ -44,7 +56,7 @@ KityMinder.registerModule('basestylemodule', function() { ...@@ -44,7 +56,7 @@ KityMinder.registerModule('basestylemodule', function() {
if (nodes.length === 0) { if (nodes.length === 0) {
return -1; return -1;
} }
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n && n.getData('font-weight')) { if (n && n.getData('font-weight')) {
result = 1; result = 1;
return false; return false;
...@@ -60,11 +72,11 @@ KityMinder.registerModule('basestylemodule', function() { ...@@ -60,11 +72,11 @@ KityMinder.registerModule('basestylemodule', function() {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
if (this.queryState('italic') == 1) { if (this.queryState('italic') == 1) {
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-style').render(); n.setData('font-style').render();
}); });
} else { } else {
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-style', 'italic').render(); n.setData('font-style', 'italic').render();
}); });
} }
...@@ -77,7 +89,7 @@ KityMinder.registerModule('basestylemodule', function() { ...@@ -77,7 +89,7 @@ KityMinder.registerModule('basestylemodule', function() {
if (nodes.length === 0) { if (nodes.length === 0) {
return -1; return -1;
} }
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n && n.getData('font-style')) { if (n && n.getData('font-style')) {
result = 1; result = 1;
return false; return false;
...@@ -92,4 +104,5 @@ KityMinder.registerModule('basestylemodule', function() { ...@@ -92,4 +104,5 @@ KityMinder.registerModule('basestylemodule', function() {
'italic': 'ctrl+i' //italic '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, var km = this,
_clipboardNodes = [], _clipboardNodes = [],
...@@ -11,7 +18,8 @@ KityMinder.registerModule( "ClipboardModule", function () { ...@@ -11,7 +18,8 @@ KityMinder.registerModule( "ClipboardModule", function () {
child.render(); child.render();
child.setLayoutOffset(null); child.setLayoutOffset(null);
var children = utils.cloneArr(child.children); 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); appendChildNode(child, ci);
} }
} }
...@@ -60,7 +68,8 @@ KityMinder.registerModule( "ClipboardModule", function () { ...@@ -60,7 +68,8 @@ KityMinder.registerModule( "ClipboardModule", function () {
var node = km.getSelectedNode(); var node = km.getSelectedNode();
if (!node) return; 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()); appendChildNode(node, ni.clone());
} }
...@@ -88,4 +97,5 @@ KityMinder.registerModule( "ClipboardModule", function () { ...@@ -88,4 +97,5 @@ KityMinder.registerModule( "ClipboardModule", function () {
'paste': 'normal::ctrl+v' '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, base: Command,
execute: function(minder, nodes, parent) { execute: function(minder, nodes, parent) {
var node; var node;
...@@ -17,9 +22,9 @@ var MoveToParentCommand = kity.createClass('MoveToParentCommand', { ...@@ -17,9 +22,9 @@ var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
parent.expand(); parent.expand();
minder.select(nodes, true); minder.select(nodes, true);
} }
}); });
var DropHinter = kity.createClass('DropHinter', { var DropHinter = kity.createClass('DropHinter', {
base: kity.Group, base: kity.Group,
constructor: function() { constructor: function() {
...@@ -41,9 +46,9 @@ var DropHinter = kity.createClass('DropHinter', { ...@@ -41,9 +46,9 @@ var DropHinter = kity.createClass('DropHinter', {
this.bringTop(); this.bringTop();
} }
} }
}); });
var OrderHinter = kity.createClass('OrderHinter', { var OrderHinter = kity.createClass('OrderHinter', {
base: kity.Group, base: kity.Group,
constructor: function() { constructor: function() {
...@@ -64,12 +69,12 @@ var OrderHinter = kity.createClass('OrderHinter', { ...@@ -64,12 +69,12 @@ var OrderHinter = kity.createClass('OrderHinter', {
hint.node.getStyle('order-hint-path-width') || 1); hint.node.getStyle('order-hint-path-width') || 1);
} }
} }
}); });
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括: // 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
// 1. 从节点列表计算出拖动部分 // 1. 从节点列表计算出拖动部分
// 2. 计算可以 drop 的节点,产生 drop 交互提示 // 2. 计算可以 drop 的节点,产生 drop 交互提示
var TreeDragger = kity.createClass('TreeDragger', { var TreeDragger = kity.createClass('TreeDragger', {
constructor: function(minder) { constructor: function(minder) {
this._minder = minder; this._minder = minder;
...@@ -97,7 +102,7 @@ var TreeDragger = kity.createClass('TreeDragger', { ...@@ -97,7 +102,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
if (!this._dragMode) { 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; return;
} }
if (!this._enterDragMode()) { if (!this._enterDragMode()) {
...@@ -296,7 +301,7 @@ var TreeDragger = kity.createClass('TreeDragger', { ...@@ -296,7 +301,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
for (j = 0; j < sourceBoxes.length; j++) { for (j = 0; j < sourceBoxes.length; j++) {
sourceBox = sourceBoxes[j]; sourceBox = sourceBoxes[j];
var intersectBox = GM.getIntersectBox(sourceBox, targetBox); var intersectBox = sourceBox.intersect(targetBox);
if (judge(intersectBox, sourceBox, targetBox)) { if (judge(intersectBox, sourceBox, targetBox)) {
return target; return target;
} }
...@@ -342,9 +347,9 @@ var TreeDragger = kity.createClass('TreeDragger', { ...@@ -342,9 +347,9 @@ var TreeDragger = kity.createClass('TreeDragger', {
preventDragMove: function() { preventDragMove: function() {
this._startPosition = null; this._startPosition = null;
} }
}); });
KityMinder.registerModule('DragTree', function() { Module.register('DragTree', function() {
var dragger; var dragger;
return { return {
...@@ -380,4 +385,5 @@ KityMinder.registerModule('DragTree', function() { ...@@ -380,4 +385,5 @@ KityMinder.registerModule('DragTree', function() {
'movetoparent': MoveToParentCommand 'movetoparent': MoveToParentCommand
} }
}; };
});
}); });
\ No newline at end of file
/* global Renderer: true */
KityMinder.registerModule('TextEditModule', function() {
var km = this;
var sel = new KityMinder.Selection();
var range = new KityMinder.Range();
var receiver = new KityMinder.Receiver(this,sel,range);
var keyboarder = new KityMinder.keyboarder(receiver);
this.receiver = receiver;
//鼠标被点击,并未太抬起时为真
var mouseDownStatus = false;
var dblclickEvent = false;
//当前是否有选区存在
var selectionReadyShow = false;
var mousedownNode,mouseupTimer,mousedownTimer;
var lastMinderNode;
function inputStatusReady(node){
if (node && km.isSingleSelect() && node.isSelected()) {
node.getTextGroup().setStyle('cursor','default');
var color = node.getStyle('text-selection-color');
//准备输入状态
receiver.updateByMinderNode(node);
sel.setHide()
.setStartOffset(0)
.setEndOffset(receiver.getTxtOfContainer().length)
.setColor(color);
receiver.updateContainerRangeBySel();
if(kity.Browser.ie ){
var timer = setInterval(function(){
var nativeRange = range.nativeSel.getRangeAt(0);
if(!nativeRange || nativeRange.collapsed){
range.select();
}else {
clearInterval(timer);
}
});
}
km.setStatus('inputready');
}
}
km.textEditNode = function(node){
inputStatusReady(node);
km.setStatus('textedit');
receiver.updateSelection();
};
return {
'events': {
'ready': function() {
document.body.appendChild(receiver.container);
},
'normal.beforemousedown textedit.beforemousedown inputready.beforemousedown': function(e) {
//右键直接退出
if (e.isRightMB()) {
if (!e.getTargetNode()) this.setStatus('normal');
return;
}
mouseDownStatus = true;
selectionReadyShow = sel.isShow();
sel.setHide();
var node = e.getTargetNode();
//点击在之前的选区上
if (!node) {
var selectionShape = e.kityEvent.targetShape;
if (selectionShape && selectionShape.getType() == 'Selection') {
node = receiver.getMinderNode();
e.stopPropagationImmediately();
}
}
if(node){
if (this.isSingleSelect() && node.isSelected()) {
lastMinderNode = node;
mousedownNode = node;
var textGroup = node.getTextGroup();
sel.collapse(true);
sel.setColor(node.getStyle('text-selection-color'));
receiver
.updateByMinderNode(node)
.updateIndexByMouse(e.getPosition(node.getRenderContainer()))
.setRange(range)
.setReady();
if(selectionReadyShow){
sel.setShowStatus();
clearTimeout(mousedownTimer);
mousedownTimer = setTimeout(function() {
if(dblclickEvent){
dblclickEvent = false;
return;
}
sel.collapse(true)
.updatePosition(receiver.getOffsetByIndex())
.setShow();
textGroup.setStyle('cursor','text');
},200);
km.setStatus('textedit');
}
return;
}
}
//模拟光标没有准备好
receiver.clearReady();
//当点击空白处时,光标需要消失
receiver.clear();
if(lastMinderNode){
lastMinderNode.getTextGroup().setStyle('cursor','default');
}
},
'inputready.keyup':function(){
if(sel.isHide()){
inputStatusReady(this.getSelectedNode());
}
},
//当节点选区通过键盘发生变化时,输入状态要准备好
'normal.keyup': function(e) {
var node = this.getSelectedNode();
var keyCode = e.getKeyCode();
if (node) {
if (this.isSingleSelect() && node.isSelected() && !sel.isShow() ) {
var orgEvt = e.originEvent;
if (keymap.isSelectedNodeKey[keyCode] &&
!orgEvt.ctrlKey &&
!orgEvt.metaKey &&
!orgEvt.shiftKey &&
!orgEvt.altKey) {
inputStatusReady(node);
}
}
}
},
'normal.mouseup textedit.mouseup inputready.mouseup': function(e) {
mouseDownStatus = false;
var node = e.getTargetNode();
mousedownNode = null;
if (node && !selectionReadyShow && receiver.isReady()) {
sel.collapse(true);
sel.setColor(node.getStyle('text-selection-color'));
//必须再次focus,要不不能呼出键盘
if(kity.Browser.ipad){
receiver.focus();
}
clearTimeout(mouseupTimer);
mouseupTimer = setTimeout(function() {
if(dblclickEvent){
dblclickEvent = false;
return;
}
sel.collapse(true)
.updatePosition(receiver.getOffsetByIndex())
.setShow();
node.getTextGroup().setStyle('cursor','text');
}, 200);
km.setStatus('textedit');
return;
}
//当选中节点后,输入状态准备
if(sel.isHide()){
inputStatusReady(e.getTargetNode());
}else {
//当有光标时,要同步选区
if(!sel.collapsed){
receiver.updateContainerRangeBySel();
}
}
},
'textedit.beforemousemove inputready.beforemousemove': function(e) {
if(kity.Browser.ipad){
return;
}
//ipad下不做框选
if (mouseDownStatus && receiver.isReady() && selectionReadyShow) {
e.stopPropagationImmediately();
if(mousedownNode){
var offset = e.getPosition( mousedownNode.getRenderContainer());
receiver
.updateSelectionByMousePosition(offset)
.updateSelection(offset);
setTimeout(function(){
receiver.updateContainerRangeBySel();
});
}
}else if(mouseDownStatus && !selectionReadyShow){
//第一次点中,第二次再次点中进行拖拽
km.setStatus('normal');
receiver.clearReady();
}
},
'normal.dblclick textedit.dblclick inputready.dblclick': function(e) {
var node = e.getTargetNode();
dblclickEvent = true;
if(node){
//跟mouseup的timeout有冲突,这里做标记处理
inputStatusReady(node);
km.setStatus('textedit');
receiver.updateSelection();
}
},
'restoreScene': function() {
receiver.clear();
inputStatusReady(this.getSelectedNode());
},
'stopTextEdit': function() {
receiver.clear();
km.setStatus('normal');
},
'resize': function(e) {
sel.setHide();
},
'execCommand': function(e) {
var cmds = {
'appendchildnode': 1,
'appendsiblingnode': 1,
'editnode': 1
};
if (cmds[e.commandName]) {
inputStatusReady(km.getSelectedNode());
receiver.updateSelection();
return;
}
if(sel.isShow()){
receiver.updateTextOffsetData().updateSelection();
}
},
'layoutfinish':function(e){
if (e.node === receiver.minderNode && (this.getStatus() == 'textedit' || this.getStatus() == 'inputready') ) {//&& selectionReadyShow
receiver.setContainerStyle();
}
},
'selectionclear': function() {
var node = km.getSelectedNode();
if(node){
inputStatusReady(node);
}else{
km.setStatus('normal');
receiver.clear();
}
},
'blur': function() {
!/\?debug#?/.test(location.href) && receiver.clear();
},
'textedit.import': function() {
km.setStatus('normal');
receiver.clear();
},
'inputready.mousewheel textedit.mousewheel': function() {
receiver.setContainerStyle();
},
'statuschange':function(e){
if(e.lastStatus == 'textedit'){
this.fire('contentchange');
}
}
}
};
});
\ No newline at end of file
//接收者
KityMinder.keyboarder = kity.createClass('keyboarder', function(){
return {
constructor: function(re) {
this.re = re;
this.container = re.container;
this.selection = re.selection;
this.range = re.range;
this.km = re.km;
this.lastMinderNode = null;
this.isTypeText = false;
this._initEvent();
this.isShortcutCopyKey = false;
},
//给接受容器绑定事件
_initEvent: function(){
var me = this;
if(kity.Browser.ipad) {
utils.listen(this.container, 'keydown keypress keyup input', function(e) {
me._handleEvents.call(me, new MinderEvent(e.type == 'keyup' ? 'beforekeyup' : e.type, e));
if(e.type == 'keyup'){
if(me.km.getStatus() == 'normal'){
me.km.fire( 'keyup', e);
}
}
});
}
this.km.on('inputready.beforekeyup ' +
'inputready.beforekeydown ' +
'textedit.beforekeyup ' +
'normal.keydown ' +
'normal.keyup ' +
'textedit.beforekeydown ' +
'textedit.keypress ' +
'textedit.paste',
utils.proxy(this._handleEvents, this));
},
_handleEvents:function(e){
switch (e.type) {
case 'input':
this._input(e);
break;
case 'beforekeydown':
this._beforeKeydown(e);
break;
case 'beforekeyup':
this._beforeKeyup(e);
break;
case 'keyup':
this._keyup(e);
}
},
_setTextToContainer : function(keyCode,iskeyUp){
var me = this;
//同步节点
me.minderNode = me.re.minderNode;
clearTimeout(me.timer);
if (!me.range.hasNativeRange()) {
return;
}
if(keymap.controlKeys[keyCode] && !iskeyUp ){
return;
}
//当第一次输入内容时进行保存
if(me.lastMinderNode !== me.minderNode && !keymap.notContentChange[keyCode]){
me.km.fire('saveScene',{
inputStatus:true
});
me.lastMinderNode = me.minderNode;
}
var text = me.re.getTxtOfContainer();
// //#46 修复在ff下定位到文字后方空格光标不移动问题
// if (kity.Browser.gecko && /\s$/.test(text)) {
// text += '\u200b';
// }
//重新渲染节点
me.minderNode.setText(text);
me.re.setContainerStyle();
me.minderNode.getRenderContainer().bringTop();
me.minderNode.render();
//移动光标不做layout
if(!keymap.notContentChange[keyCode]){
clearTimeout(me.inputTextTimer);
me.inputTextTimer = setTimeout(function(){
me.km.layout(300);
},300);
}
me.re.updateTextOffsetData()
.updateRange()
.updateSelectionByRange();
me.selection
.updateOffsetByTextData(me.re.textData)
.updatePosition();
//当然inputready状态时,如果输入文字,节点内文本会被先选中然后再消失,体验不好
if(me.km.getStatus() != 'inputready'){
me.selection.setHoldShow();
}
me.timer = setTimeout(function() {
if(me.selection.isShow()){
me.selection.setShow();
}
}, 200);
me.km.setStatus('textedit');
},
_input:function(){
var me = this;
if (kity.Browser.ipad) {
setTimeout(function() {
me._setTextToContainer();
});
}
},
_beforeKeydown:function(e){
var me = this;
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode;
this.isTypeText = keyCode == 229 || keyCode === 0;
switch (keyCode) {
case keymap.Enter:
if(e.originEvent.shiftKey && me.selection.isShow()){
me._handlerEnterkey();
e.preventDefault();
return false;
};
case keymap.Tab:
case keymap.Insert:
if(this.selection.isShow()){
this.re.clear();
this.km.setStatus('inputready');
clearTimeout(me.inputTextTimer);
e.preventDefault();
}else{
this.km.setStatus('normal');
this.km.fire('contentchange');
}
return;
case keymap.left:
case keymap.right:
case keymap.up:
case keymap.down:
case keymap.Backspace:
case keymap.Del:
case keymap['/']:
case keymap.F2:
case keymap.Insert:
if(this.selection.isHide()){
this.km.setStatus('normal');
return;
}
break;
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
if(this.selection.isHide() && this.km.getStatus() != 'textedit' && this.km.getStatus() !='inputready'){
this.km.setStatus('normal');
return;
}
}
if (e.originEvent.ctrlKey || e.originEvent.metaKey) {
//选中节点时的复制粘贴,要变成normal
if(this.selection.isHide() && {
86:1,
88:1,
67:1
}[keyCode]){
//修正在cvs方式下_keyup会把节点文字选中
this.isShortcutCopyKey = true;
this.km.setStatus('normal');
return;
}
//粘贴
if (keyCode == keymap.v) {
setTimeout(function () {
me.range.updateNativeRange().insertNode($('<span>$$_kityminder_bookmark_$$</span>')[0]);
var brArr = [];
utils.each(me.container.getElementsByTagName('br'),function(i,br){
brArr.push(br);
});
utils.each(brArr,function(i,br){
var textNode = document.createTextNode('\n');
br.parentNode.insertBefore(textNode,br);
br.parentNode.removeChild(br);
});
var textContent = me.container.textContent.replace(/[\u200b\t\r]/g,'');
var index = textContent.indexOf('$$_kityminder_bookmark_$$');
me.re.setContainerTxt(textContent.replace('$$_kityminder_bookmark_$$',''));
me.range.setStartOffset(index).collapse(true).select();
me._setTextToContainer(keyCode);
},50);
return;
}
//剪切
if (keyCode == keymap.x) {
setTimeout(function () {
me._setTextToContainer(keyCode);
},50);
return;
}
}
this.isShortcutCopyKey = false;
//针对不能连续删除做处理
//if(keymap.Del == keyCode || keymap.Backspace == keyCode)
// me._setTextToContainer(keyCode);
me._setTextToContainer(keyCode);
},
_beforeKeyup:function(e){
var me = this;
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode;
switch (keyCode) {
case keymap.Enter:
case keymap.Tab:
case keymap.Insert:
case keymap.F2:
if(kity.Browser.ipad){
if(this.selection.isShow()){
this.re.clear();
this.km.setStatus('inputready');
clearTimeout(me.inputTextTimer);
e.preventDefault();
}else{
this.km.setStatus('normal');
this.km.fire('contentchange');
}
return;
}
if (keymap.Enter == keyCode && (this.isTypeText || kity.Browser.mac && kity.Browser.gecko)) {
me._setTextToContainer(keyCode,true);
}
if (this.re.keydownNode === this.re.minderNode) {
this.km.rollbackStatus();
this.re.clear();
}
e.preventDefault();
return;
case keymap.Del:
case keymap.Backspace:
case keymap.Spacebar:
if(kity.Browser.ipad){
if(this.selection.isHide()){
this.km.setStatus('normal');
return;
}
}
me._setTextToContainer(keyCode,true);
return;
}
if (this.isTypeText) {
me._setTextToContainer(keyCode,true);
return;
}
if (kity.Browser.mac && kity.Browser.gecko){
me._setTextToContainer(keyCode,true);
return;
}
me._setTextToContainer(keyCode,true);
return true;
},
_keyup:function(e){
var me = this;
var timer;
var node = this.km.getSelectedNode();
if(this.km.getStatus() == 'normal' && node && this.selection.isHide()){
if(this.isShortcutCopyKey){
return;
}
if (node && this.km.isSingleSelect() && node.isSelected()) {
this.re.updateByMinderNode(node);
this.selection.setHide()
.setStartOffset(0)
.setEndOffset(this.re.getTxtOfContainer().length)
.setColor( node.getStyle('text-selection-color'));
setTimeout(function(){
me.re.updateContainerRangeBySel();
});
if(kity.Browser.ie ){
timer = setInterval(function(){
var nativeRange = me.range.nativeSel.getRangeAt(0);
if(!nativeRange || nativeRange.collapsed){
me.range.select();
}else {
clearInterval(timer);
}
});
}
this.km.setStatus('inputready');
}
}
},
//处理软回车操作
_handlerEnterkey:function(){
function removeTmpTextNode(node){
if(node && node.nodeType == 3 && node.nodeValue.length === 0){
node.parentNode.removeChild(node);
}
}
var rng = this.range;
var br = document.createElement('br');
var me = this;
if(!rng.collapsed){
rng.deleteContents();
}
rng.insertNode(br);
removeTmpTextNode(br.previousSibling);
removeTmpTextNode(br.nextSibling);
rng.setStartAfter(br);
rng.collapse(true);
var start = rng.startContainer.childNodes[rng.startOffset];
if(!start){
br = br.cloneNode(false);
rng.startContainer.appendChild(br);
rng.setStartBefore(br);
rng.collapse(true);
}
rng.select();
me._setTextToContainer(keymap.Enter);
}
};
}());
\ No newline at end of file
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
//接收者
KityMinder.Receiver = kity.createClass('Receiver', {
clear: function() {
this.container.innerHTML = '';
if (this.selection) {
this.selection.setHide();
}
if (this.range) {
this.range.clear();
}
this.index = 0;
return this;
},
constructor: function(km,sel,range) {
//初始化接收者
this.setKityMinder(km);
//创建接收者容器
var _div = document.createElement('div');
_div.setAttribute('contenteditable', true);
_div.className = 'km_receiver';
this.container = _div;
utils.addCssRule('km_receiver_css',
' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;'
+ (/\?debug#?/.test(location.href)?'':'clip:rect(1em 1em 1em 1em);'));
this.index = 0;
this.selection = sel;
this.range = range;
this.range.container = _div;
},
setRange: function(range, index) {
this.index = index || this.index;
this.range = range;
range.setStartOffset(this.index);
range.collapse(true);
var me = this;
setTimeout(function() {
me.container.focus();
range.select();
});
return this;
},
setTextGroup: function(textGroup) {
this.textGroup = textGroup;
return this;
},
setKityMinder: function(km) {
this.km = km;
return this;
},
updateByMinderNode:function(node){
this.setMinderNode(node);
//追加selection到节点
this._addSelection();
//更新minderNode下的textGroup
this.setTextGroup(node.getTextGroup());
//更新接受容器的样式
this.setContainerStyle();
//更新textOffsetData数据
this.updateTextOffsetData();
//更新选取高度
this.setSelectionHeight();
//更新接收容器内容
this.setContainerTxt();
return this;
},
setMinderNode: function(node) {
this.minderNode = node;
this.selection.setMinderNode(node);
return this;
},
_addSelection:function(){
if (this.selection.container){
this.selection.remove();
}
this.minderNode.getRenderContainer().addShape(this.selection);
return this;
},
getMinderNode:function(){
return this.minderNode;
},
updateIndex: function() {
this.index = this.range.getStartOffset();
return this;
},
setSelection: function(selection) {
this.selection = selection;
return this;
},
updateSelection: function(offset) {
this.selection.update(this.textData,offset);
return this;
},
getOffsetByIndex:function(index){
return utils.getValueByIndex(this.textData, index !== undefined ? index : this.index);
},
getBaseOffset: function() {
var offset = this.textGroup.getRenderBox('screen');
return offset;
},
setContainerStyle: function() {
var textGroupBox = this.getBaseOffset();
this.container.style.cssText = ';left:' + (kity.Browser.ipad ? '-' : '') +
textGroupBox.x + 'px;top:' + (textGroupBox.y + (/\?debug#?/.test(location.href)?this.textGroup.getItems().length * this.getlineHeight():0)) +
'px;width:' + textGroupBox.width + 'px;height:' + textGroupBox.height + 'px;';
return this;
},
updateTextOffsetData: function() {
var me = this;
var fontHeight = this.minderNode.getData('font-size') || this.minderNode.getStyle('font-size');
var lineHeight = this.minderNode.getStyle('line-height') * fontHeight;
var offsetHeight = (me.textGroup.getShapes().length * lineHeight - (lineHeight - fontHeight)) / 2;
var box;
this.textData = [];
me.textGroup.eachItem(function(index,textShape){
me.textData[index] = [];
var currentLineTop = index * lineHeight + 1;
var text = textShape.getContent();
for (var i = 0, l = text.length; i < l; i++) {
try {
box = textShape.getExtentOfChar(i);
} catch (e) {
console.log(e);
}
me.textData[index].push({
x: box.x ,
y: currentLineTop - offsetHeight,
width: box.width,
height: box.height
});
}
if(text.length === 0){
me.textData[index].push({
x: 0,
y: currentLineTop - offsetHeight,
width: 0,
height:lineHeight
});
}
});
return this;
},
getlineHeight:function(){
return this.minderNode.getStyle('line-height') * (this.minderNode.getData('font-size') || this.minderNode.getStyle('font-size'));
},
updateIndexByMouse : function(offset) {
var me = this;
//更新文本字符坐标
me.updateTextOffsetData();
this.index = 0;
var lineHeight = this.getlineHeight();
utils.each(this.textData,function(l,arr){
var first = arr[0];
//确定行号
if(first.y <= offset.y && first.y + lineHeight >= offset.y){
utils.each(arr,function(i,v){
//点击开始之前
if (i === 0 && offset.x <= v.x) {
return false;
}
if (offset.x >= v.x && offset.x <= v.x + v.width) {
if (offset.x - v.x > v.width / 2) {
me.index += i + 1;
} else {
me.index += i;
}
return false;
}
if (i == arr.length - 1 && offset.x >= v.x) {
me.index += (arr.length == 1 && arr[0].width === 0 ? 0 : arr.length);
return false;
}
});
return false;
}else{
me.index += arr.length + (arr.length == 1 && arr[0].width === 0 ? 0 : 1);
return;
}
});
this.selection.setStartOffset(this.index).collapse(true);
return this;
},
setSelectionHeight: function() {
this.selection.setHeight((this.minderNode.getData('font-size') || this.minderNode.getStyle('font-size')) * 1);
return this;
},
updateSelectionByMousePosition: function(offset) {
var me = this;
var result = 0;
var lineHeight = this.getlineHeight();
utils.each(this.textData,function(l,arr){
var first = arr[0];
//确定行号
if(first.y <= offset.y && first.y + lineHeight >= offset.y){
utils.each(arr,function(i,v){
//点击开始之前
if (i === 0 && offset.x <= v.x) {
return false;
}
if (offset.x >= v.x && offset.x <= v.x + v.width) {
result += i;
if (offset.x - v.x > v.width / 2) {
result += 1;
}
return false;
}
if (i == arr.length - 1 && offset.x >= v.x) {
result += (arr.length == 1 && arr[0].width === 0 ? 0 : arr.length);
return false;
}
});
return false;
}else{
if(first.y > offset.y && l === 0){
result = 0;
return false;
}else if(l == me.textData.length - 1 && first.y + lineHeight < offset.y){
result += arr.length + 1;
return false;
}
result += arr.length + (arr.length == 1 && arr[0].width === 0 ? 0 : 1);
return;
}
});
if(result < me.index){
this.selection.setStartOffset(result);
this.selection.setEndOffset(me.index);
}else if(result == me.index){
this.selection.setStartOffset(result).collapse(true);
}else{
this.selection.setStartOffset(me.index);
this.selection.setEndOffset(result);
}
return this;
},
updateRange: function() {
this.range.update();
return this;
},
updateContainerRangeBySel:function(){
var me = this;
this.range.setStartOffset(this.selection.startOffset);
this.range.setEndOffset(this.selection.endOffset);
if(kity.Browser.gecko){
this.container.focus();
setTimeout(function(){
me.range.select();
});
}else{
this.range.select();
}
return this;
},
updateSelectionByRange:function(){
this.selection.setStartOffset(this.range.getStartOffset());
this.selection.setEndOffset(this.range.getEndOffset());
return this;
},
setIndex: function(index) {
this.index = index;
return this;
},
setContainerTxt: function(txt) {
function encodeHtml(text) {
return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
if(txt){
txt = encodeHtml(txt);
txt = txt.replace(/[\n]/g,'<br\/>');
}else{
txt = '';
this.textGroup.eachItem(function(i,item){
txt += encodeHtml(item.getContent()) + '<br/>';
});
}
this.container.innerHTML = txt;
return this;
},
setReady:function(){
this._ready = true;
},
clearReady:function(){
this._ready = false;
},
isReady:function(){
return this._ready;
},
focus:function(){
this.container.focus();
},
getTxtOfContainer:function(){
var result = '',cont = this.container;
utils.each(cont.childNodes,function(i,n){
if(n.nodeType == 3){
result += n.nodeValue.replace(/[\u200b]/g, '');
}else{
if(n !== cont.lastChild)
result += '\n';
}
});
return result;
}
});
\ No newline at end of file
//模拟光标
KityMinder.Selection = kity.createClass( 'Selection', {
base: kity.Path,
constructor: function ( height, color, width ) {
this.callBase();
this.height = height || 20;
this.setAttr('id','_kity_selection');
this.width = 2;
this.fill('rgb(27,171,255)');
this.setHide();
this.timer = null;
this.collapsed = true;
this.startOffset = this.endOffset = 0;
this.setOpacity(0.5);
this.setStyle('cursor','text');
this._show = false;
this.offset = [];
this.setTranslate(-0.5, -1.5);
},
setMinderNode : function(node){
this.minderNode = node;
},
setColor:function(color){
this.fill(color);
},
updateOffsetByTextData:function(data,offset){
if(this.collapsed){
this.offset = utils.getValueByIndex(data,this.startOffset);
return this;
}else{
var arrOffset = [],tmpOffset = {},
startOffset = this.startOffset,
endOffset = this.endOffset,
cIndex = 0;
utils.each(data,function(l,arr){
tmpOffset = {
width:0,
x:0,
y:0
};
utils.each(arr,function(i,o){
if(cIndex >= startOffset && cIndex <= endOffset){
if(i === 0 || cIndex === startOffset){
tmpOffset.x = o.x;
tmpOffset.y = o.y;
tmpOffset.width = o.width;
//i === 0 && offset && offset.x <= o.x && cIndex != startOffset ? 0 :
}else if(cIndex < endOffset){
tmpOffset.width += o.width;
}else if(cIndex === endOffset){
return false;
}
}
cIndex++;
});
if(tmpOffset.x !== undefined) {
arrOffset.push(tmpOffset);
}
if(cIndex === endOffset) {
return false;
}
if(arr.length == 1 && arr[0].width === 0)
return;
cIndex++;
});
this.offset = arrOffset;
return this;
}
this._show = true;
},
updatePosition: function(offset){
var me = this;
var r = Math.round;
var rect = function (x, y, w, h) {
return ['M', r(x), r(y),
'h', r(w),
'v', r(h),
'h', -r(w),
'v', -r(h),
'z'];
};
offset = offset !== undefined ? offset : this.offset;
if(this.collapsed){
if (isNaN(offset.x) || isNaN(offset.y)) {
if (console) console.warn('editor.selection.js 不正确的偏移位置');
return this;
}
this.setPathData(rect(offset.x, offset.y, this.width, this.height));
} else {
this.setPathData(offset.reduce(function (prev, current) {
return prev.concat(rect(current.x, current.y, current.width, me.height));
}, []));
}
this._show = true;
return this;
},
collapse : function(toStart){
this.setOpacity(1);
this.collapsed = true;
if(toStart){
this.endOffset = this.startOffset;
}else{
this.startOffset = this.endOffset;
}
return this;
},
setStartOffset:function(offset){
this.startOffset = offset;
if(this.startOffset >= this.endOffset){
this.collapse(true);
return this;
}
this.collapsed = false;
this.setOpacity(0.5);
return this;
},
setEndOffset:function(offset){
this.endOffset = offset;
if(this.endOffset <= this.startOffset){
this.startOffset = offset;
this.collapse(true);
return this;
}
this.collapsed = false;
this.setOpacity(0.5);
return this;
},
update : function(data,offset){
if(data){
this.updateOffsetByTextData(data,offset);
}
this.updatePosition();
this.setShow();
return this;
},
setHeight: function ( height ) {
this.height = Math.round(height) + 2;
return this;
},
setHide: function () {
clearInterval( this.timer );
this.setStyle( 'display', 'none' );
this._show = false;
return this;
},
setHoldShow:function(){
this.setStyle('display','');
clearInterval(this.timer);
return this;
},
setShow: function () {
this.bringTop();
clearInterval( this.timer );
var me = this,
state = '';
me.setStyle( 'display', '' );
me._show = true;
if(this.collapsed){
me.setOpacity(1);
this.timer = setInterval( function () {
me.setStyle( 'display', state );
state = state ? '' : 'none';
}, 400 );
}
return this;
},
setShowStatus:function(){
this._show = true;
return this;
},
isShow:function(){
return this._show;
},
isHide:function(){
return !this._show;
}
} );
\ No newline at end of file
/* global Renderer: true */ define(function(require, exports, module) {
var kity = require('core/kity');
KityMinder.registerModule('Expand', function() { 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 minder = this;
var EXPAND_STATE_DATA = 'expandState', var EXPAND_STATE_DATA = 'expandState',
STATE_EXPAND = 'expand', STATE_EXPAND = 'expand',
...@@ -86,7 +93,7 @@ KityMinder.registerModule('Expand', function() { ...@@ -86,7 +93,7 @@ KityMinder.registerModule('Expand', function() {
this.sign = new kity.Path().stroke('gray'); this.sign = new kity.Path().stroke('gray');
this.addShapes([this.outline, this.sign]); this.addShapes([this.outline, this.sign]);
this.initEvent(node); this.initEvent(node);
this.setId(KityMinder.uuid('node_expander')); this.setId(utils.uuid('node_expander'));
this.setStyle('cursor', 'pointer'); this.setStyle('cursor', 'pointer');
}, },
...@@ -236,4 +243,5 @@ KityMinder.registerModule('Expand', function() { ...@@ -236,4 +243,5 @@ KityMinder.registerModule('Expand', function() {
divider: true divider: true
}] }]
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule("fontmodule", 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');
function getNodeDataOrStyle(node, name) { function getNodeDataOrStyle(node, name) {
return node.getData(name) || node.getStyle(name); return node.getData(name) || node.getStyle(name);
} }
KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) { TextRenderer.registerStyleHook(function(node, textGroup) {
var dataColor = node.getData('color'); var dataColor = node.getData('color');
var selectedColor = node.getStyle('selected-color'); var selectedColor = node.getStyle('selected-color');
var styleColor = node.getStyle('color'); var styleColor = node.getStyle('color');
...@@ -11,74 +21,32 @@ KityMinder.registerModule("fontmodule", function() { ...@@ -11,74 +21,32 @@ KityMinder.registerModule("fontmodule", function() {
var foreColor = dataColor || (node.isSelected() && selectedColor ? selectedColor : styleColor); var foreColor = dataColor || (node.isSelected() && selectedColor ? selectedColor : styleColor);
var fontFamily = getNodeDataOrStyle(node, 'font-family'); var fontFamily = getNodeDataOrStyle(node, 'font-family');
var fontSize = getNodeDataOrStyle(node, 'font-size'); var fontSize = getNodeDataOrStyle(node, 'font-size');
var fontHash = [fontFamily, fontSize].join('/');
textGroup.fill(foreColor); textGroup.fill(foreColor);
node.setTmpData('fore-color', foreColor.toString());
textGroup.eachItem(function(index,item){ textGroup.eachItem(function(index, item) {
item.setFont({ item.setFont({
'family': fontFamily, 'family': fontFamily,
'size': fontSize 'size': fontSize
}); });
}); });
node.setTmpData('font-hash', fontHash);
}); });
return {
Module.register('fontmodule', {
defaultOptions: { defaultOptions: {
'fontfamily': [{ 'commands': {
name: '宋体', 'forecolor': kity.createClass('fontcolorCommand', {
val: '宋体,SimSun'
}, {
name: '微软雅黑',
val: '微软雅黑,Microsoft YaHei'
}, {
name: '楷体',
val: '楷体,楷体_GB2312,SimKai'
}, {
name: '黑体',
val: '黑体, SimHei'
}, {
name: '隶书',
val: '隶书, SimLi'
}, {
name: 'Andale Mono',
val: 'andale mono'
}, {
name: 'Arial',
val: 'arial,helvetica,sans-serif'
}, {
name: 'arialBlack',
val: 'arial black,avant garde'
}, {
name: 'Comic Sans Ms',
val: 'comic sans ms'
}, {
name: 'Impact',
val: 'impact,chicago'
}, {
name: 'Times New Roman',
val: 'times new roman'
}, {
name: 'Sans-Serif',
val: 'sans-serif'
}],
'fontsize': [10, 12, 16, 18, 24, 32, 48]
},
"commands": {
"forecolor": kity.createClass("fontcolorCommand", {
base: Command, base: Command,
execute: function(km, color) { execute: function(km, color) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('color', color); n.setData('color', color);
n.render(); n.render();
}); });
}, },
queryState: function(km) { queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0 return km.getSelectedNodes().length === 0 ? -1 : 0;
}, },
queryValue: function(km) { queryValue: function(km) {
if (km.getSelectedNodes().length == 1) { if (km.getSelectedNodes().length == 1) {
...@@ -88,18 +56,18 @@ KityMinder.registerModule("fontmodule", function() { ...@@ -88,18 +56,18 @@ KityMinder.registerModule("fontmodule", function() {
} }
}), }),
"background": kity.createClass("backgroudCommand", { 'background': kity.createClass('backgroudCommand', {
base: Command, base: Command,
execute: function(km, color) { execute: function(km, color) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('background', color); n.setData('background', color);
n.render(); n.render();
}); });
}, },
queryState: function(km) { queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0 return km.getSelectedNodes().length === 0 ? -1 : 0;
}, },
queryValue: function(km) { queryValue: function(km) {
if (km.getSelectedNodes().length == 1) { if (km.getSelectedNodes().length == 1) {
...@@ -107,21 +75,20 @@ KityMinder.registerModule("fontmodule", function() { ...@@ -107,21 +75,20 @@ KityMinder.registerModule("fontmodule", function() {
} }
return 'mixed'; return 'mixed';
} }
}), }),
"fontfamily": kity.createClass("fontfamilyCommand", { 'fontfamily': kity.createClass('fontfamilyCommand', {
base: Command, base: Command,
execute: function(km, family) { execute: function(km, family) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-family', family); n.setData('font-family', family);
n.render(); n.render();
km.layout(); km.layout();
}); });
}, },
queryState: function(km) { queryState: function(km) {
return km.getSelectedNodes().length === 0 ? -1 : 0 return km.getSelectedNodes().length === 0 ? -1 : 0;
}, },
queryValue: function(km) { queryValue: function(km) {
var node = km.getSelectedNode(); var node = km.getSelectedNode();
...@@ -129,19 +96,19 @@ KityMinder.registerModule("fontmodule", function() { ...@@ -129,19 +96,19 @@ KityMinder.registerModule("fontmodule", function() {
return null; return null;
} }
}), }),
"fontsize": kity.createClass("fontsizeCommand", { 'fontsize': kity.createClass('fontsizeCommand', {
base: Command, base: Command,
execute: function(km, size) { execute: function(km, size) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('font-size', size); n.setData('font-size', size);
n.render(); n.render();
km.layout(300); km.layout(300);
}); });
}, },
queryState: function(km) { queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0 return km.getSelectedNodes().length === 0 ? -1 : 0;
}, },
queryValue: function(km) { queryValue: function(km) {
var node = km.getSelectedNode(); var node = km.getSelectedNode();
...@@ -150,5 +117,6 @@ KityMinder.registerModule("fontmodule", function() { ...@@ -150,5 +117,6 @@ KityMinder.registerModule("fontmodule", function() {
} }
}) })
} }
}; }
});
}); });
\ No newline at end of file
KityMinder.registerModule("HistoryModule", 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');
function compareObject(source, target) {
var tmp;
if (isEmptyObject(source) !== isEmptyObject(target)) {
return false;
}
if (getObjectLength(source) != getObjectLength(target)) {
return false;
}
for (var p in source) {
if (source.hasOwnProperty(p)) {
tmp = source[p];
if (target[p] === undefined) {
return false;
}
if (this.isObject(tmp) || this.isArray(tmp)) {
if (this.isObject(target[p]) !== this.isObject(tmp)) {
return false;
}
if (this.isArray(tmp) !== this.isArray(target[p])) {
return false;
}
if (this.compareObject(tmp, target[p]) === false) {
return false;
}
} else {
if (tmp != target[p]) {
return false;
}
}
}
}
return true;
}
function getObjectLength(obj) {
if (utils.isArray(obj) || utils.isString(obj)) return obj.length;
var count = 0;
for (var key in obj)
if (obj.hasOwnProperty(key)) count++;
return count;
}
function isEmptyObject(obj) {
if (obj === null || obj === undefined) return true;
if (utils.isArray(obj) || utils.isString(obj)) return obj.length === 0;
for (var key in obj)
if (obj.hasOwnProperty(key)) return false;
return true;
}
function getValueByIndex(data, index) {
var initIndex = 0,
result = 0;
data.forEach(function(arr, i) {
if (initIndex + arr.length >= index) {
if (index - initIndex == arr.length) {
if (arr.length == 1 && arr[0].width === 0) {
initIndex++;
return;
}
result = {
x: arr[arr.length - 1].x + arr[arr.length - 1].width,
y: arr[arr.length - 1].y
};
} else {
result = arr[index - initIndex];
}
return false;
} else {
initIndex += arr.length + (arr.length == 1 && arr[0].width === 0 ? 0 : 1);
}
});
return result;
}
function getNodeIndex(node, ignoreTextNode) {
var preNode = node,
i = 0;
while (preNode = preNode.previousSibling) {
if (ignoreTextNode && preNode.nodeType == 3) {
if (preNode.nodeType != preNode.nextSibling.nodeType) {
i++;
}
continue;
}
i++;
}
return i;
}
var km = this; var km = this;
var Scene = kity.createClass('Scene', { var Scene = kity.createClass('Scene', {
constructor: function(root,inputStatus) { constructor: function(root, inputStatus) {
this.data = root.clone(); this.data = root.clone();
this.inputStatus = inputStatus; this.inputStatus = inputStatus;
}, },
...@@ -14,12 +115,12 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -14,12 +115,12 @@ KityMinder.registerModule("HistoryModule", function() {
return this.getData().clone(); return this.getData().clone();
}, },
equals: function(scene) { equals: function(scene) {
return this.getData().equals(scene.getData()); return this.getData().compareTo(scene.getData());
}, },
isInputStatus:function(){ isInputStatus: function() {
return this.inputStatus; return this.inputStatus;
}, },
setInputStatus:function(status){ setInputStatus: function(status) {
this.inputStatus = status; this.inputStatus = status;
} }
}); });
...@@ -35,13 +136,13 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -35,13 +136,13 @@ KityMinder.registerModule("HistoryModule", function() {
if (this.hasUndo) { if (this.hasUndo) {
var currentScene = this.list[this.index]; var currentScene = this.list[this.index];
//如果是输入文字时的保存,直接回复当前场景 //如果是输入文字时的保存,直接回复当前场景
if(currentScene && currentScene.isInputStatus()){ if (currentScene && currentScene.isInputStatus()) {
this.saveScene(); this.saveScene();
this.restore(--this.index); this.restore(--this.index);
currentScene.setInputStatus(false); currentScene.setInputStatus(false);
return; return;
} }
if(this.list.length == 1){ if (this.list.length == 1) {
this.restore(0); this.restore(0);
return; return;
} }
...@@ -71,14 +172,12 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -71,14 +172,12 @@ KityMinder.registerModule("HistoryModule", function() {
}, },
partialRenewal: function(target) { partialRenewal: function(target) {
var selectedNodes = []; var selectedNodes = [];
function compareNode(source, target) { function compareNode(source, target) {
if (source.getText() != target.getText()) { if (source.getText() != target.getText()) {
return false; return false;
} }
if (utils.compareObject(source.getData(), target.getData()) === false) { if (compareObject(source.getData(), target.getData()) === false) {
return false;
}
if (utils.compareObject(source.getTmpData(), target.getTmpData()) === false) {
return false; return false;
} }
return true; return true;
...@@ -91,7 +190,7 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -91,7 +190,7 @@ KityMinder.registerModule("HistoryModule", function() {
km.appendNode(child, parent); km.appendNode(child, parent);
child.render(); child.render();
var children = utils.cloneArr(child.children); var children = child.children.slice();
for (var i = 0, ci; ci = children[i++];) { for (var i = 0, ci; ci = children[i++];) {
appendChildNode(child, ci); appendChildNode(child, ci);
} }
...@@ -121,10 +220,11 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -121,10 +220,11 @@ KityMinder.registerModule("HistoryModule", function() {
} }
} }
var km = this.km;
traverseNode(km.getRoot(), target); traverseNode(km.getRoot(), target);
km.layout(200); km.layout(200);
km.select(selectedNodes,true); km.select(selectedNodes, true);
selectedNodes = []; selectedNodes = [];
...@@ -138,13 +238,13 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -138,13 +238,13 @@ KityMinder.registerModule("HistoryModule", function() {
this.km.fire('contentChange'); this.km.fire('contentChange');
}, },
getScene: function(inputStatus) { getScene: function(inputStatus) {
return new Scene(this.km.getRoot(),inputStatus); return new Scene(this.km.getRoot(), inputStatus);
}, },
saveScene: function(inputStatus) { saveScene: function(inputStatus) {
var currentScene = this.getScene(inputStatus); var currentScene = this.getScene(inputStatus);
var lastScene = this.list[this.index]; var lastScene = this.list[this.index];
if (lastScene && lastScene.equals(currentScene)) { if (lastScene && lastScene.equals(currentScene)) {
if(inputStatus){ if (inputStatus) {
lastScene.setInputStatus(true); lastScene.setInputStatus(true);
this.update(); this.update();
} }
...@@ -153,7 +253,7 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -153,7 +253,7 @@ KityMinder.registerModule("HistoryModule", function() {
this.list = this.list.slice(0, this.index + 1); this.list = this.list.slice(0, this.index + 1);
this.list.push(currentScene); this.list.push(currentScene);
//如果大于最大数量了,就把最前的剔除 //如果大于最大数量了,就把最前的剔除
if (this.list.length > this.km.getOptions('maxUndoCount')) { if (this.list.length > this.km.getOption('maxUndoCount')) {
this.list.shift(); this.list.shift();
} }
this.index = this.list.length - 1; this.index = this.list.length - 1;
...@@ -165,7 +265,7 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -165,7 +265,7 @@ KityMinder.registerModule("HistoryModule", function() {
this.hasRedo = !!this.list[this.index + 1]; this.hasRedo = !!this.list[this.index + 1];
this.hasUndo = !!this.list[this.index - 1]; this.hasUndo = !!this.list[this.index - 1];
var currentScene = this.list[this.index]; var currentScene = this.list[this.index];
if(currentScene && currentScene.isInputStatus()){ if (currentScene && currentScene.isInputStatus()) {
this.hasUndo = true; this.hasUndo = true;
} }
...@@ -177,10 +277,12 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -177,10 +277,12 @@ KityMinder.registerModule("HistoryModule", function() {
this.hasRedo = false; this.hasRedo = false;
} }
}); });
Module.register('HistoryModule', function() {
//为km实例添加history管理 //为km实例添加history管理
this.historyManager = new HistoryManager(this); this.historyManager = new HistoryManager(this);
return { return {
defaultOptions: { defaultOptions: {
maxUndoCount: 20, maxUndoCount: 20,
...@@ -230,4 +332,6 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -230,4 +332,6 @@ KityMinder.registerModule("HistoryModule", function() {
} }
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule("hyperlink", function() { define(function(require, exports, module) {
var linkShapePath = "M16.614,10.224h-1.278c-1.668,0-3.07-1.07-3.599-2.556h4.877c0.707,0,1.278-0.571,1.278-1.278V3.834 c0-0.707-0.571-1.278-1.278-1.278h-4.877C12.266,1.071,13.668,0,15.336,0h1.278c2.116,0,3.834,1.716,3.834,3.834V6.39 C20.448,8.508,18.73,10.224,16.614,10.224z M5.112,5.112c0-0.707,0.573-1.278,1.278-1.278h7.668c0.707,0,1.278,0.571,1.278,1.278 S14.765,6.39,14.058,6.39H6.39C5.685,6.39,5.112,5.819,5.112,5.112z M2.556,3.834V6.39c0,0.707,0.573,1.278,1.278,1.278h4.877 c-0.528,1.486-1.932,2.556-3.599,2.556H3.834C1.716,10.224,0,8.508,0,6.39V3.834C0,1.716,1.716,0,3.834,0h1.278 c1.667,0,3.071,1.071,3.599,2.556H3.834C3.129,2.556,2.556,3.127,2.556,3.834z"; var kity = require('core/kity');
return { var utils = require('core/utils');
"commands": {
"hyperlink": kity.createClass("hyperlink", { 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');
// jscs:disable maximumLineLength
var linkShapePath = 'M16.614,10.224h-1.278c-1.668,0-3.07-1.07-3.599-2.556h4.877c0.707,0,1.278-0.571,1.278-1.278V3.834 c0-0.707-0.571-1.278-1.278-1.278h-4.877C12.266,1.071,13.668,0,15.336,0h1.278c2.116,0,3.834,1.716,3.834,3.834V6.39 C20.448,8.508,18.73,10.224,16.614,10.224z M5.112,5.112c0-0.707,0.573-1.278,1.278-1.278h7.668c0.707,0,1.278,0.571,1.278,1.278 S14.765,6.39,14.058,6.39H6.39C5.685,6.39,5.112,5.819,5.112,5.112z M2.556,3.834V6.39c0,0.707,0.573,1.278,1.278,1.278h4.877 c-0.528,1.486-1.932,2.556-3.599,2.556H3.834C1.716,10.224,0,8.508,0,6.39V3.834C0,1.716,1.716,0,3.834,0h1.278 c1.667,0,3.071,1.071,3.599,2.556H3.834C3.129,2.556,2.556,3.127,2.556,3.834z';
Module.register('hyperlink',{
'commands': {
'hyperlink': kity.createClass('hyperlink', {
base: Command, base: Command,
execute: function(km, url, title) { execute: function(km, url, title) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('hyperlink', url); n.setData('hyperlink', url);
n.setData('hyperlinkTitle', title); n.setData('hyperlinkTitle', title);
n.render(); n.render();
...@@ -20,7 +31,7 @@ KityMinder.registerModule("hyperlink", function() { ...@@ -20,7 +31,7 @@ KityMinder.registerModule("hyperlink", function() {
if (nodes.length === 0) { if (nodes.length === 0) {
return -1; return -1;
} }
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n && n.getData('hyperlink')) { if (n && n.getData('hyperlink')) {
result = 0; result = 0;
return false; return false;
...@@ -36,12 +47,12 @@ KityMinder.registerModule("hyperlink", function() { ...@@ -36,12 +47,12 @@ KityMinder.registerModule("hyperlink", function() {
}; };
} }
}), }),
"unhyperlink": kity.createClass("hyperlink", { 'unhyperlink': kity.createClass('hyperlink', {
base: Command, base: Command,
execute: function(km) { execute: function(km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('hyperlink'); n.setData('hyperlink');
n.render(); n.render();
}); });
...@@ -54,7 +65,7 @@ KityMinder.registerModule("hyperlink", function() { ...@@ -54,7 +65,7 @@ KityMinder.registerModule("hyperlink", function() {
return -1; return -1;
} }
var link = false; var link = false;
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n.getData('hyperlink')) { if (n.getData('hyperlink')) {
link = true; link = true;
return false; return false;
...@@ -69,7 +80,7 @@ KityMinder.registerModule("hyperlink", function() { ...@@ -69,7 +80,7 @@ KityMinder.registerModule("hyperlink", function() {
}, },
'renderers': { 'renderers': {
right: kity.createClass('hyperlinkrender', { right: kity.createClass('hyperlinkrender', {
base: KityMinder.Renderer, base: Renderer,
create: function() { create: function() {
...@@ -122,6 +133,5 @@ KityMinder.registerModule("hyperlink", function() { ...@@ -122,6 +133,5 @@ KityMinder.registerModule("hyperlink", function() {
} }
}) })
} }
});
};
}); });
\ No newline at end of file
KityMinder.registerModule('image', 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 Renderer = require('core/render');
Module.register('image', function() {
function loadImageSize(url, callback) { function loadImageSize(url, callback) {
var img = document.createElement('img'); var img = document.createElement('img');
img.onload = function() { img.onload = function() {
...@@ -37,17 +47,17 @@ KityMinder.registerModule('image', function() { ...@@ -37,17 +47,17 @@ KityMinder.registerModule('image', function() {
loadImageSize(url, function(width, height) { loadImageSize(url, function(width, height) {
if (!width) return; if (!width) return;
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
var size = fitImageSize( var size = fitImageSize(
width, height, width, height,
km.getOptions('maxImageWidth'), km.getOption('maxImageWidth'),
km.getOptions('maxImageHeight')); km.getOption('maxImageHeight'));
n.setData('image', url); n.setData('image', url);
n.setData('imageTitle', title); n.setData('imageTitle', title);
n.setData('imageSize', size); n.setData('imageSize', size);
n.render(); n.render();
}); });
km.fire("saveScene"); km.fire('saveScene');
km.layout(300); km.layout(300);
}); });
...@@ -58,7 +68,7 @@ KityMinder.registerModule('image', function() { ...@@ -58,7 +68,7 @@ KityMinder.registerModule('image', function() {
if (nodes.length === 0) { if (nodes.length === 0) {
return -1; return -1;
} }
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n && n.getData('image')) { if (n && n.getData('image')) {
result = 0; result = 0;
return false; return false;
...@@ -80,7 +90,7 @@ KityMinder.registerModule('image', function() { ...@@ -80,7 +90,7 @@ KityMinder.registerModule('image', function() {
execute: function(km) { execute: function(km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
n.setData('image').render(); n.setData('image').render();
}); });
km.layout(300); km.layout(300);
...@@ -92,7 +102,7 @@ KityMinder.registerModule('image', function() { ...@@ -92,7 +102,7 @@ KityMinder.registerModule('image', function() {
return -1; return -1;
} }
var image = false; var image = false;
utils.each(nodes, function(i, n) { nodes.forEach(function(n) {
if (n.getData('image')) { if (n.getData('image')) {
image = true; image = true;
return false; return false;
...@@ -106,7 +116,7 @@ KityMinder.registerModule('image', function() { ...@@ -106,7 +116,7 @@ KityMinder.registerModule('image', function() {
}); });
var ImageRenderer = kity.createClass('ImageRenderer', { var ImageRenderer = kity.createClass('ImageRenderer', {
base: KityMinder.Renderer, base: Renderer,
create: function(node) { create: function(node) {
return new kity.Image(node.getData('image')); return new kity.Image(node.getData('image'));
...@@ -155,4 +165,5 @@ KityMinder.registerModule('image', function() { ...@@ -155,4 +165,5 @@ KityMinder.registerModule('image', function() {
'top': ImageRenderer 'top': ImageRenderer
} }
}; };
});
}); });
\ No newline at end of file
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, var min = Math.min,
max = Math.max, max = Math.max,
abs = Math.abs, abs = Math.abs,
...@@ -171,9 +182,8 @@ KityMinder.registerModule('KeyboardModule', function() { ...@@ -171,9 +182,8 @@ KityMinder.registerModule('KeyboardModule', function() {
}, },
'normal.keyup': function(e) { 'normal.keyup': function(e) {
if (kity.Browser.ipad) { if (kity.Browser.ipad) {
var keys = KityMinder.keymap; var keys = keymap;
var node = e.getTargetNode(); var node = e.getTargetNode();
var lang = this.getLang();
if (this.receiver) this.receiver.keydownNode = node; if (this.receiver) this.receiver.keydownNode = node;
...@@ -183,7 +193,7 @@ KityMinder.registerModule('KeyboardModule', function() { ...@@ -183,7 +193,7 @@ KityMinder.registerModule('KeyboardModule', function() {
switch (keyEvent.keyCode) { switch (keyEvent.keyCode) {
case keys.Enter: case keys.Enter:
this.execCommand('AppendSiblingNode', lang.topic); this.execCommand('AppendSiblingNode');
e.preventDefault(); e.preventDefault();
break; break;
...@@ -199,4 +209,5 @@ KityMinder.registerModule('KeyboardModule', function() { ...@@ -199,4 +209,5 @@ KityMinder.registerModule('KeyboardModule', function() {
} }
} }
}; };
});
}); });
\ No newline at end of file
/**
* @fileOverview
*
* 布局模块
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var kity = require('../core/kity');
var Command = require('../core/command');
var Module = require('../core/module');
var LayoutCommand = kity.createClass('LayoutCommand', {
base: Command,
execute: function(minder, name) {
var nodes = minder.getSelectedNodes();
nodes.forEach(function(node) {
node.layout(name);
});
},
queryValue: function(minder) {
var node = minder.getSelectedNode();
if (node) {
return node.getData('layout');
}
},
queryState: function(minder) {
return minder.getSelectedNode() ? 0 : -1;
}
});
var ResetLayoutCommand = kity.createClass('ResetLayoutCommand', {
base: Command,
execute: function(minder, name) {
var nodes = minder.getSelectedNodes();
if (!nodes.length) nodes = [minder.getRoot()];
nodes.forEach(function(node) {
node.traverse(function(child) {
child.resetLayoutOffset();
if (!child.isRoot()) {
child.setData('layout', null);
}
});
});
minder.layout(300);
},
enableReadOnly: true
});
Module.register('LayoutModule', {
commands: {
'layout': LayoutCommand,
'resetlayout': ResetLayoutCommand
},
contextmenu: [{
command: 'resetlayout'
}, {
divider: true
}],
commandShortcutKeys: {
'resetlayout': 'Ctrl+Shift+L'
}
});
});
\ No newline at end of file
var AppendChildCommand = kity.createClass('AppendChildCommand', { 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 Renderer = require('core/render');
var AppendChildCommand = kity.createClass('AppendChildCommand', {
base: Command, base: Command,
execute: function(km, text) { execute: function(km, text) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if (!parent) { if (!parent) {
return null; return null;
} }
text = text || km.getLang('topic');
parent.expand(); parent.expand();
var node = km.createNode(text, parent); var node = km.createNode(text, parent);
km.select(node, true); km.select(node, true);
...@@ -16,9 +25,9 @@ var AppendChildCommand = kity.createClass('AppendChildCommand', { ...@@ -16,9 +25,9 @@ var AppendChildCommand = kity.createClass('AppendChildCommand', {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1; return selectedNode ? 0 : -1;
} }
}); });
var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', { var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
base: Command, base: Command,
execute: function(km, text) { execute: function(km, text) {
var sibling = km.getSelectedNode(); var sibling = km.getSelectedNode();
...@@ -26,7 +35,6 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', { ...@@ -26,7 +35,6 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
if (!parent) { if (!parent) {
return km.execCommand('AppendChildNode', text); return km.execCommand('AppendChildNode', text);
} }
text = text || km.getLang('topic');
var node = km.createNode(text, parent, sibling.getIndex() + 1); var node = km.createNode(text, parent, sibling.getIndex() + 1);
km.select(node, true); km.select(node, true);
node.render(); node.render();
...@@ -36,9 +44,9 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', { ...@@ -36,9 +44,9 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1; return selectedNode ? 0 : -1;
} }
}); });
var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', { var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
base: Command, base: Command,
execute: function(km, text) { execute: function(km, text) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
...@@ -55,9 +63,9 @@ var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', { ...@@ -55,9 +63,9 @@ var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1; return selectedNode ? 0 : -1;
} }
}); });
var EditNodeCommand = kity.createClass('EditNodeCommand', { var EditNodeCommand = kity.createClass('EditNodeCommand', {
base: Command, base: Command,
execute: function(km) { execute: function(km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
...@@ -78,9 +86,9 @@ var EditNodeCommand = kity.createClass('EditNodeCommand', { ...@@ -78,9 +86,9 @@ var EditNodeCommand = kity.createClass('EditNodeCommand', {
isNeedUndo: function() { isNeedUndo: function() {
return false; return false;
} }
}); });
KityMinder.registerModule('NodeModule', function() { Module.register('NodeModule', function() {
return { return {
commands: { commands: {
...@@ -109,4 +117,5 @@ KityMinder.registerModule('NodeModule', function() { ...@@ -109,4 +117,5 @@ KityMinder.registerModule('NodeModule', function() {
'removenode': 'normal::Del|Backspace' 'removenode': 'normal::Del|Backspace'
} }
}; };
});
}); });
\ No newline at end of file
...@@ -6,7 +6,17 @@ ...@@ -6,7 +6,17 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
KityMinder.registerModule('NoteModule', 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 Renderer = require('core/render');
Module.register('NoteModule', function() {
var NOTE_PATH = 'M9,9H3V8h6L9,9L9,9z M9,7H3V6h6V7z M9,5H3V4h6V5z M8.5,11H2V2h8v7.5 M9,12l2-2V1H1v11'; var NOTE_PATH = 'M9,9H3V8h6L9,9L9,9z M9,7H3V6h6V7z M9,5H3V4h6V5z M8.5,11H2V2h8v7.5 M9,12l2-2V1H1v11';
...@@ -52,7 +62,7 @@ KityMinder.registerModule('NoteModule', function() { ...@@ -52,7 +62,7 @@ KityMinder.registerModule('NoteModule', function() {
}); });
var NoteIconRenderer = kity.createClass('NoteIconRenderer', { var NoteIconRenderer = kity.createClass('NoteIconRenderer', {
base: KityMinder.Renderer, base: Renderer,
create: function(node) { create: function(node) {
var icon = new NoteIcon(); var icon = new NoteIcon();
...@@ -93,4 +103,5 @@ KityMinder.registerModule('NoteModule', function() { ...@@ -93,4 +103,5 @@ KityMinder.registerModule('NoteModule', function() {
'note': NoteCommand 'note': NoteCommand
} }
}; };
});
}); });
\ No newline at end of file
/* global Renderer: true */ 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 Renderer = require('core/render');
var OutlineRenderer = kity.createClass('OutlineRenderer', { var OutlineRenderer = kity.createClass('OutlineRenderer', {
base: Renderer, base: Renderer,
create: function(node) { create: function(node) {
var outline = new kity.Rect() var outline = new kity.Rect()
.setId(KityMinder.uuid('node_outline')); .setId(utils.uuid('node_outline'));
this.bringToBack = true; this.bringToBack = true;
...@@ -40,9 +47,9 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', { ...@@ -40,9 +47,9 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', {
return new kity.Box(outlineBox); return new kity.Box(outlineBox);
} }
}); });
var ShadowRenderer = kity.createClass('ShadowRenderer', { var ShadowRenderer = kity.createClass('ShadowRenderer', {
base: Renderer, base: Renderer,
create: function(node) { create: function(node) {
...@@ -60,19 +67,19 @@ var ShadowRenderer = kity.createClass('ShadowRenderer', { ...@@ -60,19 +67,19 @@ var ShadowRenderer = kity.createClass('ShadowRenderer', {
.fill(node.getStyle('shadow')) .fill(node.getStyle('shadow'))
.setRadius(node.getStyle('radius')); .setRadius(node.getStyle('radius'));
} }
}); });
var marker = new kity.Marker(); var marker = new kity.Marker();
marker.setWidth(10); marker.setWidth(10);
marker.setHeight(12); marker.setHeight(12);
marker.setRef(0, 0); marker.setRef(0, 0);
marker.setViewBox(-6, -4, 8, 10); marker.setViewBox(-6, -4, 8, 10);
marker.addShape(new kity.Path().setPathData('M-5-3l5,3,-5,3').stroke('#33ffff')); marker.addShape(new kity.Path().setPathData('M-5-3l5,3,-5,3').stroke('#33ffff'));
var wireframeOption = /wire/.test(window.location.href); var wireframeOption = /wire/.test(window.location.href);
var WireframeRenderer = kity.createClass('WireframeRenderer', { var WireframeRenderer = kity.createClass('WireframeRenderer', {
base: Renderer, base: Renderer,
create: function() { create: function() {
...@@ -110,9 +117,9 @@ var WireframeRenderer = kity.createClass('WireframeRenderer', { ...@@ -110,9 +117,9 @@ var WireframeRenderer = kity.createClass('WireframeRenderer', {
this.vectorIn.setPathData(['M', pin.offset(vin.reverse()), 'L', pin]); this.vectorIn.setPathData(['M', pin.offset(vin.reverse()), 'L', pin]);
this.vectorOut.setPathData(['M', pout, 'l', vout]); this.vectorOut.setPathData(['M', pout, 'l', vout]);
} }
}); });
KityMinder.registerModule('OutlineModule', function() { Module.register('OutlineModule', function() {
return { return {
events: (!wireframeOption ? null : { events: (!wireframeOption ? null : {
'ready': function() { 'ready': function() {
...@@ -129,4 +136,5 @@ KityMinder.registerModule('OutlineModule', function() { ...@@ -129,4 +136,5 @@ KityMinder.registerModule('OutlineModule', function() {
outside: [ShadowRenderer, WireframeRenderer] outside: [ShadowRenderer, WireframeRenderer]
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule( "pasteModule", function () {
var km = this,
_cacheNodes = [],
_selectedNodes = [],
_copystatus= false,
_curstatus = false;
function appendChildNode(parent, child) {
_selectedNodes.push(child);
km.appendNode(child,parent);
child.render();
child.setLayoutOffset(null);
var children = utils.cloneArr(child.children);
for (var i = 0, ci; ci = children[i++]; ) {
appendChildNode(child, ci);
}
}
function getNodes(arr,isCut){
_cacheNodes = [];
for(var i= 0,ni;ni=arr[i++];){
_cacheNodes.push(ni.clone());
if(isCut && !ni.isRoot()){
km.removeNode(ni);
}
}
}
return {
'events': {
'normal.keydown': function (e) {
var keys = KityMinder.keymap;
var keyEvent = e.originEvent;
if (keyEvent.ctrlKey || keyEvent.metaKey) {
switch (keyEvent.keyCode) {
case keys.c:
getNodes(km.getSelectedAncestors(true));
_copystatus = true;
break;
case keys.x:
getNodes(km.getSelectedAncestors(),true);
km.layout(300);
_curstatus = true;
break;
case keys.v:
if(_cacheNodes.length){
var node = km.getSelectedNode();
if(node){
km.fire('saveScene');
for(var i= 0,ni;ni=_cacheNodes[i++];){
appendChildNode(node,ni.clone());
}
km.layout(300);
km.select(_selectedNodes,true);
_selectedNodes = [];
km.fire('saveScene');
}
}
}
}
}
}
};
} );
\ No newline at end of file
KityMinder.registerModule('PriorityModule', 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 Renderer = require('core/render');
Module.register('PriorityModule', function() {
var minder = this; var minder = this;
// Designed by Akikonata // Designed by Akikonata
// [MASK, BACK] // [MASK, BACK]
var PRIORITY_COLORS = [null, var PRIORITY_COLORS = [null, ['#FF1200', '#840023'], // 1 - red
['#FF1200', '#840023'], // 1 - red
['#0074FF', '#01467F'], // 2 - blue ['#0074FF', '#01467F'], // 2 - blue
['#00AF00', '#006300'], // 3 - green ['#00AF00', '#006300'], // 3 - green
['#FF962E', '#B25000'], // 4 - orange ['#FF962E', '#B25000'], // 4 - orange
...@@ -15,6 +24,7 @@ KityMinder.registerModule('PriorityModule', function() { ...@@ -15,6 +24,7 @@ KityMinder.registerModule('PriorityModule', function() {
['#A3A3A3', '#515151'], ['#A3A3A3', '#515151'],
]; // hue from 1 to 5 ]; // hue from 1 to 5
// jscs:disable maximumLineLength
var BACK_PATH = 'M0,13c0,3.866,3.134,7,7,7h6c3.866,0,7-3.134,7-7V7H0V13z'; var BACK_PATH = 'M0,13c0,3.866,3.134,7,7,7h6c3.866,0,7-3.134,7-7V7H0V13z';
var MASK_PATH = 'M20,10c0,3.866-3.134,7-7,7H7c-3.866,0-7-3.134-7-7V7c0-3.866,3.134-7,7-7h6c3.866,0,7,3.134,7,7V10z'; var MASK_PATH = 'M20,10c0,3.866-3.134,7-7,7H7c-3.866,0-7-3.134-7-7V7c0-3.866,3.134-7,7-7h6c3.866,0,7,3.134,7,7V10z';
...@@ -28,7 +38,7 @@ KityMinder.registerModule('PriorityModule', function() { ...@@ -28,7 +38,7 @@ KityMinder.registerModule('PriorityModule', function() {
this.callBase(); this.callBase();
this.setSize(20); this.setSize(20);
this.create(); this.create();
this.setId(KityMinder.uuid('node_priority')); this.setId(utils.uuid('node_priority'));
}, },
setSize: function(size) { setSize: function(size) {
...@@ -102,7 +112,7 @@ KityMinder.registerModule('PriorityModule', function() { ...@@ -102,7 +112,7 @@ KityMinder.registerModule('PriorityModule', function() {
}, },
'renderers': { 'renderers': {
left: kity.createClass('PriorityRenderer', { left: kity.createClass('PriorityRenderer', {
base: KityMinder.Renderer, base: Renderer,
create: function(node) { create: function(node) {
return new PriorityIcon(); return new PriorityIcon();
...@@ -133,4 +143,5 @@ KityMinder.registerModule('PriorityModule', function() { ...@@ -133,4 +143,5 @@ KityMinder.registerModule('PriorityModule', function() {
}) })
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule('ProgressModule', 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 Renderer = require('core/render');
Module.register('ProgressModule', function() {
var minder = this; var minder = this;
var PROGRESS_DATA = 'progress'; var PROGRESS_DATA = 'progress';
...@@ -8,7 +18,10 @@ KityMinder.registerModule('ProgressModule', function() { ...@@ -8,7 +18,10 @@ KityMinder.registerModule('ProgressModule', function() {
var PIE_COLOR = '#43BC00'; var PIE_COLOR = '#43BC00';
var SHADOW_PATH = 'M10,3c4.418,0,8,3.582,8,8h1c0-5.523-3.477-10-9-10S1,5.477,1,11h1C2,6.582,5.582,3,10,3z'; var SHADOW_PATH = 'M10,3c4.418,0,8,3.582,8,8h1c0-5.523-3.477-10-9-10S1,5.477,1,11h1C2,6.582,5.582,3,10,3z';
var SHADOW_COLOR = '#8E8E8E'; var SHADOW_COLOR = '#8E8E8E';
// jscs:disable maximumLineLength
var FRAME_PATH = 'M10,0C4.477,0,0,4.477,0,10c0,5.523,4.477,10,10,10s10-4.477,10-10C20,4.477,15.523,0,10,0zM10,18c-4.418,0-8-3.582-8-8s3.582-8,8-8s8,3.582,8,8S14.418,18,10,18z'; var FRAME_PATH = 'M10,0C4.477,0,0,4.477,0,10c0,5.523,4.477,10,10,10s10-4.477,10-10C20,4.477,15.523,0,10,0zM10,18c-4.418,0-8-3.582-8-8s3.582-8,8-8s8,3.582,8,8S14.418,18,10,18z';
var FRAME_GRAD = new kity.LinearGradientBrush().pipe(function(g) { var FRAME_GRAD = new kity.LinearGradientBrush().pipe(function(g) {
g.setStartPosition(0, 0); g.setStartPosition(0, 0);
g.setEndPosition(0, 1); g.setEndPosition(0, 1);
...@@ -29,7 +42,7 @@ KityMinder.registerModule('ProgressModule', function() { ...@@ -29,7 +42,7 @@ KityMinder.registerModule('ProgressModule', function() {
this.setSize(20); this.setSize(20);
this.create(); this.create();
this.setValue(value); this.setValue(value);
this.setId(KityMinder.uuid('node_progress')); this.setId(utils.uuid('node_progress'));
this.translate(0.5, 0.5); this.translate(0.5, 0.5);
}, },
...@@ -89,7 +102,7 @@ KityMinder.registerModule('ProgressModule', function() { ...@@ -89,7 +102,7 @@ KityMinder.registerModule('ProgressModule', function() {
val = nodes[i].getData(PROGRESS_DATA); val = nodes[i].getData(PROGRESS_DATA);
if (val) break; if (val) break;
} }
return val|| null; return val || null;
}, },
queryState: function(km) { queryState: function(km) {
...@@ -103,7 +116,7 @@ KityMinder.registerModule('ProgressModule', function() { ...@@ -103,7 +116,7 @@ KityMinder.registerModule('ProgressModule', function() {
}, },
'renderers': { 'renderers': {
left: kity.createClass('ProgressRenderer', { left: kity.createClass('ProgressRenderer', {
base: KityMinder.Renderer, base: Renderer,
create: function(node) { create: function(node) {
return new ProgressIcon(); return new ProgressIcon();
...@@ -129,4 +142,5 @@ KityMinder.registerModule('ProgressModule', function() { ...@@ -129,4 +142,5 @@ KityMinder.registerModule('ProgressModule', function() {
}) })
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule('Resource', 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 Renderer = require('core/render');
Module.register('Resource', function() {
/** /**
* 自动使用的颜色序列 * 自动使用的颜色序列
...@@ -10,9 +20,9 @@ KityMinder.registerModule('Resource', function() { ...@@ -10,9 +20,9 @@ KityMinder.registerModule('Resource', function() {
var RESOURCE_COLOR_OVERFLOW = kity.Color.createHSL(0, 0, 95); var RESOURCE_COLOR_OVERFLOW = kity.Color.createHSL(0, 0, 95);
/** /**
* 在 KityMinder 上拓展一些关于资源的支持接口 * 在 Minder 上拓展一些关于资源的支持接口
*/ */
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
/** /**
* 获取脑图中某个资源对应的颜色 * 获取脑图中某个资源对应的颜色
...@@ -213,7 +223,7 @@ KityMinder.registerModule('Resource', function() { ...@@ -213,7 +223,7 @@ KityMinder.registerModule('Resource', function() {
* @class 资源渲染器 * @class 资源渲染器
*/ */
var ResourceRenderer = kity.createClass('ResourceRenderer', { var ResourceRenderer = kity.createClass('ResourceRenderer', {
base: KityMinder.Renderer, base: Renderer,
create: function(node) { create: function(node) {
this.overlays = []; this.overlays = [];
...@@ -271,4 +281,5 @@ KityMinder.registerModule('Resource', function() { ...@@ -271,4 +281,5 @@ KityMinder.registerModule('Resource', function() {
right: ResourceRenderer right: ResourceRenderer
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule('Select', 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 Renderer = require('core/render');
Module.register('Select', function() {
var minder = this; var minder = this;
var rc = minder.getRenderContainer(); var rc = minder.getRenderContainer();
var g = KityMinder.Geometry;
// 在实例上渲染框选矩形、计算框选范围的对象 // 在实例上渲染框选矩形、计算框选范围的对象
var marqueeActivator = (function() { var marqueeActivator = (function() {
...@@ -99,7 +108,8 @@ KityMinder.registerModule('Select', function() { ...@@ -99,7 +108,8 @@ KityMinder.registerModule('Select', function() {
}; };
})(); })();
var lastDownNode = null, lastDownPosition = null; var lastDownNode = null,
lastDownPosition = null;
return { return {
'init': function() { 'init': function() {
window.addEventListener('mouseup', function() { window.addEventListener('mouseup', function() {
...@@ -156,18 +166,19 @@ KityMinder.registerModule('Select', function() { ...@@ -156,18 +166,19 @@ KityMinder.registerModule('Select', function() {
marqueeActivator.selectEnd(e); marqueeActivator.selectEnd(e);
}, },
//全选操作 //全选操作
'normal.keydown inputready.keydown':function(e){ 'normal.keydown inputready.keydown': function(e) {
if ( e.isShortcutKey('ctrl+a') ){ if (e.isShortcutKey('ctrl+a')) {
var selectedNodes = []; var selectedNodes = [];
this.getRoot().traverse(function(node){ this.getRoot().traverse(function(node) {
selectedNodes.push(node); selectedNodes.push(node);
}); });
this.select(selectedNodes,true); this.select(selectedNodes, true);
e.preventDefault(); e.preventDefault();
} }
} }
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule('StyleModule', 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 Renderer = require('core/render');
Module.register('StyleModule', function() {
var styleNames = ['font-size', 'font-family', 'font-weight', 'font-style', 'background', 'color']; var styleNames = ['font-size', 'font-family', 'font-weight', 'font-style', 'background', 'color'];
var styleClipBoard = null; var styleClipBoard = null;
function hasStyle(node) { function hasStyle(node) {
var data = node.getData(); var data = node.getData();
for(var i = 0; i < styleNames.length; i++) { for (var i = 0; i < styleNames.length; i++) {
if (styleNames[i] in data) return true; if (styleNames[i] in data) return true;
} }
} }
return { return {
"commands": { 'commands': {
"copystyle": kity.createClass("CopyStyleCommand", { 'copystyle': kity.createClass('CopyStyleCommand', {
base: Command, base: Command,
execute: function(minder) { execute: function(minder) {
...@@ -35,7 +45,7 @@ KityMinder.registerModule('StyleModule', function() { ...@@ -35,7 +45,7 @@ KityMinder.registerModule('StyleModule', function() {
} }
}), }),
"pastestyle": kity.createClass("PastStyleCommand", { 'pastestyle': kity.createClass('PastStyleCommand', {
base: Command, base: Command,
execute: function(minder) { execute: function(minder) {
...@@ -55,7 +65,7 @@ KityMinder.registerModule('StyleModule', function() { ...@@ -55,7 +65,7 @@ KityMinder.registerModule('StyleModule', function() {
} }
}), }),
"clearstyle": kity.createClass("ClearStyleCommand", { 'clearstyle': kity.createClass('ClearStyleCommand', {
base: Command, base: Command,
execute: function(minder) { execute: function(minder) {
minder.getSelectedNodes().forEach(function(node) { minder.getSelectedNodes().forEach(function(node) {
...@@ -71,7 +81,7 @@ KityMinder.registerModule('StyleModule', function() { ...@@ -71,7 +81,7 @@ KityMinder.registerModule('StyleModule', function() {
queryState: function(minder) { queryState: function(minder) {
var nodes = minder.getSelectedNodes(); var nodes = minder.getSelectedNodes();
if (!nodes.length) return -1; if (!nodes.length) return -1;
for(var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
if (hasStyle(nodes[i])) return 0; if (hasStyle(nodes[i])) return 0;
} }
return -1; return -1;
...@@ -79,4 +89,5 @@ KityMinder.registerModule('StyleModule', function() { ...@@ -79,4 +89,5 @@ KityMinder.registerModule('StyleModule', function() {
}) })
} }
}; };
});
}); });
\ No newline at end of file
/* global Renderer: true */ define(function(require, exports, module) {
var kity = require('core/kity');
var FONT_ADJUST = { 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 Renderer = require('core/render');
var FONT_ADJUST = {
'微软雅黑,Microsoft YaHei': -0.15, '微软雅黑,Microsoft YaHei': -0.15,
'arial black,avant garde': -0.17, 'arial black,avant garde': -0.17,
'default': -0.15 'default': -0.15
}; };
var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { var TextRenderer = kity.createClass('TextRenderer', {
base: Renderer, base: Renderer,
create: function() { create: function() {
return new kity.Group().setId(KityMinder.uuid('node_text')); return new kity.Group().setId(utils.uuid('node_text'));
}, },
update: function(textGroup, node) { update: function(textGroup, node) {
...@@ -19,7 +26,8 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { ...@@ -19,7 +26,8 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
return node.getData(name) || node.getStyle(name); return node.getData(name) || node.getStyle(name);
} }
var textArr = node.getText(true); var nodeText = node.getText() || '';
var textArr = nodeText.split('\n');
var lineHeight = node.getStyle('line-height'); var lineHeight = node.getStyle('line-height');
...@@ -42,14 +50,16 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { ...@@ -42,14 +50,16 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
var textGroupLength = textGroup.getItems().length; var textGroupLength = textGroup.getItems().length;
if(textLength < textGroupLength){ var i, ci, textShape, text;
for( var i = textLength,ci;ci = textGroup.getItem(i);){
if (textLength < textGroupLength) {
for (i = textLength, ci; ci = textGroup.getItem(i);) {
textGroup.removeItem(i); textGroup.removeItem(i);
} }
}else if(textLength > textGroupLength){ } else if (textLength > textGroupLength) {
var length = textLength - textGroupLength; var length = textLength - textGroupLength;
for(var i = 0;i < length;i++){ for (i = 0; i < length; i++) {
var textShape = new kity.Text() textShape = new kity.Text()
.setAttr('text-rendering', 'inherit'); .setAttr('text-rendering', 'inherit');
if (kity.Browser.ie) { if (kity.Browser.ie) {
textShape.setVerticalAlign('top'); textShape.setVerticalAlign('top');
...@@ -61,14 +71,15 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { ...@@ -61,14 +71,15 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
} }
for (var i = 0, text, textShape; for (i = 0, text, textShape;
(text = textArr[i], textShape = textGroup.getItem(i)); i++) { (text = textArr[i], textShape = textGroup.getItem(i)); i++) {
textShape.setContent(text); textShape.setContent(text);
} }
this.setTextStyle(node, textGroup); this.setTextStyle(node, textGroup);
var textHash = node.getText() + [s('font-size'), s('font-name'), s('font-weight'), s('font-style')].join('/'); var textHash = node.getText() +
[s('font-size'), s('font-name'), s('font-weight'), s('font-style')].join('/');
if (node._currentTextHash == textHash && node._currentTextGroupBox) return node._currentTextGroupBox; if (node._currentTextHash == textHash && node._currentTextGroupBox) return node._currentTextGroupBox;
...@@ -97,23 +108,27 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { ...@@ -97,23 +108,27 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
hook(node, text); hook(node, text);
}); });
} }
}); });
utils.extend(TextRenderer, { utils.extend(TextRenderer, {
_styleHooks: [], _styleHooks: [],
registerStyleHook: function(fn) { registerStyleHook: function(fn) {
TextRenderer._styleHooks.push(fn); TextRenderer._styleHooks.push(fn);
} }
}); });
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
getTextGroup: function() { getTextGroup: function() {
return this.getRenderer('TextRenderer').getRenderShape(); return this.getRenderer('TextRenderer').getRenderShape();
} }
}); });
KityMinder.registerModule('text', {
Module.register('text', {
'renderers': { 'renderers': {
center: TextRenderer center: TextRenderer
} }
});
module.exports = TextRenderer;
}); });
\ No newline at end of file
var ViewDragger = kity.createClass("ViewDragger", { 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 Renderer = require('core/render');
var ViewDragger = kity.createClass('ViewDragger', {
constructor: function(minder) { constructor: function(minder) {
this._minder = minder; this._minder = minder;
this._enabled = false; this._enabled = false;
...@@ -97,7 +107,8 @@ var ViewDragger = kity.createClass("ViewDragger", { ...@@ -97,7 +107,8 @@ var ViewDragger = kity.createClass("ViewDragger", {
this._minder.on('normal.mousedown normal.touchstart ' + this._minder.on('normal.mousedown normal.touchstart ' +
'inputready.mousedown inputready.touchstart ' + 'inputready.mousedown inputready.touchstart ' +
'readonly.mousedown readonly.touchstart', function(e) { 'readonly.mousedown readonly.touchstart',
function(e) {
if (e.originEvent.button == 2) { if (e.originEvent.button == 2) {
e.originEvent.preventDefault(); // 阻止中键拉动 e.originEvent.preventDefault(); // 阻止中键拉动
} }
...@@ -110,7 +121,8 @@ var ViewDragger = kity.createClass("ViewDragger", { ...@@ -110,7 +121,8 @@ var ViewDragger = kity.createClass("ViewDragger", {
.on('normal.mousemove normal.touchmove ' + .on('normal.mousemove normal.touchmove ' +
'readonly.mousemove readonly.touchmove ' + 'readonly.mousemove readonly.touchmove ' +
'inputready.mousemove inputready.touchmove', function(e) { 'inputready.mousemove inputready.touchmove',
function(e) {
if (e.type == 'touchmove') { if (e.type == 'touchmove') {
e.preventDefault(); // 阻止浏览器的后退事件 e.preventDefault(); // 阻止浏览器的后退事件
} }
...@@ -154,9 +166,9 @@ var ViewDragger = kity.createClass("ViewDragger", { ...@@ -154,9 +166,9 @@ var ViewDragger = kity.createClass("ViewDragger", {
e.preventDefault(); e.preventDefault();
}); });
} }
}); });
KityMinder.registerModule('View', function() { Module.register('View', function() {
var km = this; var km = this;
...@@ -287,12 +299,12 @@ KityMinder.registerModule('View', function() { ...@@ -287,12 +299,12 @@ KityMinder.registerModule('View', function() {
var view = dragger.getView(); var view = dragger.getView();
var focus = selected.getLayoutBox(); var focus = selected.getLayoutBox();
var space = 50; var space = 50;
var dx = 0, dy = 0; var dx = 0,
dy = 0;
if (focus.right > view.right) { if (focus.right > view.right) {
dx += view.right - focus.right - space; dx += view.right - focus.right - space;
} } else if (focus.left < view.left) {
else if (focus.left < view.left) {
dx += view.left - focus.left + space; dx += view.left - focus.left + space;
} }
...@@ -303,8 +315,11 @@ KityMinder.registerModule('View', function() { ...@@ -303,8 +315,11 @@ KityMinder.registerModule('View', function() {
dy += view.top - focus.top + space; dy += view.top - focus.top + space;
} }
if (dx || dy) dragger.move(new kity.Point(dx, dy), 100); if (dx || dy) {
dragger.move(new kity.Point(dx, dy), 100);
}
} }
} }
}; };
});
}); });
\ No newline at end of file
KityMinder.registerModule('Zoom', 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 Renderer = require('core/render');
Module.register('Zoom', function() {
var me = this; var me = this;
var timeline; var timeline;
...@@ -15,7 +25,7 @@ KityMinder.registerModule('Zoom', function() { ...@@ -15,7 +25,7 @@ KityMinder.registerModule('Zoom', function() {
node.setAttribute('transform', 'matrix(' + matrix.toString() + ')'); node.setAttribute('transform', 'matrix(' + matrix.toString() + ')');
} }
kity.extendClass(KityMinder, { kity.extendClass(Minder, {
zoom: function(value) { zoom: function(value) {
var paper = this.getPaper(); var paper = this.getPaper();
var viewport = paper.getViewPort(); var viewport = paper.getViewPort();
...@@ -61,7 +71,9 @@ KityMinder.registerModule('Zoom', function() { ...@@ -61,7 +71,9 @@ KityMinder.registerModule('Zoom', function() {
minder.fire('viewchange'); minder.fire('viewchange');
}); });
} }
minder.fire('zoom', { zoom: value }); minder.fire('zoom', {
zoom: value
});
} }
var ZoomCommand = kity.createClass('Zoom', { var ZoomCommand = kity.createClass('Zoom', {
...@@ -81,7 +93,7 @@ KityMinder.registerModule('Zoom', function() { ...@@ -81,7 +93,7 @@ KityMinder.registerModule('Zoom', function() {
return +!this.nextValue(minder); return +!this.nextValue(minder);
}, },
nextValue: function(minder) { nextValue: function(minder) {
var stack = minder.getOptions('zoom'), var stack = minder.getOption('zoom'),
i; i;
for (i = 0; i < stack.length; i++) { for (i = 0; i < stack.length; i++) {
if (stack[i] > minder._zoomValue) return stack[i]; if (stack[i] > minder._zoomValue) return stack[i];
...@@ -100,7 +112,7 @@ KityMinder.registerModule('Zoom', function() { ...@@ -100,7 +112,7 @@ KityMinder.registerModule('Zoom', function() {
return +!this.nextValue(minder); return +!this.nextValue(minder);
}, },
nextValue: function(minder) { nextValue: function(minder) {
var stack = minder.getOptions('zoom'), var stack = minder.getOption('zoom'),
i; i;
for (i = stack.length - 1; i >= 0; i--) { for (i = stack.length - 1; i >= 0; i--) {
if (stack[i] < minder._zoomValue) return stack[i]; if (stack[i] < minder._zoomValue) return stack[i];
...@@ -157,4 +169,5 @@ KityMinder.registerModule('Zoom', function() { ...@@ -157,4 +169,5 @@ KityMinder.registerModule('Zoom', function() {
'zoom-out': 'ctrl+-' 'zoom-out': 'ctrl+-'
} }
}; };
});
}); });
\ No newline at end of file
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('default', { template.register('default', {
getLayout: function(node) { getLayout: function(node) {
...@@ -32,4 +34,5 @@ KityMinder.registerTemplate('default', { ...@@ -32,4 +34,5 @@ KityMinder.registerTemplate('default', {
if (node.getLevel() == 1) return 'arc'; if (node.getLevel() == 1) return 'arc';
return 'under'; return 'under';
} }
});
}); });
\ No newline at end of file
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('filetree', { template.register('filetree', {
getLayout: function(node) { getLayout: function(node) {
if (node.getData('layout')) return node.getData('layout'); if (node.getData('layout')) return node.getData('layout');
...@@ -22,4 +24,5 @@ KityMinder.registerTemplate('filetree', { ...@@ -22,4 +24,5 @@ KityMinder.registerTemplate('filetree', {
} }
return 'l'; return 'l';
} }
});
}); });
\ No newline at end of file
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('fish-bone', { template.register('fish-bone', {
getLayout: function(node) { getLayout: function(node) {
...@@ -35,4 +37,5 @@ KityMinder.registerTemplate('fish-bone', { ...@@ -35,4 +37,5 @@ KityMinder.registerTemplate('fish-bone', {
default: return 'l'; default: return 'l';
} }
} }
});
}); });
\ No newline at end of file
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('right', { template.register('right', {
getLayout: function(node) { getLayout: function(node) {
return node.getData('layout') || 'right'; return node.getData('layout') || 'right';
...@@ -17,4 +19,5 @@ KityMinder.registerTemplate('right', { ...@@ -17,4 +19,5 @@ KityMinder.registerTemplate('right', {
if (node.getLevel() == 1) return 'arc'; if (node.getLevel() == 1) return 'arc';
return 'bezier'; return 'bezier';
} }
});
}); });
\ No newline at end of file
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* @author: techird * @author: techird
* @copyright: Baidu FEX, 2014 * @copyright: Baidu FEX, 2014
*/ */
define(function(require, exports, module) {
var template = require('core/template');
KityMinder.registerTemplate('structure', { template.register('structure', {
getLayout: function(node) { getLayout: function(node) {
return node.getData('layout') || 'bottom'; return node.getData('layout') || 'bottom';
...@@ -16,4 +18,5 @@ KityMinder.registerTemplate('structure', { ...@@ -16,4 +18,5 @@ KityMinder.registerTemplate('structure', {
getConnect: function(node) { getConnect: function(node) {
return 'poly'; return 'poly';
} }
});
}); });
\ No newline at end of file
['classic', 'classic-compact'].forEach(function(name) { define(function(require, exports, module) {
var theme = require('core/theme');
['classic', 'classic-compact'].forEach(function(name) {
var compact = name == 'classic-compact'; var compact = name == 'classic-compact';
KityMinder.registerTheme(name, { /* jscs:disable maximumLineLength */
'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat', theme.register(name, {
'background': '#3A4144 url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowQzg5QTQ0NDhENzgxMUUzOENGREE4QTg0RDgzRTZDNyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDowQzg5QTQ0NThENzgxMUUzOENGREE4QTg0RDgzRTZDNyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkMwOEQ1NDRGOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkMwOEQ1NDUwOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+e9P33AAAACVJREFUeNpisXJ0YUACTAyoAMr/+eM7EGGRZ4FQ7BycEAZAgAEAHbEGtkoQm/wAAAAASUVORK5CYII=") repeat',
'root-color': '#430', 'root-color': '#430',
'root-background': '#e9df98', 'root-background': '#e9df98',
...@@ -58,4 +62,5 @@ ...@@ -58,4 +62,5 @@
'text-selection-color': 'rgb(27,171,255)', 'text-selection-color': 'rgb(27,171,255)',
'line-height':1.5 'line-height':1.5
}); });
});
}); });
\ No newline at end of file
KityMinder.registerTheme('fish', { define(function(require, exports, module) {
var theme = require('core/theme');
theme.register('fish', {
'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat', 'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',
'root-color': '#430', 'root-color': '#430',
...@@ -50,4 +53,5 @@ KityMinder.registerTheme('fish', { ...@@ -50,4 +53,5 @@ KityMinder.registerTheme('fish', {
'text-selection-color': 'rgb(27,171,255)', 'text-selection-color': 'rgb(27,171,255)',
'line-height':1.5 'line-height':1.5
});
}); });
\ No newline at end of file
(function() { define(function(require, exports, module) {
var kity = require('core/kity');
var theme = require('core/theme');
function hsl(h, s, l) { function hsl(h, s, l) {
return kity.Color.createHSL(h, s, l); return kity.Color.createHSL(h, s, l);
} }
...@@ -67,8 +70,8 @@ ...@@ -67,8 +70,8 @@
}; };
var name; var name;
for (name in plans) { for (name in plans) {
KityMinder.registerTheme('fresh-' + name, generate(plans[name])); theme.register('fresh-' + name, generate(plans[name]));
KityMinder.registerTheme('fresh-' + name + '-compat', generate(plans[name], true)); theme.register('fresh-' + name + '-compat', generate(plans[name], true));
} }
})(); });
\ No newline at end of file \ No newline at end of file
define(function(require, exports, module) {
var theme = require('core/theme');
['snow', 'snow-compact'].forEach(function(name) {
['snow', 'snow-compact'].forEach(function(name) {
var compact = name == 'snow-compact'; var compact = name == 'snow-compact';
KityMinder.registerTheme(name, { /* jscs:disable maximumLineLength */
'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat', theme.register(name, {
'background': '#3A4144 url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowQzg5QTQ0NDhENzgxMUUzOENGREE4QTg0RDgzRTZDNyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDowQzg5QTQ0NThENzgxMUUzOENGREE4QTg0RDgzRTZDNyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkMwOEQ1NDRGOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkMwOEQ1NDUwOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+e9P33AAAACVJREFUeNpisXJ0YUACTAyoAMr/+eM7EGGRZ4FQ7BycEAZAgAEAHbEGtkoQm/wAAAAASUVORK5CYII=") repeat',
'root-color': '#430', 'root-color': '#430',
'root-background': '#e9df98', 'root-background': '#e9df98',
...@@ -56,4 +58,5 @@ ...@@ -56,4 +58,5 @@
'text-selection-color': 'rgb(27,171,255)', 'text-selection-color': 'rgb(27,171,255)',
'line-height':1.5 'line-height':1.5
}); });
});
}); });
\ No newline at end of file
KityMinder.registerTheme('wire', { define(function(require, exports, module) {
var theme = require('core/theme');
theme.register('wire', {
'background': 'black', 'background': 'black',
'color': '#999', 'color': '#999',
...@@ -27,4 +30,5 @@ KityMinder.registerTheme('wire', { ...@@ -27,4 +30,5 @@ KityMinder.registerTheme('wire', {
'text-selection-color': 'rgb(27,171,255)', 'text-selection-color': 'rgb(27,171,255)',
'line-height':1.5 'line-height':1.5
});
}); });
\ No newline at end of file
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