UNPKG

ts-mind

Version:

A web-mind lib write in typescript.Sound apis and friendly plug-in mechanism in this lib.

1,399 lines (1,373 loc) 159 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("TSMind", [], factory); else if(typeof exports === 'object') exports["TSMind"] = factory(); else root["TSMind"] = factory(); })(window, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 12); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; exports.$noop = function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { arg[_i] = arguments[_i]; } }; exports.$logger = console || { log: exports.$noop, debug: exports.$noop, error: exports.$noop, warn: exports.$noop, info: exports.$noop }; // NODE Operation exports.$doc = window.document; // $g=>getElementById function $elByID(id) { return exports.$doc.getElementById(id); } exports.$elByID = $elByID; // $t=>push-textNode function $pushText(parent, txt) { if (parent.hasChildNodes()) { parent.firstChild.nodeValue = txt; } else parent.appendChild(exports.$doc.createTextNode(txt)); } exports.$pushText = $pushText; // $h=>push-childNode function $pushChild(parent, child) { if (child instanceof HTMLElement) { parent.innerHTML = ""; parent.appendChild(child); } else { parent.innerHTML = child; } } exports.$pushChild = $pushChild; // $i=>isElement function $isEl(el) { return "nodeType" in el; } exports.$isEl = $isEl; // To determine whether a string starting with [beg]. function $startWith(str, beg) { return str.slice(0, beg.length) === beg; } exports.$startWith = $startWith; // To determine whether a target is a Function. function $isFunc(tar) { return typeof tar === "function"; } exports.$isFunc = $isFunc; // The abbreviation of hasOwnProperty method. exports.$hasOwnProperty = Object.prototype.hasOwnProperty; // To determine the plain-object. function $isPlainObject(obj) { // Must be an Object. // Because of IE, we also have to check the presence of the constructor property. // Make sure that DOM nodes and window objects don't pass through, as well if (!obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval) { return false; } // Not own constructor property must be Object if (obj.constructor && !exports.$hasOwnProperty.call(obj, "constructor") && !exports.$hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) { return false; } // Own properties are enumerated firstly, so to speed up, // if last one is own, then all properties are own. var key; for (key in obj) { } return key === undefined || exports.$hasOwnProperty.call(obj, key); } exports.$isPlainObject = $isPlainObject; function $extend() { var options; var name; var src; var copy; var copyIsArray; var clone; var target = arguments[0] || {}; var i = 1; var length = arguments.length; var deep = false; // Handle a deep copy situation if (typeof target === "boolean") { deep = target; // Skip the boolean and the target target = arguments[i] || {}; i++; } // Handle case when target is a string or something (possible in deep copy) if (typeof target !== "object" && !$isFunc(target)) { target = {}; } // Extend jQuery itself if only one argument is passed if (i === length) { target = this || {}; i--; } for (; i < length; i++) { options = arguments[i]; // Only deal with non-null/undefined values if (options !== null) { // Extend the base object for (name in options) { if (!!name) { copy = options[name]; // Prevent never-ending loop if (target === copy) { continue; } copyIsArray = Array.isArray(copy); // Recurse if we're merging plain objects or arrays if (deep && copy && ($isPlainObject(copy) || copyIsArray)) { src = target[name]; // Ensure proper type for the source value if (copyIsArray && !Array.isArray(src)) { clone = []; } else if (!copyIsArray && !$isPlainObject(src)) { clone = {}; } else { clone = src; } copyIsArray = false; // Never move original objects, clone them target[name] = $extend(deep, clone, copy); // Don't bring in undefined values } else if (copy !== undefined) { target[name] = copy; } } } } } // Return the modified object return target; } exports.$extend = $extend; // debounce method function $debounce(handler, tick) { if (tick === void 0) { tick = 10; } var _timer = null; function _dbce() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _ctx = this; if (_timer) { return; } _timer = setTimeout(function () { handler.apply(_ctx, args); _timer = null; }, tick); } // clear debounce _dbce.clear = function () { clearTimeout(_timer); _timer = null; }; return _dbce; } exports.$debounce = $debounce; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var constants_1 = __webpack_require__(2); var tools_1 = __webpack_require__(0); var data_1 = __webpack_require__(14); var layout_1 = __webpack_require__(20); var view_1 = __webpack_require__(21); var util_1 = __webpack_require__(7); var node_array_1 = __webpack_require__(9); var shortcut_1 = __webpack_require__(22); var pugin_1 = __webpack_require__(23); // global use register exports.use = pugin_1.globalUse; // mind direction exports.TSMindDirectionMap = { left: -1, center: 0, right: 1 }; // mind event type exports.TSMindEventTypeMap = { show: 1, resize: 2, edit: 3, select: 4 }; // mind core class var TSMind = /** @class */ (function () { function TSMind(options) { var _this = this; // public properties this.options = { container: "" }; this.mind = null; this.initialized = false; this.event_handles = []; // private plugin list this._plugins = {}; this.plugins = {}; /** * register private plugin * @param plugin: ITSMPlugin */ this.use = function (pname, plugin) { _this._plugins[pname] = plugin; }; // initial plugin's main methods this.init_plugins = function (tsm, opts) { var _all_plug = tools_1.$extend({}, _this._plugins, pugin_1.GLOBAl_PLUGIN_LIST); // call plugin in async way, to make sure plugin register no execution-order dependences. setTimeout(function () { for (var pname in _all_plug) { if (pname) // 确保Class类型的插件能够成功初始化 _this.plugins[pname] = new _all_plug[pname](tsm, opts); } }, 0); }; this.enable_edit = function () { return (_this.options.editable = true); }; this.disable_edit = function () { return (_this.options.editable = false); }; // call enable_event_handle('dblclick') // options are 'mousedown', 'click', 'dblclick' this.enable_event_handle = function (event_handle) { _this.options.default_event_handle["enable_" + event_handle + "_handle"] = true; }; // call disable_event_handle('dblclick') // options are 'mousedown', 'click', 'dblclick' this.disable_event_handle = function (event_handle) { _this.options.default_event_handle["enable_" + event_handle + "_handle"] = false; }; this.get_editable = function () { return _this.options.editable; }; this.set_theme = function (theme) { var theme_old = _this.options.theme; _this.options.theme = !!theme ? theme : "primary"; if (theme_old !== _this.options.theme) { _this.view_provider.reset_theme(); _this.view_provider.reset_custom_style(); } }; this._event_bind = function () { _this.view_provider.add_event(_this, "mousedown", _this.mousedown_handle); _this.view_provider.add_event(_this, "click", _this.click_handle); _this.view_provider.add_event(_this, "dblclick", _this.dblclick_handle); }; this.mousedown_handle = function (e) { if (e === void 0) { e = event; } if (!_this.options.default_event_handle.enable_mousedown_handle) { return; } var element = (e.target || e.srcElement); var nodeid = _this.view_provider.get_binded_nodeid(element); if (!!nodeid) { _this.select_node(nodeid); } else { _this.select_clear(); } }; this.click_handle = function (e) { if (e === void 0) { e = event; } if (!_this.options.default_event_handle.enable_click_handle) { return; } var element = (e.target || e.srcElement); var isexpander = _this.view_provider.is_expander(element); if (isexpander) { var nodeid = _this.view_provider.get_binded_nodeid(element); if (!!nodeid) { _this.toggle_node(nodeid); } } }; this.dblclick_handle = function (e) { if (e === void 0) { e = event; } if (!_this.options.default_event_handle.enable_dblclick_handle) { return; } if (_this.get_editable()) { var element = (e.target || e.srcElement); var nodeid = _this.view_provider.get_binded_nodeid(element); if (!!nodeid) { _this.begin_edit(nodeid); } } }; this.begin_edit = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return false; } else { return _this.begin_edit(the_node); } } if (_this.get_editable()) { _this.view_provider.edit_node_begin(node); } else { tools_1.$logger.error("fail, this mind map is not editable."); return; } }; this.end_edit = function () { _this.view_provider.edit_node_end(); }; this.toggle_node = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return; } else { return _this.toggle_node(the_node); } } if (node.isroot) { return; } _this.view_provider.save_location(node); _this.layout_provider.toggle_node(node); _this.view_provider.relayout(); _this.view_provider.restore_location(node); }; this.expand_node = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return; } else { return _this.expand_node(the_node); } } if (node.isroot) { return; } _this.view_provider.save_location(node); _this.layout_provider.expand_node(node); _this.view_provider.relayout(); _this.view_provider.restore_location(node); }; this.collapse_node = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return; } else { return _this.collapse_node(the_node); } } if (node.isroot) { return; } _this.view_provider.save_location(node); _this.layout_provider.collapse_node(node); _this.view_provider.relayout(); _this.view_provider.restore_location(node); }; this.expand_all = function () { _this.layout_provider.expand_all(); _this.view_provider.relayout(); }; this.collapse_all = function () { _this.layout_provider.collapse_all(); _this.view_provider.relayout(); }; this.expand_to_depth = function (depth) { _this.layout_provider.expand_to_depth(depth); _this.view_provider.relayout(); }; this._reset = function () { _this.view_provider.reset(); _this.layout_provider.reset(); _this.data_provider.reset(); }; this._show = function (mind) { var m = mind || node_array_1.node_array.example; _this.mind = _this.data_provider.load(m); if (!_this.mind) { tools_1.$logger.error("data.load error"); return; } else { tools_1.$logger.debug("data.load ok"); } _this.view_provider.load(); tools_1.$logger.debug("view.load ok"); _this.layout_provider.layout(); tools_1.$logger.debug("layout.layout ok"); _this.view_provider.show(true); tools_1.$logger.debug("view.show ok"); _this.invoke_event_handle(exports.TSMindEventTypeMap.show, { data: [mind] }); }; this.show = function (mind) { _this._reset(); _this._show(mind); }; this.get_meta = function () { return { name: _this.mind.name, author: _this.mind.author, version: _this.mind.version }; }; this.get_data = function (data_format) { if (data_format === void 0) { data_format = "node_tree"; } return _this.data_provider.get_data(data_format); }; this.get_root = function () { return _this.mind.root; }; this.get_node = function (nodeid) { return _this.mind.get_node(nodeid); }; this.add_node = function (parent_node, nodeid, topic, data) { if (_this.get_editable()) { var node = _this.mind.add_node(parent_node, nodeid, topic, data); if (!!node) { _this.view_provider.add_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); _this.view_provider.reset_node_custom_style(node); _this.expand_node(parent_node); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "add_node", data: [parent_node.id, nodeid, topic, data], node: nodeid }); } return node; } else { tools_1.$logger.error("fail, this mind map is not editable"); return null; } }; this.insert_node_before = function (node_before, nodeid, topic, data) { if (_this.get_editable()) { var beforeid = util_1["default"].is_node(node_before) ? node_before.id : node_before; var node = _this.mind.insert_node_before(node_before, nodeid, topic, data); if (!!node) { _this.view_provider.add_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "insert_node_before", data: [beforeid, nodeid, topic, data], node: nodeid }); } return node; } else { tools_1.$logger.error("fail, this mind map is not editable"); return null; } }; this.insert_node_after = function (node_after, nodeid, topic, data) { if (_this.get_editable()) { var afterid = util_1["default"].is_node(node_after) ? node_after.id : node_after; var node = _this.mind.insert_node_after(node_after, nodeid, topic, data); if (!!node) { _this.view_provider.add_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "insert_node_after", data: [afterid, nodeid, topic, data], node: nodeid }); } return node; } else { tools_1.$logger.error("fail, this mind map is not editable"); return null; } }; this.remove_node = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return false; } else { return _this.remove_node(the_node); } } if (_this.get_editable()) { if (node.isroot) { tools_1.$logger.error("fail, can not remove root node"); return false; } var nodeid = node.id; var parentid = node.parent.id; var parent_node = _this.get_node(parentid); parent_node && _this.view_provider.save_location(parent_node); _this.view_provider.remove_node(node); _this.mind.remove_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); parent_node && _this.view_provider.restore_location(parent_node); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "remove_node", data: [nodeid], node: parentid }); return true; } else { tools_1.$logger.error("fail, this mind map is not editable"); return false; } }; this.update_node = function (nodeid, topic) { if (_this.get_editable()) { if (util_1["default"].text.is_empty(topic)) { tools_1.$logger.warn("fail, topic can not be empty"); return; } var node = _this.get_node(nodeid); if (!!node) { if (node.topic === topic) { tools_1.$logger.info("nothing changed"); _this.view_provider.update_node(node); return; } node.topic = topic; _this.view_provider.update_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "update_node", data: [nodeid, topic], node: nodeid }); } } else { tools_1.$logger.error("fail, this mind map is not editable"); return; } }; this.move_node = function (nodeid, beforeid, parentid, direction) { if (_this.get_editable()) { var node = _this.mind.move_node(nodeid, beforeid, parentid, direction); if (!!node) { _this.view_provider.update_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); _this.invoke_event_handle(exports.TSMindEventTypeMap.edit, { evt: "move_node", data: [nodeid, beforeid, parentid, direction], node: nodeid }); } } else { tools_1.$logger.error("fail, this mind map is not editable"); return; } }; this.select_node = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return; } else { return _this.select_node(the_node); } } if (!_this.layout_provider.is_visible(node)) { return; } _this.mind.selected = node; _this.view_provider.select_node(node); }; this.get_selected_node = function () { if (!!_this.mind) { return _this.mind.selected; } else { return null; } }; this.select_clear = function () { if (!!_this.mind) { _this.mind.selected = null; _this.view_provider.select_clear(); } }; this.is_node_visible = function (node) { return _this.layout_provider.is_visible(node); }; this.find_node_before = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return null; } else { return _this.find_node_before(the_node); } } if (node.isroot) { return null; } var n = null; if (node.parent.isroot) { var c = node.parent.children; var prev = null; for (var _i = 0, c_1 = c; _i < c_1.length; _i++) { var ni = c_1[_i]; if (node.direction === ni.direction) { if (node.id === ni.id) { n = prev; } prev = ni; } } } else { n = _this.mind.get_node_before(node); } return n; }; this.find_node_after = function (node) { if (!util_1["default"].is_node(node)) { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return; } else { return _this.find_node_after(the_node); } } if (node.isroot) { return null; } var n = null; if (node.parent.isroot) { var c = node.parent.children; var getthis = false; for (var _i = 0, c_2 = c; _i < c_2.length; _i++) { var ni = c_2[_i]; if (node.direction === ni.direction) { if (getthis) { n = ni; break; } if (node.id === ni.id) { getthis = true; } } } } else { n = _this.mind.get_node_after(node); } return n; }; this.set_node_color = function (nodeid, bgcolor, fgcolor) { if (_this.get_editable()) { var node = _this.mind.get_node(nodeid); if (!!node) { if (!!bgcolor) { node.data["background-color"] = bgcolor; } if (!!fgcolor) { node.data["foreground-color"] = fgcolor; } _this.view_provider.reset_node_custom_style(node); return true; } } else { tools_1.$logger.error("fail, this mind map is not editable"); } return false; }; this.set_node_font_style = function (nodeid, size, weight, style) { if (_this.get_editable()) { var node = _this.mind.get_node(nodeid); if (!!node) { if (!!size) { node.data["font-size"] = size; } if (!!weight) { node.data["font-weight"] = weight; } if (!!style) { node.data["font-style"] = style; } _this.view_provider.reset_node_custom_style(node); _this.view_provider.update_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); return true; } } else { tools_1.$logger.error("fail, this mind map is not editable"); } return false; }; this.set_node_background_image = function (nodeid, image, width, height, rotation) { if (_this.get_editable()) { var node = _this.mind.get_node(nodeid); if (!!node) { if (!!image) { node.data["background-image"] = image; } if (!!width) { node.data.width = width; } if (!!height) { node.data.height = height; } if (!!rotation) { node.data["background-rotation"] = rotation; } _this.view_provider.reset_node_custom_style(node); _this.view_provider.update_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); return true; } } else { tools_1.$logger.error("fail, this mind map is not editable"); } return false; }; this.set_node_background_rotation = function (nodeid, rotation) { if (_this.get_editable()) { var node = _this.mind.get_node(nodeid); if (!!node) { if (!node.data["background-image"]) { tools_1.$logger.error("fail, only can change rotation angle of node with background image"); return false; } node.data["background-rotation"] = rotation; _this.view_provider.reset_node_custom_style(node); _this.view_provider.update_node(node); _this.layout_provider.layout(); _this.view_provider.show(false); return true; } } else { tools_1.$logger.error("fail, this mind map is not editable"); } return false; }; this.resize = function () { _this.view_provider.resize(); }; // callback(type ,data) this.add_event_listener = function (callback) { if (callback === void 0) { callback = function () { return void 0; }; } if (typeof callback === "function") { _this.event_handles.push(callback); } }; this.invoke_event_handle = function (type, data) { var j = _this; window.setTimeout(function () { j._invoke_event_handle(type, data); }, 0); }; this._invoke_event_handle = function (type, data) { var l = _this.event_handles.length; for (var i = 0; i < l; i++) { _this.event_handles[i](type, data); } }; if (!options.container) { throw Error("the options.container should not be null or empty."); } this.options = tools_1.$extend(true, constants_1.DEFAULT_OPTIONS, options); if (this.initialized) { return; } this.initialized = true; var opts = this.options; var opts_layout = { mode: opts.mode, hspace: opts.layout.hspace, vspace: opts.layout.vspace, pspace: opts.layout.pspace }; var opts_view = { container: opts.container, support_html: opts.support_html, hmargin: opts.view.hmargin, vmargin: opts.view.vmargin, line_width: opts.view.line_width, line_color: opts.view.line_color }; // create instance of function provider this.data_provider = new data_1.data_provider(this); this.layout_provider = new layout_1["default"](this, opts_layout); this.view_provider = new view_1["default"](this, opts_view); this.shortcut_provider = new shortcut_1["default"](this, opts.shortcut); this._event_bind(); this.init_plugins(this, options); } // static properties TSMind.version = constants_1.__version__; TSMind.direction = exports.TSMindDirectionMap; TSMind.event_type = exports.TSMindEventTypeMap; return TSMind; }()); exports.TSMind = TSMind; exports["default"] = TSMind; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; exports.__name__ = "TSMind"; // library version exports.__version__ = "0.5.0"; // authores exports.__authores__ = ["1071115676@qq.com", "hizzgdev@163.com"]; exports.DEFAULT_OPTIONS = { container: "", editable: false, theme: "primary", mode: "full", support_html: true, view: { hmargin: 100, vmargin: 50, line_width: 2, line_color: "#555" }, layout: { hspace: 30, vspace: 20, pspace: 13 }, default_event_handle: { enable_mousedown_handle: true, enable_click_handle: true, enable_dblclick_handle: true }, shortcut: { enable: true, handles: {}, mapping: { addchild: 45, addbrother: 13, editnode: 113, delnode: 46, toggle: 32, left: 37, up: 38, right: 39, down: 40 // Down } } }; // custom node names exports.TSM_Node_Names = { nodes: "tsmnodes", node: "tsmnode", fold: "tsmfold" }; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var __1 = __webpack_require__(1); var TSM_node = /** @class */ (function () { function TSM_node(sId, iIndex, sTopic, oData, bIsRoot, oParent, eDirection, bExpanded) { if (oData === void 0) { oData = {}; } if (eDirection === void 0) { eDirection = __1.TSMindDirectionMap.right; } if (bExpanded === void 0) { bExpanded = true; } var _this = this; this.id = ""; this.index = 0; this.topic = ""; this.data = {}; this.isroot = true; this.direction = __1.TSMindDirectionMap.left; this.expanded = true; this.children = []; this.expands = {}; this.width = 0; this.height = 0; this.view_data = { element: null, expander: null, abs_x: 0, abs_y: 0, width: 0, height: 0, _saved_location: { x: 0, y: 0 } }; this.layout_data = { direction: __1.TSMindDirectionMap.right, side_index: 0, offset_x: 0, offset_y: 0, outer_height: 0, left_nodes: [], right_nodes: [], outer_height_left: 0, outer_height_right: 0, visible: true, _offset_: { x: 0, y: 0 } }; this.get_location = function () { var vd = _this.view_data; return { x: vd.abs_x || 0, y: vd.abs_y || 0 }; }; this.get_size = function () { var vd = _this.view_data; return { w: vd.width || 0, h: vd.height || 0 }; }; this.id = sId; this.index = iIndex; this.topic = sTopic; this.data = oData; this.isroot = bIsRoot; this.parent = oParent; this.direction = eDirection; this.expanded = bExpanded; } TSM_node.inherited = function (pnode, node) { if (!!pnode && !!node) { if (pnode.id === node.id) { return true; } if (pnode.isroot) { return true; } var pid = pnode.id; var p = node; while (!p.isroot) { p = p.parent; if (p.id === pid) { return true; } } } return false; }; TSM_node.compare = function (node1, node2) { // '-1' is alwary the last var r = 0; var i1 = node1.index; var i2 = node2.index; if (i1 >= 0 && i2 >= 0) { r = i1 - i2; } else if (i1 === -1 && i2 === -1) { r = 0; } else if (i1 === -1) { r = 1; } else if (i2 === -1) { r = -1; } else { r = 0; } // logger.debug(i1+' <> '+i2+' = '+r); return r; }; return TSM_node; }()); exports.TSM_node = TSM_node; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; exports.dom = { // target,eventType,handler add_event: function (target, event, call) { target.addEventListener(event, call, false); }, css: function (cstyle, property_name) { return cstyle.getPropertyValue(property_name); }, is_visible: function (cstyle) { var visibility = exports.dom.css(cstyle, "visibility"); var display = exports.dom.css(cstyle, "display"); exports.dom.css(cstyle, "backface-visibility"); return visibility !== "hidden" && display !== "none"; } }; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; exports.canvas = { bezierto: function (ctx, x1, y1, x2, y2) { ctx.beginPath(); ctx.moveTo(x1, y1); ctx.bezierCurveTo(x1 + ((x2 - x1) * 2) / 3, y1, x1, y2, x2, y2); ctx.stroke(); }, lineto: function (ctx, x1, y1, x2, y2) { ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); }, clear: function (ctx, x, y, w, h) { ctx.clearRect(x, y, w, h); }, rect: function (ctx, x, y, w, h, r) { if (w < 2 * r) r = w / 2; if (h < 2 * r) r = h / 2; ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); }, text_multiline: function (ctx, text, x, y, w, h, lineheight) { var line = ""; var text_len = text.length; var chars = text.split(""); var test_line = null; ctx.textAlign = "left"; ctx.textBaseline = "top"; for (var i = 0; i < text_len; i++) { test_line = line + chars[i]; if (ctx.measureText(test_line).width > w && i > 0) { ctx.fillText(line, x, y); line = chars[i]; y += lineheight; } else { line = test_line; } } ctx.fillText(line, x, y); }, text_ellipsis: function (ctx, text, x, y, w, h) { var center_y = y + h / 2; text = exports.canvas.fittingString(ctx, text, w); ctx.textAlign = "left"; ctx.textBaseline = "middle"; ctx.fillText(text, x, center_y, w); }, fittingString: function (ctx, text, max_width) { var width = ctx.measureText(text).width; var ellipsis = "…"; var ellipsis_width = ctx.measureText(ellipsis).width; if (width <= max_width || width <= ellipsis_width) { return text; } else { var len = text.length; while (width >= max_width - ellipsis_width && len-- > 0) { text = text.substring(0, len); width = ctx.measureText(text).width; } return text + ellipsis; } }, image: function (ctx, backgroundUrl, x, y, w, h, r, rotation, callback) { if (callback === void 0) { callback = function () { }; } var img = new Image(); img.onload = function () { ctx.save(); ctx.translate(x, y); ctx.save(); ctx.beginPath(); exports.canvas.rect(ctx, 0, 0, w, h, r); ctx.closePath(); ctx.clip(); ctx.translate(w / 2, h / 2); ctx.rotate((rotation * Math.PI) / 180); ctx.drawImage(img, -w / 2, -h / 2); ctx.restore(); ctx.restore(); callback(); }; img.src = backgroundUrl; } }; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var tools_1 = __webpack_require__(0); var util_1 = __webpack_require__(7); var node_1 = __webpack_require__(3); var __1 = __webpack_require__(1); var TSM_mind = /** @class */ (function () { function TSM_mind() { var _this = this; this.name = null; this.author = null; this.version = null; this.root = null; this.selected = null; this.nodes = {}; this.get_node = function (nodeid) { if (nodeid in _this.nodes) { return _this.nodes[nodeid]; } else { tools_1.$logger.warn("the node[id=" + nodeid + "] can not be found"); return null; } }; this.set_root = function (nodeid, topic, data) { if (_this.root == null) { _this.root = new node_1.TSM_node(nodeid, 0, topic, data, true); _this._put_node(_this.root); } else { tools_1.$logger.error("root node is already exist"); } }; this.add_node = function (parent_node, nodeid, topic, data, idx, direction, expanded) { if (idx === void 0) { idx = -1; } if (!util_1["default"].is_node(parent_node)) { var the_parent_node = _this.get_node(parent_node); if (!the_parent_node) { tools_1.$logger.error("the parent_node[id=" + parent_node + "] can not be found."); return null; } else { return _this.add_node(the_parent_node, nodeid, topic, data, idx, direction, expanded); } } var nodeindex = idx; var node = null; parent_node = parent_node; if (parent_node.isroot) { var d = __1["default"].direction.right; if (isNaN(direction)) { var children = parent_node.children; var children_len = children.length; var r = 0; for (var i = 0; i < children_len; i++) { if (children[i].direction === __1["default"].direction.left) { r--; } else { r++; } } d = children_len > 1 && r > 0 ? __1["default"].direction.left : __1["default"].direction.right; } else { d = direction !== __1["default"].direction.left ? __1["default"].direction.right : __1["default"].direction.left; } node = new node_1.TSM_node(nodeid, nodeindex, topic, data, false, parent_node, d, expanded); } else { node = new node_1.TSM_node(nodeid, nodeindex, topic, data, false, parent_node, parent_node.direction, expanded); } if (_this._put_node(node)) { parent_node.children.push(node); _this._reindex(parent_node); } else { tools_1.$logger.error("fail, the nodeid '" + node.id + "' has been already exist."); node = null; } return node; }; this.insert_node_before = function (node_before, nodeid, topic, data) { if (!util_1["default"].is_node(node_before)) { var the_node_before = _this.get_node(node_before); if (!the_node_before) { tools_1.$logger.error("the node_before[id=" + node_before + "] can not be found."); return null; } else { return _this.insert_node_before(the_node_before, nodeid, topic, data); } } node_before = node_before; var node_index = node_before.index - 0.5; return node_before.parent ? _this.add_node(node_before.parent, nodeid, topic, data, node_index) : null; }; this.get_node_before = function (node) { if (typeof node === "string") { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return null; } else { return _this.get_node_before(the_node); } } if (node.isroot) { return null; } var idx = node.index - 2; if (idx >= 0) { return node.parent.children[idx] || null; } else { return null; } }; this.insert_node_after = function (node_after, nodeid, topic, data) { if (typeof node_after === "string") { var the_node_after = _this.get_node(node_after); if (!the_node_after) { tools_1.$logger.error("the node_after[id=" + node_after + "] can not be found."); return null; } else { return _this.insert_node_after(the_node_after, nodeid, topic, data); } } var node_index = node_after.index + 0.5; return node_after.parent ? _this.add_node(node_after.parent, nodeid, topic, data, node_index) : null; }; this.get_node_after = function (node) { if (typeof node === "string") { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return null; } else { return _this.get_node_after(the_node); } } if (node.isroot) { return null; } var idx = node.index; var brothers = node.parent.children || null; if (brothers.length >= idx) { return node.parent.children[idx] || null; } else { return null; } }; this.move_node = function (node, beforeid, parentid, direction) { if (typeof node === "string") { var the_node = _this.get_node(node); if (!the_node) { tools_1.$logger.error("the node[id=" + node + "] can not be found."); return null; } else { return _this