started updating editor code to new js syntax
parent
ff141aab15
commit
817308639a
|
@ -2,6 +2,10 @@
|
|||
* Copyright (c) 2006-2015, JGraph Ltd
|
||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||
*/
|
||||
|
||||
import mxKeyHandler from "../handler/mxKeyHandler";
|
||||
import mxEventObject from "../util/mxEventObject";
|
||||
|
||||
/**
|
||||
* Class: mxDefaultKeyHandler
|
||||
*
|
||||
|
@ -16,7 +20,7 @@
|
|||
* Bind the delete key to the delete action in an existing editor.
|
||||
*
|
||||
* (code)
|
||||
* var keyHandler = new mxDefaultKeyHandler(editor);
|
||||
* let keyHandler = new mxDefaultKeyHandler(editor);
|
||||
* keyHandler.bindAction(46, 'delete');
|
||||
* (end)
|
||||
*
|
||||
|
@ -43,40 +47,38 @@
|
|||
*
|
||||
* editor - Reference to the enclosing <mxEditor>.
|
||||
*/
|
||||
function mxDefaultKeyHandler(editor)
|
||||
{
|
||||
if (editor != null)
|
||||
{
|
||||
this.editor = editor;
|
||||
this.handler = new mxKeyHandler(editor.graph);
|
||||
|
||||
// Extends the escape function of the internal key
|
||||
// handle to hide the properties dialog and fire
|
||||
// the escape event via the editor instance
|
||||
var old = this.handler.escape;
|
||||
|
||||
this.handler.escape = function(evt)
|
||||
{
|
||||
old.apply(this, arguments);
|
||||
editor.hideProperties();
|
||||
editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
class mxDefaultKeyHandler {
|
||||
/**
|
||||
* Variable: editor
|
||||
*
|
||||
* Reference to the enclosing <mxEditor>.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.editor = null;
|
||||
editor = null;
|
||||
|
||||
/**
|
||||
* Variable: handler
|
||||
*
|
||||
* Holds the <mxKeyHandler> for key event handling.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.handler = null;
|
||||
handler = null;
|
||||
|
||||
constructor(editor) {
|
||||
if (editor != null) {
|
||||
this.editor = editor;
|
||||
this.handler = new mxKeyHandler(editor.graph);
|
||||
|
||||
// Extends the escape function of the internal key
|
||||
// handle to hide the properties dialog and fire
|
||||
// the escape event via the editor instance
|
||||
let old = this.handler.escape;
|
||||
|
||||
this.handler.escape = (evt)=>{
|
||||
old.apply(this, arguments);
|
||||
editor.hideProperties();
|
||||
editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: bindAction
|
||||
|
@ -92,22 +94,16 @@ mxDefaultKeyHandler.prototype.handler = null;
|
|||
* control - Optional boolean that specifies if control must be pressed.
|
||||
* Default is false.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.bindAction = function (code, action, control)
|
||||
{
|
||||
var keyHandler = mxUtils.bind(this, function()
|
||||
{
|
||||
bindAction=(code, action, control)=>{
|
||||
let keyHandler = mxUtils.bind(this, ()=>{
|
||||
this.editor.execute(action);
|
||||
});
|
||||
|
||||
if (control) {
|
||||
// Binds the function to control-down keycode
|
||||
if (control)
|
||||
{
|
||||
this.handler.bindControlKey(code, keyHandler);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Binds the function to the normal keycode
|
||||
else
|
||||
{
|
||||
this.handler.bindKey(code, keyHandler);
|
||||
}
|
||||
};
|
||||
|
@ -119,8 +115,10 @@ mxDefaultKeyHandler.prototype.bindAction = function (code, action, control)
|
|||
* not need to be called, the <handler> is destroyed automatically when the
|
||||
* window unloads (in IE) by <mxEditor>.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.destroy = function ()
|
||||
{
|
||||
destroy=()=>{
|
||||
this.handler.destroy();
|
||||
this.handler = null;
|
||||
};
|
||||
}
|
||||
|
||||
export default mxDefaultKeyHandler;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* Copyright (c) 2006-2015, JGraph Ltd
|
||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class: mxDefaultPopupMenu
|
||||
*
|
||||
|
@ -30,17 +32,13 @@
|
|||
*
|
||||
* config - XML node that contains the configuration data.
|
||||
*/
|
||||
function mxDefaultPopupMenu(config)
|
||||
{
|
||||
this.config = config;
|
||||
};
|
||||
|
||||
class mxDefaultPopupMenu {
|
||||
/**
|
||||
* Variable: imageBasePath
|
||||
*
|
||||
* Base path for all icon attributes in the config. Default is null.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.imageBasePath = null;
|
||||
imageBasePath = null;
|
||||
|
||||
/**
|
||||
* Variable: config
|
||||
|
@ -49,7 +47,11 @@ mxDefaultPopupMenu.prototype.imageBasePath = null;
|
|||
* used in <createMenu> to dynamically create the menu items if their
|
||||
* respective conditions evaluate to true for the given arguments.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.config = null;
|
||||
config = null;
|
||||
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: createMenu
|
||||
|
@ -151,12 +153,10 @@ mxDefaultPopupMenu.prototype.config = null;
|
|||
* cell - Optional <mxCell> which is under the mousepointer.
|
||||
* evt - Optional mouse event which triggered the menu.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.createMenu = function(editor, menu, cell, evt)
|
||||
{
|
||||
if (this.config != null)
|
||||
{
|
||||
var conditions = this.createConditions(editor, cell, evt);
|
||||
var item = this.config.firstChild;
|
||||
createMenu=(editor, menu, cell, evt)=>{
|
||||
if (this.config != null) {
|
||||
let conditions = this.createConditions(editor, cell, evt);
|
||||
let item = this.config.firstChild;
|
||||
|
||||
this.addItems(editor, menu, cell, evt, conditions, item, null);
|
||||
}
|
||||
|
@ -177,26 +177,22 @@ mxDefaultPopupMenu.prototype.createMenu = function(editor, menu, cell, evt)
|
|||
* item - XML node that represents the current menu item.
|
||||
* parent - DOM node that represents the parent menu item.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, conditions, item, parent)
|
||||
{
|
||||
var addSeparator = false;
|
||||
addItems=(editor, menu, cell, evt, conditions, item, parent)=>{
|
||||
let addSeparator = false;
|
||||
|
||||
while (item != null)
|
||||
{
|
||||
if (item.nodeName == 'add')
|
||||
{
|
||||
var condition = item.getAttribute('if');
|
||||
while (item != null) {
|
||||
if (item.nodeName === 'add') {
|
||||
let condition = item.getAttribute('if');
|
||||
|
||||
if (condition == null || conditions[condition])
|
||||
{
|
||||
var as = item.getAttribute('as');
|
||||
if (condition == null || conditions[condition]) {
|
||||
let as = item.getAttribute('as');
|
||||
as = mxResources.get(as) || as;
|
||||
var funct = mxUtils.eval(mxUtils.getTextContent(item));
|
||||
var action = item.getAttribute('action');
|
||||
var icon = item.getAttribute('icon');
|
||||
var iconCls = item.getAttribute('iconCls');
|
||||
var enabledCond = item.getAttribute('enabled-if');
|
||||
var enabled = enabledCond == null || conditions[enabledCond];
|
||||
let funct = mxUtils.eval(mxUtils.getTextContent(item));
|
||||
let action = item.getAttribute('action');
|
||||
let icon = item.getAttribute('icon');
|
||||
let iconCls = item.getAttribute('iconCls');
|
||||
let enabledCond = item.getAttribute('enabled-if');
|
||||
let enabled = enabledCond == null || conditions[enabledCond];
|
||||
|
||||
if (addSeparator)
|
||||
{
|
||||
|
@ -209,12 +205,10 @@ mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, condit
|
|||
icon = this.imageBasePath + icon;
|
||||
}
|
||||
|
||||
var row = this.addAction(menu, editor, as, icon, funct, action, cell, parent, iconCls, enabled);
|
||||
let row = this.addAction(menu, editor, as, icon, funct, action, cell, parent, iconCls, enabled);
|
||||
this.addItems(editor, menu, cell, evt, conditions, item.firstChild, row);
|
||||
}
|
||||
}
|
||||
else if (item.nodeName == 'separator')
|
||||
{
|
||||
} else if (item.nodeName === 'separator') {
|
||||
addSeparator = true;
|
||||
}
|
||||
|
||||
|
@ -243,21 +237,15 @@ mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, condit
|
|||
* enabled - Optional boolean that specifies if the menu item is enabled.
|
||||
* Default is true.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.addAction = function(menu, editor, lab, icon, funct, action, cell, parent, iconCls, enabled)
|
||||
{
|
||||
var clickHandler = function(evt)
|
||||
{
|
||||
if (typeof(funct) == 'function')
|
||||
{
|
||||
addAction=(menu, editor, lab, icon, funct, action, cell, parent, iconCls, enabled)=>{
|
||||
let clickHandler=(evt)=>{
|
||||
if (typeof(funct) == 'function') {
|
||||
funct.call(editor, editor, cell, evt);
|
||||
}
|
||||
|
||||
if (action != null)
|
||||
{
|
||||
if (action != null) {
|
||||
editor.execute(action, cell, evt);
|
||||
}
|
||||
};
|
||||
|
||||
return menu.addItem(lab, icon, clickHandler, parent, iconCls, enabled);
|
||||
};
|
||||
|
||||
|
@ -266,41 +254,40 @@ mxDefaultPopupMenu.prototype.addAction = function(menu, editor, lab, icon, funct
|
|||
*
|
||||
* Evaluates the default conditions for the given context.
|
||||
*/
|
||||
mxDefaultPopupMenu.prototype.createConditions = function(editor, cell, evt)
|
||||
{
|
||||
createConditions=(editor, cell, evt)=>{
|
||||
// Creates array with conditions
|
||||
var model = editor.graph.getModel();
|
||||
var childCount = model.getChildCount(cell);
|
||||
let model = editor.graph.getModel();
|
||||
let childCount = model.getChildCount(cell);
|
||||
|
||||
// Adds some frequently used conditions
|
||||
var conditions = [];
|
||||
let conditions = [];
|
||||
conditions['nocell'] = cell == null;
|
||||
conditions['ncells'] = editor.graph.getSelectionCount() > 1;
|
||||
conditions['notRoot'] = model.getRoot() !=
|
||||
model.getParent(editor.graph.getDefaultParent());
|
||||
conditions['notRoot'] = model.getRoot() != model.getParent(editor.graph.getDefaultParent());
|
||||
conditions['cell'] = cell != null;
|
||||
|
||||
var isCell = cell != null && editor.graph.getSelectionCount() == 1;
|
||||
let isCell = cell != null && editor.graph.getSelectionCount() === 1;
|
||||
conditions['nonEmpty'] = isCell && childCount > 0;
|
||||
conditions['expandable'] = isCell && editor.graph.isCellFoldable(cell, false);
|
||||
conditions['collapsable'] = isCell && editor.graph.isCellFoldable(cell, true);
|
||||
conditions['validRoot'] = isCell && editor.graph.isValidRoot(cell);
|
||||
conditions['emptyValidRoot'] = conditions['validRoot'] && childCount == 0;
|
||||
conditions['emptyValidRoot'] = conditions['validRoot'] && childCount === 0;
|
||||
conditions['swimlane'] = isCell && editor.graph.isSwimlane(cell);
|
||||
|
||||
// Evaluates dynamic conditions from config file
|
||||
var condNodes = this.config.getElementsByTagName('condition');
|
||||
let condNodes = this.config.getElementsByTagName('condition');
|
||||
|
||||
for (var i=0; i<condNodes.length; i++)
|
||||
{
|
||||
var funct = mxUtils.eval(mxUtils.getTextContent(condNodes[i]));
|
||||
var name = condNodes[i].getAttribute('name');
|
||||
for (let i=0; i<condNodes.length; i++) {
|
||||
let funct = mxUtils.eval(mxUtils.getTextContent(condNodes[i]));
|
||||
let name = condNodes[i].getAttribute('name');
|
||||
|
||||
if (name != null && typeof(funct) == 'function')
|
||||
{
|
||||
if (name != null && typeof(funct) == 'function') {
|
||||
conditions[name] = funct(editor, cell, evt);
|
||||
}
|
||||
}
|
||||
|
||||
return conditions;
|
||||
};
|
||||
}
|
||||
|
||||
export default mxDefaultPopupMenu;
|
||||
|
|
Loading…
Reference in New Issue