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,42 +47,40 @@
|
|||
*
|
||||
* editor - Reference to the enclosing <mxEditor>.
|
||||
*/
|
||||
function mxDefaultKeyHandler(editor)
|
||||
{
|
||||
if (editor != null)
|
||||
{
|
||||
class mxDefaultKeyHandler {
|
||||
/**
|
||||
* Variable: editor
|
||||
*
|
||||
* Reference to the enclosing <mxEditor>.
|
||||
*/
|
||||
editor = null;
|
||||
|
||||
/**
|
||||
* Variable: handler
|
||||
*
|
||||
* Holds the <mxKeyHandler> for key event handling.
|
||||
*/
|
||||
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
|
||||
var old = this.handler.escape;
|
||||
let old = this.handler.escape;
|
||||
|
||||
this.handler.escape = function(evt)
|
||||
{
|
||||
this.handler.escape = (evt)=>{
|
||||
old.apply(this, arguments);
|
||||
editor.hideProperties();
|
||||
editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Variable: editor
|
||||
*
|
||||
* Reference to the enclosing <mxEditor>.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.editor = null;
|
||||
|
||||
/**
|
||||
* Variable: handler
|
||||
*
|
||||
* Holds the <mxKeyHandler> for key event handling.
|
||||
*/
|
||||
mxDefaultKeyHandler.prototype.handler = null;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: bindAction
|
||||
*
|
||||
* Binds the specified keycode to the given action in <editor>. The
|
||||
|
@ -92,35 +94,31 @@ 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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: destroy
|
||||
*
|
||||
* Destroys the <handler> associated with this object. This does normally
|
||||
* 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,28 +32,28 @@
|
|||
*
|
||||
* 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
|
||||
*
|
||||
* XML node used as the description of new menu items. This node is
|
||||
* 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
|
||||
*
|
||||
* This function is called from <mxEditor> to add items to the
|
||||
|
@ -151,18 +153,16 @@ 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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: addItems
|
||||
*
|
||||
* Recursively adds the given items and all of its children into the given menu.
|
||||
|
@ -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,20 +205,18 @@ 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;
|
||||
}
|
||||
|
||||
item = item.nextSibling;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: addAction
|
||||
*
|
||||
* Helper method to bind an action to a new menu item.
|
||||
|
@ -243,64 +237,57 @@ 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);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: createConditions
|
||||
*
|
||||
* 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