From 0eb281355bc243661204ed3a18277e7012cc2f91 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:40:11 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/ui/mxgraph/src/js/view/mxCellEditor.js | 1052 +++++++++++++++++++++ 1 file changed, 1052 insertions(+) create mode 100644 js/ui/mxgraph/src/js/view/mxCellEditor.js diff --git a/js/ui/mxgraph/src/js/view/mxCellEditor.js b/js/ui/mxgraph/src/js/view/mxCellEditor.js new file mode 100644 index 0000000..27bf707 --- /dev/null +++ b/js/ui/mxgraph/src/js/view/mxCellEditor.js @@ -0,0 +1,1052 @@ +/** + * Copyright (c) 2006-2015, JGraph Ltd + * Copyright (c) 2006-2015, Gaudenz Alder + */ +/** + * Class: mxCellEditor + * + * In-place editor for the graph. To control this editor, use + * , and + * . If is true then + * ctrl-enter or shift-enter can be used to create a linefeed. The F2 and + * escape keys can always be used to stop editing. + * + * To customize the location of the textbox in the graph, override + * as follows: + * + * (code) + * graph.cellEditor.getEditorBounds = function(state) + * { + * var result = mxCellEditor.prototype.getEditorBounds.apply(this, arguments); + * + * if (this.graph.getModel().isEdge(state.cell)) + * { + * result.x = state.getCenterX() - result.width / 2; + * result.y = state.getCenterY() - result.height / 2; + * } + * + * return result; + * }; + * (end) + * + * Note that this hook is only called if is false. If is true, + * then is used to compute the current bounds of the textbox. + * + * The textarea uses the mxCellEditor CSS class. You can modify this class in + * your custom CSS. Note: You should modify the CSS after loading the client + * in the page. + * + * Example: + * + * To only allow numeric input in the in-place editor, use the following code. + * + * (code) + * var text = graph.cellEditor.textarea; + * + * mxEvent.addListener(text, 'keydown', function (evt) + * { + * if (!(evt.keyCode >= 48 && evt.keyCode <= 57) && + * !(evt.keyCode >= 96 && evt.keyCode <= 105)) + * { + * mxEvent.consume(evt); + * } + * }); + * (end) + * + * Placeholder: + * + * To implement a placeholder for cells without a label, use the + * variable. + * + * Resize in Chrome: + * + * Resize of the textarea is disabled by default. If you want to enable + * this feature extend and set this.textarea.style.resize = ''. + * + * To start editing on a key press event, the container of the graph + * should have focus or a focusable parent should be used to add the + * key press handler as follows. + * + * (code) + * mxEvent.addListener(graph.container, 'keypress', mxUtils.bind(this, function(evt) + * { + * if (!graph.isEditing() && !graph.isSelectionEmpty() && evt.which !== 0 && + * !mxEvent.isAltDown(evt) && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt)) + * { + * graph.startEditing(); + * + * if (mxClient.IS_FF) + * { + * graph.cellEditor.textarea.value = String.fromCharCode(evt.which); + * } + * } + * })); + * (end) + * + * To allow focus for a DIV, and hence to receive key press events, some browsers + * require it to have a valid tabindex attribute. In this case the following + * code may be used to keep the container focused. + * + * (code) + * var graphFireMouseEvent = graph.fireMouseEvent; + * graph.fireMouseEvent = function(evtName, me, sender) + * { + * if (evtName == mxEvent.MOUSE_DOWN) + * { + * this.container.focus(); + * } + * + * graphFireMouseEvent.apply(this, arguments); + * }; + * (end) + * + * Constructor: mxCellEditor + * + * Constructs a new in-place editor for the specified graph. + * + * Parameters: + * + * graph - Reference to the enclosing . + */ +function mxCellEditor(graph) +{ + this.graph = graph; + + // Stops editing after zoom changes + this.zoomHandler = mxUtils.bind(this, function() + { + if (this.graph.isEditing()) + { + this.resize(); + } + }); + + this.graph.view.addListener(mxEvent.SCALE, this.zoomHandler); + this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.zoomHandler); +}; + +/** + * Variable: graph + * + * Reference to the enclosing . + */ +mxCellEditor.prototype.graph = null; + +/** + * Variable: textarea + * + * Holds the DIV that is used for text editing. Note that this may be null before the first + * edit. Instantiated in . + */ +mxCellEditor.prototype.textarea = null; + +/** + * Variable: editingCell + * + * Reference to the that is currently being edited. + */ +mxCellEditor.prototype.editingCell = null; + +/** + * Variable: trigger + * + * Reference to the event that was used to start editing. + */ +mxCellEditor.prototype.trigger = null; + +/** + * Variable: modified + * + * Specifies if the label has been modified. + */ +mxCellEditor.prototype.modified = false; + +/** + * Variable: autoSize + * + * Specifies if the textarea should be resized while the text is being edited. + * Default is true. + */ +mxCellEditor.prototype.autoSize = true; + +/** + * Variable: selectText + * + * Specifies if the text should be selected when editing starts. Default is + * true. + */ +mxCellEditor.prototype.selectText = true; + +/** + * Variable: emptyLabelText + * + * Text to be displayed for empty labels. Default is '' or '
' in Firefox as + * a workaround for the missing cursor bug for empty content editable. This can + * be set to eg. "[Type Here]" to easier visualize editing of empty labels. The + * value is only displayed before the first keystroke and is never used as the + * actual editing value. + */ +mxCellEditor.prototype.emptyLabelText = (mxClient.IS_FF) ? '
' : ''; + +/** + * Variable: escapeCancelsEditing + * + * If true, pressing the escape key will stop editing and not accept the new + * value. Change this to false to accept the new value on escape, and cancel + * editing on Shift+Escape instead. Default is true. + */ +mxCellEditor.prototype.escapeCancelsEditing = true; + +/** + * Variable: textNode + * + * Reference to the label DOM node that has been hidden. + */ +mxCellEditor.prototype.textNode = ''; + +/** + * Variable: zIndex + * + * Specifies the zIndex for the textarea. Default is 5. + */ +mxCellEditor.prototype.zIndex = 5; + +/** + * Variable: minResize + * + * Defines the minimum width and height to be used in . Default is 0x20px. + */ +mxCellEditor.prototype.minResize = new mxRectangle(0, 20); + +/** + * Variable: wordWrapPadding + * + * Correction factor for word wrapping width. Default is 2 in quirks, 0 in IE + * 11 and 1 in all other browsers and modes. + */ +mxCellEditor.prototype.wordWrapPadding = (mxClient.IS_QUIRKS) ? 2 : (!mxClient.IS_IE11) ? 1 : 0; + +/** + * Variable: blurEnabled + * + * If should be called if