From 6201247875ade2f793b733434e5c9a3f2bfbd1ab Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 10 Dec 2018 15:23:02 +0000 Subject: [PATCH] Tidy up markdown toolbar handling across all editors Any editor for the markdown mode will now automatically get the markdown toolbar added. The comment node has been updated to handle this properly and to not add two copies of its content to the sidebar. --- .../editor-client/locales/en-US/editor.json | 7 +-- .../editor-client/locales/ja/editor.json | 4 +- .../editor-client/locales/zh-CN/editor.json | 4 +- .../editor-client/src/js/ui/common/popover.js | 14 ++++- .../editor-client/src/js/ui/editor.js | 60 ++++++++++++------- .../src/js/ui/editors/markdown.js | 8 +-- .../editor-client/src/js/ui/workspaces.js | 6 -- .../editor-client/src/sass/editor.scss | 19 +++++- .../@node-red/nodes/core/core/90-comment.html | 10 +--- .../nodes/locales/en-US/messages.json | 7 +-- .../@node-red/nodes/locales/ja/messages.json | 7 +-- .../nodes/locales/zh-CN/messages.json | 5 -- 12 files changed, 83 insertions(+), 68 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index e618c18a0..769fcaa44 100644 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -27,8 +27,7 @@ "status": "Status", "enabled": "Enabled", "disabled":"Disabled", - "info": "Description", - "tip": "Description accepts Markdown and will appear in the Info tab." + "info": "Description" }, "menu": { "label": { @@ -279,7 +278,6 @@ "deleteSubflow": "delete subflow", "info": "Description", "category": "Category", - "format":"markdown format", "errors": { "noNodesSelected": "Cannot create subflow: no nodes selected", "multipleInputsToSelection": "Cannot create subflow: multiple inputs to selection" @@ -719,7 +717,8 @@ "format": "format JSON" }, "markdownEditor": { - "title": "Markdown editor" + "title": "Markdown editor", + "format": "Formatted with markdown" }, "bufferEditor": { "title": "Buffer editor", diff --git a/packages/node_modules/@node-red/editor-client/locales/ja/editor.json b/packages/node_modules/@node-red/editor-client/locales/ja/editor.json index 2b9df9e45..bf5e98520 100644 --- a/packages/node_modules/@node-red/editor-client/locales/ja/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/ja/editor.json @@ -27,8 +27,7 @@ "status": "状態", "enabled": "有効", "disabled": "無効", - "info": "詳細", - "tip": "マークダウン形式で記述した「詳細」は「情報タブ」に表示されます。" + "info": "詳細" }, "menu": { "label": { @@ -278,7 +277,6 @@ "deleteSubflow": "サブフローを削除", "info": "詳細", "category": "カテゴリ", - "format": "マークダウン形式", "errors": { "noNodesSelected": "サブフローを作成できません: ノードが選択されていません", "multipleInputsToSelection": "サブフローを作成できません: 複数の入力が選択されています" diff --git a/packages/node_modules/@node-red/editor-client/locales/zh-CN/editor.json b/packages/node_modules/@node-red/editor-client/locales/zh-CN/editor.json index 93cf323ea..975a20448 100644 --- a/packages/node_modules/@node-red/editor-client/locales/zh-CN/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/zh-CN/editor.json @@ -22,8 +22,7 @@ "status": "状态", "enabled": "有效", "disabled": "无效", - "info": "详细描述", - "tip": "详细描述支持Markdown轻量级标记语言,并将出现在信息标签中。" + "info": "详细描述" }, "menu": { "label": { @@ -191,7 +190,6 @@ "output": "输出:", "deleteSubflow": "删除子流程", "info": "详细描述", - "format": "标记格式", "errors": { "noNodesSelected": "无法创建子流程: 未选择节点", "multipleInputsToSelection": "无法创建子流程: 多个输入到了选择" diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js index 5b5057666..50aa5eb83 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js @@ -38,7 +38,7 @@ RED.popover = (function() { var direction = options.direction || "right"; var trigger = options.trigger; var content = options.content; - var delay = options.delay; + var delay = options.delay || { show: 750, hide: 50 }; var autoClose = options.autoClose; var width = options.width||"auto"; var size = options.size||"default"; @@ -172,6 +172,18 @@ RED.popover = (function() { openPopup(); } }); + if (autoClose) { + target.on('mouseleave disabled', function(e) { + if (timer) { + clearTimeout(timer); + } + if (active) { + active = false; + setTimeout(closePopup,autoClose); + } + }); + } + } else if (trigger === 'modal') { $(document).on('mousedown.modal-popover-close', function (event) { var target = event.target; diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js index e261fefd4..86d37761e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js @@ -929,7 +929,7 @@ RED.editor = (function() { function buildDescriptionForm(container,node) { var dialogForm = $('
').appendTo(container); var toolbarRow = $('
').appendTo(dialogForm); - var row = $('
').appendTo(dialogForm); + var row = $('
').appendTo(dialogForm); $('
').appendTo(row); var nodeInfoEditor = RED.editor.createEditor({ id: "node-info-input-info-editor", @@ -939,26 +939,6 @@ RED.editor = (function() { if (node.info) { nodeInfoEditor.getSession().setValue(node.info, -1); } - var toolbar = RED.editor.types._markdown.buildToolbar(toolbarRow,nodeInfoEditor); - - $('').appendTo(toolbar); - - $('#node-info-input-info-expand').click(function(e) { - e.preventDefault(); - var value = nodeInfoEditor.getValue(); - RED.editor.editMarkdown({ - value: value, - width: "Infinity", - cursor: nodeInfoEditor.getCursorPosition(), - complete: function(v,cursor) { - nodeInfoEditor.setValue(v, -1); - nodeInfoEditor.gotoLine(cursor.row+1,cursor.column,false); - setTimeout(function() { - nodeInfoEditor.focus(); - },300); - } - }) - }); return nodeInfoEditor; } @@ -2206,7 +2186,10 @@ RED.editor = (function() { createEditor: function(options) { - var editor = ace.edit(options.id||options.element); + var el = options.element || $("#"+options.id)[0]; + var toolbarRow = $("
").appendTo(el); + el = $("
").appendTo(el).addClass("node-text-editor-container")[0]; + var editor = ace.edit(el); editor.setTheme("ace/theme/tomorrow"); var session = editor.getSession(); session.on("changeAnnotation", function () { @@ -2254,6 +2237,39 @@ RED.editor = (function() { } },100); } + if (options.mode === 'ace/mode/markdown') { + $(el).addClass("node-text-editor-container-toolbar"); + editor.toolbar = RED.editor.types._markdown.buildToolbar(toolbarRow,editor); + if (options.expandable !== false) { + var expandButton = $('').appendTo(editor.toolbar); + + expandButton.click(function(e) { + e.preventDefault(); + var value = editor.getValue(); + RED.editor.editMarkdown({ + value: value, + width: "Infinity", + cursor: editor.getCursorPosition(), + complete: function(v,cursor) { + editor.setValue(v, -1); + editor.gotoLine(cursor.row+1,cursor.column,false); + setTimeout(function() { + editor.focus(); + },300); + } + }) + }); + } + var helpButton = $('').appendTo($(el).parent()); + RED.popover.create({ + target: helpButton, + trigger: 'click', + size: "small", + direction: "left", + content: RED._("markdownEditor.format"), + autoClose: 50 + }); + } return editor; } } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/markdown.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/markdown.js index e75e1b617..4e3f8a125 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/markdown.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/markdown.js @@ -41,7 +41,7 @@ RED.editor.types._markdown = (function() { '
'+ '
'+ '
'+ - '
'+ + '
'+ '
'+ '
'+ '
'+ @@ -112,7 +112,8 @@ RED.editor.types._markdown = (function() { expressionEditor = RED.editor.createEditor({ id: 'node-input-markdown', value: value, - mode:"ace/mode/markdown" + mode:"ace/mode/markdown", + expandable: false }); var changeTimer; expressionEditor.getSession().on("change", function() { @@ -138,11 +139,10 @@ RED.editor.types._markdown = (function() { } }); panels.ratio(1); - var toolbar = RED.editor.types._markdown.buildToolbar($("#node-input-markdown-toolbar"), expressionEditor); $(''+ ''+ - '').appendTo(toolbar); + '').appendTo(expressionEditor.toolbar); $("#node-btn-markdown-preview").click(function(e) { e.preventDefault(); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js b/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js index 7a8da060e..ca2a88f9c 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js @@ -146,7 +146,6 @@ RED.workspaces = (function() { height -= $(rows[i]).outerHeight(true); } height -= (parseInt($("#dialog-form").css("marginTop"))+parseInt($("#dialog-form").css("marginBottom"))); - height -= 28; $(".node-text-editor").css("height",height+"px"); tabflowEditor.resize(); }, @@ -166,7 +165,6 @@ RED.workspaces = (function() { var row = $('
'+ ''+ - '
'+ '
'+ '
').appendTo(dialogForm); tabflowEditor = RED.editor.createEditor({ @@ -175,10 +173,6 @@ RED.workspaces = (function() { value: "" }); - var toolbar = RED.editor.types._markdown.buildToolbar(row.find(".node-text-editor-toolbar"),tabflowEditor); - - $('').appendTo(toolbar); - $('#node-info-input-info-expand').click(function(e) { e.preventDefault(); var value = tabflowEditor.getValue(); diff --git a/packages/node_modules/@node-red/editor-client/src/sass/editor.scss b/packages/node_modules/@node-red/editor-client/src/sass/editor.scss index 8563c2f12..2d39cc108 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/editor.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/editor.scss @@ -209,11 +209,28 @@ } .node-text-editor { + position: relative; + .node-text-editor-help { + position: absolute; + bottom: 0px; + right: 1px; + border-bottom-right-radius: 5px; + z-Index: 8; + border-bottom: none; + border-right: none; + } +} +.node-text-editor-container { border:1px solid #ccc; border-radius:5px; overflow: hidden; font-size: 14px !important; font-family: Menlo, Consolas, 'DejaVu Sans Mono', Courier, monospace !important; + height: 100%; + + &.node-text-editor-container-toolbar { + height: calc(100% - 40px); + } } .editor-button { @@ -333,7 +350,7 @@ padding: 10px; border:1px solid #ccc; border-radius:5px; - height: calc(100% - 31px); + height: calc(100% - 21px); overflow-y: scroll; background: #fff; } diff --git a/packages/node_modules/@node-red/nodes/core/core/90-comment.html b/packages/node_modules/@node-red/nodes/core/core/90-comment.html index dd390f120..5cb4e9ea5 100644 --- a/packages/node_modules/@node-red/nodes/core/core/90-comment.html +++ b/packages/node_modules/@node-red/nodes/core/core/90-comment.html @@ -1,17 +1,13 @@