smart-energy-monitor/software/dashboard/grafana/csv/Node-RED_files/red.min.js
2023-02-27 17:21:01 +01:00

18 lines
874 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Copyright OpenJS Foundation and other contributors, https://openjsf.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
!function(){var o;!window.MSInputMethodContext||!document.documentMode||(window.DOMTokenList.prototype.toggle=function(e,t){1===arguments.length&&(t=!this.contains(e)),this[t?"add":"remove"](e)},"classList"in SVGElement.prototype||Object.defineProperty(SVGElement.prototype,"classList",Object.getOwnPropertyDescriptor(HTMLElement.prototype,"classList")),"children"in SVGElement.prototype||Object.defineProperty(SVGElement.prototype,"children",Object.getOwnPropertyDescriptor(HTMLElement.prototype,"children")),Array.from=function(){if(1<arguments.length)throw new Error("Node-RED's IE11 Array.from polyfill doesn't support multiple arguments");var e=arguments[0],t=[];if(e.forEach)e.forEach(function(e){t.push(e)});else for(var o=0;o<e.length;o++)t.push(arrayList[o]);return t},0===new Set([0]).size&&(o=Set,(Set=function(e){var t=new o;return e&&e.forEach(t.add,t),t}).prototype=o.prototype,Set.prototype.constructor=Set))}(),jQuery.propHooks.disabled={set:function(e,t){e.disabled!==t&&((e.disabled=t)?$(e).trigger("disabled"):$(e).trigger("enabled"))}};var RED=function(){function i(){f.reportProgress(RED._("event.loadPlugins"),10),$.ajax({headers:{Accept:"application/json"},cache:!1,url:"plugins",success:function(e){f.reportProgress(RED._("event.loadPlugins"),13),RED.i18n.loadPluginCatalogs(function(){var i,e;i=function(){f.reportProgress(RED._("event.loadPalette"),20),$.ajax({headers:{Accept:"application/json"},cache:!1,url:"nodes",success:function(e){RED.nodes.setNodeList(e),f.reportProgress(RED._("event.loadNodeCatalogs"),25),RED.i18n.loadNodeCatalogs(function(){r(t)})}})},f.reportProgress(RED._("event.loadPlugins",{count:""}),17),e=localStorage.getItem("editor-language")||RED.i18n.detectLanguage(),$.ajax({headers:{Accept:"text/html","Accept-Language":e},cache:!1,url:"plugins",success:function(e){var o=e.trim().split(/(?=<!-- --- \[red-plugin:\S+\] --- -->)/),n=(o.length,function(){var e,t;0===o.length?i():(e=o.shift(),t=n,a(e,/<!-- --- \[red-plugin:(\S+)\] --- -->/.exec(e.trim()),"#red-ui-editor-plugin-configs",t))});n()}})})}})}function a(e,t,i,a){var s;a=a||function(){},t?(s=t[1],RED._loadingModule=s):s="unknown";try{var r=!1,d=$("<div>"+e+"</div>"),o=d.find("script"),l=o.length;o.each(function(e,t){var o,n=$(t).attr("src");n&&!/^\s*(https?:|\/|\.)/.test(n)?($(t).remove(),(o=document.createElement("script")).onload=function(){0===--l&&($(i).append(d),delete RED._loadingModule,a())},"module"===$(t).attr("type")&&(o.type="module"),$(i).append(o),o.src=RED.settings.apiRootUrl+n,r=!0):((/\/ace.js$/.test(n)||/\/ext-language_tools.js$/.test(n))&&(console.warn("Blocked attempt to load",n,"by",s),$(t).remove()),l--)}),r||($(i).append(d),delete RED._loadingModule,a())}catch(e){RED.notify(RED._("notification.errors.failedToAppendNode",{module:s,error:e.toString()}),{type:"error",timeout:1e4}),console.log("["+s+"] "+e.toString()),delete RED._loadingModule,a()}}function s(e,t){a(e,/<!-- --- \[red-module:(\S+)\] --- -->/.exec(e.trim()),"#red-ui-editor-node-configs",t)}function r(t){$.ajax({headers:{Accept:"application/json"},cache:!1,url:"icons",success:function(e){RED.nodes.setIconSets(e),t&&t()}})}function t(){f.reportProgress(RED._("event.loadNodes",{count:""}),30);var e=localStorage.getItem("editor-language")||RED.i18n.detectLanguage();$.ajax({headers:{Accept:"text/html","Accept-Language":e},cache:!1,url:"nodes",success:function(e){var t=e.trim().split(/(?=<!-- --- \[red-module:\S+\] --- -->)/),o=t.length,n=function(){f.reportProgress(RED._("event.loadNodes",{count:o-t.length+"/"+o}),30+(o-t.length)/o*40),0===t.length?($("#red-ui-editor").i18n(),$("#red-ui-palette > .red-ui-palette-spinner").hide(),$(".red-ui-palette-scroll").removeClass("hide"),$("#red-ui-palette-search").removeClass("hide"),RED.settings.theme("projects.enabled",!1)?RED.projects.refresh(function(t){d(function(){RED.sidebar.info.refresh();var e=!1;t||(RED.menu.setDisabled("menu-item-projects-open",!0),RED.menu.setDisabled("menu-item-projects-settings",!0),!1!==t&&(e=!0)),l(e)})}):d(function(){RED.sidebar.info.refresh(),l()})):s(t.shift(),n)};n()}})}function d(a){f.reportProgress(RED._("event.loadFlows"),80),$.ajax({headers:{Accept:"application/json"},cache:!1,url:"flows",success:function(e){if(e){var t=window.location.hash;RED.nodes.version(e.rev),f.reportProgress(RED._("event.importFlows"),90);try{if(RED.nodes.import(e.flows),RED.nodes.dirty(!1),RED.view.redraw(!0),/^#flow\/.+$/.test(t)&&RED.workspaces.show(t.substring(6),!0),0<RED.workspaces.count()){var o=JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}"),n=RED.nodes.getWorkspaceOrder();if(0===RED.workspaces.active())for(let e=0;e<n.length;e++){var i=n[e];if(!o[i]){RED.workspaces.show(i);break}}0===RED.workspaces.active()&&RED.workspaces.show(n[0])}}catch(e){console.warn(e),RED.notify(RED._("event.importError",{message:e.message}),{fixed:!0,type:"error"})}}a()}})}function l(t){var i={};RED.comms.subscribe("notification/#",function(e,t){var o,n=e.split("/")[1];"runtime-deploy"!==n&&"node"!==n&&"flows-run-state"!==n&&("project-update"===n?(f.start(RED._("event.loadingProject"),0),RED.nodes.clear(),RED.history.clear(),RED.view.redraw(!0),RED.projects.refresh(function(){d(function(){var e=RED.projects.getActiveProject(),e={"change-branch":RED._("notification.project.change-branch",{project:e.git.branches.local}),"merge-abort":RED._("notification.project.merge-abort"),loaded:RED._("notification.project.loaded",{project:t.project}),updated:RED._("notification.project.updated",{project:t.project}),pull:RED._("notification.project.pull",{project:t.project}),revert:RED._("notification.project.revert",{project:t.project}),"merge-complete":RED._("notification.project.merge-complete")}[t.action];f.end(),RED.notify($("<p>").text(e)),RED.sidebar.info.refresh()})})):(t.text?(t.default=t.text,e=RED._(t.text,t),o={type:t.type,fixed:void 0===t.timeout,timeout:t.timeout,id:n},"runtime-state"===n&&("safe-mode"===t.error?o.buttons=[{text:RED._("common.label.close"),click:function(){i[n].hideNotification()}}]:"missing-types"===t.error?(e+="<ul><li>"+t.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.projects.getActiveProject()?o.buttons=[{text:RED._("notification.label.manage-project-dep"),click:function(){i[n].hideNotification(),RED.projects.settings.show("deps")}}]:o.buttons=[{text:RED._("notification.label.unknownNodesButton"),class:"pull-left",click:function(){RED.actions.invoke("core:search","type:unknown ")}},{class:"primary",text:RED._("common.label.close"),click:function(){i[n].hideNotification()}}]):"missing-modules"===t.error?(e+="<ul><li>"+t.modules.map(function(e){return RED.utils.sanitize(e.module)+(e.error?" - <small>"+RED.utils.sanitize(""+e.error)+"</small>":"")}).join("</li><li>")+"</li></ul>",o.buttons=[{text:RED._("common.label.close"),click:function(){i[n].hideNotification()}}]):"credentials_load_failed"===t.error?RED.settings.theme("projects.enabled",!1)?RED.user.hasPermission("projects.write")&&(o.buttons=[{text:RED._("notification.project.setupCredentials"),click:function(){i[n].hideNotification(),RED.projects.showCredentialsPrompt()}}]):o.buttons=[{text:RED._("common.label.close"),click:function(){i[n].hideNotification()}}]:"missing_flow_file"===t.error||"missing_package_file"===t.error?RED.user.hasPermission("projects.write")&&(o.buttons=[{text:RED._("notification.project.setupProjectFiles"),click:function(){i[n].hideNotification(),RED.projects.showFilesPrompt()}}]):"project_empty"===t.error?RED.user.hasPermission("projects.write")&&(o.buttons=[{text:RED._("notification.project.no"),click:function(){i[n].hideNotification()}},{text:RED._("notification.project.createDefault"),click:function(){i[n].hideNotification(),RED.projects.createDefaultFileSet()}}]):"git_merge_conflict"===t.error&&(RED.nodes.clear(),RED.sidebar.versionControl.refresh(!0),RED.user.hasPermission("projects.write")&&(o.buttons=[{text:RED._("notification.project.mergeConflict"),click:function(){i[n].hideNotification(),RED.sidebar.versionControl.showLocalChanges()}}]))),i.hasOwnProperty(n)?i[n].update(e,o):i[n]=RED.notify(e,o)):i.hasOwnProperty(n)&&(i[n].close(),delete i[n]),"runtime-state"===n&&RED.events.emit("runtime-state",t)))}),RED.comms.subscribe("status/#",function(e,t){e=e.split("/"),e=RED.nodes.node(e[1]);e&&(t.hasOwnProperty("text")&&null!==t.text&&/^[@a-zA-Z]/.test(t.text)&&(t.text=e._(t.text.toString(),{defaultValue:t.text.toString()})),e.status=t,e.dirtyStatus=!0,e.dirty=!0,RED.view.redrawStatus(e))}),RED.comms.subscribe("notification/node/#",function(e,n){var t,o,i;if("notification/node/added"==e)RED.settings.refreshSettings(function(e,t){var o=[];n.forEach(function(e){var t=e.id;RED.nodes.addNodeSet(e),o=o.concat(e.types),RED.i18n.loadNodeCatalog(t,function(){var e=localStorage.getItem("editor-language")||RED.i18n.detectLanguage();$.ajax({headers:{Accept:"text/html","Accept-Language":e},cache:!1,url:"nodes/"+t,success:function(e){s(e)}})})}),o.length&&(i="<ul><li>"+o.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeAdded",{count:o.length})+i,"success")),r()});else if("notification/node/removed"==e){for(t=0;t<n.length;t++)o=n[t],RED.nodes.removeNodeSet(o.id).added&&(i="<ul><li>"+o.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeRemoved",{count:o.types.length})+i,"success"));r()}else"notification/node/enabled"==e?n.types&&RED.settings.refreshSettings(function(e,t){var o;RED.nodes.getNodeSet(n.id).added?(RED.nodes.enableNodeSet(n.id),i="<ul><li>"+n.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeEnabled",{count:n.types.length})+i,"success")):(o=localStorage.getItem("editor-language")||RED.i18n.detectLanguage(),$.ajax({headers:{Accept:"text/html","Accept-Language":o},cache:!1,url:"nodes/"+n.id,success:function(e){s(e),i="<ul><li>"+n.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeAdded",{count:n.types.length})+i,"success")}}))}):"notification/node/disabled"==e?n.types&&(RED.nodes.disableNodeSet(n.id),i="<ul><li>"+n.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeDisabled",{count:n.types.length})+i,"success")):"notification/node/upgraded"==e&&(RED.notify(RED._("palette.event.nodeUpgraded",{module:n.module,version:n.version}),"success"),RED.nodes.registry.setModulePendingUpdated(n.module,n.version))}),RED.comms.subscribe("event-log/#",function(e,t){e=e.substring(9);RED.eventLog.log(e,t)}),$(".red-ui-header-toolbar").show(),RED.sidebar.show(":first",!0),setTimeout(function(){var e;f.end(),!(e=function(){t&&RED.projects.showStartup()})!==RED.settings.theme("tours")&&RED.settings.get("editor.view.view-show-welcome-tours",!0)?RED.actions.invoke("core:show-welcome-tour",RED.settings.get("editor.tours.welcome"),e):e()},100)}function c(){var e=[];RED.settings.theme("projects.enabled",!1)&&e.push({id:"menu-item-projects-menu",label:RED._("menu.label.projects"),options:[{id:"menu-item-projects-new",label:RED._("menu.label.projects-new"),disabled:!1,onselect:"core:new-project"},{id:"menu-item-projects-open",label:RED._("menu.label.projects-open"),disabled:!1,onselect:"core:open-project"},{id:"menu-item-projects-settings",label:RED._("menu.label.projects-settings"),disabled:!1,onselect:"core:show-project-settings"}]}),e.push({id:"menu-item-edit-menu",label:RED._("menu.label.edit"),options:[{id:"menu-item-edit-undo",label:RED._("keyboard.undoChange"),disabled:!0,onselect:"core:undo"},{id:"menu-item-edit-redo",label:RED._("keyboard.redoChange"),disabled:!0,onselect:"core:redo"},null,{id:"menu-item-edit-cut",label:RED._("keyboard.cutNode"),onselect:"core:cut-selection-to-internal-clipboard"},{id:"menu-item-edit-copy",label:RED._("keyboard.copyNode"),onselect:"core:copy-selection-to-internal-clipboard"},{id:"menu-item-edit-paste",label:RED._("keyboard.pasteNode"),disabled:!0,onselect:"core:paste-from-internal-clipboard"},null,{id:"menu-item-edit-copy-group-style",label:RED._("keyboard.copyGroupStyle"),onselect:"core:copy-group-style"},{id:"menu-item-edit-paste-group-style",label:RED._("keyboard.pasteGroupStyle"),disabled:!0,onselect:"core:paste-group-style"},null,{id:"menu-item-edit-select-all",label:RED._("keyboard.selectAll"),onselect:"core:select-all-nodes"},{id:"menu-item-edit-select-connected",label:RED._("keyboard.selectAllConnected"),onselect:"core:select-connected-nodes"},{id:"menu-item-edit-select-none",label:RED._("keyboard.selectNone"),onselect:"core:select-none"},null,{id:"menu-item-edit-split-wire-with-links",label:RED._("keyboard.splitWireWithLinks"),onselect:"core:split-wire-with-link-nodes"}]}),e.push({id:"menu-item-view-menu",label:RED._("menu.label.view.view"),options:[{id:"menu-item-palette",label:RED._("menu.label.palette.show"),toggle:!0,onselect:"core:toggle-palette",selected:!0},{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:!0,onselect:"core:toggle-sidebar",selected:!0},{id:"menu-item-event-log",label:RED._("eventLog.title"),onselect:"core:show-event-log"},{id:"menu-item-action-list",label:RED._("keyboard.actionList"),onselect:"core:show-action-list"},null]}),e.push({id:"menu-item-arrange-menu",label:RED._("menu.label.arrange"),options:[{id:"menu-item-view-tools-move-to-back",label:RED._("menu.label.moveToBack"),disabled:!0,onselect:"core:move-selection-to-back"},{id:"menu-item-view-tools-move-to-front",label:RED._("menu.label.moveToFront"),disabled:!0,onselect:"core:move-selection-to-front"},{id:"menu-item-view-tools-move-backwards",label:RED._("menu.label.moveBackwards"),disabled:!0,onselect:"core:move-selection-backwards"},{id:"menu-item-view-tools-move-forwards",label:RED._("menu.label.moveForwards"),disabled:!0,onselect:"core:move-selection-forwards"},null,{id:"menu-item-view-tools-align-left",label:RED._("menu.label.alignLeft"),disabled:!0,onselect:"core:align-selection-to-left"},{id:"menu-item-view-tools-align-center",label:RED._("menu.label.alignCenter"),disabled:!0,onselect:"core:align-selection-to-center"},{id:"menu-item-view-tools-align-right",label:RED._("menu.label.alignRight"),disabled:!0,onselect:"core:align-selection-to-right"},null,{id:"menu-item-view-tools-align-top",label:RED._("menu.label.alignTop"),disabled:!0,onselect:"core:align-selection-to-top"},{id:"menu-item-view-tools-align-middle",label:RED._("menu.label.alignMiddle"),disabled:!0,onselect:"core:align-selection-to-middle"},{id:"menu-item-view-tools-align-bottom",label:RED._("menu.label.alignBottom"),disabled:!0,onselect:"core:align-selection-to-bottom"},null,{id:"menu-item-view-tools-distribute-horizontally",label:RED._("menu.label.distributeHorizontally"),disabled:!0,onselect:"core:distribute-selection-horizontally"},{id:"menu-item-view-tools-distribute-veritcally",label:RED._("menu.label.distributeVertically"),disabled:!0,onselect:"core:distribute-selection-vertically"}]}),e.push(null),RED.settings.theme("menu.menu-item-import-library",!0)&&e.push({id:"menu-item-import",label:RED._("menu.label.import"),onselect:"core:show-import-dialog"}),RED.settings.theme("menu.menu-item-export-library",!0)&&e.push({id:"menu-item-export",label:RED._("menu.label.export"),onselect:"core:show-export-dialog"}),e.push(null),e.push({id:"menu-item-search",label:RED._("menu.label.search"),onselect:"core:search"}),e.push(null),e.push({id:"menu-item-config-nodes",label:RED._("menu.label.displayConfig"),onselect:"core:show-config-tab"}),e.push({id:"menu-item-workspace",label:RED._("menu.label.flows"),options:[{id:"menu-item-workspace-add",label:RED._("menu.label.add"),onselect:"core:add-flow"},{id:"menu-item-workspace-edit",label:RED._("menu.label.rename"),onselect:"core:edit-flow"},{id:"menu-item-workspace-delete",label:RED._("menu.label.delete"),onselect:"core:remove-flow"}]}),e.push({id:"menu-item-subflow",label:RED._("menu.label.subflows"),options:[{id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:"core:create-subflow"},{id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:!0,onselect:"core:convert-to-subflow"}]}),e.push({id:"menu-item-group",label:RED._("menu.label.groups"),options:[{id:"menu-item-group-group",label:RED._("menu.label.groupSelection"),disabled:!0,onselect:"core:group-selection"},{id:"menu-item-group-ungroup",label:RED._("menu.label.ungroupSelection"),disabled:!0,onselect:"core:ungroup-selection"},null,{id:"menu-item-group-merge",label:RED._("menu.label.groupMergeSelection"),disabled:!0,onselect:"core:merge-selection-to-group"},{id:"menu-item-group-remove",label:RED._("menu.label.groupRemoveSelection"),disabled:!0,onselect:"core:remove-selection-from-group"}]}),e.push(null),!1!==RED.settings.get("externalModules.palette.allowInstall",!0)&&(e.push({id:"menu-item-edit-palette",label:RED._("menu.label.editPalette"),onselect:"core:manage-palette"}),e.push(null)),e.push({id:"menu-item-user-settings",label:RED._("menu.label.settings"),onselect:"core:show-user-settings"}),e.push(null),RED.settings.theme("menu.menu-item-keyboard-shortcuts",!0)&&e.push({id:"menu-item-keyboard-shortcuts",label:RED._("menu.label.keyboardShortcuts"),onselect:"core:show-help"}),e.push({id:"menu-item-help",label:RED.settings.theme("menu.menu-item-help.label",RED._("menu.label.help")),href:RED.settings.theme("menu.menu-item-help.url","http://nodered.org/docs")}),e.push({id:"menu-item-node-red-version",label:"v"+RED.settings.version,onselect:"core:show-about"}),$('<li><a id="red-ui-header-button-sidemenu" class="button" href="#"><i class="fa fa-bars"></i></a></li>').appendTo(".red-ui-header-toolbar"),RED.menu.init({id:"red-ui-header-button-sidemenu",options:e})}var u=null,p=!1;var f={init:function(){var e=$('<div id="red-ui-loading-progress"></div>').hide(),t=$("<div>").appendTo(e),t=($("<div>",{class:"red-ui-loading-bar-label"}).appendTo(t),$("<div>",{class:"red-ui-loading-bar"}).appendTo(t));$("<span>").appendTo(t);return e},start:function(e,t){e&&f.reportProgress(e,t),$("#red-ui-loading-progress").show()},reportProgress:function(e,t){$(".red-ui-loading-bar-label").text(e),$(".red-ui-loading-bar span").width(t+"%")},end:function(){$("#red-ui-loading-progress").hide(),f.reportProgress("",0)}};return{init:function(e){if(p)throw new Error("RED already initialised");var t,o,n;p=!0,window.ace&&window.ace.require("ace/ext/language_tools"),(e=e||{}).apiRootUrl=e.apiRootUrl||"",e.apiRootUrl&&!/\/$/.test(e.apiRootUrl)&&(e.apiRootUrl=e.apiRootUrl+"/"),e.target=$("#red-ui-editor"),e.target.addClass("red-ui-editor"),t=e,o=$('<div id="red-ui-header"></div>').appendTo(t.target),n=$('<span class="red-ui-header-logo"></span>').appendTo(o),$('<ul class="red-ui-header-toolbar hide"></ul>').appendTo(o),$('<div id="red-ui-header-shade" class="hide"></div>').appendTo(o),$('<div id="red-ui-main-container" class="red-ui-sidebar-closed hide"><div id="red-ui-workspace"></div><div id="red-ui-editor-stack" tabindex="-1"></div><div id="red-ui-palette"></div><div id="red-ui-sidebar"></div><div id="red-ui-sidebar-separator"></div></div>').appendTo(t.target),$('<div id="red-ui-editor-plugin-configs"></div>').appendTo(t.target),$('<div id="red-ui-editor-node-configs"></div>').appendTo(t.target),$('<div id="red-ui-full-shade" class="hide"></div>').appendTo(t.target),f.init().appendTo("#red-ui-main-container"),f.start("...",0),$.getJSON(t.apiRootUrl+"theme",function(e){e.header&&(e.header.url&&(n=$("<a>",{href:e.header.url}).appendTo(n)),e.header.image&&$("<img>",{src:e.header.image}).appendTo(n),e.header.title&&$("<span>").html(e.header.title).appendTo(n)),e.themes&&(u=e.themes)}),RED.i18n.init(e,function(){RED.settings.init(e,function(){u&&(RED.settings.editorTheme=RED.settings.editorTheme||{},RED.settings.editorTheme.themes=u),RED.workspaces.init(),RED.statusBar.init(),RED.view.init(),RED.userSettings.init(),RED.user.init(),RED.notifications.init(),RED.library.init(),RED.palette.init(),RED.eventLog.init(),!1!==RED.settings.get("externalModules.palette.allowInstall",!0)?RED.palette.editor.init():console.log("Palette editor disabled"),RED.sidebar.init(),RED.settings.theme("projects.enabled",!1)?RED.projects.init():console.log("Projects disabled"),RED.subflow.init(),RED.group.init(),RED.clipboard.init(),RED.search.init(),RED.actionList.init(),RED.editor.init(),RED.diagnostics.init(),RED.diff.init(),RED.deploy.init(RED.settings.theme("deployButton",null)),RED.keyboard.init(c),RED.nodes.init(),RED.runtime.init(),RED.comms.connect(),$("#red-ui-main-container").show(),i()})})},loader:f}}();RED.events=function(){var i={};return{on:function(e,t){i[e]=i[e]||[],i[e].push(t)},off:function(e,t){var o=i[e];if(o)for(var n=0;n<o.length;n++)if(o[n]===t)return void o.splice(n,1)},emit:function(){var t=arguments[0],e=Array.prototype.slice.call(arguments,1);if(RED.events.DEBUG&&console.warn(t,e),i[t])for(var o=0;o<i[t].length;o++)try{i[t][o].apply(null,e)}catch(e){console.warn("RED.events.emit error: ["+t+"] "+e.toString()),console.warn(e)}}}}(),RED.hooks=function(){var s={},r={};function d(e,t){var o=t.previousHook,n=t.nextHook;o?o.nextHook=n:s[e]=n,n&&(n.previousHook=o),t.removed=!0,o||n||delete s[e]}return{has:function(e){var t=(e=e.split("."))[0];return(e=e[1])?!(!r[e]||!r[e][t]):!!s[t]},clear:function(){s={},r={}},add:function(e,t){var o=e.split("."),n=o[0];if((o=o[1])&&r[o]&&r[o][n])throw new Error("Hook "+e+" already registered");var e={cb:t,previousHook:null,nextHook:null},i=s[n];if(void 0===i)s[n]=e;else{for(;null!==i.nextHook;)i=i.nextHook;(i.nextHook=e).previousHook=i}o&&(r[o]=r[o]||{},r[o][n]=e)},remove:function(e){var t=e.split("."),o=t[0],n=t[1];if(!n)throw new Error("Cannot remove hook without label: "+e);if(r[n])if("*"===o){for(var i=Object.keys(r[n]),a=0;a<i.length;a++)d(i[a],r[n][i[a]]);delete r[n]}else r[n][o]&&(d(o,r[n][o]),delete r[n][o],0===Object.keys(r[n]).length&&delete r[n])},trigger:function(e,n,i){var a=s[e];if(a)return function t(e){if(!a||e)return i&&i(e),e;if(a.removed)return a=a.nextHook,t();e=a.cb;if(1===e.length)try{var o=e(n);return!1===o?(i&&i(!1),o):(a=a.nextHook,t())}catch(e){return console.warn(e),i&&i(e),e}else try{e(n,function(e){void 0===e?(a=a.nextHook,t()):i&&i(e)})}catch(e){return console.warn(e),i&&i(e),e}}();i&&i()}}}(),RED.i18n=function(){var a;function s(){return navigator.language}return{init:function(e,t){a=e.apiRootUrl||"";var e=localStorage.getItem("editor-language")||s(),o={compatibilityJSON:"v3",backend:{loadPath:a+"locales/__ns__?lng=__lng__"},lng:"en-US",preload:["en-US"],ns:["editor","node-red","jsonata","infotips"],defaultNS:"editor",fallbackLng:["en-US"],returnObjects:!0,keySeparator:".",nsSeparator:":",interpolation:{unescapeSuffix:"HTML",escapeValue:!1,prefix:"__",suffix:"__"}};e&&(o.lng=e),i18next.use(i18nextHttpBackend).init(o,function(){t()}),jqueryI18next.init(i18next,$,{handleName:"i18n"}),RED._=function(){var e=i18next.t.apply(i18next,arguments);return"string"==typeof e?e:arguments[0]}},lang:function(){for(var e=[localStorage.getItem("editor-language")||s()].concat(i18next.languages),t=RED.settings.theme("languages")||["en-US"],o=0;o<e.length;o++)if(-1<t.indexOf(e[o]))return e[o];return"en-US"},loadNodeCatalog:function(o,n){var e=[localStorage.getItem("editor-language")||s()].concat(i18next.languages),i=e.length;e.forEach(function(t){$.ajax({headers:{Accept:"application/json"},cache:!1,url:a+"nodes/"+o+"/messages?lng="+t,success:function(e){i18next.addResourceBundle(t,o,e),0===--i&&n()}})})},loadNodeCatalogs:function(e){var t=[localStorage.getItem("editor-language")||s()].concat(i18next.languages),n=t.length;t.forEach(function(o){$.ajax({headers:{Accept:"application/json"},cache:!1,url:a+"nodes/messages?lng="+o,success:function(t){Object.keys(t).forEach(function(e){i18next.addResourceBundle(o,e,t[e])}),0===--n&&e()}})})},loadPluginCatalogs:function(e){var t=[localStorage.getItem("editor-language")||s()].concat(i18next.languages),n=t.length;t.forEach(function(o){$.ajax({headers:{Accept:"application/json"},cache:!1,url:a+"plugins/messages?lng="+o,success:function(t){Object.keys(t).forEach(function(e){i18next.addResourceBundle(o,e,t[e])}),0===--n&&e()}})})},detectLanguage:s}}(),RED.settings=function(){function n(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return}}function o(e){s=e}function i(o){r(function(e,t){e||(RED.settings.user&&!RED.settings.user.anonymous||RED.settings.remove("auth-tokens"),console.log("Node-RED: "+t.version),console.groupCollapsed("Versions"),console.log("jQuery",$().jquery),console.log("jQuery UI",$.ui.version),window.ace&&console.log("ACE",ace.version),window.monaco&&console.log("MONACO",monaco.version||"unknown"),console.log("D3",d3.version),console.groupEnd(),d(o))})}var e,a={},s={},r=function(n){$.ajax({headers:{Accept:"application/json"},dataType:"json",cache:!1,url:"settings",success:function(e){var t,o=e;for(t in a)a.hasOwnProperty(t)&&RED.settings.hasOwnProperty(t)&&delete RED.settings[t];for(t in o)o.hasOwnProperty(t)&&(RED.settings[t]=o[t]);a=o,n(null,e)},error:function(e,t,o){401===e.status?(/[?&]access_token=(.*?)(?:$|&)/.test(window.location.search)&&(window.location.search=""),RED.user.login(function(){r(n)})):console.log("Unexpected error loading settings:",e.status,t)}})};function d(t){$.ajax({headers:{Accept:"application/json"},dataType:"json",cache:!1,url:"settings/user",success:function(e){o(e),t()},error:function(e,t,o){console.log("Unexpected error loading user settings:",e.status,t)}})}function l(){RED.user.hasPermission("settings.write")&&(e&&clearTimeout(e),e=setTimeout(function(){e=null,$.ajax({method:"POST",contentType:"application/json",url:"settings/user",data:JSON.stringify(s),success:function(e){},error:function(e,t,o){console.log("Unexpected error saving user settings:",e.status,t)}})},300))}return{init:function(o,e){var t=/[?&]access_token=(.*?)(?:$|&)/.exec(window.location.search);t&&(t=t[1],RED.settings.set("auth-tokens",{access_token:t}),window.location.search=""),RED.settings.apiRootUrl=o.apiRootUrl,$.ajaxSetup({beforeSend:function(e,t){/^\s*(https?:|\/|\.)/.test(t.url)||(o.apiRootUrl&&(t.url=o.apiRootUrl+t.url),(t=RED.settings.get("auth-tokens"))&&e.setRequestHeader("Authorization","Bearer "+t.access_token),e.setRequestHeader("Node-RED-API-Version","v2"))}}),i(e)},load:i,loadUserSettings:d,refreshSettings:r,set:function(e,t){n()&&("auth-tokens"===e?localStorage.setItem(e,JSON.stringify(t)):(RED.utils.setMessageProperty(s,e,t),l()))},get:function(e,t){if(n()){if("auth-tokens"===e)return JSON.parse(localStorage.getItem(e));var o;try{o=RED.utils.getMessageProperty(s,e)}catch(e){}if(void 0===o)try{o=RED.utils.getMessageProperty(RED.settings,e)}catch(e){}return o=void 0===o?t:o}},remove:function(e){n()&&("auth-tokens"===e?localStorage.removeItem(e):(delete s[e],l()))},theme:function(e,t){if(!RED.settings.editorTheme)return t;var o=e.split("."),n=RED.settings.editorTheme;try{for(var i=0;i<o.length;i++)n=n[o[i]];return void 0===n?t:n}catch(e){return t}},setLocal:function(e,t){localStorage.setItem(e,t)},getLocal:function(e){return localStorage.getItem(e)},removeLocal:function(e){localStorage.removeItem(e)}}}(),RED.user=function(){function p(){$("#red-ui-header-button-user-submenu li").remove(),RED.settings.user.anonymous?RED.menu.addItem("red-ui-header-button-user",{id:"usermenu-item-login",label:RED._("menu.label.login"),onselect:function(){RED.user.login({cancelable:!0},function(){RED.settings.load(function(){RED.notify(RED._("user.loggedInAs",{name:RED.settings.user.username}),"success"),p(),RED.events.emit("login",RED.settings.user.username)})})}}):(RED.menu.addItem("red-ui-header-button-user",{id:"usermenu-item-username",label:"<b>"+RED.settings.user.username+"</b>"}),RED.menu.addItem("red-ui-header-button-user",{id:"usermenu-item-logout",label:RED._("menu.label.logout"),onselect:function(){RED.user.logout()}}))}var i=/^((.+)\.)?read$/,a=/^((.+)\.)?write$/;return{init:function(){var e;!RED.settings.user||RED.settings.editorTheme&&RED.settings.editorTheme.hasOwnProperty("userMenu")&&!RED.settings.editorTheme.userMenu||(e=$('<li><a id="red-ui-header-button-user" class="button hide" href="#"></a></li>').prependTo(".red-ui-header-toolbar"),(RED.settings.user.image?$('<span class="user-profile"></span>').css({backgroundImage:"url("+RED.settings.user.image+")"}):$('<i class="fa fa-user"></i>')).appendTo(e.find("a")),RED.menu.init({id:"red-ui-header-button-user",options:[]}),p())},login:function(l,c){"function"==typeof l&&(c=l,l={});var u=$('<div id="node-dialog-login" class="hide" style="display: flex; align-items: flex-end;"><div style="width: 250px; flex-grow: 0;"><img id="node-dialog-login-image" src=""/></div><div style="flex-grow: 1;"><form id="node-dialog-login-fields" class="form-horizontal" style="margin-bottom: 0px; margin-left:20px;"></form></div></div>');u.dialog({autoOpen:!1,classes:{"ui-dialog":"red-ui-editor-dialog","ui-dialog-titlebar-close":"hide","ui-widget-overlay":"red-ui-editor-dialog"},modal:!0,closeOnEscape:!!l.cancelable,width:600,resizable:!1,draggable:!1,close:function(e,t){$("#node-dialog-login").dialog("destroy").remove(),RED.keyboard.enable()}}),$("#node-dialog-login-fields").empty(),$.ajax({dataType:"json",url:"auth/login",success:function(i){var e=0;if("credentials"==i.type){for(;e<i.prompts.length;e++){var t=i.prompts[e],o=$("<div/>",{class:"form-row"}),n=($('<label for="node-dialog-login-'+t.id+'">'+RED._(t.label)+":</label><br/>").appendTo(o),$('<input style="width: 100%" id="node-dialog-login-'+t.id+'" type="'+t.type+'" tabIndex="'+(e+1)+'"/>').appendTo(o));e<i.prompts.length-1&&n.keypress(function(){var t=o;return function(e){13==e.keyCode&&(t.next("div").find("input").trigger("focus"),e.preventDefault())}}()),o.appendTo("#node-dialog-login-fields")}$('<div class="form-row" style="text-align: right; margin-top: 10px;"><span id="node-dialog-login-failed" style="line-height: 2em;float:left;color:var(--red-ui-text-color-error);" class="hide">'+RED._("user.loginFailed")+'</span><img src="red/images/spin.svg" style="height: 30px; margin-right: 10px; " class="login-spinner hide"/>'+(l.cancelable?'<a href="#" id="node-dialog-login-cancel" class="red-ui-button" style="margin-right: 20px;" tabIndex="'+(e+1)+'">'+RED._("common.label.cancel")+"</a>":"")+'<input type="submit" id="node-dialog-login-submit" class="red-ui-button" style="width: auto;" tabIndex="'+(e+2)+'" value="'+RED._("user.login")+'"></div>').appendTo("#node-dialog-login-fields"),$("#node-dialog-login-submit").button(),$("#node-dialog-login-fields").on("submit",function(e){$("#node-dialog-login-submit").button("option","disabled",!0),$("#node-dialog-login-failed").hide(),$(".login-spinner").show();for(var t={client_id:"node-red-editor",grant_type:"password",scope:""},o=0;o<i.prompts.length;o++){var n=i.prompts[o];t[n.id]=$("#node-dialog-login-"+n.id).val()}$.ajax({url:"auth/token",type:"POST",data:t}).done(function(e,t,o){RED.settings.set("auth-tokens",e),l.updateMenu&&p(),$("#node-dialog-login").dialog("close"),c()}).fail(function(e,t,o){RED.settings.remove("auth-tokens"),$("#node-dialog-login-failed").show()}).always(function(){$("#node-dialog-login-submit").button("option","disabled",!1),$(".login-spinner").hide()}),e.preventDefault()})}else if("strategy"==i.type){var a=/[?&]session_message=(.*?)(?:$|&)/.exec(window.location.search);if(RED.sessionMessages=RED.sessionMessages||[],a&&(RED.sessionMessages.push(decodeURIComponent(a[1])),history.pushState?(a=window.location.protocol+"//"+window.location.host+window.location.pathname,window.history.replaceState({path:a},"",a)):window.location.search=""),0===RED.sessionMessages.length&&i.autoLogin)return void(document.location=i.loginRedirect);for(e=0;e<i.prompts.length;e++){var s,r,t=i.prompts[e],o=(RED.sessionMessages&&(s=$("<div/>",{class:"form-row",style:"text-align: center"}).appendTo("#node-dialog-login-fields"),RED.sessionMessages.forEach(function(e){$("<div>").css("color","var(--red-ui-text-color-error)").text(e).appendTo(s)}),delete RED.sessionMessages),$("<div/>",{class:"form-row",style:"text-align: center"}).appendTo("#node-dialog-login-fields")),d=$('<a href="#" class="red-ui-button"></a>',{style:"padding: 10px"}).appendTo(o).on("click",function(){document.location=t.url});t.image?$("<img>",{src:t.image}).appendTo(d):t.label&&(r=$("<span></span>").text(t.label),t.icon&&($("<i></i>",{class:"fa fa-2x "+t.icon,style:"vertical-align: middle"}).appendTo(d),r.css({verticalAlign:"middle",marginLeft:"8px"})),r.appendTo(d)),d.button()}}l.cancelable&&$("#node-dialog-login-cancel").button().on("click",function(e){$("#node-dialog-login").dialog("close")});a=i.image||"red/images/node-red-256.svg";$("#node-dialog-login-image").load(function(){u.dialog("open")}).attr("src",a),RED.keyboard.disable()}})},logout:function(){var e=(e=RED.settings.get("auth-tokens"))?e.access_token:"";$.ajax({url:"auth/revoke",type:"POST",data:{token:e}}).done(function(e,t,o){RED.settings.remove("auth-tokens"),e&&e.redirect?document.location.href=e.redirect:document.location.reload(!0)}).fail(function(e,t,o){401===e.status?document.location.reload(!0):console.log(t)})},hasPermission:function(e){return""===e||(!RED.settings.user||function e(t,o){if(""===o)return!0;var n;if(Array.isArray(o)){for(n=0;n<o.length;n++)if(!e(t,o[n]))return!1;return!0}if(Array.isArray(t)){if(0!==t.length)for(n=0;n<t.length;n++)if(e(t[n],o))return!0;return!1}if("*"===t||t===o)return!0;{if("read"===t||"*.read"===t)return i.test(o);if("write"===t||"*.write"===t)return a.test(o)}return!1}(RED.settings.user.permissions||"",e))}}}(),RED.comms=function(){var i,a=null,s=null,l=null,c=10,u={},p=!1,f=0,h=!1;return{connect:function r(){h=!0,RED.settings.apiRootUrl?(t=/^(https?):\/\/(.*)$/.exec(RED.settings.apiRootUrl))&&(console.log(t),e="ws"+("https"===t[1]?"s":"")+"://"+t[2]+"comms"):(t=location.hostname,0!==(o=location.port).length&&(t=t+":"+o),t=(t+=document.location.pathname)+("/"==t.slice(-1)?"":"/")+"comms",e="ws"+("https:"==document.location.protocol?"s":"")+"://"+t);var e,t,o,n=RED.settings.get("auth-tokens");function d(){for(var e in u)u.hasOwnProperty(e)&&i.send(JSON.stringify({subscribe:e}))}p=null!=n,(i=new WebSocket(e)).onopen=function(){f=0,a&&(s=setTimeout(function(){a.close(),a=null},1e3)),p?i.send(JSON.stringify({auth:n.access_token})):d()},i.onmessage=function(e){var t=JSON.parse(e.data);if(t.auth)p&&"ok"===t.auth?(p=!1,d()):"fail"===t.auth&&(h=!1,RED.user.login({updateMenu:!0},function(){r()}));else for(var o=0;o<t.length;o++){var n=t[o];if(n.topic)for(var i in u)if(u.hasOwnProperty(i)&&new RegExp("^"+i.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(/.*)?")+"$").test(n.topic)){var a=u[i];if(a)for(var s=0;s<a.length;s++)a[s](n.topic,n.data)}}},i.onclose=function(){h&&(s&&(clearTimeout(s),s=null),++f<10?(setTimeout(r,1e3),5<f&&null==a&&(a=RED.notify(RED._("notification.errors.lostConnection"),"error",!0))):f<20?setTimeout(r,2e3):(c=60,l=setInterval(function(){var e;0==--c?(a.update(RED._("notification.errors.lostConnection")),clearInterval(l),r()):(e=RED._("notification.errors.lostConnectionReconnect",{time:c})+' <a href="#">'+RED._("notification.errors.lostConnectionTry")+"</a>",a.update(e,{silent:!0}),$(a).find("a").on("click",function(e){e.preventDefault(),a.update(RED._("notification.errors.lostConnection"),{silent:!0}),clearInterval(l),r()}))},1e3)))}},subscribe:function(e,t){null==u[e]&&(u[e]=[]),u[e].push(t),i&&1==i.readyState&&i.send(JSON.stringify({subscribe:e}))},unsubscribe:function(e,t){if(u[e]){for(var o=0;o<u[e].length;o++)if(u[e][o]===t){u[e].splice(o,1);break}0===u[e].length&&delete u[e]}}}}(),RED.runtime=function(){let o="",n={ui:!1,enabled:!1};const i="start";return{init:function(){n=Object.assign({},n,RED.settings.runtimeState),RED.events.on("runtime-state",function(e){var t;e.state&&(t=o,o=e.state,$(".red-ui-flow-node-button").toggleClass("red-ui-flow-node-button-stopped",o!==i),!0===n.enabled&&!0===n.ui&&(RED.menu.setVisible("deploymenu-item-runtime-stop",o===i),RED.menu.setVisible("deploymenu-item-runtime-start",o!==i)),""===t||o===t||e.deploy||"safe"===o||RED.notify(RED._("notification.state.flows"+("stop"===o?"Stopped":"Started"),e),"success"))})},get started(){return o===i}}}(),RED.text={},RED.text.bidi=function(){var t="";function o(e){return"auto"==t?function(e){for(var t,o=e.length,n=0;n<o;n++){if(1488<=(t=e.charCodeAt(n))&&t<=1535||1536<=t&&t<=1631||1642<=t&&t<=1775||1786<=t&&t<=2047||64285<=t&&t<=65023||65136<=t&&t<=65276)return 1;if(64<(t=e.charCodeAt(n))&&t<91||96<t&&t<123)return}}(e)?"rtl":"ltr":t}function n(){$(this).attr("dir",o($(this).val()))}return{setTextDirection:function(e){t=e,RED.nodes.eachNode(function(e){e.dirty=!0}),RED.view.redraw(),RED.palette.refresh(),$("#red-ui-workspace").find("span.red-ui-text-bidi-aware").each(function(){$(this).attr("dir",o($(this).html()))}),$("#red-ui-sidebar").find("span.red-ui-text-bidi-aware").each(function(){$(this).attr("dir",o($(this).text()))})},enforceTextDirectionWithUCC:function(e){if(e){var t=o(e);if("ltr"==t)return""+e+"";if("rtl"==t)return""+e+""}return e},resolveBaseTextDir:o,prepareInput:function(e){e.on("keyup",n).on("paste",n).on("cut",n),n.call(e)}}}(),RED.text.format=function(){var e,u=function(e){this.content="",this.actual="",this.textDirection="",this.localGui="",this.isVisible=!0,this.isSeparator=!1,this.isParsed=!1,this.keep=!1,this.inBounds=!1,this.inPoints=!1;var t="";for(t in e)e.hasOwnProperty(t)&&(this[t]=e[t])},d={handleSubcontents:function(e,t,o,n,i){if(!o.content||"string"!=typeof o.content||0===o.content.length)return e;var a=!0;void 0!==o.loops&&(a=!!o.loops);for(var s=0;;s++){1;{if(s>=e.length)break;if(!(e[s].isParsed||e.keep||e[s].isSeparator)){var r=e[s].content,d=r.indexOf(o.content);if(!(d<0)){var l,c=0;if(o.continued)for(;c++,0===(l=r.indexOf(o.content,d+c*o.content.length)););else c=1;if(l=d+c*o.content.length,e.splice(s,1),0<d&&(e.splice(s,0,new u({content:r.substring(0,d),localGui:t.dir,keep:!0})),s++),e.splice(s,0,new u({content:r.substring(d,l),textDirection:o.subDir,localGui:t.dir})),l<r.length&&e.splice(s+1,0,new u({content:r.substring(l,r.length),localGui:t.dir,keep:!0})),!a)break}}}}},handleBounds:function(e,t,o,n,i){for(var a=0;a<o.length;a++)if(function(e){var t;if(e)return void 0===e.start&&(e.start=""),void 0===e.end&&(e.end=""),void 0!==e.startAfter?(e.start=e.startAfter,e.after=!0):e.after=!1,void 0!==e.endBefore?(e.end=e.endBefore,e.before=!0):e.before=!1,t=parseInt(e.startPos,10),isNaN(t)?e.usePos=!1:e.usePos=!0,t=parseInt(e.length,10),isNaN(t)?e.useLength=!1:e.useLength=!0,e.loops=void 0===e.loops||!!e.loops,1}(o[a]))for(var s=0;;s++){1;{if(s>=e.length)break;if(!(e[s].isParsed||e[s].inBounds||e.keep||e[s].isSeparator)){var r=function(e,t){var o,n={};for(o in t)t.hasOwnProperty(o)&&(n[o]=t[o]);var e=e.content,i=n.usePos&&n.startPos<e.length;return i&&(n.start="",n.loops=!1),n.bStart=i?n.startPos:0<n.start.length?e.indexOf(n.start):0,(i=n.useLength&&0<n.length&&n.bStart+n.length<e.length)&&(n.end=""),n.bEnd=i?n.bStart+n.length:0<n.end.length?e.indexOf(n.end,n.bStart+n.start.length)+1:e.length,n.after||(n.start=""),n.before||(n.end=""),n}(e[s],o[a]),d=r.bStart,l=r.bEnd;if(!(d<0||l<0)){var c=e[s].content;if(e.splice(s,1),0<d&&(e.splice(s,0,new u({content:c.substring(0,d),localGui:t.dir,keep:!0})),s++),r.start&&(e.splice(s,0,new u({content:r.start,localGui:t.dir,isSeparator:!0})),s++),e.splice(s,0,new u({content:c.substring(d+r.start.length,l-r.end.length),textDirection:r.subDir,localGui:t.dir,inBounds:!0})),r.end&&(s++,e.splice(s,0,new u({content:r.end,localGui:t.dir,isSeparator:!0}))),l+r.end.length<c.length&&e.splice(s+1,0,new u({content:c.substring(l+r.end.length,c.length),localGui:t.dir,keep:!0})),!r.loops)break}}}}for(a=0;a<e.length;a++)e[a].inBounds=!1;return e},handleCases:function(e,t,o,n,i){if(0!==o.length){var a,s={};for(a in t)t.hasOwnProperty(a)&&(s[a]=t[a]);for(var r=0;r<o.length;r++)o[r].handler&&"function"==typeof o[r].handler.handle||(o[r].handler=t.commonHandler),o[r].args?(s.cases=o[r].args.cases,s.points=o[r].args.points,s.bounds=o[r].args.bounds,s.subs=o[r].args.subs):(s.cases=[],s.points=[],s.bounds=[],s.subs={}),o[r].handler.handle(n,e,s,i)}return e},handlePoints:function(e,t,o,n,i){for(var a=0;a<o.length;a++)for(var s,r,d=0;;d++){1;{if(d>=e.length)break;e[d].isParsed||e[d].keep||e[d].isSeparator||0<=(r=(s=e[d].content).indexOf(o[a]))&&(e.splice(d,1),0<r&&(e.splice(d,0,new u({content:s.substring(0,r),textDirection:t.subDir,localGui:t.dir,inPoints:!0})),d++),e.splice(d,0,new u({content:o[a],localGui:t.dir,isSeparator:!0})),r+o[a].length+1<=s.length&&e.splice(d+1,0,new u({content:s.substring(r+o[a].length),textDirection:t.subDir,localGui:t.dir,inPoints:!0})))}}for(a=0;a<e.length;a++)e[a].keep?e[a].keep=!1:e[a].inPoints&&(e[a].isParsed=!0,e[a].inPoints=!1);return e}},r={handle:function(e,t,o,n){var i=[],a=(Array.isArray(o.cases)&&(i=o.cases),[]),s=(void 0!==o.points&&(Array.isArray(o.points)?a=o.points:"string"==typeof o.points&&(a=o.points.split(""))),{}),r=("object"==typeof o.subs&&(s=o.subs),[]);return Array.isArray(o.bounds)&&(r=o.bounds),d.handleBounds(t,o,r,e,n),d.handleSubcontents(t,o,s,e,n),d.handleCases(t,o,i,e,n),d.handlePoints(t,o,a,e,n),t}},b={LRE:"",RLE:"",PDF:"",LRM:"",RLM:"",LRO:"",RLO:"",getLocaleDetails:function(e){var t,o;return e=(e=e||"undefined"!=typeof navigator&&(navigator.language||navigator.userLanguage)||"").toLowerCase(),!(o=(t=e)?t.split("-")[0]:"")||o.length<2||!["iw","he","ar","fa","ur"].some(function(e){return e===o})?{lang:"not-bidi"}:{lang:(t=e.split("-"))[0],country:t[1]||""}},removeUcc:function(e){return e&&e.replace(/[\u200E\u200F\u202A-\u202E]/g,"")},removeTags:function(e){return e&&e.replace(/<[^<]*>/g,"")},getDirection:function(e,t,o,n){if("auto"!==t&&/^(rtl|ltr)$/i.test(t))return t;o=/^(rtl|ltr)$/i.test(o)?o:"ltr";t=n?e.split("").reverse().join(""):e,n=/[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(t);return n?n[0]<="z"?"ltr":"rtl":o},hasArabicChar:function(e){return!!/[\u0600-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(e)},showMarks:function(e,t){for(var o="",n=0;n<e.length;n++){var i=""+e.charAt(n);switch(i){case"":o+="<LRM>";break;case"":o+="<RLM>";break;case"":o+="<LRE>";break;case"":o+="<RLE>";break;case"":o+="<LRO>";break;case"":o+="<RLO>";break;case"":o+="<PDF>";break;default:o+=i}}t=void 0!==t&&/^(rtl|ltr)$/i.test(t)?"rtl"===t?"":"":"";return t+o+(t?"":"")},hideMarks:function(e){return e.replace(/<LRM>/g,this.LRM).replace(/<RLM>/g,this.RLM).replace(/<LRE>/g,this.LRE).replace(/<RLE>/g,this.RLE).replace(/<LRO>/g,this.LRO).replace(/<RLO>/g,this.RLO).replace(/<PDF>/g,this.PDF)},showTags:function(e){return"<xmp>"+e+"</xmp>"},hideTags:function(e){return e.replace(/<xmp>/g,"").replace(/<\/xmp>/g,"")}},l=((e={}).parseAndDisplayStructure=function(e,t,o,n){return e&&t?a(i(e,t,n),t,o):e},e.parseStructure=i,e.displayStructure=a,e.restore=function(e,t){return e},e);function y(e,t){e=Array.isArray(e)?e[0]:e;return e.guiDir||(e.guiDir="ltr"),e.dir||(e.dir=e.guiDir),t&&(void 0===e.points&&(e.points=[]),e.cases||(e.cases=[]),e.bounds||(e.bounds=[]),e.commonHandler=r),e}function i(e,t,o){if(!e||!t)return new u({content:""});var t=y(t,!0),n=[new u({content:e,actual:e,localGui:t.dir})],i=r.handle;return(i=t.handler&&"function"==typeof t.handler?t.handler.handle:i)(e,n,t,o),n}function a(e,t,o){t=y(t,!1);if(o){for(var n,i,a=e,s=t,r="",d="",l=0;l<a.length;l++)stop=!a[l].isVisible||(i=a[l].textDirection,""!==(n=a[l].localGui)&&""===d?r+="<bdi dir='"+("rtl"===n?"rtl":"ltr")+"'>":""===d||""!==n&&n===d&&!stop||(r+="</bdi>"+(l==a.length-1&&""!==n?"":"<span style='unicode-bidi: embed; direction: "+("rtl"===s.dir?"rtl":"ltr")+";'></span>"),""!==n&&(r+="<bdi dir='"+("rtl"===n?"rtl":"ltr")+"'>")),"auto"===i&&(i=b.getDirection(a[l].content,i,s.guiDir)),/^(rtl|ltr)$/i.test(i)?r+="<bdi dir='"+("rtl"===i?"rtl":"ltr")+"'>"+a[l].content+"</bdi>":(r+=a[l].content,b.getDirection(a[l].content,i,s.guiDir,!0)),l<a.length-1?(i=n&&a[l+1].localGui?n:s.dir,r+="<span style='unicode-bidi: embed; direction: "+("rtl"===i?"rtl":"ltr")+";'></span>"):""!==d&&(r+="</bdi>"),d=n,!1);o="auto"===s.dir?b.getDirection(a[0].actual,s.dir,s.guiDir):s.dir;return r=o!==s.guiDir?"<bdi dir='"+("rtl"===o?"rtl":"ltr")+"'>"+r+"</bdi>":r}for(var c,u,p=e,f=t,h="",g="",m=!1,v=0;v<p.length;v++)m=!p[v].isVisible||(u=p[v].textDirection,""!==(c=p[v].localGui)&&""===g?h+="rtl"===c?b.RLE:b.LRE:""===g||""!==c&&c===g&&!m||(h+=b.PDF+(v==p.length-1&&""!==c?"":"rtl"===f.dir?b.RLM:b.LRM),""!==c&&(h+="rtl"===c?b.RLE:b.LRE)),"auto"===u&&(u=b.getDirection(p[v].content,u,f.guiDir)),/^(rtl|ltr)$/i.test(u)?h+=("rtl"===u?b.RLE:b.LRE)+p[v].content+b.PDF:(h+=p[v].content,b.getDirection(p[v].content,u,f.guiDir,!0)),v<p.length-1?(u=c&&p[v+1].localGui?c:f.dir,h+="rtl"===u?b.RLM:b.LRM):""!==g&&(h+=b.PDF),g=c,!1);o="auto"===f.dir?b.getDirection(p[0].actual,f.dir,f.guiDir):f.dir;return h=o!==f.guiDir?("rtl"===o?b.RLE:b.LRE)+h+b.PDF:h}var t,o,n={format:function(e,t,o,n,i,a){t={guiDir:o?"rtl":"ltr",dir:t.dir||(o?"rtl":"ltr"),subs:{content:">",continued:!0,subDir:o?"rtl":"ltr"},cases:[{args:{subs:{content:"<",continued:!0,subDir:o?"ltr":"rtl"}}}]};return a?l.parseStructure(e,t,!!n,i):l.parseAndDisplayStructure(e,t,!!n,i)}},s={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:","};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},c={format:function(e,t,o,n,i,a){var s,o={guiDir:o?"rtl":"ltr",dir:(o=e,s=i,"ar"===b.getLocaleDetails(s).lang&&0<(s=o.indexOf("@"))&&s<o.length-1&&b.hasArabicChar(o.substring(s+1))?"rtl":"ltr"),points:"<>.:,;@",cases:[{handler:r,args:{bounds:[{startAfter:'"',endBefore:'"'},{startAfter:"(",endBefore:")"}],points:""}}]};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},p={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:"/\\:."};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},f={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:" /%^&[]<>=!?~:.,|()+-*{}"};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},h={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:"\t!#%&()*+,-./:;<=>?|[]{}",cases:[{handler:r,args:{bounds:[{startAfter:"/*",endBefore:"*/"},{startAfter:"--",end:"\n"},{startAfter:"--"}]}},{handler:r,args:{subs:{content:" ",continued:!0}}},{handler:r,args:{bounds:[{startAfter:"'",endBefore:"'"},{startAfter:'"',endBefore:'"'}]}}]};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},g={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:"_"};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},m={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:":?#/@.[]="};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},v={format:function(e,t,o,n,i,a){t={guiDir:o?"rtl":"ltr",dir:t.dir||(o?"rtl":"ltr"),points:" ,.!?;:"};return a?l.parseStructure(e,t,!!n,i):l.parseAndDisplayStructure(e,t,!!n,i)}},w={format:function(e,t,o,n,i,a){o={guiDir:o?"rtl":"ltr",dir:"ltr",points:" /[]<>=!:@.|()+-*",cases:[{handler:r,args:{bounds:[{startAfter:'"',endBefore:'"'},{startAfter:"'",endBefore:"'"}],points:""}}]};return a?l.parseStructure(e,o,!!n,i):l.parseAndDisplayStructure(e,o,!!n,i)}},E={format:function(e,t,o,n,i,a){var s={},r="",d=Array.isArray(t)?t[0]:t;for(r in d)d.hasOwnProperty(r)&&(s[r]=d[r]);return s.guiDir=o?"rtl":"ltr",s.dir=s.dir||s.guiDir,a?l.parseStructure(e,s,!!n,i):l.parseAndDisplayStructure(e,s,!!n,i)}};o=!(t={msgLang:"en",msgDir:"",phLang:"",phDir:"",phPacking:["{","}"],phStt:{type:"none",args:{}},guiDir:""});function D(e){return"he"===e||"iw"===e||"ar"===e?"rtl":"ltr"}function R(e){0===e.msgDir.length&&(e.msgDir=D(e.msgLang)),e.msgDir="ltr"!==e.msgDir&&"rtl"!==e.msgDir&&"auto"!=e.msgDir?"ltr":e.msgDir,0===e.guiDir.length&&(e.guiDir=e.msgDir),e.guiDir="rtl"!==e.guiDir?"ltr":"rtl",0===e.phDir.length&&(e.phDir=0===e.phLang.length?e.msgDir:D(e.phLang)),e.phDir="ltr"!==e.phDir&&"rtl"!==e.phDir&&"auto"!=e.phDir?"ltr":e.phDir,"string"==typeof e.phPacking&&(e.phPacking=e.phPacking.split("")),e.phPacking.length<2&&(e.phPacking=["{","}"])}var x=null;function _(e){switch(e){case"breadcrumb":return n;case"comma":return s;case"email":return c;case"filepath":return p;case"formula":return f;case"sql":return h;case"underscore":return g;case"url":return m;case"word":return v;case"xpath":return w;default:return E}}function $(t,e,o,n,i){if(!t||1!=t.nodeType)return!1;x||(x=document.createEvent("Event")).initEvent("TF",!0,!0),t.setAttribute("data-tf-type",e);e="undefined"===o?"{}":JSON.stringify(Array.isArray(o)?o[0]:o),t.setAttribute("data-tf-args",e),o="ltr";return"undefined"===n&&(t.dir?o=t.dir:t.style&&t.style.direction&&(o=t.style.direction),n="rtl"===o.toLowerCase()),t.setAttribute("data-tf-dir",n),t.setAttribute("data-tf-locale",b.getLocaleDetails(i).lang),!function(e){var t=window.navigator.userAgent;if(!(0<=t.indexOf("MSIE")||0<=t.indexOf("Trident")||0<=t.indexOf("Edge")))return(t=document.createElement(e.tagName)).contentEditable=!0,(e="oninput"in t)||(t.setAttribute("oninput","return;"),e="function"==typeof t.oninput),t=null,e}(t)?(t.onkeyup=function(e){k(e.target),t.dispatchEvent(x)},t.onmouseup=function(e){k(e.target),t.dispatchEvent(x)}):(t.oninput,t.oninput=function(e){k(e.target)}),k(t),!0}function k(e){var t=e.textContent||"",o=document.getSelection();if(0===t.length||!o||o.rangeCount<=0)e.dispatchEvent(x);else{var n=o.getRangeAt(0),i=n.cloneRange(),a=n.startContainer,s=n.startOffset,r=0,s=(3===a.nodeType&&(r+=s),i.setStart(e,0),i.setEndBefore(a),document.createElement("div")),d=(s.appendChild(i.cloneContents()),r+=s.textContent.length,e.innerHTML=_(e.getAttribute("data-tf-type")).format(t,JSON.parse(e.getAttribute("data-tf-args")),"true"===e.getAttribute("data-tf-dir"),!0,e.getAttribute("data-tf-locale")),e),l=e,c=0,u=!1;for(o.removeAllRanges(),n.setStart(e,0),n.setEnd(e,0);l;){if(3===l.nodeType){if(c+l.nodeValue.length>=r){n.setStart(l,r-c);break}c+=l.nodeValue.length,l=l.nextSibling}else{if(l.hasChildNodes()){l=(d=l).firstChild;continue}l=l.nextSibling}for(;!l;){if(d===e){u=!0;break}l=d.nextSibling,d=d.parentNode}if(u)break}o.addRange(n),e.dispatchEvent(x)}}return{getHtml:function(e,t,o,n,i){return _(t).format(e,o,n,!0,i)},attach:$}}(),RED.state={DEFAULT:0,MOVING:1,JOINING:2,MOVING_ACTIVE:3,ADDING:4,EDITING:5,EXPORT:6,IMPORT:7,IMPORT_DRAGGING:8,QUICK_JOINING:9,PANNING:10,SELECTING_NODE:11,GROUP_DRAGGING:12,GROUP_RESIZE:13,DETACHED_DRAGGING:14,SLICING:15,SLICING_JUNCTION:16},RED.plugins=function(){var t={},o={};return{registerPlugin:function(e,n){(t[e]=n).type&&(o[n.type]=o[n.type]||[],o[n.type].push(n)),RED._loadingModule?(n.module=RED._loadingModule,n._=function(){var e=Array.prototype.slice.call(arguments),t=e[0],o=(/:/.test(e[0])||(e[0]=n.module+":"+e[0]),RED._.apply(null,e));return o===e[0]?t:o}):n._=RED._,n.onadd&&"function"==typeof n.onadd&&n.onadd(),RED.events.emit("registry:plugin-added",e)},getPlugin:function(e){return t[e]},getPluginsByType:function(e){return o[e]||[]}}}(),RED.nodes=function(){var ae,se,l={},re={},h=[],c={},de={},u=[],le={},x=null,ce={},p={},ue={},d={},t=!1;a={},s=[],r={},f={},o={},(g={}).tab={defaults:{label:{value:""},disabled:{value:!1},info:{value:""},env:{value:[]}}};var a,s,r,f,g,o,m,v,b,y,pe=m={setModulePendingUpdated:function(e,t){a[e].pending_version=t,RED.events.emit("registry:module-updated",{module:e,version:t})},getModule:function(e){return a[e]},getNodeSetForType:function(e){return m.getNodeSet(f[e])},getModuleList:function(){return a},getNodeList:function(){return s},getNodeTypes:function(){return Object.keys(g)},setNodeList:function(e){s=[];for(var t=0;t<e.length;t++){var o=e[t];m.addNodeSet(o)}},addNodeSet:function(e){if(e.types){e.added=!1,r[e.id]=e;for(var t=0;t<e.types.length;t++)f[e.types[t]]=e.id;s.push(e),a[e.module]=a[e.module]||{name:e.module,version:e.version,local:e.local,sets:{}},e.pending_version&&(a[e.module].pending_version=e.pending_version),a[e.module].sets[e.name]=e,RED.events.emit("registry:node-set-added",e)}},removeNodeSet:function(e){for(var t=r[e],o=0;o<t.types.length;o++)delete f[t.types[o]];delete r[e];for(var n=0;n<s.length;n++)if(s[n].id===e){s.splice(n,1);break}return delete a[t.module].sets[t.name],0===Object.keys(a[t.module].sets).length&&delete a[t.module],RED.events.emit("registry:node-set-removed",t),t},getNodeSet:function(e){return r[e]},enableNodeSet:function(e){e=r[e];e.enabled=!0,RED.events.emit("registry:node-set-enabled",e)},disableNodeSet:function(e){e=r[e];e.enabled=!1,RED.events.emit("registry:node-set-disabled",e)},registerNodeType:function(e,t){if("subflow:"!=e.substring(0,8)){var o,n,i;if(!r[f[e]])return o="",n=e,RED._loadingModule&&(n="["+RED._loadingModule+"] "+e,o=r[RED._loadingModule]?r[RED._loadingModule].err||"":"Unknown error"),void RED.notify(RED._("palette.event.unknownNodeRegistered",{type:n,error:o}),"error");t.set=r[f[e]],r[f[e]].added=!0,r[f[e]].enabled=!0,i="node-red"===t.set.module?"node-red":t.set.id,t._=function(){var e=Array.prototype.slice.call(arguments,0),t=e[0],o=(-1===e[0].indexOf(":")&&(e[0]=i+":"+e[0]),RED._.apply(null,e));return o=o===e[0]?t:o}}if(t.type=e,(g[e]=t).defaults)for(var a in t.defaults)if(t.defaults.hasOwnProperty(a)&&t.defaults[a].type)try{t.defaults[a]._type=function(e){e=e.trim();var t,o=0,n=/\[\]$/.test(e);n&&(e=e.substring(0,e.length-2));var i=e.length,a=!1,s=!1,r="",d=[];for(;o<i;){if(t=e[o],s)"|"===t?(d.push(r.trim()),r="",s=!1):")"===t?(d.push(r.trim()),r="",s=a=!1):r+=t;else if("("===t){if(a)throw new Error("Invalid character '"+t+"' at position "+o);a=!0}else" "!==t&&(s=!0,r=t);o++}0<(r=r.trim()).length&&d.push(r);return{types:d,array:n}}(t.defaults[a].type)}catch(e){console.warn(e)}RED.events.emit("registry:node-type-added",e)},removeNodeType:function(e){if("subflow:"!=e.substring(0,8))throw new Error("this api is subflow only. called with:",e);delete g[e],RED.events.emit("registry:node-type-removed",e)},getNodeType:function(e){return g[e]},setIconSets:function(e){(o=e)["font-awesome"]=RED.nodes.fontAwesome.getIconList()},getIconSets:function(){return o}},fe=(v={},b={},y={addTab:function(e){b[e]=[]},hasTab:function(e){return b.hasOwnProperty(e)},removeTab:function(e){delete b[e]},addNode:function(e){v[e.id]=e,b.hasOwnProperty(e.z)?b[e.z].push(e):(console.warn("Node added to unknown tab/subflow:",e),b._=b._||[],b._.push(e))},removeNode:function(e){var t;delete v[e.id],b.hasOwnProperty(e.z)&&-1<(t=b[e.z].indexOf(e))&&b[e.z].splice(t,1)},hasNode:function(e){return v.hasOwnProperty(e)},getNode:function(e){return v[e]},moveNode:function(e,t){y.removeNode(e),e.z=t,y.addNode(e)},moveNodesForwards:function(e){for(var t=[],o=(Array.isArray(e)||(e=[e]),b[e[0].z]),n=new Set(e.filter(function(e){return"group"!==e.type&&"subflow"!==e.type})),i=new Set,a=o.length-1;0<=a&&0!==n.size;a--){var s=o[a];n.has(s)&&(a<o.length-1&&!i.has(o[a+1])&&(o.splice(a,1),o.splice(a+1,0,s),s._reordered=!0,t.push(s)),n.delete(s),i.add(s))}return 0<t.length&&RED.events.emit("nodes:reorder",{z:e[0].z,nodes:t}),t},moveNodesBackwards:function(e){for(var t=[],o=(Array.isArray(e)||(e=[e]),b[e[0].z]),n=new Set(e.filter(function(e){return"group"!==e.type&&"subflow"!==e.type})),i=new Set,a=0;a<o.length&&0!==n.size;a++){var s=o[a];n.has(s)&&(0<a&&!i.has(o[a-1])&&(o.splice(a,1),o.splice(a-1,0,s),s._reordered=!0,t.push(s)),n.delete(s),i.add(s))}return 0<t.length&&RED.events.emit("nodes:reorder",{z:e[0].z,nodes:t}),t},moveNodesToFront:function(e){for(var t=[],o=(Array.isArray(e)||(e=[e]),b[e[0].z]),n=new Set(e.filter(function(e){return"group"!==e.type&&"subflow"!==e.type})),i=o.length-1,a=o.length-1;0<=a&&0!==n.size;a--){var s=o[a];n.has(s)&&(a<i&&(o.splice(a,1),o.splice(i,0,s),s._reordered=!0,t.push(s)),i--,n.delete(s))}return 0<t.length&&RED.events.emit("nodes:reorder",{z:e[0].z,nodes:t}),t},moveNodesToBack:function(e){for(var t=[],o=(Array.isArray(e)||(e=[e]),b[e[0].z]),n=new Set(e.filter(function(e){return"group"!==e.type&&"subflow"!==e.type})),i=0,a=0;a<o.length&&0!==n.size;a++){var s=o[a];n.has(s)&&(i<a&&(o.splice(a,1),o.splice(i,0,s),s._reordered=!0,t.push(s)),i++,n.delete(s))}return 0<t.length&&RED.events.emit("nodes:reorder",{z:e[0].z,nodes:t}),t},getNodes:function(e){return b[e]},clear:function(){v={},b={}},eachNode:function(e){var t,o,n;for(o in le)if(le.hasOwnProperty(o))for(t=b[o],n=0;n<t.length;n++)if(!1===e(t[n]))return;for(o=0;o<u.length;o++)for(t=b[u[o]],n=0;n<t.length;n++)if(!1===e(t[n]))return;if(b._)for(t=b._,n=0;n<t.length;n++)if(!1===e(t[n]))return},filterNodes:function(e){var t=[],o=null,n=!1,i=(e.hasOwnProperty("z")&&(b.hasOwnProperty(e.z)?o=b[e.z]:n=!0),!1);null===o&&(o=Object.keys(v),i=!0);for(var a=0;a<o.length;a++){var s=o[a];i&&(s=v[s]),e.hasOwnProperty("type")&&s.type!==e.type||n&&s.z!==e.z||t.push(s)}return t},getNodeOrder:function(e){return b[e].map(function(e){return e.id})},setNodeOrder:function(e,t){var o={};t.forEach(function(e,t){o[e]=t}),b[e].sort(function(e,t){return e._reordered=!0,t._reordered=!0,o[e.id]-o[t.id]})}});function he(){for(var e=[],t=0;t<8;t++)e.push(Math.round(255*Math.random()).toString(16).padStart(2,"0"));return e.join("")}function we(e){var t,o;0!==e.type.indexOf("subflow")?e._=e._def._:(t=e.type.substring(8),(t=RED.nodes.subflow(t))&&t.instances.push(t),e._=RED._),"config"==e._def.category?re[e.id]=e:(e.wires&&e.wires.length>e.outputs&&(e.outputs=e.wires.length),e.dirty=!0,C(e),"subflows"==e._def.category&&void 0===e.i&&(o=0,RED.nodes.eachNode(function(e){o=Math.max(o,e.i||0)}),e.i=o+1),fe.addNode(e),c[e.id]||(c[e.id]={in:[],out:[]})),RED.events.emit("nodes:add",e)}function ge(t){if(c[t.source.id]&&!c[t.source.id].out.every(function(e){return e.sourcePort!==t.sourcePort||e.target.id!==t.target.id}))return;h.push(t),t.source&&(c[t.source.id]||(c[t.source.id]={in:[],out:[]}),c[t.source.id].out.push(t)),t.target&&(c[t.target.id]||(c[t.target.id]={in:[],out:[]}),c[t.target.id].in.push(t)),t.source.z===t.target.z&&l[t.source.z]&&l[t.source.z].push(t),RED.events.emit("links:add",t)}function _(e){return e in re?re[e]:fe.getNode(e)}function w(e){var t,o=[],i=[];if(e in re)t=re[e],delete re[e],RED.events.emit("nodes:remove",t),RED.workspaces.refresh();else if(fe.hasNode(e)){t=fe.getNode(e),fe.removeNode(t),delete c[e],(o=h.filter(function(e){return e.source===t||e.target===t})).forEach(E);var a,s,r,d=!1;for(a in t._def.defaults)!t._def.defaults.hasOwnProperty(a)||(s=t._def.defaults[a]).type&&(s=pe.getNodeType(s.type))&&"config"==s.category&&(s=re[t[a]])&&(d=!0,s._def.exclusive?(w(t[a]),i.push(s)):((r=s.users).splice(r.indexOf(t),1),RED.events.emit("nodes:change",s)));0===t.type.indexOf("subflow:")&&(e=t.type.substring(8),(e=RED.nodes.subflow(e))&&e.instances.splice(e.instances.indexOf(t),1)),d&&RED.workspaces.refresh();try{t._def.oneditdelete&&t._def.oneditdelete.call(t)}catch(e){console.log("oneditdelete",t.id,t.type,e.toString())}RED.events.emit("nodes:remove",t)}return t&&t._def.onremove&&(console.log("Deprecated API warning: node type ",t.type," has an onremove function - should be oneditremove - please report"),t._def.onremove.call(n)),{links:o,nodes:i}}function E(e){var t,o=h.indexOf(e);-1!=o&&(h.splice(o,1),e.source&&c[e.source.id]&&(-1!==(t=c[e.source.id].out.indexOf(e))&&c[e.source.id].out.splice(t,1)),e.target&&c[e.target.id]&&(-1!==(t=c[e.target.id].in.indexOf(e))&&c[e.target.id].in.splice(t,1)),e.source.z===e.target.z&&l[e.source.z]&&-1!==(o=l[e.source.z].indexOf(e))&&l[e.source.z].splice(o,1)),RED.events.emit("links:remove",e)}function me(e,t){de[e.id]=e,fe.addTab(e.id),l[e.id]=[],e._def=RED.nodes.getType("tab"),void 0===t?u.push(e.id):u.splice(t,0,e.id),RED.events.emit("flows:add",e),void 0!==t&&RED.events.emit("flows:reorder",u)}function Ee(t,e){var o,n;e&&((e=Object.keys(le).map(function(e){return le[e].name})).sort(),o=1,n=t.name,e.forEach(function(e){n==e&&(o++,n=t.name+" ("+o+")")}),t.name=n),le[t.id]=t,fe.addTab(t.id),l[t.id]=[],RED.nodes.registerType("subflow:"+t.id,{defaults:{name:{value:""},env:{value:[]}},icon:function(){return t.icon||"subflow.svg"},category:t.category||"subflows",inputs:t.in.length,outputs:t.out.length,color:t.color||"#DDAA99",label:function(){return this.name||RED.nodes.subflow(t.id).name},labelStyle:function(){return this.name?"red-ui-flow-node-label-italic":""},paletteLabel:function(){return RED.nodes.subflow(t.id).name},inputLabels:function(e){return t.inputLabels?t.inputLabels[e]:null},outputLabels:function(e){return t.outputLabels?t.outputLabels[e]:null},oneditprepare:function(){"subflow"!==this.type?RED.subflow.buildEditForm("subflow",this):RED.subflow.buildEditForm("subflow-template",this)},oneditresize:function(e){"subflow"===this.type&&$("#node-input-env-container").editableList("height",e.height-80)},set:{module:"node-red"}}),t.instances=[],t._def=RED.nodes.getType("subflow:"+t.id),RED.events.emit("subflows:add",t)}function ve(e){return le[e]}function be(e,t){for(var o=fe.getNodes(e),n=0;n<o.length;n++){var i=o[n],i=/^subflow:(.+)$/.exec(i.type);if(i){if(i[1]===t)return!0;if(be(i[1],t))return!0}}return!1}function e(e,t){RED.view.selection();for(var o=new Set,n=[e],i=!0;0<n.length;){var a=n.shift(),s=(o.add(a),[]);i&&t&&(!i||"up"!==t)||(s=s.concat(c[a.id].in)),i&&t&&(!i||"down"!==t)||(s=s.concat(c[a.id].out)),i=!1,s.forEach(function(e){o.has(e.source)||n.push(e.source),o.has(e.target)||n.push(e.target)})}return Array.from(o)}function k(e,t){var o,n=!0,i=(t&&t.hasOwnProperty("credentials")&&(n=t.credentials),{});for(o in i.id=e.id,i.type=e.type,e._def.defaults)e._def.defaults.hasOwnProperty(o)&&(i[o]=e[o]);if(n){var a={};if(e.credentials){for(var s in e.credentials)e.credentials.hasOwnProperty(s)&&(!e.credentials._||e.credentials["has_"+s]!=e.credentials._["has_"+s]||e.credentials["has_"+s]&&e.credentials[s])&&(a[s]=e.credentials[s]);0<Object.keys(a).length&&(i.credentials=a)}}return i}function D(t,e){var o=!0,n=!1;if(!1===e?o=!1:"object"==typeof e&&(e.hasOwnProperty("credentials")&&(o=e.credentials),e.hasOwnProperty("dimensions")&&(n=e.dimensions)),"tab"===t.type)return k(t,{credentials:o});var i={};if(i.id=t.id,i.type=t.type,i.z=t.z,0!==i.z&&""!==i.z||delete i.z,!0===t.d&&(i.d=!0),t.g&&(i.g=t.g),"unknown"==i.type)for(var a in t._orig)t._orig.hasOwnProperty(a)&&(i[a]=t._orig[a]);else{for(var s in t._def.defaults)t._def.defaults.hasOwnProperty(s)&&(i[s]=t[s]);if(o){var r={};if((/^subflow:/.test(i.type)||"group"===i.type)&&t.credentials)for(var d in t.credentials)t.credentials.hasOwnProperty(d)&&(!t.credentials._||t.credentials["has_"+d]!=t.credentials._["has_"+d]||t.credentials["has_"+d]&&t.credentials[d])&&(r[d]=t.credentials[d]);else if(t.credentials)for(var l in i.credentials={},t._def.credentials)t._def.credentials.hasOwnProperty(l)&&("password"==t._def.credentials[l].type?(!t.credentials._||t.credentials["has_"+l]!=t.credentials._["has_"+l]||t.credentials["has_"+l]&&t.credentials[l])&&(r[l]=t.credentials[l]):null==t.credentials[l]||t.credentials._&&t.credentials[l]==t.credentials._[l]||(r[l]=t.credentials[l]));0<Object.keys(r).length&&(i.credentials=r)}}if("group"===t.type&&(i.x=t.x,i.y=t.y,i.w=t.w,i.h=t.h,i.nodes=i.nodes.filter(function(e){return!!e}).map(function(e){return e.id})),"tab"!==t.type&&"group"!==t.type||i.env&&0===i.env.length&&delete i.env,"config"!=t._def.category||"junction"===t.type){i.x=t.x,i.y=t.y,n&&(t.hasOwnProperty("w")||(e=RED.view.calculateNodeDimensions(t),t.w=e[0],t.h=e[1]),i.w=t.w,i.h=t.h),i.wires=[];for(var c=0;c<t.outputs;c++)i.wires.push([]);for(var u=h.filter(function(e){return e.source===t}),p=0;p<u.length;p++){var f=u[p];"subflow"!=f.target.type&&f.sourcePort<i.wires.length&&i.wires[f.sourcePort].push(f.target.id)}0<t.inputs&&t.inputLabels&&!/^\s*$/.test(t.inputLabels.join(""))&&(i.inputLabels=t.inputLabels.slice()),0<t.outputs&&t.outputLabels&&!/^\s*$/.test(t.outputLabels.join(""))&&(i.outputLabels=t.outputLabels.slice()),t._def.defaults&&t._def.defaults.hasOwnProperty("icon")||!t.icon||(o=RED.utils.getDefaultNodeIcon(t._def,t),t.icon!==o.module+"/"+o.file&&(i.icon=t.icon)),t._def.defaults&&t._def.defaults.hasOwnProperty("l")||!t.hasOwnProperty("l")||(!t._def.hasOwnProperty("showLabel")||t._def.showLabel)!=t.l&&(i.l=t.l)}return t.info&&(i.info=t.info),i}function T(a,e){var t=!0,s=(!1===e?t=!1:"object"==typeof e&&(e.hasOwnProperty("credentials")&&(t=e.credentials),e.hasOwnProperty("dimensions")&&e.dimensions),{});if(s.id=a.id,s.type=a.type,s.name=a.name,s.info=a.info,s.category=a.category,s.in=[],s.out=[],s.env=a.env,s.meta=a.meta,t){var o,n={};for(o in a.credentials)a.credentials.hasOwnProperty(o)&&(!a.credentials._||a.credentials["has_"+o]!=a.credentials._["has_"+o]||a.credentials["has_"+o]&&a.credentials[o])&&(n[o]=a.credentials[o]);0<Object.keys(n).length&&(s.credentials=n)}return s.color=a.color,a.in.forEach(function(t){for(var e={x:t.x,y:t.y,wires:[]},o=h.filter(function(e){return e.source===t}),n=0;n<o.length;n++){var i=o[n];"subflow"!=i.target.type&&e.wires.push({id:i.target.id})}s.in.push(e)}),a.out.forEach(function(t,e){var o={x:t.x,y:t.y,wires:[]},n=h.filter(function(e){return e.target===t});for(i=0;i<n.length;i++)"subflow"!=n[i].source.type?o.wires.push({id:n[i].source.id,port:n[i].sourcePort}):o.wires.push({id:a.id,port:0});s.out.push(o)}),0<s.in.length&&a.inputLabels&&!/^\s*$/.test(a.inputLabels.join(""))&&(s.inputLabels=a.inputLabels.slice()),0<s.out.length&&a.outputLabels&&!/^\s*$/.test(a.outputLabels.join(""))&&(s.outputLabels=a.outputLabels.slice()),a.icon&&"node-red/subflow.svg"!==a.icon&&(s.icon=a.icon),a.status&&(s.status={x:a.status.x,y:a.status.y,wires:[]},h.forEach(function(e){e.target===a.status&&("subflow"!=e.source.type?s.status.wires.push({id:e.source.id,port:e.sourcePort}):s.status.wires.push({id:a.id,port:0}))})),s}function ye(o,t,e,n){var i=[];t=t||{},o=o.filter(function(e){return!t[e.id]&&(t[e.id]=!0)}),n=n||{},e=e||{};for(var a=0;a<o.length;a++){var s,r,d=o[a];if("subflow:"!=d.type.substring(0,8)||e[s=d.type.substring(8)]||(e[s]=!0,p=ve(s),(r=fe.getNodes(s).slice()).unshift(p),RED.nodes.eachConfig(function(e){e.z==s&&(r.push(e),n[e.id]=!0)}),i=ye(r=(r=r.concat(RED.nodes.junctions(s))).concat(RED.nodes.groups(s)),t,e,n).concat(i)),"subflow"!==d.type){var l,c,u=RED.nodes.convertNode(d);for(l in d._def.defaults)d._def.defaults[l].type&&(c=d[l],0===(c=(c=Array.isArray(c)?c:[c]).filter(function(e){var t;return!(e in re)||!1!==(t=re[e])._def.exportable&&(e in n||(n[e]=!0,o.push(t)),!0)})).length?u[l]=Array.isArray(d[l])?[]:"":u[l]=Array.isArray(d[l])?c:c[0]);i.push(u),"group"===d.type&&(i=i.concat(ye(d.nodes,t,e,n)))}else{var p=T(d);i.push(p)}}return i}function De(e){var o={tabs:{},subflows:{},groups:{},junctions:{},configs:{},nodes:{},all:[],conflicted:{},zMap:{}};return e.forEach(function(e){o.all.push(e),"tab"===e.type?o.tabs[e.id]=e:"subflow"===e.type?o.subflows[e.id]=e:"group"===e.type?o.groups[e.id]=e:"junction"===e.type?o.junctions[e.id]=e:e.hasOwnProperty("x")&&e.hasOwnProperty("y")?o.nodes[e.id]=e:o.configs[e.id]=e;var t=e.z||"__global__";o.zMap[t]=o.zMap[t]||[],o.zMap[t].push(e),(fe.hasNode(e.id)||re[e.id]||de[e.id]||le[e.id]||ce[e.id]||ue[e.id])&&(o.conflicted[e.id]=e)}),o}function Re(e){var a={},s={},o={},r=[],e=(e.forEach(function(e){"subflow"===e.type?s[e.id]=e:e.hasOwnProperty("x")||e.hasOwnProperty("y")||(o[e.id]=e),e.z&&(a[e.z]=a[e.z]||[],a[e.z].push(e))}),Object.keys(o)),t=(e.forEach(function(e){var t=o[e];s[t.z]&&delete o[e]}),e=Object.keys(o),Object.keys(s));return t.forEach(function(e){var t,o,n,i=s[e];r=r.concat((t=ve(t=e),(n=fe.getNodes(t.id))?(o=n.slice()).unshift(t):o=[t],ye(o))),RED.subflow.removeSubflow(i.id,!0),R([i].concat(a[i.id]));s[e]=ve(e)}),RED.nodes.eachNode(function(e){var t;/^subflow:/.test(e.type)&&(t=e.type.substring(8),s[t]&&(s[t].instances.push(e),e._def=RED.nodes.getType(e.type),e.dirty=!0,e.changed=!0,e._colorChanged=!0))}),t.forEach(function(e){e=s[e];RED.events.emit("subflows:change",e)}),RED.utils.clearNodeColorCache(),e.forEach(function(e){r=r.concat(D(_(e))),w(e),R([o[e]])}),{removedNodes:r}}function R(e,o){(o=Object.assign({},{generateIds:!1,addFlow:!1,reimport:!1,importMap:{}},o)).importMap=o.importMap||{};var t,n=o.generateIds,A=!n&&!!o.reimport,M=o.addFlow,i={};if("string"==typeof e){if(""===e)return;try{r=JSON.parse(e)}catch(g){var a=new Error(RED._("clipboard.invalidFlow",{message:g.message}));throw a.code="NODE_RED",a}}else r=e;$.isArray(r)||(r=[r]);var z,B={},s=[],G=[],r=r.filter(function(e){var t=e.id;if(B[e.id])return!1;if(B[e.id]=!0,!o.generateIds)if(o.importMap[t]){if("replace"===o.importMap[t])return G.push(e),!1}else{t=fe.getNode(t)||re[t]||de[t]||le[t]||ce[t]||ue[t];t&&s.push({existing:t,imported:e})}return!0});if(0<s.length){for(var a=RED._("clipboard.importDuplicate",{count:s.length}),d=$("<ul>"),F=Math.min(5,s.length),l=0;l<F;l++){var c=s[l];$("<li>").text(c.existing.id+" [ "+c.existing.type+(c.imported.type!==c.existing.type?" | "+c.imported.type:"")+" ]").appendTo(d)}F!==s.length&&$("<li>").text(RED._("deploy.confirm.plusNMore",{count:s.length-F})).appendTo(d);e=$("<p>").append(d),a=new Error(a+e.html());throw a.code="import_conflict",a.importConfig=De(r),a}0<G.length&&(z=Re(G).removedNodes);var u,U=!1,p=(se||(U=!0,se=JSON.parse(JSON.stringify(r))),[]);for(l=0;l<r.length;l++){var f;(f=r[l]).id;"workspace"==f.type||"tab"==f.type||"subflow"==f.type||"group"==f.type||"junction"==f.type||pe.getNodeType(f.type)||"subflow:"==f.type.substring(0,8)||-1!=p.indexOf(f.type)||p.push(f.type),f.z?(i[f.z]=i[f.z]||[],i[f.z].push(f)):U&&f.hasOwnProperty("x")&&f.hasOwnProperty("y")&&!f.z&&(t||(me(t={id:RED.nodes.id(),type:"tab",disabled:!1,label:RED._("clipboard.recoveredNodes"),info:RED._("clipboard.recoveredNodesInfo"),env:[]}),RED.workspaces.add(t),i[t.id]=[]),f.z=t.id,i[t.id].push(f))}!U&&0<p.length&&(u=$("<ul>"),p.forEach(function(e){$("<li>").text(e).appendTo(u)}),u=u[0].outerHTML,RED.notify("<p>"+RED._("clipboard.importUnrecognised",{count:p.length})+"</p>"+u,"error",!1,1e4));var h=RED.workspaces.active(),V=ve(h);for(l=0;l<r.length;l++){var J=/^subflow:(.+)$/.exec(r[l].type);if(J){var g,J=J[1],q=ve(h);if(q)if(J===q.id&&(g=new Error(RED._("notification.errors.cannotAddSubflowToItself"))),g=be(J,q.id)?new Error(RED._("notification.errors.cannotAddCircularReference")):g)throw g.code="NODE_RED",g}}var m,v,b,y,W,w=[],E={},K=[],D={},H={},R={},x=[],_=[],k=[],T=[],X=new Set,C=null;for(t&&w.push(t),l=0;l<r.length;l++)"workspace"===(f=r[l]).type||"tab"===f.type?("workspace"===f.type&&(f.type="tab"),null==ae&&(ae=f),0===h&&(h=f.id),n||"copy"===o.importMap[f.id]?(m=he(),E[f.id]=m,f.id=m):E[f.id]=f.id,me(f),RED.workspaces.add(f),w.push(f)):"subflow"===f.type&&((W=o.importMap[f.id]?W:function(a,s){s=s||[];var r,d=null;return RED.nodes.eachSubflow(function(e){if(e.name==a.name&&e.info==a.info&&e.in.length==a.in.length&&e.out.length==a.out.length){var t=RED.nodes.filterNodes({z:e.id});if(t.length==s.length){var o=[a].concat(s),n=[e].concat(t),i=JSON.stringify(o),o=JSON.stringify(ye(n));for(r=0;r<t.length;r++)i=i.replace(new RegExp('"'+s[r].id+'"',"g"),'"'+t[r].id+'"');if((i=i.replace(new RegExp('"'+a.id+'"',"g"),'"'+e.id+'"'))===o)return d=e,!1}}}),d}(f,i[f.id]))?H[f.id]=W:(D[f.id]=f,!n&&"copy"!==o.importMap[f.id]||(m=he(),f.id=m),f.in.forEach(function(e,t){e.type="subflow",e.direction="in",e.z=f.id,e.i=t,e.id=he()}),f.out.forEach(function(e,t){e.type="subflow",e.direction="out",e.z=f.id,e.i=t,e.id=he()}),f.status&&(f.status.type="subflow",f.status.direction="status",f.status.z=f.id,f.status.id=he()),K.push(f),Ee(f,n||"copy"===o.importMap[f.id])));for(null==ae&&(me(ae={type:"tab",id:he(),disabled:!1,info:"",label:RED._("workspace.defaultName",{number:1}),env:[]}),RED.workspaces.add(ae),w.push(ae),h=RED.workspaces.active()),l=0;l<r.length;l++)if(f=r[l],(v=pe.getNodeType(f.type))&&"config"==v.category){var j=null;if(n||"copy"===o.importMap[f.id]){if(f.z){if(H[f.z])continue;D[f.z]?f.z=D[f.z].id:(f.z=E[f.z],de[f.z]||(M?(null===C&&(C=RED.workspaces.add(null,!0),w.push(C)),f.z=C.id):f.z=h))}if("copy"!==o.importMap[f.id]&&(j=RED.nodes.node(f.id))&&f.z&&j.z!==f.z)for(var L in j=null,re)if(re.hasOwnProperty(L)&&re[L].z===f.z&&function(e,t,o){if((!o||e.id==t.id)&&e.type==t.type){var n,i=e._def;for(n in i.defaults)if(i.defaults.hasOwnProperty(n)){var a=e[n],s=t[n];if(typeof a!=typeof s)return;if(null===a||"string"==typeof a||"number"==typeof a){if(a!==s)return}else if(JSON.stringify(a)!==JSON.stringify(s))return}return 1}}(re[L],f,!1)){j=re[L],R[f.id]=re[L];break}}else A&&f.z&&RED.workspaces.contains(f.z)||!f.z||E[f.z]||D[f.z]||(f.z=h);if(!j||j._def.exclusive){for(y in b={id:f.id,z:f.z,type:f.type,info:f.info,users:[],_config:{}},f.z||delete b.z,f.hasOwnProperty("d")&&(b.d=f.d),v.defaults)v.defaults.hasOwnProperty(y)&&(b[y]=f[y],b._config[y]=JSON.stringify(f[y]));if(v.hasOwnProperty("credentials")&&f.hasOwnProperty("credentials"))for(y in b.credentials={},v.credentials)v.credentials.hasOwnProperty(y)&&f.credentials.hasOwnProperty(y)&&(b.credentials[y]=f.credentials[y]);b.label=v.label,b._def=v,!n&&"copy"!==o.importMap[f.id]||(b.id=he()),R[f.id]=b,x.push(b)}}for(l=0;l<r.length;l++)if("workspace"!==(f=r[l]).type&&"tab"!==f.type&&"subflow"!==f.type&&(!(v=pe.getNodeType(f.type))||"config"!=v.category)){var S={x:parseFloat(f.x||0),y:parseFloat(f.y||0),z:f.z,type:0,info:f.info,changed:!1,_config:{}};if("group"!==f.type&&"junction"!==f.type&&(S.wires=f.wires||[],S.inputLabels=f.inputLabels,S.outputLabels=f.outputLabels,S.icon=f.icon),"junction"===f.type&&(S.wires=f.wires||[]),f.hasOwnProperty("l")&&(S.l=f.l),f.hasOwnProperty("d")&&(S.d=f.d),f.hasOwnProperty("g")&&(S.g=f.g),n||"copy"===o.importMap[f.id]){if(H[f.z])continue;D[S.z]?S.z=D[S.z].id:(S.z=E[S.z],de[S.z]||(M?(null===C&&(C=RED.workspaces.add(null,!0),w.push(C)),S.z=C.id):S.z=h)),S.id=he()}else S.id=f.id,A&&S.z&&RED.workspaces.contains(S.z)||null!=S.z&&(E[S.z]||D[S.z])||(M?(null===C&&(C=RED.workspaces.add(null,!0),w.push(C)),S.z=C.id):S.z=h);if(S.type=f.type,S._def=v,"group"===S.type){for(y in S._def=RED.group.def,S._def.defaults)S._def.defaults.hasOwnProperty(y)&&"inputs"!==y&&"outputs"!==y&&(S[y]=f[y],S._config[y]=JSON.stringify(f[y]));S._config.x=S.x,S._config.y=S.y}else if("subflow"===f.type.substring(0,7)){var Y=f.type.split(":")[1],Z=H[Y]||D[Y]||ve(Y);!n&&"copy"!==o.importMap[f.id]||(Y=Z.id,S.type="subflow:"+Y,S._def=pe.getNodeType(S.type),delete S.i),S.name=f.name,S.outputs=Z.out.length,S.inputs=Z.in.length,S.env=f.env}else if("junction"===f.type)S._def={defaults:{}},S._config.x=S.x,S._config.y=S.y,S.inputs=1,S.outputs=1,S.w=0,S.h=0;else{if(!S._def){S.x&&S.y?S._def={color:"#fee",defaults:{},label:"unknown: "+f.type,labelStyle:"red-ui-flow-node-label-italic",outputs:f.outputs||f.wires&&f.wires.length||0,set:pe.getNodeSet("node-red/unknown")}:(S._def={category:"config",set:pe.getNodeSet("node-red/unknown")},S.users=[],delete S.x,delete S.y,delete S.wires,delete S.inputLabels,delete S.outputLabels,f.z||delete S.z);var O,Q={};for(O in f)f.hasOwnProperty(O)&&"x"!=O&&"y"!=O&&"z"!=O&&"id"!=O&&"wires"!=O&&(Q[O]=f[O]);S._orig=Q,S.name=f.type,S.type="unknown"}if("config"!=S._def.category){for(y in f.hasOwnProperty("inputs")?(S.inputs=f.inputs,S._config.inputs=JSON.stringify(f.inputs)):S.inputs=S._def.inputs,f.hasOwnProperty("outputs")?(S.outputs=f.outputs,S._config.outputs=JSON.stringify(f.outputs)):S.outputs=S._def.outputs,S.hasOwnProperty("wires")&&S.wires.length>S.outputs&&(S._def.defaults.hasOwnProperty("outputs")&&isNaN(parseInt(f.outputs))?S.outputs=S.wires.length:(console.log("Warning: node.wires longer than node.outputs - trimming wires:",S.id," wires:",S.wires.length," outputs:",S.outputs),S.wires=S.wires.slice(0,S.outputs))),S._def.defaults)S._def.defaults.hasOwnProperty(y)&&"inputs"!==y&&"outputs"!==y&&(S[y]=f[y],S._config[y]=JSON.stringify(f[y]));if(S._config.x=S.x,S._config.y=S.y,S._def.hasOwnProperty("credentials")&&f.hasOwnProperty("credentials"))for(y in S.credentials={},S._def.credentials)S._def.credentials.hasOwnProperty(y)&&f.credentials.hasOwnProperty(y)&&(S.credentials[y]=f.credentials[y])}}"junction"===(R[f.id]=S).type?T.push(S):"unknown"===S.type||"config"!==S._def.category?x.push(S):"group"===S.type&&(k.push(S),X.add(S.id))}for(l=0;l<x.length+T.length;l++){if((f=l<x.length?x[l]:T[l-x.length]).wires){for(var I=0;I<f.wires.length;I++)for(var ee,te=Array.isArray(f.wires[I])?f.wires[I]:[f.wires[I]],N=0;N<te.length;N++)R.hasOwnProperty(te[N])&&(f.z===R[te[N]].z?(ge(ee={source:f,sourcePort:I,target:R[te[N]]}),_.push(ee)):console.log("Warning: dropping link that crosses tabs:",f.id,"->",R[te[N]].id));delete f.wires}for(var oe in f.g&&R[f.g]?f.g=R[f.g].id:delete f.g,f._def.defaults)f._def.defaults.hasOwnProperty(oe)&&f._def.defaults[oe].type&&(d=f[oe],d=(d=Array.isArray(d)?d:[d]).map(function(e){var t=R[e];return t?("config"===t._def.category&&-1===t.users.indexOf(f)&&t.users.push(f),t.id):e}),f[oe]=Array.isArray(f[oe])?d:d[0]);V&&/^link /.test(f.type)&&f.links&&(f.links=f.links.filter(function(e){e=RED.nodes.node(e);return e&&e.z===h}))}for(l=0;l<K.length;l++)(f=K[l]).in.forEach(function(t){t.wires.forEach(function(e){e={source:t,sourcePort:0,target:R[e.id]};ge(e),_.push(e)}),delete t.wires}),f.out.forEach(function(t){t.wires.forEach(function(e){e=D[e.id]&&D[e.id].id==f.id?{source:f.in[e.port],sourcePort:e.port,target:t}:{source:R[e.id]||D[e.id],sourcePort:e.port,target:t};ge(e),_.push(e)}),delete t.wires}),f.status&&(f.status.wires.forEach(function(e){e=D[e.id]&&D[e.id].id==f.id?{source:f.in[e.port],sourcePort:e.port,target:f.status}:{source:R[e.id]||D[e.id],sourcePort:e.port,target:f.status};ge(e),_.push(e)}),delete f.status.wires);var ne,ie,P={};for(l=0;l<k.length;l++)(f=k[l]).g&&!X.has(f.g)&&delete f.g,f.nodes=f.nodes.map(function(e){return R[e]}),f.nodes=f.nodes.filter(function(e){return e&&e.g!==f.id&&(e.g=f.id),!!e}),f.g||(P[f.id]=0);do{for(ne=!1,l=0;l<k.length;l++)(f=k[l]).g&&P[f.id]!==P[f.g]+1&&(P[f.id]=P[f.g]+1,ne=!0)}while(ne);for(k.sort(function(e,t){return P[e.id]-P[t.id]}),l=0;l<k.length;l++)xe(f=k[l]);for(l=0;l<T.length;l++)_e(T[l]);for(l=0;l<x.length;l++)we(S=x[l]);for(l=0;l<x.length;l++){S=x[l];RED.editor.validateNode(S)}return RED.workspaces.refresh(),t&&(ie=RED.notify(RED._("clipboard.recoveredNodesNotification",{flowName:RED._("clipboard.recoveredNodes")}),{type:"warning",fixed:!0,buttons:[{text:RED._("common.label.close"),click:function(){ie.close()}}]})),{nodes:x,links:_,groups:k,junctions:T,workspaces:w,subflows:K,missingWorkspace:C,removedNodes:z}}function C(e){for(var t in e._def.defaults){var o;!e._def.defaults.hasOwnProperty(t)||(o=e._def.defaults[t]).type&&(o=pe.getNodeType(o.type))&&"config"==o.category&&(o=re[e[t]])&&-1===o.users.indexOf(e)&&(o.users.push(e),RED.events.emit("nodes:change",o))}}function xe(e){p[e.z]=p[e.z]||[],p[e.z].push(e),ce[e.id]=e,RED.events.emit("groups:add",e)}function j(e){var t=p[e.z].indexOf(e);p[e.z].splice(t,1),0===p[e.z].length&&delete p[e.z],e.g&&ce[e.g]&&(t=ce[e.g].nodes.indexOf(e),ce[e.g].nodes.splice(t,1)),RED.group.markDirty(e),delete ce[e.id],RED.events.emit("groups:remove",e)}function _e(e){d[e.z]=d[e.z]||[],d[e.z].push(e),ue[e.id]=e,c[e.id]||(c[e.id]={in:[],out:[]}),RED.events.emit("junctions:add",e)}function L(t){var e=d[t.z].indexOf(t),e=(d[t.z].splice(e,1),0===d[t.z].length&&delete d[t.z],delete ue[t.id],delete c[t.id],RED.events.emit("junctions:remove",t),h.filter(function(e){return e.source===t||e.target===t}));return e.forEach(E),{links:e}}return{init:function(){RED.events.on("registry:node-type-added",function(t){pe.getNodeType(t);var o,n,i,a={},e=(RED.nodes.eachNode(function(e){"unknown"===e.type&&e.name===t&&(a[e.id]=e)}),RED.nodes.eachConfig(function(e){"unknown"===e.type&&e.name===t&&(a[e.id]=e)}),Object.keys(a));0<e.length&&(o=[],e.forEach(function(e){e=a[e];re.hasOwnProperty(e.id)?delete re[e.id]:fe.removeNode(e),o.push(D(e)),RED.events.emit("nodes:remove",e)}),n=[],RED.nodes.eachLink(function(e){a.hasOwnProperty(e.source.id)&&a.hasOwnProperty(e.target.id)&&n.push(e)}),n.forEach(E),RED.view.redraw(!0,!0),e=R(o,{generateIds:!1,reimport:!0}),i={},e.nodes.forEach(function(e){i[e.id]=e}),RED.nodes.eachLink(function(e){i.hasOwnProperty(e.source.id)&&(e.source=i[e.source.id]),i.hasOwnProperty(e.target.id)&&(e.target=i[e.target.id])}),RED.view.redraw(!0))})},registry:pe,setNodeList:pe.setNodeList,getNodeSet:pe.getNodeSet,addNodeSet:pe.addNodeSet,removeNodeSet:pe.removeNodeSet,enableNodeSet:pe.enableNodeSet,disableNodeSet:pe.disableNodeSet,setIconSets:pe.setIconSets,getIconSets:pe.getIconSets,registerType:pe.registerNodeType,getType:pe.getNodeType,getNodeHelp:function(e){var t="";return(e=$("script[data-help-name='"+e+"']"))&&(t=e.html(),"text/markdown"===e.attr("type")&&(t=RED.utils.renderMarkdown(t))),t},convertNode:D,add:we,remove:w,clear:function(){h=[],l={},c={},re={},u=[],ce={},p={},ue={},d={},Object.keys(le).forEach(function(e){RED.subflow.removeSubflow(e)}),Object.keys(de).forEach(function(e){RED.workspaces.remove(de[e])}),se=ae=null,de={},fe.clear(),RED.nodes.dirty(!1),RED.view.redraw(!0,!0),RED.palette.refresh(),RED.workspaces.refresh(),RED.sidebar.config.refresh(),RED.sidebar.info.refresh(),RED.events.emit("workspace:clear")},detachNodes:function(e){let o=[];if(e.forEach(e=>{var t;"group"===e.type?(t=RED.group.getNodes(e,!0,!0),o=o.concat(t)):o.push(e)}),0<o.length){const n=RED.nodes.getNodeIslands(o);let t=[],d=[],l=new Set;return n.forEach(e=>{let r=new Set(e),o=[],n=[];e.forEach(e=>{var t=RED.nodes.getNodeLinks(e,1),e=RED.nodes.getNodeLinks(e,0);t.forEach(e=>{r.has(e.source)||o.push(e)}),e.forEach(e=>{r.has(e.target)||n.push(e)})}),o.forEach(o=>{let n=o.source,t=new Set,i=new Set,a=[o.target];for(;0<a.length;){var s=a.pop(a);i.add(s);let e=RED.nodes.getNodeLinks(s,0);e.forEach(e=>{i.has(e.target)||(i.add(e.target),r.has(e.target)?a.push(e.target):t.add(e.target))})}t.forEach(e=>{var t=`${n.id}[${o.sourcePort}] -> `+e.id;l.has(t)||(l.add(t),t={source:n,sourcePort:o.sourcePort,target:e},0===RED.nodes.filterLinks(t).length&&d.push(t))})}),o.forEach(e=>{RED.nodes.removeLink(e),t.push(e)}),n.forEach(e=>{RED.nodes.removeLink(e),t.push(e)})}),d.forEach(e=>RED.nodes.addLink(e)),{newLinks:d,removedLinks:t}}},moveNodesForwards:function(e){return fe.moveNodesForwards(e)},moveNodesBackwards:function(e){return fe.moveNodesBackwards(e)},moveNodesToFront:function(e){return fe.moveNodesToFront(e)},moveNodesToBack:function(e){return fe.moveNodesToBack(e)},getNodeOrder:function(e){return fe.getNodeOrder(e)},setNodeOrder:function(e,t){fe.setNodeOrder(e,t)},moveNodeToTab:function(e,o){var t,n,i,a,s,r;"group"===e.type?(a=o,t=p[(r=e).z].indexOf(r),p[r.z].splice(t,1),p[a]=p[a]||[],p[a].push(r),r.z=a,RED.events.emit("groups:change",r)):"junction"===e.type?(n=o,a=d[(t=e).z].indexOf(t),d[t.z].splice(a,1),d[n]=d[n]||[],d[n].push(t),i=t.z,t.z=n,(a=c[t.id])&&(a.in.forEach(function(e){var t=l[i].indexOf(e);-1!=t&&l[i].splice(t,1),e.source.z===n&&l[n]&&l[n].push(e)}),a.out.forEach(function(e){var t=l[i].indexOf(e);-1!=t&&l[i].splice(t,1),e.target.z===n&&l[n]&&l[n].push(e)})),RED.events.emit("junctions:change",t)):(s=e.z,fe.moveNode(e,o),(r=c[e.id])&&(r.in.forEach(function(e){var t=l[s].indexOf(e);-1!=t&&l[s].splice(t,1),e.source.z===o&&l[o]&&l[o].push(e)}),r.out.forEach(function(e){var t=l[s].indexOf(e);-1!=t&&l[s].splice(t,1),e.target.z===o&&l[o]&&l[o].push(e)})),RED.events.emit("nodes:change",e))},addLink:ge,removeLink:E,getNodeLinks:function(e,t){return"string"!=typeof e&&(e=e.id),c[e]?[].concat(1===t?c[e].in:c[e].out):[]},addWorkspace:me,removeWorkspace:function(e){var t,o,n=de[e],i=[],a=[],s=[],r=[];if(n){for(t in delete de[e],delete l[e],u.splice(u.indexOf(e),1),fe.hasTab(e)&&(i=fe.getNodes(e).slice()),re)re.hasOwnProperty(t)&&(o=re[t]).z==e&&i.push(o);for(r=RED.nodes.junctions(e),t=0;t<i.length;t++)var d=w(i[t].id),a=a.concat(d.links);for(t=0;t<r.length;t++){d=L(r[t]);a=a.concat(d.links)}for(s=(p[e]||[]).filter(function(e){return!e.g}),t=0;t<s.length;t++)s[t].nodes.forEach(function(e){"group"===e.type&&s.push(e)});for(t=s.length-1;0<=t;t--)j(s[t]);fe.removeTab(e),RED.events.emit("flows:remove",n)}return{nodes:i,links:a,groups:s,junctions:r}},getWorkspaceOrder:function(){return u},setWorkspaceOrder:function(e){u=e},workspace:function(e){return de[e]},addSubflow:Ee,removeSubflow:function(e){le[e.id]&&(delete le[e.id],fe.removeTab(e.id),pe.removeNodeType("subflow:"+e.id),RED.events.emit("subflows:remove",e))},subflow:ve,subflowContains:be,addGroup:xe,removeGroup:j,group:function(e){return ce[e]},groups:function(e){return p[e]?p[e].slice():[]},addJunction:_e,removeJunction:L,junction:function(e){return ue[e]},junctions:function(e){return d[e]?d[e].slice():[]},eachNode:function(e){fe.eachNode(e)},eachLink:function(e){for(var t=0;t<h.length&&!1!==e(h[t]);t++);},eachConfig:function(e){for(var t in re)if(re.hasOwnProperty(t)&&!1===e(re[t]))break},eachSubflow:function(e){for(var t in le)if(le.hasOwnProperty(t)&&!1===e(le[t]))break},eachWorkspace:function(e){for(var t=0;t<u.length&&!1!==e(de[u[t]]);t++);},node:_,version:function(e){if(void 0===e)return x;x=e},originalFlow:function(e){if(void 0===e)return se;se=e},filterNodes:function(e){return fe.filterNodes(e)},filterLinks:function(e){var t,o=[],n=[],i=!1,a=e.source&&e.source.z,s=e.target&&e.target.z;(t=a||s?a!==s&&void 0===a?s:a:t)?(n=l[t]||[],i=!0):e.source&&e.source.hasOwnProperty("id")?c[e.source.id]&&(i=!0,n=n.concat(c[e.source.id].out)):e.target&&e.target.hasOwnProperty("id")&&c[e.target.id]&&(i=!0,n=n.concat(c[e.target.id].in)),i||(n=h);for(var r=0;r<n.length;r++){var d=n[r];if(e.source){if(e.source.hasOwnProperty("id")&&d.source.id!==e.source.id)continue;if(e.source.hasOwnProperty("z")&&d.source.z!==e.source.z)continue}if(e.target){if(e.target.hasOwnProperty("id")&&d.target.id!==e.target.id)continue;if(e.target.hasOwnProperty("z")&&d.target.z!==e.target.z)continue}e.hasOwnProperty("sourcePort")&&d.sourcePort!==e.sourcePort||o.push(d)}return o},import:R,identifyImportConflicts:De,getAllFlowNodes:e,getAllUpstreamNodes:function(t){return e(t,"up").filter(function(e){return e!==t})},getAllDownstreamNodes:function(t){return e(t,"down").filter(function(e){return e!==t})},getNodeIslands:function(e){var o=new Set(e),i=new Map,a=new Map,n=new Set;e.forEach((e,t)=>{i.set(e,t),a.set(t,[e]);t=RED.nodes.getNodeLinks(e,1),e=RED.nodes.getNodeLinks(e,0);t.forEach(e=>{o.has(e.source)&&n.add(e)}),e.forEach(e=>{o.has(e.target)&&n.add(e)})}),n.forEach(o=>{var n=o.source,o=o.target;if(i.get(n)!==i.get(o)){let t=i.get(n);n=i.get(o);let e=a.get(n);e.forEach(e=>{i.set(e,t),a.get(t).push(e)}),a.delete(n)}});const s=[];return a.forEach((e,t)=>{s.push(e)}),s},createExportableNodeSet:ye,createCompleteNodeSet:function(t){for(var o=[],e=0;e<u.length;e++)"tab"==de[u[e]].type&&o.push(k(de[u[e]],t));for(e in le)le.hasOwnProperty(e)&&o.push(T(le[e],t));for(e in ce)ce.hasOwnProperty(e)&&o.push(D(ce[e],t));for(e in ue)ue.hasOwnProperty(e)&&o.push(D(ue[e],t));for(e in re)re.hasOwnProperty(e)&&o.push(D(re[e],t));return RED.nodes.eachNode(function(e){o.push(D(e,t))}),o},updateConfigNodeUsers:C,id:he,dirty:function(e){if(null==e)return t;t=e,RED.events.emit("workspace:dirty",{dirty:t})}}}(),RED.nodes.fontAwesome=function(){var t={"fa-address-book-o":"","fa-address-book":"","fa-address-card-o":"","fa-address-card":"","fa-adjust":"","fa-align-center":"","fa-align-justify":"","fa-align-left":"","fa-align-right":"","fa-ambulance":"","fa-american-sign-language-interpreting":"","fa-anchor":"","fa-angle-double-down":"","fa-angle-double-left":"","fa-angle-double-right":"","fa-angle-double-up":"","fa-angle-down":"","fa-angle-left":"","fa-angle-right":"","fa-angle-up":"","fa-archive":"","fa-area-chart":"","fa-arrow-circle-down":"","fa-arrow-circle-left":"","fa-arrow-circle-o-down":"","fa-arrow-circle-o-left":"","fa-arrow-circle-o-right":"","fa-arrow-circle-o-up":"","fa-arrow-circle-right":"","fa-arrow-circle-up":"","fa-arrow-down":"","fa-arrow-left":"","fa-arrow-right":"","fa-arrow-up":"","fa-arrows-alt":"","fa-arrows-h":"","fa-arrows-v":"","fa-arrows":"","fa-asl-interpreting":"","fa-assistive-listening-systems":"","fa-asterisk":"","fa-at":"","fa-audio-description":"","fa-automobile":"","fa-backward":"","fa-balance-scale":"","fa-ban":"","fa-bank":"","fa-bar-chart-o":"","fa-bar-chart":"","fa-barcode":"","fa-bars":"","fa-bath":"","fa-bathtub":"","fa-battery-0":"","fa-battery-1":"","fa-battery-2":"","fa-battery-3":"","fa-battery-4":"","fa-battery-empty":"","fa-battery-full":"","fa-battery-half":"","fa-battery-quarter":"","fa-battery-three-quarters":"","fa-battery":"","fa-bed":"","fa-beer":"","fa-bell-o":"","fa-bell-slash-o":"","fa-bell-slash":"","fa-bell":"","fa-bicycle":"","fa-binoculars":"","fa-birthday-cake":"","fa-blind":"","fa-bold":"","fa-bolt":"","fa-bomb":"","fa-book":"","fa-bookmark-o":"","fa-bookmark":"","fa-braille":"","fa-briefcase":"","fa-bug":"","fa-building-o":"","fa-building":"","fa-bullhorn":"","fa-bullseye":"","fa-bus":"","fa-cab":"","fa-calculator":"","fa-calendar-check-o":"","fa-calendar-minus-o":"","fa-calendar-o":"","fa-calendar-plus-o":"","fa-calendar-times-o":"","fa-calendar":"","fa-camera-retro":"","fa-camera":"","fa-car":"","fa-caret-down":"","fa-caret-left":"","fa-caret-right":"","fa-caret-square-o-down":"","fa-caret-square-o-left":"","fa-caret-square-o-right":"","fa-caret-square-o-up":"","fa-caret-up":"","fa-cart-arrow-down":"","fa-cart-plus":"","fa-cc":"","fa-certificate":"","fa-chain-broken":"","fa-chain":"","fa-check-circle-o":"","fa-check-circle":"","fa-check-square-o":"","fa-check-square":"","fa-check":"","fa-chevron-circle-down":"","fa-chevron-circle-left":"","fa-chevron-circle-right":"","fa-chevron-circle-up":"","fa-chevron-down":"","fa-chevron-left":"","fa-chevron-right":"","fa-chevron-up":"","fa-child":"","fa-circle-o-notch":"","fa-circle-o":"","fa-circle-thin":"","fa-circle":"","fa-clipboard":"","fa-clock-o":"","fa-clone":"","fa-close":"","fa-cloud-download":"","fa-cloud-upload":"","fa-cloud":"","fa-cny":"","fa-code-fork":"","fa-code":"","fa-coffee":"","fa-cog":"","fa-cogs":"","fa-columns":"","fa-comment-o":"","fa-comment":"","fa-commenting-o":"","fa-commenting":"","fa-comments-o":"","fa-comments":"","fa-compass":"","fa-compress":"","fa-copy":"","fa-copyright":"","fa-creative-commons":"","fa-credit-card-alt":"","fa-credit-card":"","fa-crop":"","fa-crosshairs":"","fa-cube":"","fa-cubes":"","fa-cut":"","fa-cutlery":"","fa-dashboard":"","fa-database":"","fa-deaf":"","fa-deafness":"","fa-dedent":"","fa-desktop":"","fa-diamond":"","fa-dollar":"","fa-dot-circle-o":"","fa-download":"","fa-drivers-license-o":"","fa-drivers-license":"","fa-edit":"","fa-eject":"","fa-ellipsis-h":"","fa-ellipsis-v":"","fa-envelope-o":"","fa-envelope-open-o":"","fa-envelope-open":"","fa-envelope-square":"","fa-envelope":"","fa-eraser":"","fa-eur":"","fa-euro":"","fa-exchange":"","fa-exclamation-circle":"","fa-exclamation-triangle":"","fa-exclamation":"","fa-expand":"","fa-external-link-square":"","fa-external-link":"","fa-eye-slash":"","fa-eye":"","fa-eyedropper":"","fa-fast-backward":"","fa-fast-forward":"","fa-fax":"","fa-feed":"","fa-female":"","fa-fighter-jet":"","fa-file-archive-o":"","fa-file-audio-o":"","fa-file-code-o":"","fa-file-excel-o":"","fa-file-image-o":"","fa-file-movie-o":"","fa-file-o":"","fa-file-pdf-o":"","fa-file-photo-o":"","fa-file-picture-o":"","fa-file-powerpoint-o":"","fa-file-sound-o":"","fa-file-text-o":"","fa-file-text":"","fa-file-video-o":"","fa-file-word-o":"","fa-file-zip-o":"","fa-file":"","fa-files-o":"","fa-film":"","fa-filter":"","fa-fire-extinguisher":"","fa-fire":"","fa-flag-checkered":"","fa-flag-o":"","fa-flag":"","fa-flash":"","fa-flask":"","fa-floppy-o":"","fa-folder-o":"","fa-folder-open-o":"","fa-folder-open":"","fa-folder":"","fa-font":"","fa-forward":"","fa-frown-o":"","fa-futbol-o":"","fa-gamepad":"","fa-gavel":"","fa-gbp":"","fa-gear":"","fa-gears":"","fa-genderless":"","fa-gift":"","fa-glass":"","fa-globe":"","fa-graduation-cap":"","fa-group":"","fa-h-square":"","fa-hand-grab-o":"","fa-hand-lizard-o":"","fa-hand-o-down":"","fa-hand-o-left":"","fa-hand-o-right":"","fa-hand-o-up":"","fa-hand-paper-o":"","fa-hand-peace-o":"","fa-hand-pointer-o":"","fa-hand-rock-o":"","fa-hand-scissors-o":"","fa-hand-spock-o":"","fa-hand-stop-o":"","fa-handshake-o":"","fa-hard-of-hearing":"","fa-hashtag":"","fa-hdd-o":"","fa-header":"","fa-headphones":"","fa-heart-o":"","fa-heart":"","fa-heartbeat":"","fa-history":"","fa-home":"","fa-hospital-o":"","fa-hotel":"","fa-hourglass-1":"","fa-hourglass-2":"","fa-hourglass-3":"","fa-hourglass-end":"","fa-hourglass-half":"","fa-hourglass-o":"","fa-hourglass-start":"","fa-hourglass":"","fa-i-cursor":"","fa-id-badge":"","fa-id-card-o":"","fa-id-card":"","fa-ils":"","fa-image":"","fa-inbox":"","fa-indent":"","fa-industry":"","fa-info-circle":"","fa-info":"","fa-inr":"","fa-institution":"","fa-intersex":"","fa-italic":"","fa-jpy":"","fa-key":"","fa-keyboard-o":"","fa-krw":"","fa-language":"","fa-laptop":"","fa-leaf":"","fa-legal":"","fa-lemon-o":"","fa-level-down":"","fa-level-up":"","fa-life-bouy":"","fa-life-buoy":"","fa-life-ring":"","fa-life-saver":"","fa-lightbulb-o":"","fa-line-chart":"","fa-link":"","fa-list-alt":"","fa-list-ol":"","fa-list-ul":"","fa-list":"","fa-location-arrow":"","fa-lock":"","fa-long-arrow-down":"","fa-long-arrow-left":"","fa-long-arrow-right":"","fa-long-arrow-up":"","fa-low-vision":"","fa-magic":"","fa-magnet":"","fa-mail-forward":"","fa-mail-reply-all":"","fa-mail-reply":"","fa-male":"","fa-map-marker":"","fa-map-o":"","fa-map-pin":"","fa-map-signs":"","fa-map":"","fa-mars-double":"","fa-mars-stroke-h":"","fa-mars-stroke-v":"","fa-mars-stroke":"","fa-mars":"","fa-medkit":"","fa-meh-o":"","fa-mercury":"","fa-microchip":"","fa-microphone-slash":"","fa-microphone":"","fa-minus-circle":"","fa-minus-square-o":"","fa-minus-square":"","fa-minus":"","fa-mobile-phone":"","fa-mobile":"","fa-money":"","fa-moon-o":"","fa-mortar-board":"","fa-motorcycle":"","fa-mouse-pointer":"","fa-music":"","fa-navicon":"","fa-neuter":"","fa-newspaper-o":"","fa-object-group":"","fa-object-ungroup":"","fa-outdent":"","fa-paint-brush":"","fa-paper-plane-o":"","fa-paper-plane":"","fa-paperclip":"","fa-paragraph":"","fa-paste":"","fa-pause-circle-o":"","fa-pause-circle":"","fa-pause":"","fa-paw":"","fa-pencil-square-o":"","fa-pencil-square":"","fa-pencil":"","fa-percent":"","fa-phone-square":"","fa-phone":"","fa-photo":"","fa-picture-o":"","fa-pie-chart":"","fa-plane":"","fa-play-circle-o":"","fa-play-circle":"","fa-play":"","fa-plug":"","fa-plus-circle":"","fa-plus-square-o":"","fa-plus-square":"","fa-plus":"","fa-podcast":"","fa-power-off":"","fa-print":"","fa-puzzle-piece":"","fa-qrcode":"","fa-question-circle-o":"","fa-question-circle":"","fa-question":"","fa-quote-left":"","fa-quote-right":"","fa-random":"","fa-recycle":"","fa-refresh":"","fa-registered":"","fa-remove":"","fa-reorder":"","fa-repeat":"","fa-reply-all":"","fa-reply":"","fa-retweet":"","fa-rmb":"","fa-road":"","fa-rocket":"","fa-rotate-left":"","fa-rotate-right":"","fa-rouble":"","fa-rss-square":"","fa-rss":"","fa-rub":"","fa-ruble":"","fa-rupee":"","fa-s15":"","fa-save":"","fa-scissors":"","fa-search-minus":"","fa-search-plus":"","fa-search":"","fa-send-o":"","fa-send":"","fa-server":"","fa-share-square-o":"","fa-share-square":"","fa-share":"","fa-shekel":"","fa-sheqel":"","fa-shield":"","fa-ship":"","fa-shopping-bag":"","fa-shopping-basket":"","fa-shopping-cart":"","fa-shower":"","fa-sign-in":"","fa-sign-language":"","fa-sign-out":"","fa-signal":"","fa-signing":"","fa-sitemap":"","fa-sliders":"","fa-smile-o":"","fa-snowflake-o":"","fa-soccer-ball-o":"","fa-sort-alpha-asc":"","fa-sort-alpha-desc":"","fa-sort-amount-asc":"","fa-sort-amount-desc":"","fa-sort-asc":"","fa-sort-desc":"","fa-sort-down":"","fa-sort-numeric-asc":"","fa-sort-numeric-desc":"","fa-sort-up":"","fa-sort":"","fa-space-shuttle":"","fa-spinner":"","fa-spoon":"","fa-square-o":"","fa-square":"","fa-star-half-empty":"","fa-star-half-full":"","fa-star-half-o":"","fa-star-half":"","fa-star-o":"","fa-star":"","fa-step-backward":"","fa-step-forward":"","fa-stethoscope":"","fa-sticky-note-o":"","fa-sticky-note":"","fa-stop-circle-o":"","fa-stop-circle":"","fa-stop":"","fa-street-view":"","fa-strikethrough":"","fa-subscript":"","fa-subway":"","fa-suitcase":"","fa-sun-o":"","fa-superscript":"","fa-support":"","fa-table":"","fa-tablet":"","fa-tachometer":"","fa-tag":"","fa-tags":"","fa-tasks":"","fa-taxi":"","fa-television":"","fa-terminal":"","fa-text-height":"","fa-text-width":"","fa-th-large":"","fa-th-list":"","fa-th":"","fa-thermometer-0":"","fa-thermometer-1":"","fa-thermometer-2":"","fa-thermometer-3":"","fa-thermometer-4":"","fa-thermometer-empty":"","fa-thermometer-full":"","fa-thermometer-half":"","fa-thermometer-quarter":"","fa-thermometer-three-quarters":"","fa-thermometer":"","fa-thumb-tack":"","fa-thumbs-down":"","fa-thumbs-o-down":"","fa-thumbs-o-up":"","fa-thumbs-up":"","fa-ticket":"","fa-times-circle-o":"","fa-times-circle":"","fa-times-rectangle-o":"","fa-times-rectangle":"","fa-times":"","fa-tint":"","fa-toggle-down":"","fa-toggle-left":"","fa-toggle-off":"","fa-toggle-on":"","fa-toggle-right":"","fa-toggle-up":"","fa-trademark":"","fa-train":"","fa-transgender-alt":"","fa-transgender":"","fa-trash-o":"","fa-trash":"","fa-tree":"","fa-trophy":"","fa-truck":"","fa-try":"","fa-tty":"","fa-turkish-lira":"","fa-tv":"","fa-umbrella":"","fa-underline":"","fa-undo":"","fa-universal-access":"","fa-university":"","fa-unlink":"","fa-unlock-alt":"","fa-unlock":"","fa-unsorted":"","fa-upload":"","fa-usd":"","fa-user-circle-o":"","fa-user-circle":"","fa-user-md":"","fa-user-o":"","fa-user-plus":"","fa-user-secret":"","fa-user-times":"","fa-user":"","fa-users":"","fa-vcard-o":"","fa-vcard":"","fa-venus-double":"","fa-venus-mars":"","fa-venus":"","fa-video-camera":"","fa-volume-control-phone":"","fa-volume-down":"","fa-volume-off":"","fa-volume-up":"","fa-warning":"","fa-wheelchair-alt":"","fa-wheelchair":"","fa-wifi":"","fa-window-close-o":"","fa-window-close":"","fa-window-maximize":"","fa-window-minimize":"","fa-window-restore":"","fa-won":"","fa-wrench":"","fa-yen":""},o={"fa-500px":"","fa-adn":"","fa-amazon":"","fa-android":"","fa-angellist":"","fa-apple":"","fa-bandcamp":"","fa-behance-square":"","fa-behance":"","fa-bitbucket-square":"","fa-bitbucket":"","fa-bitcoin":"","fa-black-tie":"","fa-bluetooth-b":"","fa-bluetooth":"","fa-btc":"","fa-buysellads":"","fa-cc-amex":"","fa-cc-diners-club":"","fa-cc-discover":"","fa-cc-jcb":"","fa-cc-mastercard":"","fa-cc-paypal":"","fa-cc-stripe":"","fa-cc-visa":"","fa-chrome":"","fa-codepen":"","fa-codiepie":"","fa-connectdevelop":"","fa-contao":"","fa-css3":"","fa-dashcube":"","fa-delicious":"","fa-deviantart":"","fa-digg":"","fa-dribbble":"","fa-dropbox":"","fa-drupal":"","fa-edge":"","fa-eercast":"","fa-empire":"","fa-envira":"","fa-etsy":"","fa-expeditedssl":"","fa-fa":"","fa-facebook-f":"","fa-facebook-official":"","fa-facebook-square":"","fa-facebook":"","fa-firefox":"","fa-first-order":"","fa-flickr":"","fa-font-awesome":"","fa-fonticons":"","fa-fort-awesome":"","fa-forumbee":"","fa-foursquare":"","fa-free-code-camp":"","fa-ge":"","fa-get-pocket":"","fa-gg-circle":"","fa-gg":"","fa-git-square":"","fa-git":"","fa-github-alt":"","fa-github-square":"","fa-github":"","fa-gitlab":"","fa-gittip":"","fa-glide-g":"","fa-glide":"","fa-google-plus-circle":"","fa-google-plus-official":"","fa-google-plus-square":"","fa-google-plus":"","fa-google-wallet":"","fa-google":"","fa-gratipay":"","fa-grav":"","fa-hacker-news":"","fa-houzz":"","fa-html5":"","fa-imdb":"","fa-instagram":"","fa-internet-explorer":"","fa-ioxhost":"","fa-joomla":"","fa-jsfiddle":"","fa-lastfm-square":"","fa-lastfm":"","fa-leanpub":"","fa-linkedin-square":"","fa-linkedin":"","fa-linode":"","fa-linux":"","fa-maxcdn":"","fa-meanpath":"","fa-medium":"","fa-meetup":"","fa-mixcloud":"","fa-modx":"","fa-odnoklassniki-square":"","fa-odnoklassniki":"","fa-opencart":"","fa-openid":"","fa-opera":"","fa-optin-monster":"","fa-pagelines":"","fa-paypal":"","fa-pied-piper-alt":"","fa-pied-piper-pp":"","fa-pied-piper":"","fa-pinterest-p":"","fa-pinterest-square":"","fa-pinterest":"","fa-product-hunt":"","fa-qq":"","fa-quora":"","fa-ra":"","fa-ravelry":"","fa-rebel":"","fa-reddit-alien":"","fa-reddit-square":"","fa-reddit":"","fa-renren":"","fa-resistance":"","fa-safari":"","fa-scribd":"","fa-sellsy":"","fa-share-alt-square":"","fa-share-alt":"","fa-shirtsinbulk":"","fa-simplybuilt":"","fa-skyatlas":"","fa-skype":"","fa-slack":"","fa-slideshare":"","fa-snapchat-ghost":"","fa-snapchat-square":"","fa-snapchat":"","fa-soundcloud":"","fa-spotify":"","fa-stack-exchange":"","fa-stack-overflow":"","fa-steam-square":"","fa-steam":"","fa-stumbleupon-circle":"","fa-stumbleupon":"","fa-superpowers":"","fa-telegram":"","fa-tencent-weibo":"","fa-themeisle":"","fa-trello":"","fa-tripadvisor":"","fa-tumblr-square":"","fa-tumblr":"","fa-twitch":"","fa-twitter-square":"","fa-twitter":"","fa-usb":"","fa-viacoin":"","fa-viadeo-square":"","fa-viadeo":"","fa-vimeo-square":"","fa-vimeo":"","fa-vine":"","fa-vk":"","fa-wechat":"","fa-weibo":"","fa-weixin":"","fa-whatsapp":"","fa-wikipedia-w":"","fa-windows":"","fa-wordpress":"","fa-wpbeginner":"","fa-wpexplorer":"","fa-wpforms":"","fa-xing-square":"","fa-xing":"","fa-y-combinator-square":"","fa-y-combinator":"","fa-yahoo":"","fa-yc-square":"","fa-yc":"","fa-yelp":"","fa-yoast":"","fa-youtube-play":"","fa-youtube-square":"","fa-youtube":""},e=Object.keys(t);return{getIconUnicode:function(e){return t[e]||o[e]},getIconList:function(){return e}}}(),RED.history=function(){var t=[],o=[];function _(t){var e,o,n,i,a,s,r,d,l,c,u,p={};if(t){if("multi"==t.t)for(n={t:"multi",events:[]},e=t.events.length-1;0<=e;e--){var f=_(t.events[e]);n.events.push(f)}else if("replace"==t.t)t.complete?(n={t:"replace",config:RED.nodes.createCompleteNodeSet(),changed:{},rev:RED.nodes.version()},RED.nodes.clear(),RED.nodes.import(t.config).nodes.forEach(function(e){t.changed[e.id]&&(e.changed=!0,n.changed[e.id]=!0)}),RED.nodes.version(t.rev)):(i={},t.config.forEach(function(e){i[e.id]="replace"}),R=RED.nodes.import(t.config,{importMap:i}),n={t:"replace",config:R.removedNodes,dirty:RED.nodes.dirty()});else if("add"==t.t){if(n={t:"delete",dirty:RED.nodes.dirty()},t.nodes)for(n.nodes=[],e=0;e<t.nodes.length;e++)(a=RED.nodes.node(t.nodes[e])).z&&(p[a.z]=!0),n.nodes.push(a),RED.nodes.remove(t.nodes[e]),a.g&&-1!==(r=(s=RED.nodes.group(a.g)).nodes.indexOf(a))&&(s.nodes.splice(r,1),RED.group.markDirty(s));if(t.links)for(n.links=[],e=0;e<t.links.length;e++)n.links.push(t.links[e]),RED.nodes.removeLink(t.links[e]);if(t.junctions)for(n.junctions=[],e=0;e<t.junctions.length;e++)n.junctions.push(t.junctions[e]),RED.nodes.removeJunction(t.junctions[e]),t.junctions[e].g&&-1!==(r=(s=RED.nodes.group(t.junctions[e].g)).nodes.indexOf(t.junctions[e]))&&(s.nodes.splice(r,1),RED.group.markDirty(s));if(t.groups)for(n.groups=[],e=t.groups.length-1;0<=e;e--)p[(s=t.groups[e]).z]=!0,n.groups.unshift(s),RED.nodes.removeGroup(s);if(t.workspaces)for(n.workspaces=[],e=0;e<t.workspaces.length;e++){var h=RED.nodes.getWorkspaceOrder();t.workspaces[e]._index=h.indexOf(t.workspaces[e].id),n.workspaces.push(t.workspaces[e]),RED.nodes.removeWorkspace(t.workspaces[e].id),RED.workspaces.remove(t.workspaces[e])}if(t.subflows)for(n.subflows=[],e=0;e<t.subflows.length;e++)n.subflows.push(t.subflows[e]),RED.nodes.removeSubflow(t.subflows[e]),RED.workspaces.remove(t.subflows[e]);if(t.subflow&&(n.subflow={},t.subflow.instances&&(n.subflow.instances=[],t.subflow.instances.forEach(function(e){n.subflow.instances.push(e);var t=RED.nodes.node(e.id);t&&(t.changed=e.changed,t.dirty=!0)})),t.subflow.hasOwnProperty("changed")&&(o=RED.nodes.subflow(t.subflow.id))&&(o.changed=t.subflow.changed)),t.removedLinks)for(n.createdLinks=[],e=0;e<t.removedLinks.length;e++)n.createdLinks.push(t.removedLinks[e]),RED.nodes.addLink(t.removedLinks[e])}else if("delete"==t.t){if(n={t:"add",dirty:RED.nodes.dirty()},t.workspaces)for(n.workspaces=[],e=0;e<t.workspaces.length;e++)n.workspaces.push(t.workspaces[e]),RED.nodes.addWorkspace(t.workspaces[e],t.workspaces[e]._index),RED.workspaces.add(t.workspaces[e],void 0,t.workspaces[e]._index),delete t.workspaces[e]._index;if(t.subflows)for(n.subflows=[],e=0;e<t.subflows.length;e++)n.subflows.push(t.subflows[e]),RED.nodes.addSubflow(t.subflows[e]);if(t.subflowInputs&&0<t.subflowInputs.length&&((o=RED.nodes.subflow(t.subflowInputs[0].z)).in.push(t.subflowInputs[0]),o.in[0].dirty=!0),t.subflowOutputs&&0<t.subflowOutputs.length)for(o=RED.nodes.subflow(t.subflowOutputs[0].z),t.subflowOutputs.sort(function(e,t){return e.i-t.i}),e=0;e<t.subflowOutputs.length;e++){var g=t.subflowOutputs[e];o.out.splice(g.i,0,g);for(var m=g.i+1;m<o.out.length;m++)o.out[m].i++,o.out[m].dirty=!0;RED.nodes.eachLink(function(e){e.source.type=="subflow:"+o.id&&e.sourcePort>=g.i&&e.sourcePort++})}if(t.subflow&&(n.subflow={},t.subflow.hasOwnProperty("instances")&&(n.subflow.instances=[],t.subflow.instances.forEach(function(e){n.subflow.instances.push(e);var t=RED.nodes.node(e.id);t&&(t.changed=e.changed,t.dirty=!0)})),t.subflow.hasOwnProperty("status")&&((o=RED.nodes.subflow(t.subflow.id)).status=t.subflow.status)),o&&RED.nodes.filterNodes({type:"subflow:"+o.id}).forEach(function(e){e.inputs=o.in.length,e.outputs=o.out.length,e.resize=!0,e.dirty=!0}),t.groups){n.groups=[];var v={};for(t.groups.forEach(function(e){v[e.id]=e}),e=t.groups.length-1;0<=e;e--)RED.nodes.addGroup(t.groups[e]),p[t.groups[e].z]=!0,n.groups.unshift(t.groups[e]),t.groups[e].g&&(-1===(s=v[t.groups[e].g]||RED.nodes.group(t.groups[e].g)).nodes.indexOf(t.groups[e])&&s.nodes.push(t.groups[e]),RED.group.markDirty(t.groups[e]))}if(t.nodes)for(n.nodes=[],e=0;e<t.nodes.length;e++)RED.nodes.add(t.nodes[e]),p[t.nodes[e].z]=!0,n.nodes.push(t.nodes[e].id),t.nodes[e].g&&(-1===(s=RED.nodes.group(t.nodes[e].g)).nodes.indexOf(t.nodes[e])&&s.nodes.push(t.nodes[e]),RED.group.markDirty(s));if(t.junctions)for(n.junctions=[],e=0;e<t.junctions.length;e++)n.junctions.push(t.junctions[e]),RED.nodes.addJunction(t.junctions[e]),t.junctions[e].g&&(-1===(s=RED.nodes.group(t.junctions[e].g)).nodes.indexOf(t.junctions[e])&&s.nodes.push(t.junctions[e]),RED.group.markDirty(s));if(t.links)for(n.links=[],e=0;e<t.links.length;e++)RED.nodes.addLink(t.links[e]),n.links.push(t.links[e]);if(t.createdLinks)for(n.removedLinks=[],e=0;e<t.createdLinks.length;e++)n.removedLinks.push(t.createdLinks[e]),RED.nodes.removeLink(t.createdLinks[e]);if(t.changes)for(e in t.changes)if(t.changes.hasOwnProperty(e)){if(a=RED.nodes.node(e)){for(var b in t.changes[e])t.changes[e].hasOwnProperty(b)&&(a[b]=t.changes[e][b]);a.dirty=!0}RED.events.emit("nodes:change",a)}o&&RED.events.emit("subflows:change",o)}else if("move"==t.t){for(n={t:"move",nodes:[],dirty:RED.nodes.dirty()},e=0;e<t.nodes.length;e++){var y=t.nodes[e],w={n:y.n,ox:y.n.x,oy:y.n.y,dirty:!0,moved:y.n.moved};n.nodes.push(w),y.n.x=y.ox,y.n.y=y.oy,y.n.dirty=!0,y.n.moved=y.moved}if(t.links)for(n.removedLinks=[],e=0;e<t.links.length;e++)n.removedLinks.push(t.links[e]),RED.nodes.removeLink(t.links[e]);if(t.removedLinks)for(n.links=[],e=0;e<t.removedLinks.length;e++)n.links.push(t.removedLinks[e]),RED.nodes.addLink(t.removedLinks[e]);t.addToGroup?(RED.group.removeFromGroup(t.addToGroup,t.nodes.map(function(e){return e.n}),!1),n.removeFromGroup=t.addToGroup):t.removeFromGroup&&(RED.group.addToGroup(t.removeFromGroup,t.nodes.map(function(e){return e.n})),n.addToGroup=t.removeFromGroup)}else if("edit"==t.t){for(e in(n={t:"edit",changes:{},changed:t.node.changed,dirty:RED.nodes.dirty()}).node=t.node,t.changes)t.changes.hasOwnProperty(e)&&(n.changes[e]=t.node[e],t.node._def.defaults&&t.node._def.defaults[e]&&t.node._def.defaults[e].type&&(d=t.node[e],(d=Array.isArray(d)?d:[d]).forEach(function(e){e=RED.nodes.node(e);e&&"config"===e._def.category&&(e.users.splice(e.users.indexOf(t.node),1),RED.events.emit("nodes:change",e))}),d=t.changes[e],(d=Array.isArray(d)?d:[d]).forEach(function(e){e=RED.nodes.node(e);e&&"config"===e._def.category&&(e.users.push(t.node),RED.events.emit("nodes:change",e))})),t.node[e]=t.changes[e]);switch(t.node.type){case"tab":l="flows";break;case"group":l="groups";break;case"subflow":l="subflows";break;default:l="nodes"}if(RED.events.emit(l+=":change",t.node),"tab"===t.node.type&&t.changes.hasOwnProperty("disabled")&&($("#red-ui-tab-"+t.node.id.replace(".","-")).toggleClass("red-ui-workspace-disabled",!!t.node.disabled),$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!t.node.disabled)),t.subflow)n.subflow={},t.subflow.hasOwnProperty("inputCount")&&(n.subflow.inputCount=t.node.in.length,t.node.in.length>t.subflow.inputCount?(n.subflow.inputs=t.node.in.slice(t.subflow.inputCount),t.node.in.splice(t.subflow.inputCount)):0<t.subflow.inputs.length&&(t.node.in=t.node.in.concat(t.subflow.inputs))),t.subflow.hasOwnProperty("outputCount")&&(n.subflow.outputCount=t.node.out.length,t.node.out.length>t.subflow.outputCount?(n.subflow.outputs=t.node.out.slice(t.subflow.outputCount),t.node.out.splice(t.subflow.outputCount)):0<t.subflow.outputs.length&&(t.node.out=t.node.out.concat(t.subflow.outputs))),t.subflow.hasOwnProperty("instances")&&(n.subflow.instances=[],t.subflow.instances.forEach(function(e){n.subflow.instances.push(e);var t=RED.nodes.node(e.id);t&&(t.changed=e.changed,t.dirty=!0)})),t.subflow.hasOwnProperty("status")&&t.subflow.status&&delete t.node.status,RED.editor.validateNode(t.node),RED.nodes.filterNodes({type:"subflow:"+t.node.id}).forEach(function(e){e.inputs=t.node.in.length,e.outputs=t.node.out.length,RED.editor.updateNodeProperties(e),RED.editor.validateNode(e)});else{if(t.outputMap)for(var E in c={},n.outputMap={},t.outputMap)t.outputMap.hasOwnProperty(E)&&"-1"!==t.outputMap[E]&&(c[t.outputMap[E]]=E,n.outputMap[t.outputMap[E]]=E);t.node.__outputs=n.changes.outputs,RED.editor.updateNodeProperties(t.node,c),RED.editor.validateNode(t.node)}if(t.links)for(n.createdLinks=[],e=0;e<t.links.length;e++)RED.nodes.addLink(t.links[e]),n.createdLinks.push(t.links[e]);if(t.createdLinks)for(n.links=[],e=0;e<t.createdLinks.length;e++)RED.nodes.removeLink(t.createdLinks[e]),n.links.push(t.createdLinks[e]);t.node.dirty=!0,t.node.changed=t.changed}else if("createSubflow"==t.t){if(n={t:"deleteSubflow",activeWorkspace:t.activeWorkspace,dirty:RED.nodes.dirty()},t.nodes){n.movedNodes=[];var D=t.activeWorkspace,R=RED.nodes.filterNodes({z:t.subflow.subflow.id});for((R=(R=R.concat(RED.nodes.groups(t.subflow.subflow.id))).concat(RED.nodes.junctions(t.subflow.subflow.id))).forEach(function(e){e.x+=t.subflow.offsetX,e.y+=t.subflow.offsetY,e.dirty=!0,n.movedNodes.push(e.id),RED.nodes.moveNodeToTab(e,D)}),n.subflows=[],e=0;e<t.nodes.length;e++)n.subflows.push((u=t.nodes[e],RED.nodes.node(u)||RED.nodes.junction(u))),RED.nodes.remove(t.nodes[e])}if(t.links)for(n.links=[],e=0;e<t.links.length;e++)n.links.push(t.links[e]),RED.nodes.removeLink(t.links[e]);if(n.subflow=t.subflow,RED.nodes.removeSubflow(t.subflow.subflow),RED.workspaces.remove(t.subflow.subflow),t.removedLinks)for(n.createdLinks=[],e=0;e<t.removedLinks.length;e++)n.createdLinks.push(t.removedLinks[e]),RED.nodes.addLink(t.removedLinks[e])}else if("deleteSubflow"==t.t){if(n={t:"createSubflow",activeWorkspace:t.activeWorkspace,dirty:RED.nodes.dirty()},t.subflow&&(RED.nodes.addSubflow(t.subflow.subflow),n.subflow=t.subflow,t.subflow.subflow.g&&RED.group.addToGroup(RED.nodes.group(t.subflow.subflow.g),t.subflow.subflow)),t.subflows)for(n.nodes=[],e=0;e<t.subflows.length;e++)RED.nodes.add(t.subflows[e]),n.nodes.push(t.subflows[e].id);if(t.movedNodes&&t.movedNodes.forEach(function(e){(nn=(nn=RED.nodes.node(e))||RED.nodes.group(e)).x-=t.subflow.offsetX,nn.y-=t.subflow.offsetY,nn.dirty=!0,RED.nodes.moveNodeToTab(nn,t.subflow.subflow.id)}),t.links)for(n.links=[],e=0;e<t.links.length;e++)n.links.push(t.links[e]),RED.nodes.addLink(t.links[e]);if(t.createdLinks)for(n.removedLinks=[],e=0;e<t.createdLinks.length;e++)n.removedLinks.push(t.createdLinks[e]),RED.nodes.removeLink(t.createdLinks[e])}else if("reorder"==t.t)n={t:"reorder",dirty:RED.nodes.dirty()},t.workspaces&&(n.workspaces={from:t.workspaces.to,to:t.workspaces.from},RED.workspaces.order(t.workspaces.from)),t.nodes&&(n.nodes={z:t.nodes.z,from:t.nodes.to,to:t.nodes.from},RED.nodes.setNodeOrder(t.nodes.z,t.nodes.from));else if("createGroup"==t.t){if(n={t:"ungroup",dirty:RED.nodes.dirty(),groups:[]},t.groups)for(e=0;e<t.groups.length;e++)n.groups.push(t.groups[e]),RED.group.ungroup(t.groups[e])}else if("ungroup"==t.t){if(n={t:"createGroup",dirty:RED.nodes.dirty(),groups:[]},t.groups)for(e=0;e<t.groups.length;e++){n.groups.push(t.groups[e]);var x=t.groups[e].nodes.slice();t.groups[e].nodes=[],RED.nodes.addGroup(t.groups[e]),RED.group.addToGroup(t.groups[e],x)}}else"addToGroup"==t.t?(n={t:"removeFromGroup",dirty:RED.nodes.dirty(),group:t.group,nodes:t.nodes,reparent:t.reparent},t.nodes&&RED.group.removeFromGroup(t.group,t.nodes,!t.hasOwnProperty("reparent")||void 0===t.hasOwnProperty("reparent")||t.reparent)):"removeFromGroup"==t.t&&(n={t:"addToGroup",dirty:RED.nodes.dirty(),group:t.group,nodes:t.nodes,reparent:t.reparent},t.nodes&&RED.group.addToGroup(t.group,t.nodes));return t.callback&&"function"==typeof t.callback&&(n.callback=t.callback,t.callback(t)),Object.keys(p).forEach(function(e){e=RED.nodes.subflow(e);e&&RED.editor.validateNode(e)}),RED.nodes.dirty(t.dirty),RED.view.updateActive(),RED.view.select(null),RED.workspaces.refresh(),RED.sidebar.config.refresh(),RED.subflow.refresh(),n}}return{markAllDirty:function(){for(var e=0;e<t.length;e++)t[e].dirty=!0},list:function(){return t},listRedo:function(){return o},depth:function(){return t.length},push:function(e){t.push(e),o=[],RED.menu.setDisabled("menu-item-edit-undo",!1),RED.menu.setDisabled("menu-item-edit-redo",!0)},pop:function(){var e=_(t.pop());e&&o.push(e),RED.menu.setDisabled("menu-item-edit-undo",0===t.length),RED.menu.setDisabled("menu-item-edit-redo",0===o.length)},peek:function(){return t[t.length-1]},replace:function(e){0===t.length?RED.history.push(e):t[t.length-1]=e},clear:function(){t=[],o=[],RED.menu.setDisabled("menu-item-edit-undo",!0),RED.menu.setDisabled("menu-item-edit-redo",!0)},redo:function(){var e=o.pop();e&&(e=_(e))&&t.push(e),RED.menu.setDisabled("menu-item-edit-undo",0===t.length),RED.menu.setDisabled("menu-item-edit-redo",0===o.length)}}}(),RED.validators={number:function(o,e){return function(e,t){return!((!o||""!==e&&void 0!==e)&&(""===e||isNaN(e)))||(t&&t.label?RED._("validator.errors.invalid-num-prop",{prop:t.label}):!!t&&RED._("validator.errors.invalid-num"))}},regex:function(o,e){return function(e,t){return!!o.test(e)||(t&&t.label?RED._("validator.errors.invalid-regex-prop",{prop:t.label}):!!t&&RED._("validator.errors.invalid-regexp"))}},typedInput:function(n,i,e){return function(e,t){var o=$("#node-"+(i?"config-":"")+"input-"+n).val()||this[n];if("json"===o)try{JSON.parse(e)}catch(e){return t&&t.label?RED._("validator.errors.invalid-json-prop",{error:e.message,prop:t.label}):!!t&&RED._("validator.errors.invalid-json",{error:e.message})}else{if("msg"===o||"flow"===o||"global"===o)return!!RED.utils.validatePropertyExpression(e)||(t&&t.label?RED._("validator.errors.invalid-prop-prop",{prop:t.label}):!!t&&RED._("validator.errors.invalid-prop"));if("num"===o)return!!/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(e)||(t&&t.label?RED._("validator.errors.invalid-num-prop",{prop:t.label}):!!t&&RED._("validator.errors.invalid-num"))}return!0}}},RED.utils=function(){window._marked=window.marked,window.marked=function(e){return console.warn("Use of 'marked()' is deprecated. Use RED.utils.renderMarkdown() instead"),t(e)};const e=new window._marked.Renderer;function t(e){e=_marked.parse(e);return DOMPurify.sanitize(e,{SAFE_FOR_JQUERY:!0})}function B(e){return e.replace(/\r?\n/g,"&crarr;").replace(/\t/g,"&rarr;")}function G(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function F(e){var t;return Array.isArray(e)?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("array["+e.length+"]"):null===e?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-null">null</span>'):"object"==typeof e?e.hasOwnProperty("type")&&"undefined"===e.type?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-null">undefined</span>'):e.hasOwnProperty("type")&&"Buffer"===e.type&&e.hasOwnProperty("data")?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("buffer["+e.length+"]"):e.hasOwnProperty("type")&&"array"===e.type&&e.hasOwnProperty("data")?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("array["+e.length+"]"):e.hasOwnProperty("type")&&"set"===e.type&&e.hasOwnProperty("data")?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("set["+e.length+"]"):e.hasOwnProperty("type")&&"map"===e.type&&e.hasOwnProperty("data")?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("map"):e.hasOwnProperty("type")&&"function"===e.type?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta"></span>').text("function"):!e.hasOwnProperty("type")||"number"!==e.type&&"bigint"!==e.type?e.hasOwnProperty("type")&&"regexp"===e.type?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-string"></span>').text(e.data):$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-meta">object</span>'):$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-number"></span>').text(e.data):"string"==typeof e?(t=30<e.length?G(e.substring(0,30))+"&hellip;":G(e),$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-string"></span>').html('"'+B(t)+'"')):("number"==typeof e?$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-number"></span>'):$('<span class="red-ui-debug-msg-object-value red-ui-debug-msg-type-other"></span>')).text(""+e)}function U(o,n,i,e){o.addClass("red-ui-debug-msg-expandable"),o.prop("toggle",function(){return function(e){var t=o.parent();if(t.hasClass("collapsed")){if(e)return n&&!t.hasClass("built")&&(n(),t.addClass("built")),t.removeClass("collapsed"),!0}else if(!e)return t.addClass("collapsed"),!0;return!1}}),o.on("click",function(e){var t=!$(this).parent().hasClass("collapsed");$(this).prop("toggle")(!t)&&i&&i(!t),e.preventDefault()}),e&&o.trigger("click")}e.list=function(e,t,o){return/dl.*?class.*?message-properties.*/.test(e)&&t?'<ol class="node-ports">'+e+"</ol>":t?"<ol>"+e+"</ol>":"<ul>"+e+"</ul>"},window._marked.setOptions({renderer:e,gfm:!0,tables:!0,breaks:!1,pedantic:!1,smartLists:!0,smartypants:!1}),window._marked.use({extensions:[{name:"descriptionList",level:"block",start(e){if(!e)return null;e=e.match(/:[^:\n]/g);return e&&e.index},tokenizer(e,t){if(!e)return null;const o=/^(?::[^:\n]+:[^:\n]*(?:\n|$))+/.exec(e);return o?{type:"descriptionList",raw:o[0],text:o[0].trim(),tokens:this.lexer.inlineTokens(o[0].trim())}:void 0},renderer(e){return`<dl class="message-properties">${this.parser.parseInline(e.tokens)}
</dl>`}},{name:"description",level:"inline",start(e){if(!e)return null;e=e.match(/:/g);return e&&e.index},tokenizer(e,t){if(!e)return null;const o=/^:([^:\n]+)\(([^:\n]+)\).*?:([^:\n]*)(?:\n|$)/.exec(e);return o?{type:"description",raw:o[0],dt:this.lexer.inlineTokens(o[1].trim()),types:this.lexer.inlineTokens(o[2].trim()),dd:this.lexer.inlineTokens(o[3].trim())}:void 0},renderer(e){return`
<dt>${this.parser.parseInline(e.dt)}<span class="property-type">${this.parser.parseInline(e.types)}</span></dt><dd>${this.parser.parseInline(e.dd)}</dd>`},childTokens:["dt","dd"],walkTokens(e){"strong"===e.type&&(e.text+=" walked")}}]});var V={},r={};function J(e,t,o,n){if(t&&0<t.length){if(""===e&&void 0===o)return!0;for(var i=0;i<t.length;i++){var a=t[i];if(0===a.indexOf(e)&&("."===a[e.length]||"["===a[e.length])){if(void 0===o||"["!==a[e.length])return!0;var a=a.substring(e.length),a=/\[(\d+)\]/.exec(a);if(a)return o<=(a=parseInt(a[1]))&&a<=n}}}return!1}function q(e,t,o,n,i,a){var s=r[o]&&r[o][n]&&r[o][n].number||a||"dec";i?(s="dec"===s?13===t.toString().length&&t<=2147483647e3?"dateMS":10===t.toString().length&&t<=2147483647?"dateS":"hex":"dateMS"===s||"dateS"==s?13===t.toString().length&&t<=2147483647e3?"dateML":10===t.toString().length&&t<=2147483647?"dateL":"hex":"dateML"===s||"dateL"==s?"hex":"dec",r[o]=r[o]||{},r[o][n]=r[o][n]||{},r[o][n].number=s):void 0!==a&&(r[o]=r[o]||{},r[o][n]=r[o][n]||{},r[o][n].number=s),"dec"===s?e.text(""+t):"dateMS"===s?e.text(new Date(t).toISOString()):"dateS"===s?e.text(new Date(1e3*t).toISOString()):"dateML"===s?(i=new Date(t),e.text(i.toLocaleString()+" [UTC"+(i.getTimezoneOffset()/-60<=0?"":"+")+i.getTimezoneOffset()/-60+"]")):"dateL"===s?(a=new Date(1e3*t),e.text(a.toLocaleString()+" [UTC"+(a.getTimezoneOffset()/-60<=0?"":"+")+a.getTimezoneOffset()/-60+"]")):"hex"===s&&e.text("0x"+t.toString(16))}function W(e,t,o,n,i){var a=r[o]&&r[o][n]&&r[o][n].buffer||"raw";i&&(a="raw"===a?"string":"raw",r[o]=r[o]||{},r[o][n]=r[o][n]||{},r[o][n].buffer=a),"raw"===a?(t.text("raw"),e.removeClass("red-ui-debug-msg-buffer-string").addClass("red-ui-debug-msg-buffer-raw")):"string"===a&&(t.text("string"),e.addClass("red-ui-debug-msg-buffer-string").removeClass("red-ui-debug-msg-buffer-raw"))}function g(e,t){t=new Error(t);return t.code=e,t}function K(e,t){var o=e.length;if(0===o)throw g("INVALID_EXPR","Invalid property expression: zero-length");for(var n,i,a=[],s=0,r=!1,d=!1,l=0;l<o;l++){var c=e[l];if(r){if(c===n){if(l-s==0)throw g("INVALID_EXPR","Invalid property expression: zero-length string at position "+s);if(a.push(e.substring(s,l)),d&&!/\]/.test(e[l+1]))throw g("INVALID_EXPR","Invalid property expression: unexpected array expression at position "+s);if(!d&&l+1!==o&&!/[\[\.]/.test(e[l+1]))throw g("INVALID_EXPR","Invalid property expression: unexpected "+e[l+1]+" expression at position "+(l+1));s=l+1,r=!1}}else if("'"===c||'"'===c){if(l!=s)throw g("INVALID_EXPR","Invalid property expression: unexpected "+c+" at position "+l);r=!0,n=c,s=l+1}else if("."===c){if(0===l)throw g("INVALID_EXPR","Invalid property expression: unexpected . at position 0");if(s!=l&&(i=e.substring(s,l),/^\d+$/.test(i)?a.push(parseInt(i)):a.push(i)),l===o-1)throw g("INVALID_EXPR","Invalid property expression: unterminated expression");if(!/[a-z0-9\$\_]/i.test(e[l+1]))throw g("INVALID_EXPR","Invalid property expression: unexpected "+e[l+1]+" at position "+(l+1));s=l+1}else if("["===c){if(0===l)throw g("INVALID_EXPR","Invalid property expression: unexpected "+c+" at position "+l);if(s!=l&&a.push(e.substring(s,l)),l===o-1)throw g("INVALID_EXPR","Invalid property expression: unterminated expression");if(/^msg[.\[]/.test(e.substring(l+1))){for(var u,p=1,f=!1,h=l+1;h<o;h++)if(/["']/.test(e[h])&&(f?e[h]===u&&(f=!1):(f=!0,u=e[h])),"["===e[h]?p++:"]"===e[h]&&p--,0===p)try{t?a.push(H(t,e.substring(l+1,h))):a.push(K(e.substring(l+1,h),t)),d=!1,s=(l=h)+1;break}catch(e){throw g("INVALID_EXPR","Invalid expression started at position "+(l+1))}if(0<p)throw g("INVALID_EXPR","Invalid property expression: unmatched '[' at position "+l)}else{if(!/["'\d]/.test(e[l+1]))throw g("INVALID_EXPR","Invalid property expression: unexpected "+e[l+1]+" at position "+(l+1));s=l+1,d=!0}}else if("]"===c){if(!d)throw g("INVALID_EXPR","Invalid property expression: unexpected "+c+" at position "+l);if(s!=l){if(i=e.substring(s,l),!/^\d+$/.test(i))throw g("INVALID_EXPR","Invalid property expression: unexpected array expression at position "+s);a.push(parseInt(i))}s=l+1,d=!1}else if(" "===c)throw g("INVALID_EXPR","Invalid property expression: unexpected ' ' at position "+l)}if(d||r)throw new g("INVALID_EXPR","Invalid property expression: unterminated expression");return s<o&&a.push(e.substring(s)),a}function H(e,t){var o=null,t="string"==typeof t?K(t=0===t.indexOf("msg.")?t.substring(4):t):t;return t.reduce(function(e,t){return o=void 0===(o=void 0!==e[t]?e[t]:void 0)&&e.hasOwnProperty("type")&&e.hasOwnProperty("data")&&e.hasOwnProperty("length")?void 0!==e.data[t]?e.data[t]:void 0:o},e),o}function a(e){var t,o={module:"",file:""};return e&&(0===e.indexOf(RED.settings.apiRootUrl+"icons/")&&(e=e.substring((RED.settings.apiRootUrl+"icons/").length)),(t=/^((?:@[^/]+\/)?[^/]+)\/(.*)$/.exec(e))?(o.module=t[1],o.file=t[2]):o.file=e),o}function n(t,e){var o;if(t=t||{},e&&"subflow"===e.type)o="node-red/subflow.svg";else if("function"==typeof t.icon)try{o=t.icon.call(e)}catch(e){console.log("Definition error: "+t.type+".icon",e),o="arrow-in.svg"}else o=t.icon;e=a(o);return e.module||(t.set?e.module=t.set.module:e.module="node-red"),e}function i(e){var t=RED.nodes.getIconSets()[e.module];return!(!t||-1===t.indexOf(e.file))}var d={};function l(e){if(/^#[a-f0-9]{6}$/i.test(e))t=parseInt(e.substring(1,3),16),o=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);else{if(!/^#[a-f0-9]{3}$/i.test(e))return e;t=parseInt(e.substring(1,2)+e.substring(1,2),16),o=parseInt(e.substring(2,3)+e.substring(2,3),16),n=parseInt(e.substring(3,4)+e.substring(3,4),16)}var t,o,n,e=(((t=Math.max(0,t-50))<<16)+((o=Math.max(0,o-50))<<8)+(n=Math.max(0,n-50))).toString(16);return"#"+"000000".slice(0,6-e.length)+e}function s(e,t,o){for(var n=0;n<o.length;n++){var i=o[n];if(i.module.test(e))return i}}return{createObjectElement:function r(t,e){var o,n,i,d,a,s,l,c,u,p,A,f=(e=e||{}).key,h=e.typeHint,M=e.hideKey,g=e.path,m=e.sourceId,v=e.rootPath,b=e.expandPaths,y=e.ontoggle,w=e.exposeApi,e=e.tools,E={},D=(void 0!==g&&void 0!==v&&(d=g.substring(v.length+("."===g[v.length]?1:0))),$('<span class="red-ui-debug-msg-element"></span>'));if(D.collapse=function(){D.find(".red-ui-debug-msg-expandable").parent().addClass("collapsed")},n=$('<span class="red-ui-debug-msg-row"></span>').appendTo(D),m&&(a=n,s=m,l=g,c=t,u=d,V.hasOwnProperty(s)||(V[s]={}),k=$('<span class="red-ui-debug-msg-tools"></span>').appendTo(a),_=$('<span class="red-ui-debug-msg-tools-copy button-group"></span>').appendTo(k),l&&(p=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-terminal"></i></button>').appendTo(_).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.clipboard.copyText(l,p,"clipboard.copyMessagePath")}),RED.popover.tooltip(p,RED._("node-red:debug.sidebar.copyPath"))),A=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-clipboard"></i></button>').appendTo(_).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.clipboard.copyText(c,A,"clipboard.copyMessageValue")}),RED.popover.tooltip(A,RED._("node-red:debug.sidebar.copyPayload")),void 0!==u&&""!==u&&(_=V[s].hasOwnProperty(u),x=$('<button class="red-ui-button red-ui-button-small red-ui-debug-msg-tools-pin"><i class="fa fa-map-pin"></i></button>').appendTo(k).on("click",function(e){e.preventDefault(),e.stopPropagation(),V[s].hasOwnProperty(u)?(delete V[s][u],$(this).removeClass("selected"),a.removeClass("red-ui-debug-msg-row-pinned")):(e="$"+("["===u[0]?"":".")+u,V[s][u]=K(e),$(this).addClass("selected"),a.addClass("red-ui-debug-msg-row-pinned"))}).toggleClass("selected",_),a.toggleClass("red-ui-debug-msg-row-pinned",_),RED.popover.tooltip(x,RED._("node-red:debug.sidebar.pinPath"))),e&&(_="function"==typeof(_=e)?_(l,c):_)&&(_.addClass("red-ui-debug-msg-tools-other"),_.appendTo(k))),f)M||($('<span class="red-ui-debug-msg-object-key"></span>').text(f).appendTo(n),$("<span>: </span>").appendTo(n));else if(D.addClass("red-ui-debug-msg-top-level"),m){var R=V[m],b=[];if(R){for(var z in R)if(R.hasOwnProperty(z))try{void 0!==H({$:t},R[z])&&b.push(z)}catch(e){}b.sort()}D.clearPinned=function(){D.find(".red-ui-debug-msg-row-pinned").removeClass("red-ui-debug-msg-row-pinned"),V[m]={}}}var x=$('<span class="red-ui-debug-msg-object-value"></span>').appendTo(n),e=Array.isArray(t),_=!1;if(t&&"object"==typeof t&&t.hasOwnProperty("type")&&t.hasOwnProperty("data")&&(t.__enc__&&"set"===t.type||t.__enc__&&"array"===t.type||"Buffer"===t.type)&&(_=e=!0),null==t)$('<span class="red-ui-debug-msg-type-null">'+t+"</span>").appendTo(x);else if(t.__enc__&&"undefined"===t.type)$('<span class="red-ui-debug-msg-type-null">undefined</span>').appendTo(x);else if(!t.__enc__||"number"!==t.type&&"bigint"!==t.type)if("regexp"===h||t.__enc__&&"regexp"===t.type)o=$('<span class="red-ui-debug-msg-type-string red-ui-debug-msg-object-header"></span>').text("string"==typeof t?t:t.data).appendTo(x);else if("function"===h||t.__enc__&&"function"===t.type)o=$('<span class="red-ui-debug-msg-type-meta red-ui-debug-msg-object-header"></span>').text("function").appendTo(x);else if("internal"===h||t.__enc__&&"internal"===t.type)o=$('<span class="red-ui-debug-msg-type-meta red-ui-debug-msg-object-header"></span>').text("[internal]").appendTo(x);else if("string"==typeof t)/[\t\n\r]/.test(t)&&(D.addClass("collapsed"),$('<i class="fa fa-caret-right red-ui-debug-msg-object-handle"></i> ').prependTo(n),U(n,function(){$('<span class="red-ui-debug-msg-type-meta red-ui-debug-msg-object-type-header"></span>').text(h||"string").appendTo(n);var e=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(D);$('<pre class="red-ui-debug-msg-type-string"></pre>').text(t).appendTo(e)},function(e){y&&y(g,e)},J(d,b))),o=$('<span class="red-ui-debug-msg-type-string red-ui-debug-msg-object-header"></span>').html('"'+B(G(t))+'"').appendTo(x),/^#[0-9a-f]{6}$/i.test(t)&&$('<span class="red-ui-debug-msg-type-string-swatch"></span>').css("backgroundColor",t).appendTo(o);else if("number"==typeof t)o=$('<span class="red-ui-debug-msg-type-number"></span>').appendTo(x),Number.isInteger(t)&&0<=t&&(o.addClass("red-ui-debug-msg-type-number-toggle"),o.on("click",function(e){e.preventDefault(),q($(this),t,m,g,!0)})),q(o,t,m,g,!1,"hex"===h?"hex":void 0);else if(e){D.addClass("collapsed");var k,T,C=t.length,j=(h&&(k=/\[(\d+)\]/.exec(h))&&(C=parseInt(k[1])),t),L="array",S=(_?(j=t.data,void 0===C&&(C=j.length),j.__enc__&&(j=j.data),L=t.type.toLowerCase()):/buffer/.test(h)&&(L="buffer"),j.length);if(0<C&&($('<i class="fa fa-caret-right red-ui-debug-msg-object-handle"></i> ').prependTo(n),T=$('<div class="red-ui-debug-msg-array-rows"></div>').appendTo(D),D.addClass("red-ui-debug-msg-buffer-raw")),f)i=$('<span class="red-ui-debug-msg-type-meta"></span>').text(h||L+"["+C+"]").appendTo(x);else{i=$('<span class="red-ui-debug-msg-object-header"></span>').appendTo(x),$("<span>[ </span>").appendTo(i);for(var O=Math.min(C,10),I=0;I<O;I++)F(j[I]).appendTo(i),I<O-1&&$("<span>, </span>").appendTo(i);O<C&&$("<span> &hellip;</span>").appendTo(i),0===O&&$('<span class="red-ui-debug-msg-type-meta">empty</span>').appendTo(i),$("<span> ]</span>").appendTo(i)}0<C&&U(n,function(){if(f||(i=$('<span class="red-ui-debug-msg-type-meta red-ui-debug-msg-object-type-header"></span>').text(h||L+"["+C+"]").appendTo(n)),"buffer"===L){var e=$('<div class="red-ui-debug-msg-string-rows"></div>').appendTo(D),e=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(e),t="";try{t=String.fromCharCode.apply(null,new Uint16Array(j))}catch(e){console.log(e)}$('<pre class="red-ui-debug-msg-type-string"></pre>').text(t).appendTo(e),t=$('<span class="red-ui-debug-msg-buffer-opts"></span>').appendTo(i),e=$('<a class="red-ui-button red-ui-button-small" href="#"></a>').text("raw").appendTo(t).on("click",function(e){e.preventDefault(),e.stopPropagation(),W(D,$(this),m,g,!0)}),W(D,e,m,g,!1)}if(S<=10)for(I=0;I<S;I++)s=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(T),E[g+"["+I+"]"]=r(j[I],{key:""+I,typeHint:"buffer"===L&&"hex",hideKey:!1,path:g+"["+I+"]",sourceId:m,rootPath:v,expandPaths:b,ontoggle:y,exposeApi:w}).appendTo(s);else{for(I=0;I<S;I+=10){var a=I,s=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(T);n=$("<span></span>").appendTo(s),$('<i class="fa fa-caret-right red-ui-debug-msg-object-handle"></i> ').appendTo(n),U(n,function(){var o=a,n=Math.min(S-1,a+9),i=s;return function(){for(var e=o;e<=n;e++){var t=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(i);E[g+"["+e+"]"]=r(j[e],{key:""+e,typeHint:"buffer"===L&&"hex",hideKey:!1,path:g+"["+e+"]",sourceId:m,rootPath:v,expandPaths:b,ontoggle:y,exposeApi:w}).appendTo(t)}}}(),function(){var t=void 0+"["+I+"]";return function(e){y&&y(t,e)}}(),J(d,b,a,Math.min(S-1,a+9))),$('<span class="red-ui-debug-msg-object-key"></span>').html("["+a+" &hellip; "+Math.min(S-1,a+9)+"]").appendTo(n)}S<C&&$('<div class="red-ui-debug-msg-object-entry collapsed"><span class="red-ui-debug-msg-object-key">['+S+" &hellip; "+C+"]</span></div>").appendTo(T)}},function(e){y&&y(g,e)},J(d,b))}else if("object"==typeof t){D.addClass("collapsed");var L="object",N=((j=t).__enc__&&(j=j.data,L=t.type.toLowerCase()),Object.keys(j));if((f||0<N.length)&&($('<i class="fa fa-caret-right red-ui-debug-msg-object-handle"></i> ').prependTo(n),U(n,function(){for(f||$('<span class="red-ui-debug-msg-type-meta red-ui-debug-msg-object-type-header"></span>').text(L).appendTo(n),I=0;I<N.length;I++){var e=$('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(D),t=g;void 0!==t&&(/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(N[I])?t+=(0<t.length?".":"")+N[I]:t+='["'+N[I].replace(/"/,'\\"')+'"]'),E[t]=r(j[N[I]],{key:N[I],typeHint:!1,hideKey:!1,path:t,sourceId:m,rootPath:v,expandPaths:b,ontoggle:y,exposeApi:w}).appendTo(e)}0===N.length&&$('<div class="red-ui-debug-msg-object-entry red-ui-debug-msg-type-meta collapsed"></div>').text("empty").appendTo(D)},function(e){y&&y(g,e)},J(d,b))),f)$('<span class="red-ui-debug-msg-type-meta"></span>').text(L).appendTo(x);else{i=$('<span class="red-ui-debug-msg-object-header"></span>').appendTo(x),$("<span>{ </span>").appendTo(i);var P=Math.min(N.length,5);for(I=0;I<P;I++)$('<span class="red-ui-debug-msg-object-key"></span>').text(N[I]).appendTo(i),$("<span>: </span>").appendTo(i),F(j[N[I]]).appendTo(i),I<P-1&&$("<span>, </span>").appendTo(i);N.length>P&&$("<span> &hellip;</span>").appendTo(i),0===P&&$('<span class="red-ui-debug-msg-type-meta">empty</span>').appendTo(i),$("<span> }</span>").appendTo(i)}}else $('<span class="red-ui-debug-msg-type-other"></span>').text(""+t).appendTo(x);else o=$('<span class="red-ui-debug-msg-type-number red-ui-debug-msg-object-header"></span>').text(t.data).appendTo(x);return w&&D.prop("expand",function(){return function(e,t){if(g===e)n.prop("toggle")&&n.prop("toggle")(t);else if(E[e]&&E[e].prop("expand"))E[e].prop("expand")(e,t);else for(var o in E)if(E.hasOwnProperty(o)&&0===e.indexOf(o)){E[o].prop("expand")&&E[o].prop("expand")(e,t);break}}}),D},getMessageProperty:H,setMessageProperty:function(e,t,o,n){void 0===n&&(n=void 0!==o);for(var i,a=K(t=0===t.indexOf("msg.")?t.substring(4):t),s=a.length,r=e,d=0;d<s-1;d++)if("string"==typeof(i=a[d])||"number"==typeof i&&!Array.isArray(r))if(r.hasOwnProperty(i))r=r[i];else{if(!n)return null;"string"==typeof a[d+1]?r[i]={}:r[i]=[],r=r[i]}else if("number"==typeof i)if(void 0===r[i]){if(!n)return null;"string"==typeof a[d+1]?r[i]={}:r[i]=[],r=r[i]}else r=r[i];i=a[s-1],void 0===o?"number"==typeof i&&Array.isArray(r)?r.splice(i,1):delete r[i]:r[i]=o},normalisePropertyExpression:K,validatePropertyExpression:function(e){try{K(e);return!0}catch(e){return!1}},separateIconPath:a,getDefaultNodeIcon:n,getNodeIcon:function(e,t){if(e=e||{},t&&"_selection_"===t.type)return"font-awesome/fa-object-ungroup";if(t&&"group"===t.type)return"font-awesome/fa-object-group";if(t&&"junction"===t.type||"junction"===e.type)return"font-awesome/fa-circle-o";if("config"===e.category)return RED.settings.apiRootUrl+"icons/node-red/cog.svg";if(t&&/^_action_:/.test(t.type)||/^_action_:/.test(e.type))return"font-awesome/fa-cogs";if(t&&"tab"===t.type)return"red-ui-icons/red-ui-icons-flow";if(t&&"unknown"===t.type)return RED.settings.apiRootUrl+"icons/node-red/alert.svg";if(t&&t.icon){if(i(o=a(t.icon)))return"font-awesome"===o.module?t.icon:RED.settings.apiRootUrl+"icons/"+t.icon;if("font-awesome"!==o.module&&/.png$/i.test(o.file)&&(o.file=o.file.replace(/.png$/,".svg"),i(o)))return RED.settings.apiRootUrl+"icons/"+t.icon.replace(/.png$/,".svg")}var o;if(i(o=n(e,t)))return"font-awesome"===o.module?o.module+"/"+o.file:RED.settings.apiRootUrl+"icons/"+o.module+"/"+o.file;if(/.png$/i.test(o.file)){t=o.file;if(o.file=o.file.replace(/.png$/,".svg"),i(o))return RED.settings.apiRootUrl+"icons/"+o.module+"/"+o.file;o.file=t}return o.module="node-red",i(o)||/.png$/i.test(o.file)&&(o.file=o.file.replace(/.png$/,".svg"),i(o))?RED.settings.apiRootUrl+"icons/"+o.module+"/"+o.file:"subflows"===e.category?RED.settings.apiRootUrl+"icons/node-red/subflow.svg":RED.settings.apiRootUrl+"icons/node-red/arrow-in.svg"},getNodeLabel:function(t,o){var n;if(o=o||"","tab"===t.type)n=t.label||o;else if("group"===t.type)n=t.name||o;else if("junction"===t.type)n="junction";else{n=t._def.label;try{n=("function"==typeof n?n.call(t):n)||o}catch(e){console.log("Definition error: "+t.type+".label",e),n=o}}return RED.text.bidi.enforceTextDirectionWithUCC(n)},getNodeColor:function(e,t){var o=(t=t||{}).color,n=RED.settings.theme("palette.theme")||[];if(0<n.length){if(!d.hasOwnProperty(e)){d[e]=t.color;for(var i=n.length,a=0;a<i;a++){var s=n[a];if((!s.hasOwnProperty("category")||(s.hasOwnProperty("_category")||(s._category=new RegExp(s.category)),s._category.test(t.category)))&&(!s.hasOwnProperty("type")||(s.hasOwnProperty("_type")||(s._type=new RegExp(s.type)),s._type.test(e)))){d[e]=s.color||t.color;break}}}o=d[e]}return o||"#ddd"},getPaletteLabel:function(t,e){var o=t;if(void 0!==e.paletteLabel)try{o=("function"==typeof e.paletteLabel?e.paletteLabel.call(e):e.paletteLabel)||""}catch(e){console.log("Definition error: "+t+".paletteLabel",e)}return o},clearNodeColorCache:function(){d={}},addSpinnerOverlay:function(e,t){return e=$('<div class="red-ui-component-spinner "><img src="red/images/spin.svg"/></div>').appendTo(e),t&&e.addClass("red-ui-component-spinner-contain"),e},decodeObject:function(e,t){if("number"===t&&"NaN"===e)e=Number.NaN;else if("number"===t&&"Infinity"===e)e=1/0;else if("number"===t&&"-Infinity"===e)e=-1/0;else if("Object"===t||/^(array|set|map)/.test(t)||"boolean"===t||"number"===t)e=JSON.parse(e);else if(/error/i.test(t))e=((e=JSON.parse(e)).name?e.name+": ":"")+e.message;else if("null"===t)e=null;else if("undefined"===t)e=void 0;else if(/^buffer/.test(t)){var o=e;e=[];for(var n=0;n<o.length;n+=2)e.push(parseInt(o.substr(n,2),16))}return e},parseContextKey:function(e,t){var o={},n=/^#:\((\S+?)\)::(.*)$/.exec(e);return n?(o.store=n[1],o.key=n[2]):(o.key=e,t?o.store=t:RED.settings.context&&(o.store=RED.settings.context.default)),o},createIconElement:function(e,t,o){var n=t.find(".red-ui-palette-icon");0!==n.length&&n.remove();0!==(n=t.find("i")).length&&n.remove();var i=a(e);if("font-awesome"===i.module){if(RED.nodes.fontAwesome.getIconUnicode(i.file))return void(n=$("<i/>").appendTo(t)).addClass("red-ui-palette-icon-fa fa fa-fw "+(o?"fa-lg ":"")+i.file);e=RED.settings.apiRootUrl+"icons/node-red/arrow-in.svg"}else if("red-ui-icons"===i.module)return void $("<i/>").appendTo(t).addClass("red-ui-palette-icon red-ui-icons "+i.file);$("<div/>",{class:"red-ui-palette-icon"}).appendTo(t).css("backgroundImage","url("+e+")")},sanitize:G,renderMarkdown:t,createNodeIcon:function(e,t){var o,n=$('<span class="red-ui-node-icon-container">'),i=e._def,a=$("<div>",{class:"red-ui-node-icon"}),s=("_selection_"===e.type?a.addClass("red-ui-palette-icon-selection"):"group"===e.type?a.addClass("red-ui-palette-icon-group"):"junction"===e.type?a.addClass("red-ui-palette-icon-junction"):"tab"===e.type?a.addClass("red-ui-palette-icon-flow"):(s=RED.utils.getNodeColor(e.type,i),a.css("backgroundColor",s),(o=l(s))!==s&&a.css("border-color",o)),RED.utils.getNodeIcon(i,e));return RED.utils.createIconElement(s,a,!0),a.appendTo(n),t&&(o=RED.utils.getNodeLabel(e,e.name||e.type+": "+e.id),i=$("<div>",{class:"red-ui-node-label"}).appendTo(n),o?i.text(o):i.html("&nbsp;")),n},getDarkerColor:l,parseModuleList:function(e){return(e=e||["*"]).map(function(e){var e=/^(.+?)(?:@(.*))?$/.exec(e),t=-1===(t=e[1].indexOf("*"))?1/0:t;return{module:new RegExp("^"+e[1].replace(/\*/g,".*")+"$"),version:e[2],wildcardPos:t}})},checkModuleAllowed:function(e,t,o,n){return!o&&!n||(0===o.length&&0===n.length||(o=s(e,0,o),e=s(e,0,n),!(!o||e)||!(!o&&e)&&(!o&&!e||(o.wildcardPos!==e.wildcardPos?o.wildcardPos>e.wildcardPos:o.module.toString().length>e.module.toString().length))))},getBrowserInfo:function(){var e={};try{var t=navigator.userAgent;e.ua=t,e.browser=/Edge\/\d+/.test(t)?"ed":/MSIE 9/.test(t)?"ie9":/MSIE 10/.test(t)?"ie10":/MSIE 11/.test(t)?"ie11":/MSIE\s\d/.test(t)?"ie?":/rv\:11/.test(t)?"ie11":/Firefox\W\d/.test(t)?"ff":/Chrom(e|ium)\W\d|CriOS\W\d/.test(t)?"gc":/\bSafari\W\d/.test(t)?"sa":/\bOpera\W\d/.test(t)||/\bOPR\W\d/i.test(t)?"op":"undefined"!=typeof MSPointerEvent?"ie?":"",e.os=/Windows NT 10/.test(t)?"win10":/Windows NT 6\.0/.test(t)?"winvista":/Windows NT 6\.1/.test(t)?"win7":/Windows NT 6\.\d/.test(t)?"win8":/Windows NT 5\.1/.test(t)?"winxp":/Windows NT [1-5]\./.test(t)?"winnt":/Mac/.test(t)?"mac":/Linux/.test(t)?"linux":/X11/.test(t)?"nix":"",e.touch="ontouchstart"in document.documentElement,e.mobile=/IEMobile|Windows Phone|Lumia/i.test(t)?"w":/iPhone|iP[oa]d/.test(t)?"i":/Android/.test(t)?"a":/BlackBerry|PlayBook|BB10/.test(t)?"b":/Mobile Safari/.test(t)?"s":/webOS|Mobile|Tablet|Opera Mini|\bCrMo\/|Opera Mobi/i.test(t)?1:0,e.tablet=/Tablet|iPad/i.test(t),e.ie=/MSIE \d|Trident.*rv:/.test(navigator.userAgent),e.android=/android/i.test(navigator.userAgent)}catch(e){}return e}}}(),function(r){r.widget("nodered.editableList",{_create:function(){var o=this,e=(this.element.addClass("red-ui-editableList-list"),this.uiWidth=this.element.width(),this.uiContainer=this.element.wrap("<div>").parent(),this.options.header?(this.options.header.addClass("red-ui-editableList-header"),this.borderContainer=this.uiContainer.wrap("<div>").parent(),this.borderContainer.prepend(this.options.header),this.topContainer=this.borderContainer.wrap("<div>").parent()):this.topContainer=this.uiContainer.wrap("<div>").parent(),this.topContainer.addClass("red-ui-editableList"),this.options.class&&this.topContainer.addClass(this.options.class),this.options.buttons||[]),t=(!1!==this.options.addButton&&("string"==typeof this.options.addButton?t=this.options.addButton:n=RED&&RED._?(t=RED._("editableList.add"),RED._("editableList.addTitle")):(t="add","add new item"),e.unshift({label:t,icon:"fa fa-plus",click:function(e){o.addItem({})},title:n})),e.forEach(function(t){var e=r('<button type="button" class="red-ui-button red-ui-button-small red-ui-editableList-addButton" style="margin-top: 4px; margin-right: 5px;"></button>').appendTo(o.topContainer).on("click",function(e){e.preventDefault(),void 0!==t.click&&t.click(e)});t.id&&e.attr("id",t.id),t.title&&e.attr("title",t.title),t.icon&&e.append(r("<i></i>").attr("class",t.icon)),t.label&&e.append(r("<span></span>").text(" "+t.label))}),"absolute"===this.element.css("position")&&(["top","left","bottom","right"].forEach(function(e){var t=o.element.css(e);"auto"!==t&&""!==t&&(o.topContainer.css(e,t),o.uiContainer.css(e,"0"),"top"===e&&o.options.header&&o.uiContainer.css(e,"20px"),o.element.css(e,"auto"))}),this.element.css("position","static"),this.topContainer.css("position","absolute"),this.uiContainer.css("position","absolute")),(this.options.header?this.borderContainer:this.uiContainer).addClass("red-ui-editableList-border"),this.uiContainer.addClass("red-ui-editableList-container"),this.uiHeight=this.element.height(),this.activeFilter=this.options.filter||null,this.activeSort=this.options.sort||null,this.scrollOnAdd=this.options.scrollOnAdd,void 0===this.scrollOnAdd&&(this.scrollOnAdd=!0),this.element.css("minHeight")),n=("0px"!==t&&(this.uiContainer.css("minHeight",t),this.element.css("minHeight",0)),this.element.css("maxHeight")),e=("0px"!==n&&(this.uiContainer.css("maxHeight",n),this.element.css("maxHeight",null)),"auto"!==this.options.height&&(this.uiContainer.css("overflow-y","auto"),isNaN(this.options.height)||(this.uiHeight=this.options.height)),this.element.height("auto"),this.element.attr("style"));null!==(t=/width\s*:\s*(\d+%)/i.exec(e))&&(this.element.width("100%"),this.uiContainer.width(t[1])),this.options.sortable&&(n={axis:"y",update:function(e,t){o.options.sortItems&&o.options.sortItems(o.items())},handle:"string"==typeof this.options.sortable?this.options.sortable:".red-ui-editableList-item-handle",cursor:"move",tolerance:"pointer",forcePlaceholderSize:!0,placeholder:"red-ui-editabelList-item-placeholder",start:function(e,t){t.placeholder.height(t.item.height()-4)}},this.options.connectWith&&(n.connectWith=this.options.connectWith),this.element.sortable(n)),this._resize()},_resize:function(){var t,e=this.topContainer.height(),o=this.uiContainer.height();0!==this.uiHeight&&this.uiContainer.height(this.uiHeight-(e-o)),this.options.resize&&this.options.resize(),this.options.resizeItem&&(t=this).element.children().each(function(e){t.options.resizeItem(r(this).children(".red-ui-editableList-item-content"),e)})},_destroy:function(){var e;this.topContainer&&(e=this.topContainer,delete this.topContainer,e.remove())},_refreshFilter:function(){var n=this,i=0;return this.activeFilter?(this.items().each(function(e,t){var o=t.data("data");try{n.activeFilter(o)?(t.parent().show(),i++):t.parent().hide()}catch(e){console.log(e),t.parent().show(),i++}}),i):this.element.children().show()},_refreshSort:function(){var e,o;this.activeSort&&(e=this.element.children(),o=this,e.sort(function(e,t){return o.activeSort(r(e).children(".red-ui-editableList-item-content").data("data"),r(t).children(".red-ui-editableList-item-content").data("data"))}),r.each(e,function(e,t){o.element.append(t)}))},width:function(e){this.uiWidth=e,this._resize()},height:function(e){this.uiHeight=e,this._resize()},getItemAt:function(e){var t=this.items();if(0<=e&&e<t.length)return r(t[e]).data("data")},indexOf:function(e){for(var t=this.items(),o=0;o<t.length;o++)if(r(t[o]).data("data")===e)return o;return-1},insertItemAt:function(n,e){var t,i=this,a=(n=n||{},r("<li>")),o=r("<div/>").addClass("red-ui-editableList-item-content").appendTo(a),s=(o.data("data",n),!0===this.options.sortable&&(r('<i class="red-ui-editableList-item-handle fa fa-bars"></i>').appendTo(a),a.addClass("red-ui-editableList-item-sortable")),this.options.removable&&(t=r("<a/>",{href:"#",class:"red-ui-editableList-item-remove red-ui-button red-ui-button-small"}).appendTo(a),r("<i/>",{class:"fa fa-remove"}).appendTo(t),a.addClass("red-ui-editableList-item-removable"),t.on("click",function(e){e.preventDefault();var t=o.data("data");a.addClass("red-ui-editableList-item-deleting"),a.fadeOut(300,function(){r(this).remove(),i.options.removeItem&&i.options.removeItem(t)})})),!1);if(this.activeSort&&this.items().each(function(e,t){var o;s||(o=t.data("data"),i.activeSort(n,o)<0&&(a.insertBefore(t.closest("li")),s=!0))}),s||(e<=0?a.prependTo(this.element):e>i.element.children().length-1?a.appendTo(this.element):a.insertBefore(this.element.children().eq(e))),this.options.addItem){e=i.element.children().length-1;if(i.options.addItem(o,e,n),i.activeFilter)try{i.activeFilter(n)||a.hide()}catch(e){}!i.activeSort&&i.scrollOnAdd&&setTimeout(function(){i.uiContainer.scrollTop(i.element.height())},0)}},addItem:function(e){this.insertItemAt(e,this.element.children().length)},addItems:function(e){for(var t=0;t<e.length;t++)this.addItem(e[t])},removeItem:function(t,e){var o=this.element.children().filter(function(e){return t===r(this).children(".red-ui-editableList-item-content").data("data")});e?o.detach():o.remove(),this.options.removeItem&&this.options.removeItem(t)},items:function(){return this.element.children().map(function(e){return r(this).children(".red-ui-editableList-item-content")})},empty:function(){this.element.empty(),this.uiContainer.scrollTop(0)},filter:function(e){return void 0!==e&&(this.activeFilter=e),this._refreshFilter()},sort:function(e){return void 0!==e&&(this.activeSort=e),this._refreshSort()},length:function(){return this.element.children().length},show:function(t){var e=this.element.children().filter(function(e){return t===r(this).children(".red-ui-editableList-item-content").data("data")});0<e.length&&this.uiContainer.scrollTop(this.uiContainer.scrollTop()+e.position().top)},getItem:function(e){e=e.children(".red-ui-editableList-item-content");return e.length?e.data("data"):null}})}(jQuery),function(u){u.widget("nodered.treeList",{_create:function(){var n=this,i=!0,e=(!1===n.options.autoSelect&&(i=!1),this.element.addClass("red-ui-treeList"),this.element.attr("tabIndex",0),u("<div>",{class:"red-ui-treeList-container"}).appendTo(this.element)),e=(this.element.on("keydown",function(e){var t,o=n._topList.find(".focus").parent().data("data");if(o||40!==e.keyCode&&38!==e.keyCode){switch(e.keyCode){case 32:case 13:if(!n.options.selectable)return;if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;e.preventDefault(),e.stopPropagation(),o.checkbox?o.treeList.checkbox.trigger("click"):o.radio?o.treeList.radio.trigger("click"):o.children?o.treeList.container.hasClass("expanded")?o.treeList.collapse():o.treeList.expand():n._trigger("confirm",null,o);break;case 37:e.preventDefault(),e.stopPropagation(),o.children&&o.treeList.container.hasClass("expanded")?o.treeList.collapse():o.parent&&(t=o.parent);break;case 38:e.preventDefault(),e.stopPropagation(),!(t=(t=n._getPreviousSibling(o))&&n._getLastDescendant(t))&&o.parent&&(t=o.parent);break;case 39:e.preventDefault(),e.stopPropagation(),!o.children||o.treeList.container.hasClass("expanded")||o.treeList.expand();break;case 40:if(e.preventDefault(),e.stopPropagation(),o.children&&Array.isArray(o.children)&&0<o.children.length&&o.treeList.container.hasClass("expanded"))t=o.children[0];else for(t=n._getNextSibling(o);!t&&o.parent;)o=o.parent,t=n._getNextSibling(o)}t&&(i?n.select(t):n._topList.find(".focus").removeClass("focus"),t.treeList.label.addClass("focus"))}else n._data[0]&&(i?n.select(n._data[0]):n._topList.find(".focus").removeClass("focus"),n._data[0].treeList.label.addClass("focus"))}),this._data=[],this._items={},this._selected=new Set,this._topList=u('<ol class="red-ui-treeList-list">').css({position:"absolute",top:0,left:0,right:0,bottom:0}).appendTo(e),{addButton:!1,scrollOnAdd:!1,height:"100%",addItem:function(e,t,o){n._addSubtree(n._topList,e,o,0)}});this.options.header&&(e.header=this.options.header),!1!==this.options.rootSortable&&this.options.sortable&&(e.sortable=this.options.sortable,e.connectWith=".red-ui-treeList-sortable",this._topList.addClass("red-ui-treeList-sortable")),this._topList.editableList(e),this.options.data&&this.data(this.options.data)},_getLastDescendant:function(e){return e.children&&e.treeList.container.hasClass("expanded")&&0!==e.children.length?this._getLastDescendant(e.children[e.children.length-1]):e},_getPreviousSibling:function(e){var t=e.parent?e.parent.children:this._data,e=t.indexOf(e);return 0===e?null:t[e-1]},_getNextSibling:function(e){var t=e.parent?e.parent.children:this._data,e=t.indexOf(e);return e===t.length-1?null:t[e+1]},_addChildren:function(e,n,o,i,a){var s=this,r=u('<ol class="red-ui-treeList-list">').appendTo(e).editableList({connectWith:".red-ui-treeList-sortable",sortable:s.options.sortable,addButton:!1,scrollOnAdd:!1,height:"auto",addItem:function(e,t,o){s._addSubtree(r,e,o,i+1)},sortItems:function(e){var t=[],o=[];e.each(function(){var e=u(this).data("data"),e=(t.push(e),s._fixDepths(n,e));e&&o.push(e)}),Array.isArray(n.children)&&(n.children=t),o.forEach(function(e){s._trigger("changeparent",null,e)}),s._trigger("sort",null,n)},filter:n.treeList.childFilter}),d=(s.options.sortable&&r.addClass("red-ui-treeList-sortable"),30),l=0,c=function(){for(var e=l,t=0;t<d;t++){if((l=e+t)===o.length)return void setTimeout(function(){a&&a()},10);o[l].parent=n,r.editableList("addItem",o[l])}++l<o.length&&setTimeout(function(){c()},10)};return c(),r.hide(),r},_fixDepths:function(e,t){var o,n=this,i=null;return t.parent!==e&&(reparented=!0,o=t.parent,t.parent=e,i={item:t,old:o}),t.depth!==e.depth+1&&(t.depth=e.depth+1,o=(t.gutter&&!t.gutter.hasClass("red-ui-treeList-gutter-float")?t.gutter.width()+2:0)+20*t.depth,t.treeList.labelPadding.width(o+"px"),t.element&&u(t.element).css({width:"calc(100% - "+(o+20+(t.icon?20:0))+"px)"}),t.children&&Array.isArray(t.children)&&t.children.forEach(function(e){n._fixDepths(t,e)})),i},_initItem:function(s,r){var d;s.treeList||(((d=this)._items[s.id]=s).treeList={},s.depth=r,s.treeList.remove=function(e){var t;if(s.treeList.parentList&&s.treeList.parentList.editableList("removeItem",s,e),s.parent&&(e=s.parent.children.indexOf(s),s.parent.children.splice(e,1),d._trigger("sort",null,s.parent)),d._selected.delete(s),delete s.treeList,delete d._items[s.id],0===s.depth){for(var o in d._items)!d._items.hasOwnProperty(o)||(t=d._items[o]).parent&&t.parent.id===s.id&&(delete d._items[o].treeList,delete d._items[o]);d._data=d._data.filter(function(e){return e.id!==s.id})}},s.treeList.insertChildAt=function(e,t,o){(e.parent=s).children.splice(t,0,e);function n(t,o){d._initItem(o,t.depth+1),o.parent=t,o.children&&"function"!=typeof o.children&&o.children.forEach(function(e){n(o,e,t.depth)})}n(s,e),!s.deferBuild&&s.treeList.childList&&(s.treeList.childList.editableList("insertItemAt",e,t),o&&setTimeout(function(){d.select(e)},100),d._trigger("sort",null,s),d.activeFilter&&d.filter(d.activeFilter))},s.treeList.addChild=function(e,t){s.treeList.insertChildAt(e,s.children.length,t)},s.treeList.expand=function(t){var o,n,i,a,e;s.children?s.treeList.container?(o=s.treeList.container).hasClass("expanded")?t&&t(!1):(o.hasClass("built")||!s.deferBuild&&"function"!=typeof s.children?(d._loadingData||20<s.children.length?s.treeList.childList.show():s.treeList.childList.slideDown("fast"),s.expanded=!0,t&&t(!d._loadingData)):(o.addClass("built"),n=!1,a=0,Date.now(),e=function(e){n=!0,s.treeList.childList=d._addChildren(o,s,e,r,function(){t&&t(!0),d._trigger("childrenloaded",null,s)});e=Date.now()-a;e<400?setTimeout(function(){s.treeList.childList.slideDown("fast"),i&&i.remove()},400-e):(s.treeList.childList.slideDown("fast"),i&&i.remove()),s.expanded=!0},"function"==typeof s.children?s.children(e,s):(delete s.deferBuild,e(s.children)),n||(a=Date.now(),i=u('<div class="red-ui-treeList-spinner">').css({"background-position":35+20*r+"px 50%"}).appendTo(o))),o.addClass("expanded")):(s.expanded=!0,t&&t(!1)):t&&t(!1)},s.treeList.collapse=function(){!1!==s.collapsible&&s.children&&(s.expanded=!1,s.treeList.container&&(s.children.length<20?s.treeList.childList.slideUp("fast"):s.treeList.childList.hide(),s.treeList.container.removeClass("expanded")))},s.treeList.sortChildren=function(e){s.children&&(s.children.sort(e),s.treeList.childList&&(s.treeList.childList.editableList("sort",e),s.treeList.childList.editableList("sort",null)))},s.treeList.replaceElement=function(e){var t;s.element&&(s.treeList.container&&(u(s.element).remove(),u(e).appendTo(s.treeList.label),t=(s.gutter?s.gutter[0].offsetWidth+2:0)+20*s.depth,u(e).css({width:"calc(100% - "+(t+20+(s.icon?20:0))+"px)"})),s.element=e)},s.children&&"function"!=typeof s.children&&s.children.forEach(function(e){d._initItem(e,r+1)}))},_addSubtree:function(e,o,n,t){var i,a,s=this,r=(this._initItem(n,t),n.treeList.container=o,n.treeList.parentList=e,u("<div>",{class:"red-ui-treeList-label"})),e=(r.appendTo(o),n.treeList.label=r,n.class&&r.addClass(n.class),n.gutter&&n.gutter.css({position:"absolute"}).appendTo(r),(n.gutter&&!n.gutter.hasClass("red-ui-treeList-gutter-float")?n.gutter.width()+2:0)+20*t),d=(n.treeList.labelPadding=u("<span>").css({display:"inline-block","flex-shrink":0,width:e+"px"}).appendTo(r),r.on("mouseover",function(e){s._trigger("itemmouseover",e,n)}),r.on("mouseout",function(e){s._trigger("itemmouseout",e,n)}),r.on("mouseenter",function(e){s._trigger("itemmouseenter",e,n)}),r.on("mouseleave",function(e){s._trigger("itemmouseleave",e,n)}),n.treeList.makeLeaf=function(e){var t;d.children().length&&(e&&n.children&&(t=function(e){e.children&&e.children.forEach(function(e){e.element&&e.element.detach(),e.gutter&&e.gutter.detach(),t(e)})})(n),d.empty(),n.deferBuild||(n.treeList.childList.remove(),delete n.treeList.childList),r.off("click.red-ui-treeList-expand"),d.off("click.red-ui-treeList-expand"),delete n.children,o.removeClass("expanded"),delete n.expanded)},n.treeList.makeParent=function(e){d.children().length||(u('<i class="fa fa-angle-right" />').toggleClass("hide",!1===n.collapsible).appendTo(d),d.on("click.red-ui-treeList-expand",function(e){e.stopPropagation(),e.preventDefault(),o.hasClass("expanded")?n.treeList.collapse():n.treeList.expand()}),r.on("click.red-ui-treeList-expand",function(e){o.hasClass("expanded")?(n.hasOwnProperty("selected")||r.hasClass("selected"))&&n.treeList.collapse():n.treeList.expand()}),n.children||(n.children=e||[],n.treeList.childList=s._addChildren(o,n,n.children,t)))},u('<span class="red-ui-treeList-icon"></span>').appendTo(r));n.children&&n.treeList.makeParent(),n.checkbox?(i=u('<span class="red-ui-treeList-icon"></span>'),(a=u('<input class="red-ui-treeList-checkbox" type="checkbox">').prop("checked",n.selected).appendTo(i)).on("click",function(e){e.stopPropagation()}),a.on("change",function(e){n.selected=this.checked,n.selected?s._selected.add(n):s._selected.delete(n),r.toggleClass("selected",this.checked),s._trigger("select",e,n)}),n.children||r.on("click",function(e){e.stopPropagation(),a.trigger("click"),s._topList.find(".focus").removeClass("focus"),r.addClass("focus")}),n.treeList.select=function(e){e!==n.selected&&a.trigger("click")},n.treeList.checkbox=a,i.appendTo(r)):n.radio?(i=u('<span class="red-ui-treeList-icon"></span>'),(a=u('<input class="red-ui-treeList-radio" type="radio">').prop("name",n.radio).prop("checked",n.selected).appendTo(i)).on("click",function(e){e.stopPropagation()}),a.on("change",function(e){n.selected=this.checked,s._selected.forEach(function(e){e.radio===n.radio&&(e.treeList.label.removeClass("selected"),e.selected=!1,s._selected.delete(e))}),n.selected?s._selected.add(n):s._selected.delete(n),r.toggleClass("selected",this.checked),s._trigger("select",e,n)}),n.children||r.on("click",function(e){e.stopPropagation(),a.trigger("click"),s._topList.find(".focus").removeClass("focus"),r.addClass("focus")}),n.treeList.select=function(e){e!==n.selected&&a.trigger("click")},i.appendTo(r),n.treeList.radio=a):(r.on("click",function(e){s.options.multi||s.clearSelection(),r.addClass("selected"),s._selected.add(n),s._topList.find(".focus").removeClass("focus"),r.addClass("focus"),s._trigger("select",e,n)}),r.on("dblclick",function(e){s._topList.find(".focus").removeClass("focus"),r.addClass("focus"),n.children||s._trigger("confirm",e,n)}),n.treeList.select=function(e){s.options.multi||s.clearSelection(),r.toggleClass("selected",e),e?(s._selected.add(n),s._trigger("select",null,n)):s._selected.delete(n),s.reveal(n)}),r.toggleClass("selected",!!n.selected),n.selected&&s._selected.add(n),n.icon&&("string"==typeof n.icon?u('<span class="red-ui-treeList-icon"><i class="'+n.icon+'" /></span>').appendTo(r):u('<span class="red-ui-treeList-icon">').appendTo(r).append(n.icon)),n.hasOwnProperty("label")||n.hasOwnProperty("sublabel")?(n.hasOwnProperty("label")&&u('<span class="red-ui-treeList-label-text"></span>').text(n.label).appendTo(r),n.hasOwnProperty("sublabel")&&u('<span class="red-ui-treeList-sublabel-text"></span>').text(n.sublabel).appendTo(r)):n.element&&(u(n.element).appendTo(r),u(n.element).css({width:"calc(100% - "+(e+20+(n.icon?20:0))+"px)"})),n.children&&(Array.isArray(n.children)&&!n.deferBuild&&(n.treeList.childList=s._addChildren(o,n,n.children,t)),n.expanded&&n.treeList.expand())},empty:function(){this._topList.editableList("empty")},data:function(e){var t=this;if(void 0===e)return this._data;this._data=e,this._items={},this._topList.editableList("empty"),this._loadingData=!0;for(var o=0;o<e.length;o++)this._topList.editableList("addItem",e[o]);setTimeout(function(){delete t._loadingData},200),this._trigger("select")},show:function(e,o){if(e="string"==typeof e?this._items[e]:e){for(var n=this,i=[],t=e;t;)i.unshift(t),t=t.parent;var a=!1,s=function(e){a=a||e;var t=i.shift();0===i.length?setTimeout(function(){n.reveal(t),o&&o()},a?200:0):t.treeList.expand(s)};s()}},reveal:function(e){var t,o,n;(e="string"==typeof e?this._items[e]:e)&&(o=this._topList.offset().top,t=e.treeList.label.offset().top,t-=o+(o=this._topList.parent().scrollTop()),n=this._topList.parent().height(),t<(e=e.treeList.label.outerHeight())/2?this._topList.parent().scrollTop(o+t-e/2-e):n<t+e&&this._topList.parent().scrollTop(o+(t+2.5*e-n)))},select:function(e,t,o){var n=this;this.options.multi||!1===o||this.clearSelection(),Array.isArray(e)?e.forEach(function(e){n.select(e,t,!1)}):(e="string"==typeof e?this._items[e]:e)&&(e.selected=!0,this._selected.add(e),e.treeList.label&&e.treeList.label.addClass("selected"),n._topList.find(".focus").removeClass("focus"),!1!==t&&this._trigger("select",null,e))},clearSelection:function(){this._selected.forEach(function(e){e.selected=!1,e.treeList.checkbox&&e.treeList.checkbox.prop("checked",!1),e.treeList.label&&e.treeList.label.removeClass("selected")}),this._selected.clear()},selected:function(){var t=[];return this._selected.forEach(function(e){t.push(e)}),this.options.multi?t:t.length?t[0]:void 0},filter:function(n){this.activeFilter=n;function i(e){var t=0,o=(n&&n(e)&&(t++,a++),0);return e.children&&"function"!=typeof e.children&&(e.treeList.childList?o=e.treeList.childList.editableList("filter",i):(e.treeList.childFilter=i,n&&e.children.forEach(function(e){i(e)&&o++})),t+=o,n&&0<o&&setTimeout(function(){e.treeList.expand()},10)),n?0<t:(a++,!0)}var a=0;return this._topList.editableList("filter",i),a},get:function(e){return this._items[e]||null}})}(jQuery),function(t){t.widget("nodered.checkboxSet",{_create:function(){var o=this,e=(this.uiElement=this.element.wrap("<span>").parent(),this.uiElement.addClass("red-ui-checkboxSet"),this.options.parent&&(this.parent=this.options.parent,this.parent.checkboxSet("addChild",this.element)),this.children=[],this.partialFlag=!1,this.stateValue=0,this.element.prop("checked"));this.states=[t('<span class="red-ui-checkboxSet-option hide"><i class="fa fa-square-o"></i></span>').appendTo(this.uiElement),t('<span class="red-ui-checkboxSet-option hide"><i class="fa fa-check-square-o"></i></span>').appendTo(this.uiElement),t('<span class="red-ui-checkboxSet-option hide"><i class="fa fa-minus-square-o"></i></span>').appendTo(this.uiElement)],(e?this.states[1]:this.states[0]).show(),this.element.on("change",function(){this.checked?(o.states[0].hide(),o.states[1].show()):(o.states[1].hide(),o.states[0].show()),o.states[2].hide();var t=this.checked;o.children.forEach(function(e){e.checkboxSet("state",t,!1,!0)})}),this.uiElement.on("click",function(e){e.stopPropagation(),o.state(!1===o.state())}),this.parent&&this.parent.checkboxSet("updateChild",this)},_destroy:function(){this.parent&&this.parent.checkboxSet("removeChild",this.element)},addChild:function(e){this.children.push(e)},removeChild:function(e){e=this.children.indexOf(e);-1<e&&this.children.splice(e,1)},updateChild:function(e){var o=0;this.children.forEach(function(e,t){!0===e.checkboxSet("state")&&o++}),0===o?this.state(!1,!0):o===this.children.length?this.state(!0,!0):this.state(null,!0)},disable:function(){this.uiElement.addClass("disabled")},state:function(e,t,o){if(0===arguments.length)return this.partialFlag?null:this.element.is(":checked");this.partialFlag=null===e;var n=this.partialFlag||e;this.element.prop("checked",n),!0===e?(this.states[0].hide(),this.states[1].show(),this.states[2].hide()):!1===e?(this.states[2].hide(),this.states[1].hide(),this.states[0].show()):null===e&&(this.states[0].hide(),this.states[1].hide(),this.states[2].show()),t||this.element.trigger("change",null),!o&&this.parent&&this.parent.checkboxSet("updateChild",this)}})}(jQuery),RED.menu=function(){var c={};let u=0;function p(t){var o;if(null!==t&&t.id&&!1===RED.settings.theme("menu."+t.id))return null;if(null===t)o=$('<li class="red-ui-menu-divider"></li>');else{o=$("<li></li>"),t.id||(t.id="red-ui-menu-item-"+u++),t.group&&o.addClass("red-ui-menu-group-"+t.group);var n="<a "+(t.id?'id="'+t.id+'" ':"")+'tabindex="-1" href="#">';t.toggle&&(n=(n+='<i class="fa fa-square'+("right"!==t.direction?" pull-left":"")+'"></i>')+'<i class="fa fa-check-square'+("right"!==t.direction?" pull-left":"")+'"></i>'),void 0!==t.icon&&(/\.(png|svg)/.test(t.icon)?n+='<img src="'+t.icon+'"/> ':n+='<i class="'+(t.icon||'" style="display: inline-block;"')+'"></i> ');let e=t.label;t.label||"string"!=typeof t.onselect||(e=RED.actions.getLabel(t.onselect)),t.sublabel?n+='<span class="red-ui-menu-label-container"><span class="red-ui-menu-label">'+e+'</span><span class="red-ui-menu-sublabel">'+t.sublabel+"</span></span>":n+='<span class="red-ui-menu-label"><span>'+e+"</span></span>",n+="</a>";var i,n=$(n).appendTo(o);if(t.link=n,"string"!=typeof t.onselect||(i=RED.keyboard.getShortcut(t.onselect))&&i.key&&(t.shortcutSpan=$('<span class="red-ui-popover-key">'+RED.keyboard.formatKey(i.key,!0)+"</span>").appendTo(n.find(".red-ui-menu-label"))),(c[t.id]=t).onselect?(n.on("click",function(e){e.preventDefault(),$(this).parent().hasClass("disabled")||(t.toggle?!0===t.toggle?g(t.id,!h(t.id)):g(t.id,!0):f(t.id))}),t.toggle&&(i=RED.settings.get("menu-"+t.id),t.setting&&(null!==i?(RED.settings.set(t.setting,i),RED.settings.remove("menu-"+t.id)):i=RED.settings.get(t.setting)),i?(n.addClass("active"),f(t.id,!0)):!1===i?(n.removeClass("active"),f(t.id,!1)):t.hasOwnProperty("selected")&&(t.selected?n.addClass("active"):n.removeClass("active"),f(t.id,t.selected)))):t.href?n.attr("target","_blank").attr("href",t.href):t.options||(o.addClass("disabled"),n.on("click",function(e){e.preventDefault()})),t.options){o.addClass("red-ui-menu-dropdown-submenu"+("right"!==t.direction?" pull-left":""));for(var a=$('<ul id="'+t.id+'-submenu" class="red-ui-menu-dropdown"></ul>').appendTo(o),s=!1,r=!1,d=0;d<t.options.length;d++){t.options[d]&&(t.onpreselect&&void 0===t.options[d].onpreselect&&(t.options[d].onpreselect=t.onpreselect),t.onpostselect&&void 0===t.options[d].onpostselect&&(t.options[d].onpostselect=t.onpostselect),t.options[d].direction=t.direction,s=s||t.options[d].icon,r=r||t.options[d].options);var l=p(t.options[d]);l&&l.appendTo(a)}s||a.addClass("red-ui-menu-dropdown-noicons"),r&&a.addClass("red-ui-menu-dropdown-submenus")}t.disabled&&o.addClass("disabled"),!1===t.visible&&o.addClass("hide")}return o}function f(e,t){var o=c[e],n=o.onselect;o.onpreselect&&o.onpreselect.call(o,t),(n="string"==typeof o.onselect?RED.actions.get(o.onselect):n)?n.call(o,t):console.log("No callback for",e,o.onselect),o.onpostselect&&o.onpostselect.call(o,t)}function h(e){return $("#"+e).hasClass("active")}function g(e,t){var o=!1,n=(h(e)==t&&(o=!0),c[e]);if(t?$("#"+e).addClass("active"):$("#"+e).removeClass("active"),n){if(n.toggle&&"string"==typeof n.toggle&&t)for(var i in c)!c.hasOwnProperty(i)||(i=c[i]).id!=n.id&&n.toggle==i.toggle&&g(i.id,!1);!o&&n.onselect&&f(n.id,t),n.local||o||RED.settings.set(n.setting||"menu-"+n.id,t)}}return{init:function(e){for(var t,o=$("<ul/>",{class:"red-ui-menu red-ui-menu-dropdown pull-right"}),n=(e.direction&&o.addClass("red-ui-menu-dropdown-direction-"+e.direction),e.id&&(o.attr({id:e.id+"-submenu"}),1===(t=$("#"+e.id)).length&&(o.insertAfter(t),t.on("click",function(e){e.stopPropagation(),e.preventDefault(),o.is(":visible")?($(document).off("click.red-ui-menu"),o.hide()):($(document).on("click.red-ui-menu",function(e){$(document).off("click.red-ui-menu"),activeMenu=null,o.hide()}),$(".red-ui-menu.red-ui-menu-dropdown").hide(),o.show())}))),!1),i=!1,a=!1,s=0;s<e.options.length;s++){var r,d=e.options[s];d&&(e.onpreselect&&void 0===d.onpreselect&&(d.onpreselect=e.onpreselect),e.onpostselect&&void 0===d.onpostselect&&(d.onpostselect=e.onpostselect),d.direction=e.direction||"left"),null===d&&n||(a=a||d&&d.icon,i=i||d&&d.options,(r=p(d))&&(r.appendTo(o),n=null===d))}return a||o.addClass("red-ui-menu-dropdown-noicons"),i&&o.addClass("red-ui-menu-dropdown-submenus"),o},setSelected:g,isSelected:h,toggleSelected:function(e){g(e,!h(e))},setDisabled:function(e,t){t?$("#"+e).parent().addClass("disabled"):$("#"+e).parent().removeClass("disabled")},setVisible:function(e,t){t?$("#"+e).parent().removeClass("hide"):$("#"+e).parent().addClass("hide")},addItem:function(e,t){var o=p(t);if(null!==t&&t.group){var n=$("#"+e+"-submenu").children(".red-ui-menu-group-"+t.group);if(0===n.length)o.appendTo("#"+e+"-submenu");else{for(var i=0;i<n.length;i++){var a=n[i],s=$(a).find(".red-ui-menu-label").html();if(t.label<s){$(a).before(o);break}}i===n.length&&o.appendTo("#"+e+"-submenu")}}else o.appendTo("#"+e+"-submenu")},removeItem:function(e){$("#"+e).parent().remove()},setAction:function(e,t){(e=c[e])&&(e.onselect=t)},refreshShortcuts:function(){for(var e in c){var t;!c.hasOwnProperty(e)||"string"==typeof(e=c[e]).onselect&&e.shortcutSpan&&(e.shortcutSpan.remove(),delete e.shortcutSpan,(t=RED.keyboard.getShortcut(e.onselect))&&t.key&&(e.shortcutSpan=$('<span class="red-ui-popover-key">'+RED.keyboard.formatKey(t.key,!0)+"</span>").appendTo(e.link.find(".red-ui-menu-label"))))}}}}(),RED.panels={create:function(a){var s=a.container||$("#"+a.id),r=s.children();if(2!==r.length)throw console.log(a.id),new Error("Container must have exactly two children");var d,l=!a.dir||"vertical"===a.dir,t=(s.addClass("red-ui-panels"),l||s.addClass("red-ui-panels-horizontal"),$(r[0]).addClass("red-ui-panel"),$(r[1]).addClass("red-ui-panel"),$('<div class="red-ui-panels-separator"></div>').insertAfter(r[0])),c=[],n=!1,u=.5,o=(t.draggable({axis:l?"y":"x",containment:s,scroll:!1,start:function(e,t){d=l?t.position.top:t.position.left,c=[l?$(r[0]).height():$(r[0]).width(),l?$(r[1]).height():$(r[1]).width()]},drag:function(e,t){var o=l?s.height():s.width(),n=(l?t.position.top:t.position.left)-d,i=[c[0]+n,c[1]-n];l?($(r[0]).height(i[0]),t.position.top-=n):($(r[0]).width(i[0]),t.position.left-=n),a.resize&&a.resize(i[0],i[1]),u=i[0]/(o-8)},stop:function(e,t){n=!0}}),{ratio:function(e){if(void 0===e)return u;n=!0,0===(u=e)||1===e?t.hide():t.show(),l?o.resize(s.height()):o.resize(s.width())},resize:function(e){var t,o;l?(o=[$(r[0]).outerHeight(),$(r[1]).outerHeight()],s.height(e)):(o=[$(r[0]).outerWidth(),$(r[1]).outerWidth()],s.width(e)),n&&(o=[t=u*(e-8),e-t-8],l?$(r[0]).outerHeight(o[0]):$(r[0]).outerWidth(o[0])),a.resize&&(o=l?[$(r[0]).height(),$(r[1]).height()]:[$(r[0]).width(),$(r[1]).width()],a.resize(o[0],o[1]))}});return o}},RED.popover=function(){var E={default:{x:12,y:12},small:{x:8,y:8}};return{create:function(n){var c=n.target,u=n.direction||"right",i=n.trigger,a=n.content,s=n.delay||{show:750,hide:50},t=n.autoClose,r=n.width||"auto",d=n.maxWidth,p=n.size||"default",f=n.offset||0;if(!E[p])throw new Error("Invalid RED.popover size value:",p);function o(e){if(g){var t=c.data("red-ui-popover");if(n.tooltip&&t)g=!1;else{if(m=$('<div class="red-ui-popover"></div>'),n.class&&m.addClass(n.class),v=$('<div class="red-ui-popover-content">').appendTo(m),"default"!==p&&m.addClass("red-ui-popover-size-"+p),"function"==typeof a){var o=a.call(w);if(null===o)return;"string"==typeof o?v.text(o):v.append(o)}else v.html(a);m.appendTo("body"),l({target:c,direction:u,width:r,maxWidth:d}),t&&t.close(!0),"manual"!==n.trigger&&c.data("red-ui-popover",w),n.tooltip&&m.on("mousedown",function(e){h(!0)}),"hover"===i&&n.interactive&&(m.on("mouseenter",function(e){clearTimeout(y),g=!0}),m.on("mouseleave",function(e){y&&clearTimeout(y),g&&(y=setTimeout(function(){g=!1,h()},s.hide))})),e?m.show():m.fadeIn("fast")}}}function l(e){c=e.target||c,u=e.direction||u||"right",f=e.offset||f;var t=e.transition,o=e.width||"auto";m.width(o),e.maxWidth?m.css("max-width",e.maxWidth):m.css("max-width","auto");var e=(o=c[0].getBoundingClientRect()).height,n=o.width,i=m.outerHeight(),a=m.outerWidth(),s=$(window).scrollTop(),r=$(window).scrollLeft(),s=s+$(window).height(),r=r+$(window).width(),d=0,l=0;"right"===u?(d=o.top+e/2-i/2,l=o.left+n+E[p].x+f):"left"===u?(d=o.top+e/2-i/2,l=o.left-E[p].x-a-f):"bottom"===u?(d=o.top+e+E[p].y+f,(l=o.left+n/2-a/2)<0?(u="right",d=o.top+e/2-i/2,l=o.left+n+E[p].x+f):r<l+a+10?(u="left",d=o.top+e/2-i/2,l=o.left-E[p].x-a-f,s<d+i+e/2+5&&(d-=d+i+e/2-s+5)):s<d+i&&(u="top",d=o.top-E[p].y-i-f,l=o.left+n/2-a/2)):"top"===u?(d=o.top-E[p].y-i-f,l=o.left+n/2-a/2,d<0&&(u="bottom",d=o.top+e+E[p].y+f,l=o.left+n/2-a/2)):/inset/.test(u)&&(d=o.top+e/2-i/2,l=o.left+n/2-a/2,/bottom/.test(u)&&(d=o.top+e-i-f),/top/.test(u)&&(d=o.top+f),/left/.test(u)&&(l=o.left+f),/right/.test(u)&&(l=o.left+n-a-f)),b&&m.removeClass(b),t&&m.css({transition:"0.6s ease","transition-property":"top,left,right,bottom"}),b="red-ui-popover-"+u,m.addClass(b).css({top:d,left:l}),t&&setTimeout(function(){m.css({transition:"none"})},600)}function h(e){$(document).off("mousedown.red-ui-popover"),g||m&&(e?m.remove():m.fadeOut("fast",function(){$(this).remove()}),m=null,c.removeData("red-ui-popover",w))}var g,m,v,b,y=null,w=(c.on("remove",function(e){y&&clearTimeout(y),g&&(g=!1,setTimeout(h,s.hide))}),"hover"===i?(c.on("mouseenter",function(e){clearTimeout(y),g||(g=!0,y=setTimeout(o,s.show))}),c.on("mouseleave disabled",function(e){y&&clearTimeout(y),g&&(g=!1,setTimeout(h,s.hide))})):"click"===i?(c.on("click",function(e){e.preventDefault(),e.stopPropagation(),((g=!g)?o:h)()}),t&&c.on("mouseleave disabled",function(e){y&&clearTimeout(y),g&&(g=!1,setTimeout(h,t))})):"modal"===i?$(document).on("mousedown.red-ui-popover",function(e){for(var t=e.target;"BODY"!==t.nodeName&&t!==m[0];)t=t.parentElement;"BODY"===t.nodeName&&(g=!1,h())}):t&&setTimeout(function(){g=!1,h()},t),{get element(){return m},setContent:function(e){return a=e,w},open:function(e){return g=!0,o(e),w},close:function(e){return g=!1,h(e),w},move:function(e){l(e)}});return w},tooltip:function(e,o,n){var t=RED.popover.create({tooltip:!0,target:e,trigger:"hover",size:"small",direction:"bottom",content:function(){var e,t=o;return t=n&&(e=RED.keyboard.getShortcut(n))&&e.key?$("<span>"+o+' <span class="red-ui-popover-key">'+RED.keyboard.formatKey(e.key,!0)+"</span></span>"):t},delay:{show:750,hide:50}});return t.setContent=function(e){o=e},t.setAction=function(e){n=e},t.delete=function(){t.close(!0),e.off("mouseenter"),e.off("mouseleave")},t},menu:function(o){var n=$('<ul class="red-ui-menu"></ul>'),i=("compact"===o.style&&n.addClass("red-ui-menu-compact"),o.options||[]),t=RED.popover.panel(n),a=(o.width&&t.container.width(o.width),o.class&&t.container.addClass(o.class),o.maxHeight&&t.container.css({"max-height":o.maxHeight,"overflow-y":"auto"}),{options:function(e){if(void 0===e)return i;i=e||[],n.empty(),i.forEach(function(t){var e=$("<li>").appendTo(n),e=$('<a href="#"></a>').appendTo(e);"string"==typeof t.label?e.text(t.label):t.label&&t.label.appendTo(e),e.on("click",function(e){e.preventDefault(),t.onselect?t.onselect():o.onselect&&o.onselect(t),a.hide()}),0})},show:function(e){$(document).on("keydown.red-ui-menu",function(e){var t=n.find(":focus").parent();40===e.keyCode?(e.preventDefault(),(!(0<t.length)||t.index()===i.length-1?n.children().first():t.next()).children().first().focus()):38===e.keyCode?(e.preventDefault(),(!(0<t.length)||0===t.index()?n.children().last():t.prev()).children().first().focus()):27===e.keyCode?(e.preventDefault(),a.hide(!0)):9===e.keyCode&&o.tabSelect&&(e.preventDefault(),t.find("a").trigger("click")),e.stopPropagation()}),e.onclose=function(){$(document).off("keydown.red-ui-menu"),o.onclose&&o.onclose(!0)},t.show(e)},hide:function(e){$(document).off("keydown.red-ui-menu"),t.hide(o.disposeOnClose),o.onclose&&o.onclose(e)}});return a.options(i),a},panel:function(e){var l=$('<div class="red-ui-editor-dialog red-ui-popover-panel"></div>');function c(e){$(document).off("mousedown.red-ui-popover-panel-close"),$(document).off("keydown.red-ui-popover-panel-close"),l.hide(),l.css({height:"auto"}),!1!==e&&l.remove()}return l.css({display:"none"}),l.appendTo(document.body),e.appendTo(l),{container:l,show:function(t){var o=t.onclose,n=t.closeButton,e=t.target,i=t.align||"right",a=t.offset||[0,0],s=t.x,r=t.y,s=(d=void 0!==s&&void 0!==r)?{left:s,top:r}:e.offset(),r=(d||e.width(),d?0:e.outerHeight()),d=l.height(),e=l.width();(r=r+s.top+a[1])+d-$(document).scrollTop()>$(window).height()&&(r-=r+d-$(window).height()+5),r<0&&(l.height(d+r),r=0),"right"===i?l.css({top:r+"px",left:s.left+a[0]+"px"}):"left"===i&&l.css({top:r+"px",left:s.left-e+a[0]+"px"}),l.slideDown(100),$(document).on("keydown.red-ui-popover-panel-close",function(e){27===e.keyCode&&(o&&o(),c(t.dispose))}),$(document).on("mousedown.red-ui-popover-panel-close",function(e){n&&$(e.target).closest(n).length||$(e.target).closest(l).length||$(e.target).closest(".red-ui-editor-dialog").length||(o&&o(),c(t.dispose))})},hide:c}}}}(),function(i){i.widget("nodered.searchBox",{_create:function(){var t,o,n=this;this.currentTimeout=null,this.lastSent="",this.element.val(""),this.element.addClass("red-ui-searchBox-input"),this.uiContainer=this.element.wrap("<div>").parent(),this.uiContainer.addClass("red-ui-searchBox-container"),"compact"===this.options.style&&this.uiContainer.addClass("red-ui-searchBox-compact"),0===this.element.parents("form").length&&this.element.wrap("<form>").parent().addClass("red-ui-searchBox-form"),i('<i class="fa fa-search"></i>').prependTo(this.uiContainer),this.clearButton=i('<a class="red-ui-searchBox-clear" href="#"><i class="fa fa-times"></i></a>').appendTo(this.uiContainer),this.clearButton.on("click",function(e){e.preventDefault(),n.element.val(""),n._change("",!0),n.element.trigger("focus")}),this.options.options&&(this.uiContainer.addClass("red-ui-searchBox-has-options"),this.optsButton=i('<a class="red-ui-searchBox-opts" href="#"><i class="fa fa-caret-down"></i></a>').appendTo(this.uiContainer),t=!1,this.optsMenu=RED.popover.menu({style:this.options.style,options:this.options.options.map(function(e){return{label:e.label,onselect:function(){n.element.val(e.value+" "),n._change(e.value,!0)}}}),onclose:function(e){t=!1,n.element.trigger("focus")},disposeOnClose:!1}),o=function(){t=!0,n.optsMenu.show({target:n.optsButton,align:"left",offset:[n.optsButton.width()-2,-1],dispose:!1})},this.optsButton.on("click",function(e){e.preventDefault(),t?n.optsMenu.hide(!0):o()}),this.optsButton.on("keydown",function(e){t||40!==e.keyCode||o()}),this.element.on("keydown",function(e){t||40!==e.keyCode||""!==i(this).val()||o()})),this.resultCount=i("<span>",{class:"red-ui-searchBox-resultCount hide"}).appendTo(this.uiContainer),this.element.val(""),this.element.on("keydown",function(e){27===e.keyCode&&n.element.val(""),13===e.keyCode&&e.preventDefault()}),this.element.on("keyup",function(e){n._change(i(this).val())}),this.element.on("focus",function(){i(document).one("mousedown",function(){n.element.blur()})})},_change:function(e,t){var o,n=!1,n=""===e?(this.clearButton.hide(),!0):(this.clearButton.show(),e.length>=(this.options.minimumLength||0)),e=this.element.val();(n=n&&e!==this.lastSent)&&(!t&&0<this.options.delay?(clearTimeout(this.currentTimeout),(o=this).currentTimeout=setTimeout(function(){o.lastSent=o.element.val(),o._trigger("change")},this.options.delay)):(this.lastSent=this.element.val(),this._trigger("change")))},value:function(e){if(void 0===e)return this.element.val();this.element.val(e),this._change(e)},count:function(e){null==e||""===e?this.resultCount.text("").hide():this.resultCount.text(e).show()},change:function(){this._trigger("change")}})}(jQuery),RED.tabs=function(){var O,I="fa fa-lemon-o",N=!1,P=!1;return{create:function(f){var d,h,g,e,t,o,n,i,a,s,m,r,v={},b=0,l=0,y=f.order,w=f.element||$("#"+f.id),c=w.wrap("<div>").parent(),E=w.wrap("<div>").parent();function u(e,t){var o,n;e.preventDefault(),$(this).hasClass("disabled")||(o=E.scrollLeft(),E.animate({scrollLeft:t},100),n=setInterval(function(){var e=E.scrollLeft();e===o?clearInterval(n):(o=e,E.animate({scrollLeft:t},100))},100),$(this).one("mouseup",function(){clearInterval(n)}))}function p(){var e=w.find("li.red-ui-tab.selected"),t=[];return e.each(function(){t.push(v[$(this).find("a").attr("href").slice(1)])}),t}function D(){f.onselect(p())}function R(e){if(!N)if(e.currentTarget!==g)g=null;else{if(g=null,O&&Date.now()-O<400)return P=!(O=0),function(e){if(e.preventDefault(),!e.metaKey&&!e.shiftKey)return f.ondblclick&&f.ondblclick(v[$(this).attr("href").slice(1)]),!1}.call(this,e);O=Date.now();var t,o,n=w.find("li.red-ui-tab.active"),i=$(this).parent(),a=!1;if(f.onselect)if(e.metaKey||e.ctrlKey){if(i.hasClass("selected")){if(i.removeClass("selected"),i[0]!==n[0])return void D();if(0===(o=w.find("li.red-ui-tab.selected")).length)return void D();i=o.first()}else n.hasClass("selected")||(v[n.find("a").attr("href").slice(1)],n.addClass("selected")),i.addClass("selected");a=!0}else e.shiftKey?(n[0]!==i[0]&&(e=n.index()<i.index()?(t=n,i):(t=i,n),w.find("li.red-ui-tab").removeClass("selected"),t.addClass("selected"),e.addClass("selected"),t.nextUntil(e).addClass("selected")),a=!0):0<(o=w.find("li.red-ui-tab.selected")).length&&(o.removeClass("selected"),a=!0);n=i.find("a");f.onclick&&f.onclick(v[n.attr("href").slice(1)]),_(n),a&&D()}}function x(){var e,t,o;0!==w.children().length&&(e=E.scrollLeft(),t=E.width(),o=w.width(),0===e?a.hide():a.show(),e===o-t?s.hide():s.show())}function _(e){var t;0!==(e="string"==typeof e?w.find("a[href='#"+e+"']"):e).length&&(e.parent().hasClass("hide-tab")&&(e.parent().removeClass("hide-tab").removeClass("hide"),f.onshow&&f.onshow(v[e.attr("href").slice(1)])),e.parent().hasClass("active")||(w.children().removeClass("active"),w.children().css({transition:"width 100ms"}),e.parent().addClass("active"),t=e.parent().attr("id"),c.find(".red-ui-tab-link-button").removeClass("active selected"),$("#"+t+"-link-button").addClass("active selected"),f.scrollable&&((t=e.parent().position().left)-21<0?E.animate({scrollLeft:"+="+(t-50)},300):t+120>E.width()&&E.animate({scrollLeft:"+="+(t+140-E.width())},300)),f.onchange&&f.onchange(v[e.attr("href").slice(1)]),k(),setTimeout(function(){w.children().css({transition:""})},100)))}function k(){if(!f.vertical){var e,t=w.find("li.red-ui-tab"),o=t.filter(":not(.hide-tab)"),t=t.filter(".hide-tab"),n=c.width(),i=o.length;if(f.collapsible){var a=m.children().length,s=m.children(":visible").length;if((e=n-m.width()-10)<=120||e<198&&5<s){var r=m.find("a:last").prev();for(m.children().length;r.is(":not(:visible)");)r=r.prev(),0;(e<=120||6<s)&&r.hide(),e=Math.max(120,n-m.width()-10)}else 40<n-(e=s!==a?s<6?120:198:e)-m.width()&&m.find("a:not(:visible):first").show(),e=n-m.width()-10;o.css({width:e})}else l=(d=100*(e=(n-12-6*i)/i)/n+"%")+"%",f.scrollable?(e=Math.max(e,140),d=e+"px",l=0,a=Math.max(c.width(),12+(e+6)*i),w.width(a),x()):f.hasOwnProperty("minimumActiveTabWidth")&&(l=e<f.minimumActiveTabWidth?(e=(n-12-f.minimumActiveTabWidth-6*--i)/i,d=100*e/n+"%",f.minimumActiveTabWidth+"px"):0),o.css({width:d}),t.css({width:"0px"}),e<50?(w.find(".red-ui-tab-icon").hide(),w.find(".red-ui-tab-label").css({paddingLeft:Math.min(12,Math.max(0,e-38))+"px"})):(w.find(".red-ui-tab-icon").show(),w.find(".red-ui-tab-label").css({paddingLeft:""})),0!==l&&(w.find("li.red-ui-tab.active").css({width:f.minimumActiveTabWidth}),w.find("li.red-ui-tab.active .red-ui-tab-icon").show(),w.find("li.red-ui-tab.active .red-ui-tab-label").css({paddingLeft:""}))}}function T(e){f.onselect&&0<(o=w.find("li.red-ui-tab.selected")).length&&(o.removeClass("selected"),D());var t,o=w.find("a[href='#"+e+"']").parent();o.hasClass("active")&&(0<(t=0===(t=C(o)).length?j(o):t).length?_(t.find("a")):f.onchange&&f.onchange(null)),o.remove(),v[e].pinned&&b--,f.onremove&&f.onremove(v[e]),delete v[e],k(),h&&(h.remove(),h=null)}function C(e){for(var t=(e=e||w.find("li.active")).prev();0<t.length&&t.hasClass("hide-tab");)t=t.prev();return t}function j(e){for(var t=(e=e||w.find("li.active")).next();0<t.length&&t.hasClass("hide-tab");)t=t.next();return t}function L(t){var o,e;v[t]&&!(o=w.find("a[href='#"+t+"']").parent()).hasClass("hide-tab")&&(o.hasClass("active")&&(0<(e=0===(e=C(o)).length?j(o):e).length?_(e.find("a")):f.onchange&&f.onchange(null)),o.removeClass("active"),o.one("transitionend",function(e){o.addClass("hide"),k(),f.onhide&&f.onhide(v[t]),setTimeout(function(){x()},200)}),o.addClass("hide-tab"),o.css({width:0}))}c.addClass("red-ui-tabs"),f.vertical&&c.addClass("red-ui-tabs-vertical"),f.addButton&&(c.addClass("red-ui-tabs-add"),(o=$('<div class="red-ui-tab-button red-ui-tabs-add"><a href="#"><i class="fa fa-plus"></i></a></div>').appendTo(c)).find("a").on("click",function(e){e.preventDefault(),"function"==typeof f.addButton?f.addButton():"string"==typeof f.addButton&&RED.actions.invoke(f.addButton)}),"string"==typeof f.addButton&&(e=f.addButton,f.addButtonCaption&&(e=f.addButtonCaption),RED.popover.tooltip(o,e,f.addButton)),w.on("dblclick",function(e){var t=w.children(),o=e.clientX,n=0;t.each(function(e){if($(this).offset().left>o)return!1;n=e+1}),"function"==typeof f.addButton?f.addButton({index:n}):"string"==typeof f.addButton&&RED.actions.invoke(f.addButton,{index:n})})),f.searchButton&&(c.addClass("red-ui-tabs-search"),(o=$('<div class="red-ui-tab-button red-ui-tabs-search"><a href="#"><i class="fa fa-list-ul"></i></a></div>').appendTo(c)).find("a").on("click",function(e){e.preventDefault(),"function"==typeof f.searchButton?f.searchButton():"string"==typeof f.searchButton&&RED.actions.invoke(f.searchButton)}),"string"==typeof f.searchButton&&(e=f.searchButton,f.searchButtonCaption&&(e=f.searchButtonCaption),RED.popover.tooltip(o,e,f.searchButton))),f.menu&&(c.addClass("red-ui-tabs-menu"),o=(t=$('<div class="red-ui-tab-button red-ui-tabs-menu"><a href="#"><i class="fa fa-caret-down"></i></a></div>').appendTo(c)).find("a"),n=!1,o.on("click",function(e){e.stopPropagation(),e.preventDefault(),n?(i.remove(),n=!1):(n=!0,e=[],"function"==typeof f.searchButton?e=f.menu():Array.isArray(f.menu)?e=f.menu:"function"==typeof f.menu&&(e=f.menu()),(i=RED.menu.init({options:e})).attr("id",f.id+"-menu"),i.css({position:"absolute"}),i.appendTo("body"),e=t.offset(),i.css({top:e.top+t.height()-2+"px",left:e.left-i.width()+t.width()+"px"}),$(".red-ui-menu.red-ui-menu-dropdown").hide(),$(document).on("click.red-ui-tabmenu",function(e){$(document).off("click.red-ui-tabmenu"),n=!1,i.remove()}),i.show())})),f.scrollable&&(c.addClass("red-ui-tabs-scrollable"),E.addClass("red-ui-tabs-scroll-container"),E.on("scroll",function(e){x()}),E.on("wheel",function(e){var t;0===e.originalEvent.deltaX&&(e.preventDefault(),t=E.scrollLeft(),t-=e.originalEvent.deltaY,E.scrollLeft(t))}),(a=$('<div class="red-ui-tab-button red-ui-tab-scroll red-ui-tab-scroll-left"><a href="#" style="display:none;"><i class="fa fa-caret-left"></i></a></div>').appendTo(c).find("a")).on("mousedown",function(e){u(e,e.shiftKey?"-="+E.scrollLeft():"-=150")}).on("click",function(e){e.preventDefault()}),(s=$('<div class="red-ui-tab-button red-ui-tab-scroll red-ui-tab-scroll-right"><a href="#" style="display:none;"><i class="fa fa-caret-right"></i></a></div>').appendTo(c).find("a")).on("mousedown",function(e){u(e,e.shiftKey?"+="+(E[0].scrollWidth-E.width()-E.scrollLeft()):"+=150")}).on("click",function(e){e.preventDefault()})),f.collapsible&&(c.addClass("red-ui-tabs-collapsible"),m=$('<div class="red-ui-tab-link-buttons"></div>').appendTo(c),!1!==f.menu&&((r=$('<a href="#"><i class="fa fa-caret-down"></i></a>').appendTo(m)).addClass("red-ui-tab-link-button-menu"),r.on("click",function(e){e.stopPropagation(),e.preventDefault(),h||(n=[],w.children().each(function(e,t){var o=$(t).data("tabId"),t={id:"red-ui-tabs-menu-option-"+o,icon:v[o].iconClass||I,label:v[o].name,onselect:function(){_(o)}};n.push(t)}),n=[].concat(n),(h=RED.menu.init({options:n})).css({position:"absolute"}),h.appendTo("body"));var n,e=r.offset();h.css({top:e.top+r.height()-2+"px",left:e.left-h.width()+r.width()+"px"}),h.is(":visible")?$(document).off("click.red-ui-tabmenu"):($(".red-ui-menu.red-ui-menu-dropdown").hide(),$(document).on("click.red-ui-tabmenu",function(e){$(document).off("click.red-ui-tabmenu"),h.hide()})),h.toggle()}))),w.children().first().addClass("active"),w.children().addClass("red-ui-tab"),w.find("li.red-ui-tab a").on("mousedown",function(e){g=e.currentTarget}).on("mouseup",R).on("click",function(e){e.preventDefault()}).on("dblclick",function(e){e.stopPropagation(),e.preventDefault()}),setTimeout(function(){k()},0);var S={addTab:function(t,e){f.onselect&&0<(n=w.find("li.red-ui-tab.selected")).length&&(n.removeClass("selected"),D()),v[t.id]=t;var o=$("<li/>",{class:"red-ui-tab"}),n=(0===(e=0===w.children().length?void 0:e)?o.prependTo(w):0<e?o.insertAfter(w.find("li:nth-child("+e+")")):o.appendTo(w),o.attr("id","red-ui-tab-"+t.id.replace(".","-")),o.data("tabId",t.id),(f.maximumTabWidth||t.maximumTabWidth)&&o.css("maxWidth",(f.maximumTabWidth||t.maximumTabWidth)+"px"),$("<a/>",{href:"#"+t.id,class:"red-ui-tab-label"}).appendTo(o));t.icon?$("<i>",{class:"red-ui-tab-icon",style:"mask-image: url("+t.icon+"); -webkit-mask-image: url("+t.icon+");"}).appendTo(n):t.iconClass&&$("<i>",{class:"red-ui-tab-icon "+t.iconClass}).appendTo(n);$("<span/>",{class:"red-ui-text-bidi-aware"}).text(t.label).appendTo(n).attr("dir",RED.text.bidi.resolveBaseTextDir(t.label)),f.collapsible&&(o.addClass("red-ui-tab-pinned"),i=$('<a href="#'+t.id+'" class="red-ui-tab-link-button"></a>'),t.pinned?0===b?i.prependTo(m):i.insertAfter(m.find("a.red-ui-tab-link-button-pinned:last")):!1!==f.menu?i.insertBefore(m.find("a:last")):i.appendTo(m),i.attr("id",o.attr("id")+"-link-button"),(t.iconClass?$("<i>",{class:t.iconClass}):$("<i>",{class:I})).appendTo(i),i.on("click",function(e){e.preventDefault(),_(t.id)}),i.data("tabId",t.id),t.pinned&&(i.addClass("red-ui-tab-link-button-pinned"),b++),RED.popover.tooltip($(i),t.name,t.action),f.onreorder&&(s=[],i.draggable({distance:10,axis:"x",containment:".red-ui-tab-link-buttons",start:function(e,t){if(N=!0,$(".red-ui-tab-link-buttons").width($(".red-ui-tab-link-buttons").width()),P)return P=!1;m.children().each(function(e){s[e]={el:$(this),text:$(this).text(),left:$(this).position().left,width:$(this).width(),menu:$(this).hasClass("red-ui-tab-link-button-menu")},$(this).is(i)&&(r=a=e)}),m.children().each(function(e){e!==a&&$(this).css({position:"absolute",left:s[e].left+"px",width:s[e].width+2,transition:"left 0.3s"})}),i.hasClass("active")||i.css({zIndex:1})},drag:function(e,t){t.position.left+=s[a].left;for(var o=t.position.left+s[a].width/2,n=0;n<s.length;n++)if(n!==a&&!s[n].menu&&!s[n].el.is(":not(:visible)")&&o>s[n].left&&o<s[n].left+s[n].width){n<a?(s[n].left+=s[a].width+8,s[a].el.detach().insertBefore(s[n].el)):(s[n].left-=s[a].width+8,s[a].el.detach().insertAfter(s[n].el)),s[n].el.css({left:s[n].left+"px"}),s.splice(n,0,s.splice(a,1)[0]),a=n;break}},stop:function(e,t){var o;N=!1,m.children().css({position:"relative",left:"",transition:""}),$(".red-ui-tab-link-buttons").width("auto"),i.css({zIndex:""}),k(),r!==a&&(h&&(h.remove(),h=null),o=$.makeArray(m.children().map(function(){return $(this).data("tabId")})),S.order(o),f.onreorder(o))}}))),n.on("mousedown",function(e){g=e.currentTarget}),n.on("mouseup",R),n.on("click",function(e){e.preventDefault()}),n.on("dblclick",function(e){e.stopPropagation(),e.preventDefault()}),$('<span class="red-ui-tabs-fade"></span>').appendTo(o),t.closeable&&(o.addClass("red-ui-tabs-closeable"),(d=$("<a/>",{href:"#",class:"red-ui-tab-close"}).appendTo(o)).append('<i class="fa fa-times" />'),d.on("click",function(e){e.preventDefault(),T(t.id)}),RED.popover.tooltip(d,RED._("workspace.hideFlow"))),t.hideable&&(o.addClass("red-ui-tabs-closeable"),(d=$("<a/>",{href:"#",class:"red-ui-tab-close red-ui-tab-hide"}).appendTo(o)).append('<i class="fa fa-eye" />'),d.append('<i class="fa fa-eye-slash" />'),d.on("click",function(e){e.preventDefault(),L(t.id)}),RED.popover.tooltip(d,RED._("workspace.hideFlow")));var i,a,s,r,d,l,c,u,p,e=$('<span class="red-ui-tabs-badges"></span>').appendTo(o);f.onselect&&($('<i class="red-ui-tabs-badge-changed fa fa-circle"></i>').appendTo(e),$('<i class="red-ui-tabs-badge-selected fa fa-check-circle"></i>').appendTo(e)),RED.popover.tooltip(n,function(){return RED.utils.sanitize(t.label)}),f.onadd&&f.onadd(t),1==w.find("li.red-ui-tab").length&&_(n),f.onreorder&&!f.collapsible&&(u=[],o.draggable({axis:"x",distance:20,start:function(e,t){if(P)return P=!1;N=!0,l=[],u=[],w.children().each(function(e){u[e]={el:$(this),text:$(this).text(),left:$(this).position().left,width:$(this).width()},$(this).is(o)&&(p=c=e),l.push($(this).data("tabId"))}),w.children().each(function(e){e!==c&&$(this).css({position:"absolute",left:u[e].left+"px",width:u[e].width+2,transition:"left 0.3s"})}),o.hasClass("active")||o.css({zIndex:1})},drag:function(e,t){t.position.left+=u[c].left+E.scrollLeft();for(var o=t.position.left+u[c].width/2-E.scrollLeft(),n=0;n<u.length;n++)if(n!==c&&o>u[n].left&&o<u[n].left+u[n].width){n<c?(u[n].left+=u[c].width+8,u[c].el.detach().insertBefore(u[n].el)):(u[n].left-=u[c].width+8,u[c].el.detach().insertAfter(u[n].el)),u[n].el.css({left:u[n].left+"px"}),u.splice(n,0,u.splice(c,1)[0]),c=n;break}},stop:function(e,t){N=!1,w.children().css({position:"relative",left:"",transition:""}),o.hasClass("active")||o.css({zIndex:""}),k(),p!==c&&f.onreorder(l,$.makeArray(w.children().map(function(){return $(this).data("tabId")}))),_(u[c].el.data("tabId"))}})),setTimeout(function(){k()},10),h&&(h.remove(),h=null),y&&S.order(y)},removeTab:T,activateTab:_,nextTab:function(){var e=j();0<e.length&&_(e.find("a"))},previousTab:function(){var e=C();0<e.length&&_(e.find("a"))},resize:k,count:function(){return w.find("li.red-ui-tab:not(.hide)").length},activeIndex:function(){return w.find("li.active").index()},contains:function(e){return 0<w.find("a[href='#"+e+"']").length},showTab:function(e){var t;v[e]&&(t=w.find("a[href='#"+e+"']").parent()).hasClass("hide-tab")&&(t.removeClass("hide-tab").removeClass("hide"),1===w.find("li.red-ui-tab:not(.hide-tab)").length&&_(t.find("a")),k(),f.onshow&&f.onshow(v[e]))},hideTab:L,renameTab:function(e,t){v[e].label=t,w.find("a[href='#"+e+"']").find("span.red-ui-text-bidi-aware").text(t).attr("dir",RED.text.bidi.resolveBaseTextDir(t)),k()},listTabs:function(){return $.makeArray(w.children().map(function(){return $(this).data("tabId")}))},selection:p,clearSelection:function(){var e;f.onselect&&0<(e=w.find("li.red-ui-tab.selected")).length&&(e.removeClass("selected"),D())},order:function(e){y=e;for(var t=$.makeArray(w.children().map(function(){return $(this).data("tabId")})),o=!0,n=0;n<e.length;n++)if(e[n]!==t[n]){o=!1;break}if(!o){var i={},a=(w.children().detach().each(function(){i[$(this).data("tabId")]=$(this)}),{});for(f.collapsible&&m.children().detach().each(function(){var e=$(this).data("tabId");a[e=e||"__menu__"]=$(this)}),n=0;n<e.length;n++)i[e[n]]&&(i[e[n]].appendTo(w),f.collapsible&&a[e[n]].appendTo(m),delete i[e[n]]);for(n in i)i.hasOwnProperty(n)&&(i[n].appendTo(w),f.collapsible&&a[n].appendTo(m));f.collapsible&&(a.__menu__.appendTo(m),k())}}};return S}}}(),RED.stack={create:function(n){function i(){var t,e;0<r.length&&(t=0,r.forEach(function(e){t+=e.header.outerHeight()}),e=a.innerHeight(),s=e-t-(r.length-1),r.forEach(function(e){e.contentWrap.height(s)}))}var a=n.container,s=(a.addClass("red-ui-stack"),0),r=[],d=!0;return n.fill&&n.singleExpanded&&($(window).on("resize",i),$(window).on("focus",i)),{add:function(t){r.push(t),t.container=$('<div class="red-ui-palette-category">').appendTo(a),d||t.container.hide();var e,o=$('<div class="red-ui-palette-header"></div>').appendTo(t.container);return t.header=o,t.contentWrap=$("<div></div>",{style:"position:relative"}).appendTo(t.container),n.fill&&t.contentWrap.css("height",s),t.content=$("<div></div>").appendTo(t.contentWrap),!1!==t.collapsible?(o.on("click",function(){if(n.singleExpanded)if(t.isExpanded())2===r.length&&(r[0]===t?(r[0].collapse(),r[1].expand()):(r[1].collapse(),r[0].expand()));else{for(var e=0;e<r.length;e++)r[e].isExpanded()&&r[e].collapse();t.expand()}else t.toggle()}),e=$('<i class="fa fa-angle-down"></i>').appendTo(o),t.expanded?(t.container.addClass("expanded"),e.addClass("expanded")):t.contentWrap.hide()):($('<i style="opacity: 0.5;" class="fa fa-angle-down expanded"></i>').appendTo(o),o.css("cursor","default")),t.title=$("<span></span>").html(t.title).appendTo(o),t.toggle=function(){return t.isExpanded()?(t.collapse(),!1):(t.expand(),!0)},t.expand=function(){if(!t.isExpanded())return t.onexpand&&t.onexpand.call(t),n.singleExpanded&&r.forEach(function(e){e!==t&&e.collapse()}),e.addClass("expanded"),t.container.addClass("expanded"),t.contentWrap.slideDown(200),!0},t.collapse=function(){if(t.isExpanded())return e.removeClass("expanded"),t.container.removeClass("expanded"),t.contentWrap.slideUp(200),!0},t.isExpanded=function(){return t.container.hasClass("expanded")},n.fill&&n.singleExpanded&&i(),t},hide:function(){return d=!1,r.forEach(function(e){e.container.hide()}),this},show:function(){return d=!0,r.forEach(function(e){e.container.show()}),this},resize:function(){i()}}}},function(l){function e(e,t){return{option:(e=RED.utils.parseContextKey(e,t&&t.value)).store,value:e.key}}function t(e,t){return t&&(t="string"==typeof t?t:t.value)!==RED.settings.context.default?"#:("+t+")::"+e:e}function o(e,t){e.css("pointer-events","none"),e.css("flex-grow",0),e.css("position","relative"),e.css("overflow","visible"),l("<div></div>").text(t).css({position:"absolute",bottom:"-2px",right:"5px","font-size":"0.7em",opacity:.3}).appendTo(e),this.elementDiv.show()}var n,s={msg:{value:"msg",label:"msg.",validate:RED.utils.validatePropertyExpression,autoComplete:(n=[{value:"payload"},{value:"topic",source:["mqtt","inject","rbe"]},{value:"action",source:["mqtt"]},{value:"complete",source:["join"]},{value:"contentType",source:["mqtt"]},{value:"cookies",source:["http request","http response"]},{value:"correlationData",source:["mqtt"]},{value:"delay",source:["delay","trigger"]},{value:"encoding",source:["file"]},{value:"error",source:["catch"]},{value:"error.message",source:["catch"]},{value:"error.source",source:["catch"]},{value:"error.source.id",source:["catch"]},{value:"error.source.type",source:["catch"]},{value:"error.source.name",source:["catch"]},{value:"filename",source:["file","file in"]},{value:"flush",source:["delay"]},{value:"followRedirects",source:["http request"]},{value:"headers",source:["http response","http request"]},{value:"host",source:["tcp request","http request"]},{value:"ip",source:["udp out"]},{value:"kill",source:["exec"]},{value:"messageExpiryInterval",source:["mqtt"]},{value:"method",source:["http request"]},{value:"options",source:["xml"]},{value:"parts",source:["split","join","batch","sort"]},{value:"pid",source:["exec"]},{value:"port",source:["tcp request"," udp out"]},{value:"qos",source:["mqtt"]},{value:"rate",source:["delay"]},{value:"rejectUnauthorized",source:["http request"]},{value:"req",source:["http in"]},{value:"req.body",source:["http in"]},{value:"req.headers",source:["http in"]},{value:"req.query",source:["http in"]},{value:"req.params",source:["http in"]},{value:"req.cookies",source:["http in"]},{value:"req.files",source:["http in"]},{value:"requestTimeout",source:["http request"]},{value:"reset",source:["delay","trigger","join","rbe"]},{value:"responseCookies",source:["http request"]},{value:"responseTopic",source:["mqtt"]},{value:"responseURL",source:["http request"]},{value:"restartTimeout",source:["join"]},{value:"retain",source:["mqtt"]},{value:"schema",source:["json"]},{value:"select",source:["html"]},{value:"statusCode",source:["http response","http request"]},{value:"status",source:["status"]},{value:"status.text",source:["status"]},{value:"status.source",source:["status"]},{value:"status.source.type",source:["status"]},{value:"status.source.id",source:["status"]},{value:"status.source.name",source:["status"]},{value:"target",source:["link call"]},{value:"template",source:["template"]},{value:"toFront",source:["delay"]},{value:"url",source:["http request"]},{value:"userProperties",source:["mqtt"]},{value:"_session",source:["websocket out","tcp out"]}],function(r){var d=[];return n.forEach(e=>{var t=e.value,e=(e.source||[]).join(","),o=c(t,r),n=c(e,r);if(o.found||n.found){var i=l("<div>",{style:"display: flex"});const a=l("<div/>",{style:"font-family: var(--red-ui-monospace-font); white-space:nowrap; overflow: hidden; flex-grow:1"});if(a.append(u(o)),a.appendTo(i),e){const s=l("<div>").css({"font-size":"0.8em"});s.append(u(n)),s.appendTo(i)}d.push({value:t,label:i,i:(o.found?o:n).index})}}),d.sort(function(e,t){return e.i-t.i}),d})},flow:{value:"flow",label:"flow.",hasValue:!0,options:[],validate:RED.utils.validatePropertyExpression,parse:e,export:t,valueLabel:o},global:{value:"global",label:"global.",hasValue:!0,options:[],validate:RED.utils.validatePropertyExpression,parse:e,export:t,valueLabel:o},str:{value:"str",label:"string",icon:"red/images/typedInput/az.svg"},num:{value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/},bool:{value:"bool",label:"boolean",icon:"red/images/typedInput/bool.svg",options:["true","false"]},json:{value:"json",label:"JSON",icon:"red/images/typedInput/json.svg",validate:function(e){try{return JSON.parse(e),!0}catch(e){return!1}},expand:function(){var o=this,e=this.value();try{e=JSON.stringify(JSON.parse(e),null,4)}catch(e){}RED.editor.editJSON({value:e,stateId:RED.editor.generateViewStateId("typedInput",o,"json"),focus:!0,complete:function(e){var t=e;try{t=JSON.stringify(JSON.parse(e))}catch(e){}o.value(t)}})}},re:{value:"re",label:"regular expression",icon:"red/images/typedInput/re.svg"},date:{value:"date",label:"timestamp",icon:"fa fa-clock-o",hasValue:!1},jsonata:{value:"jsonata",label:"expression",icon:"red/images/typedInput/expr.svg",validate:function(e){try{return jsonata(e),!0}catch(e){return!1}},expand:function(){var t=this;RED.editor.editExpression({value:this.value().replace(/\t/g,"\n"),stateId:RED.editor.generateViewStateId("typedInput",t,"jsonata"),focus:!0,complete:function(e){t.value(e.replace(/\n/g,"\t"))}})}},bin:{value:"bin",label:"buffer",icon:"red/images/typedInput/bin.svg",expand:function(){var t=this;RED.editor.editBuffer({value:this.value(),stateId:RED.editor.generateViewStateId("typedInput",t,"bin"),focus:!0,complete:function(e){t.value(e)}})}},env:{value:"env",label:"env variable",icon:"red/images/typedInput/env.svg"},node:{value:"node",label:"node",icon:"red/images/typedInput/target.svg",valueLabel:function(e,t){var o,n,t=RED.nodes.node(t),i=l("<div>",{class:"red-ui-search-result-node"}).css({"margin-top":"2px","margin-left":"3px"}).appendTo(e),e=l("<span>").css({"line-height":"32px","margin-left":"6px"}).appendTo(e);t?(o=RED.utils.getNodeColor(t.type,t._def),n=RED.utils.getNodeIcon(t._def,t),"tab"===t.type&&(o="#C0DEED"),i.css("backgroundColor",o),o=l("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(i),RED.utils.createIconElement(n,o,!0),n=RED.utils.getNodeLabel(t,t.id),e.text(n)):i.css({backgroundColor:"#eee","border-style":"dashed"})},expand:function(){var t=this;RED.tray.hide(),RED.view.selectNodes({single:!0,selected:[t.value()],onselect:function(e){t.value(e.id),RED.tray.show()},oncancel:function(){RED.tray.show()}})}},cred:{value:"cred",label:"credential",icon:"fa fa-lock",inputType:"password",valueLabel:function(t,e){var o,n,i,a=this,s=(t.css("pointer-events","none"),t.css("flex-grow",0),this.elementDiv.hide(),l("<div>").css({position:"absolute",right:"6px",top:"6px","pointer-events":"all"}).appendTo(t)),r=l('<button type="button" class="red-ui-button red-ui-button-small"></button>').css({width:"20px"}).appendTo(s).on("click",function(e){e.preventDefault();var t=a.input[0].selectionStart;"text"===a.input.attr("type")?(a.input.attr("type","password"),d.removeClass("fa-eye-slash").addClass("fa-eye")):(a.input.attr("type","text"),d.removeClass("fa-eye").addClass("fa-eye-slash")),setTimeout(function(){a.input.focus(),a.input[0].setSelectionRange(t,t)},50)}).hide(),d=l('<i class="fa fa-eye"></i>').css("margin-left","-2px").appendTo(r);"__PWRD__"===e?(o=l('<div><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i></div>').css({padding:"6px 6px",borderRadius:"4px"}).addClass("red-ui-typedInput-value-label-inactive").appendTo(t),n=l('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-pencil"></i></button>').appendTo(s).on("click",function(e){e.preventDefault(),o.hide(),t.css("background","none"),t.css("pointer-events","none"),a.input.val(""),a.element.val(""),a.elementDiv.show(),n.hide(),i.show(),r.show(),setTimeout(function(){a.input.focus()},50)}),i=l('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-times"></i></button>').css("margin-left","3px").appendTo(s).on("click",function(e){e.preventDefault(),o.show(),t.css("background",""),a.input.val("__PWRD__"),a.element.val("__PWRD__"),a.elementDiv.hide(),n.show(),i.hide(),r.hide(),a.input.attr("type","password"),d.removeClass("fa-eye-slash").addClass("fa-eye")}).hide()):(t.css("background","none"),t.css("pointer-events","none"),this.elementDiv.show(),r.show())}}};function c(e,t){var o=e.toLowerCase().indexOf(t.toLowerCase()),t=-1<o?t.length:0;return{index:o,found:-1<o,pre:e.substring(0,o),match:e.substring(o,o+t),post:e.substring(o+t)}}function u(e){const t=[];return e.pre&&t.push(l("<span/>").text(e.pre)),e.match&&t.push(l("<span/>",{style:"font-weight: bold; color: var(--red-ui-text-color-link);"}).text(e.match)),e.post&&t.push(l("<span/>").text(e.post)),t}function r(e,t){if(e.multiple){var o={},n=[];t.split(",").forEach(function(e){e&&(o[e]=!0)});for(a=0;a<e.options.length;a++){var i="string"==typeof(op=e.options[a])?op:op.value;o.hasOwnProperty(i)&&(delete o[i],n.push("string"==typeof op?{value:op}:op.value))}return l.isEmptyObject(o)?n:null}for(var a=0;a<e.options.length;a++){if("string"==typeof(op=e.options[a])&&op===t)return{value:t};if(op.value===t)return op}}var d=!1;l.widget("nodered.typedInput",{_create:function(){try{if(!d&&RED&&RED._){for(var e in s)s.hasOwnProperty(e)&&(s[e].label=RED._("typedInput.type."+e,{defaultValue:s[e].label}));var t=RED.settings.context.stores.map(function(e){return{value:e,label:e,icon:'<i class="red-ui-typedInput-icon fa fa-database"></i>'}}).sort(function(e,t){return e.value===RED.settings.context.default?-1:t.value===RED.settings.context.default?1:e.value.localeCompare(t.value)});t.length<2?(s.flow.options=[],s.global.options=[]):(s.flow.options=t,s.global.options=t)}d=!0;var o,n,i=this,a=(this.identifier=this.element.attr("id")||"TypedInput-"+Math.floor(100*Math.random()),this.options.debug&&console.log(this.identifier,"Create",{defaultType:this.options.default,value:this.element.val()}),this.disarmClick=!1,this.input=l('<input class="red-ui-typedInput-input" type="text"></input>'),this.input.insertAfter(this.element),this.input.val(this.element.val()),this.element.addClass("red-ui-typedInput"),this.uiWidth=this.element.outerWidth(),this.elementDiv=this.input.wrap("<div>").parent().addClass("red-ui-typedInput-input-wrap"),this.uiSelect=this.elementDiv.wrap("<div>").parent(),this.element.attr("style"));null!==(o=/width\s*:\s*(calc\s*\(.*\)|\d+(%|px))/i.exec(a))?(this.input.css("width","100%"),this.uiSelect.width(o[1]),this.uiWidth=null):0!==this.uiWidth&&this.uiSelect.width(this.uiWidth),["Right","Left"].forEach(function(e){var t=i.element.css("margin"+e);i.uiSelect.css("margin"+e,t),i.input.css("margin"+e,0)}),["type","placeholder","autocomplete","data-i18n"].forEach(function(e){var t=i.element.attr(e);i.input.attr(e,t)}),this.defaultInputType=this.input.attr("type"),this.oldValues={},this.uiSelect.addClass("red-ui-typedInput-container"),this.element.attr("type","hidden"),!this.options.types&&this.options.type?this.options.types=[this.options.type]:this.options.types=this.options.types||Object.keys(s),this.selectTrigger=l('<button type="button" class="red-ui-typedInput-type-select" tabindex="0"></button>').prependTo(this.uiSelect),l('<i class="red-ui-typedInput-icon fa fa-caret-down"></i>').toggle(1<this.options.types.length).appendTo(this.selectTrigger),this.selectLabel=l('<span class="red-ui-typedInput-type-label"></span>').appendTo(this.selectTrigger),this.valueLabelContainer=l('<div class="red-ui-typedInput-value-label">').appendTo(this.uiSelect),this.types(this.options.types),this.options.typeField?(this.typeField=l(this.options.typeField).hide(),(n=this.typeField.val())&&this.typeMap[n]&&(this.options.default=n)):this.typeField=l("<input>",{type:"hidden"}).appendTo(this.uiSelect),this.input.on("focus",function(){i.uiSelect.addClass("red-ui-typedInput-focus")}),this.input.on("blur",function(){i.uiSelect.removeClass("red-ui-typedInput-focus")}),this.input.on("change",function(){i.validate(),i.element.val(i.value()),i.element.trigger("change",[i.propertyType,i.value()])}),this.input.on("keyup",function(e){i.validate(),i.element.val(i.value()),i.element.trigger("keyup",e)}),this.input.on("paste",function(e){i.validate(),i.element.val(i.value()),i.element.trigger("paste",e)}),this.input.on("keydown",function(e){i.typeMap[i.propertyType].autoComplete||37<=e.keyCode&&e.keyCode<=40&&e.stopPropagation()}),this.selectTrigger.on("click",function(e){e.preventDefault(),e.stopPropagation(),i._showTypeMenu()}),this.selectTrigger.on("keydown",function(e){40===e.keyCode&&i._showTypeMenu(),e.stopPropagation()}).on("focus",function(){i.uiSelect.addClass("red-ui-typedInput-focus")}).on("blur",function(){!1===i.typeMap[i.propertyType].hasValue&&i.uiSelect.removeClass("red-ui-typedInput-focus")}),this.optionSelectTrigger=l('<button type="button" tabindex="0" class="red-ui-typedInput-option-trigger" style="display:inline-block"><span class="red-ui-typedInput-option-caret"><i class="red-ui-typedInput-icon fa fa-caret-down"></i></span></button>').appendTo(this.uiSelect),this.optionSelectLabel=l('<span class="red-ui-typedInput-option-label"></span>').prependTo(this.optionSelectTrigger),this.optionSelectTrigger.on("click",function(e){e.preventDefault(),e.stopPropagation(),i._showOptionSelectMenu()}).on("keydown",function(e){40===e.keyCode&&i._showOptionSelectMenu(),e.stopPropagation()}).on("blur",function(){i.uiSelect.removeClass("red-ui-typedInput-focus")}).on("focus",function(){i.uiSelect.addClass("red-ui-typedInput-focus")}),this.optionExpandButton=l('<button type="button" tabindex="0" class="red-ui-typedInput-option-expand" style="display:inline-block"></button>').appendTo(this.uiSelect),this.optionExpandButtonIcon=l('<i class="red-ui-typedInput-icon fa fa-ellipsis-h"></i>').appendTo(this.optionExpandButton),this.type(this.typeField.val()||this.options.default||this.typeList[0].value),this.typeChanged=!!this.options.default}catch(e){console.log(e.stack)}},_showTypeMenu:function(){var e;1<this.typeList.length?(this._showMenu(this.menu,this.selectTrigger),e=this.menu.find("[value='"+this.propertyType+"']"),setTimeout(function(){e.trigger("focus")},120)):this.input.trigger("focus")},_showOptionSelectMenu:function(){var e;this.optionMenu&&(this.optionMenu.css({minWidth:this.optionSelectLabel.width()}),this._showMenu(this.optionMenu,this.optionSelectTrigger),e=this.optionValue,null!==this.optionValue&&void 0!==this.optionValue||(e=this.value()),(e=0===(e=this.optionMenu.find("[value='"+e+"']")).length?this.optionMenu.children(":first"):e).trigger("focus"))},_hideMenu:function(e){var t;l(document).off("mousedown.red-ui-typedInput-close-property-select"),e.hide(),e.css({height:"auto"}),e.opts.multiple&&(t=[],e.find('input[type="checkbox"]').each(function(){l(this).prop("checked")&&t.push(l(this).data("value"))}),e.callback(t)),(this.elementDiv.is(":visible")?this.input:this.optionSelectTrigger.is(":visible")?this.optionSelectTrigger:this.selectTrigger).trigger("focus")},_createMenu:function(e,n,i){var a=this,s=l("<div>").addClass("red-ui-typedInput-options red-ui-editor-dialog");return s.opts=n,s.callback=i,e.forEach(function(t){"string"==typeof t&&(t={value:t,label:t});var o,e=l('<a href="#"></a>').attr("value",t.value).appendTo(s);t.label&&e.text(t.label),t.title&&e.prop("title",t.title),t.icon?(0===t.icon.indexOf("<")?l(t.icon):-1!==t.icon.indexOf("/")?l("<i>",{class:"red-ui-typedInput-icon",style:"mask-image: url("+t.icon+"); -webkit-mask-image: url("+t.icon+");"}):l("<i>",{class:"red-ui-typedInput-icon "+t.icon})).prependTo(e):e.css({paddingLeft:"18px"}),t.icon||t.label||e.text(t.value),n.multiple&&(o=l('<input type="checkbox">').css("pointer-events","none").data("value",t.value).prependTo(e).on("mousedown",function(e){e.preventDefault()})),e.on("click",function(e){e.preventDefault(),e.stopPropagation(),n.multiple?o.prop("checked",!o.prop("checked")):(i(t.value),a._hideMenu(s))})}),s.css({display:"none"}),s.appendTo(document.body),s.on("keydown",function(e){40===e.keyCode?(e.preventDefault(),l(this).children(":focus").next().trigger("focus")):38===e.keyCode?(e.preventDefault(),l(this).children(":focus").prev().trigger("focus")):27===e.keyCode&&(e.preventDefault(),a._hideMenu(s)),e.stopPropagation()}),s},_showMenu:function(t,o){var n,i,e,a,s;this.disarmClick?this.disarmClick=!1:(t.opts.multiple&&(n={},this.value().split(",").forEach(function(e){n[e]=!0}),t.find('input[type="checkbox"]').each(function(){l(this).prop("checked",n[l(this).data("value")])})),i=this,e=o.offset(),s=o.height(),a=t.height(),(s=s+e.top)+a-l(document).scrollTop()>l(window).height()&&(s-=s+a-l(window).height()+5),s<0&&(t.height(a+s),s=0),t.css({top:s+"px",left:e.left+"px"}),t.slideDown(100),this._delay(function(){i.uiSelect.addClass("red-ui-typedInput-focus"),l(document).on("mousedown.red-ui-typedInput-close-property-select",function(e){l(e.target).closest(t).length||i._hideMenu(t),l(e.target).closest(o).length&&(i.disarmClick=!0,e.preventDefault())})}))},_getLabelWidth:function(e,t){var o,n,i,a=e.outerWidth();0===a?(o=l('<div class="red-ui-editor"></div>').css({position:"absolute","white-space":"nowrap",top:-2e3}).appendTo(document.body),n=l('<div class="red-ui-typedInput-container"></div>').appendTo(o),i=e.clone().appendTo(n),setTimeout(function(){a=i.outerWidth(),o.remove(),t(a)},50)):t(a)},_updateOptionSelectLabel:function(e){var t,o=this.typeMap[this.propertyType];this.optionSelectLabel.empty(),o.hasValue?(this.valueLabelContainer.empty(),this.valueLabelContainer.show()):this.valueLabelContainer.hide(),this.typeMap[this.propertyType].valueLabel&&(o.multiple?this.typeMap[this.propertyType].valueLabel.call(this,o.hasValue?this.valueLabelContainer:this.optionSelectLabel,e):this.typeMap[this.propertyType].valueLabel.call(this,o.hasValue?this.valueLabelContainer:this.optionSelectLabel,e.value)),this.typeMap[this.propertyType].valueLabel&&!o.hasValue||(o.multiple?this.optionSelectLabel.text(e.length+" selected"):(e.icon?(0===e.icon.indexOf("<")?l(e.icon):-1!==e.icon.indexOf("/")?l("<img>",{src:(t=e.icon,t=/^red\/images\/typedInput\/.+\.png$/.test(t)?t.replace(/.png$/,".svg"):t),style:"height: 18px;"}):l("<i>",{class:"red-ui-typedInput-icon "+e.icon})).prependTo(this.optionSelectLabel):e.label?this.optionSelectLabel.text(e.label):this.optionSelectLabel.text(e.value),o.hasValue&&(this.optionValue=e.value,this.input.trigger("change",[this.propertyType,this.value()]))))},_destroy:function(){this.optionMenu&&this.optionMenu.remove(),this.menu.remove(),this.uiSelect.remove()},types:function(e){var t=this,o=this.type(),n=(this.typeMap={},void 0===this.typeList);this.typeList=e.map(function(e){e="string"==typeof e?s[e]:e;return t.typeMap[e.value]=e}),this.typeList.length<2?(this.selectTrigger.attr("tabindex",-1),this.selectTrigger.on("mousedown.red-ui-typedInput-focus-block",function(e){e.preventDefault()})):(this.selectTrigger.attr("tabindex",0),this.selectTrigger.off("mousedown.red-ui-typedInput-focus-block")),this.selectTrigger.toggleClass("disabled",1===this.typeList.length),this.selectTrigger.find(".fa-caret-down").toggle(1<this.typeList.length),this.menu&&this.menu.remove(),this.menu=this._createMenu(this.typeList,{},function(e){t.type(e)}),o&&!this.typeMap.hasOwnProperty(o)?n||this.type(this.typeList[0].value):(this.propertyType=null,n||this.type(o)),1!==this.typeList.length||this.typeList[0].icon||this.typeList[0].label&&!1!==this.typeList[0].showLabel?this.selectTrigger.show():this.selectTrigger.hide()},width:function(e){this.uiWidth=e,null!==this.uiWidth&&this.uiSelect.width(this.uiWidth)},value:function(e){var n,t,o,i=this,a=this.typeMap[this.propertyType]||{};if(!arguments.length)return o=this.input.val(),a.export?a.export(o,this.optionValue):o;this.options.debug&&console.log(this.identifier,"----- SET VALUE ------",e),n=[],o=e,a.options?(a.hasValue&&a.parse&&(t=a.parse(e),this.options.debug&&console.log(this.identifier,"new parse",t),e=t.value,o=t.option||t.value),t=[o],a.multiple&&(n=[],t=o.split(",")),t.forEach(function(e){for(var t=0;t<a.options.length;t++){var o=a.options[t];if("string"==typeof o){if(o===e||o===""+e){n.push(i.activeOptions[o]);break}}else if(o.value===e){n.push(o);break}}}),this.options.debug&&console.log(this.identifier,"set value to",e),this.input.val(e),a.multiple?this._updateOptionSelectLabel(n):(0===n.length&&(n=[{value:""}]),this._updateOptionSelectLabel(n[0]))):(this.input.val(e),a.valueLabel&&(this.valueLabelContainer.empty(),a.valueLabel.call(this,this.valueLabelContainer,e))),this.input.trigger("change",[this.type(),e])},type:function(e){if(!arguments.length)return this.propertyType;var t,o,n=this,i=(this.options.debug&&console.log(this.identifier,"----- SET TYPE -----",e),null),a=this.typeMap[e];a&&this.propertyType!==e&&(o=this.typeMap[this.propertyType],i=this.input.val(),o&&this.typeChanged&&(this.options.debug&&console.log(this.identifier,"typeChanged",{previousType:o,previousValue:i}),o.options&&!0!==a.hasValue||!1===o.hasValue?this.oldValues[o.value]=i:this.oldValues._=i,a.options&&!0!==a.hasValue||!1===a.hasValue?this.oldValues.hasOwnProperty(a.value)?(this.options.debug&&console.log(this.identifier,"restored previous (1)",this.oldValues[a.value]),this.input.val(this.oldValues[a.value])):a.options?(t=r(a,i),this.options.debug&&console.log(this.identifier,{previousValue:i,opt:a,validOptions:t}),(i||""===i)&&t?(this.options.debug&&console.log(this.identifier,"restored previous (2)"),this.input.val(i)):"string"==typeof a.default?(this.options.debug&&console.log(this.identifier,"restored previous (3)",a.default),this.input.val(a.default)):Array.isArray(a.default)?(this.options.debug&&console.log(this.identifier,"restored previous (4)",a.default.join(",")),this.input.val(a.default.join(","))):(this.options.debug&&console.log(this.identifier,"restored previous (5)"),this.input.val(""))):(this.options.debug&&console.log(this.identifier,"restored default/blank",a.default||""),this.input.val(a.default||"")):(this.options.debug&&console.log(this.identifier,"restored old/default/blank"),this.input.val(this.oldValues.hasOwnProperty("_")?this.oldValues._:a.default||"")),o.autoComplete&&this.input.autoComplete("destroy")),this.propertyType=e,this.typeChanged=!0,this.typeField&&this.typeField.val(e),this.selectLabel.empty(),a.icon&&!1!==a.showLabel&&(0===a.icon.indexOf("<")?l(a.icon):-1!==a.icon.indexOf("/")?l("<i>",{class:"red-ui-typedInput-icon",style:"mask-image: url("+a.icon+"); -webkit-mask-image: url("+a.icon+"); margin-right: 4px;height: 18px;width:13px"}):l("<i>",{class:"red-ui-typedInput-icon "+a.icon,style:"min-width: 13px; margin-right: 4px;"})).prependTo(this.selectLabel),!1!==a.hasValue&&(!1===a.showLabel||a.icon)||this.selectLabel.text(a.label),a.label?this.selectTrigger.attr("title",a.label):this.selectTrigger.attr("title",""),!1===a.hasValue?this.selectTrigger.addClass("red-ui-typedInput-full-width"):this.selectTrigger.removeClass("red-ui-typedInput-full-width"),this.optionMenu&&(this.optionMenu.remove(),this.optionMenu=null),a.options?(this.optionExpandButton&&(this.optionExpandButton.hide(),this.optionExpandButton.shown=!1),this.optionSelectTrigger&&(this.optionSelectTrigger.css({display:"inline-flex"}),a.hasValue?(this.optionSelectTrigger.css({"flex-grow":0}),this.elementDiv.show()):(this.optionSelectTrigger.css({"flex-grow":1}),this.elementDiv.hide()),this.valueLabelContainer.hide(),this.activeOptions={},a.options.forEach(function(e){"string"==typeof e?n.activeOptions[e]={label:e,value:e}:n.activeOptions[e.value]=e}),n.activeOptions.hasOwnProperty(n.optionValue)||(n.optionValue=null),a.hasValue?(t=this.optionValue||a.options[0],a.parse&&(i="string"==typeof t?{value:t}:t,(o=a.parse(this.input.val(),i)).option&&(t=o.option,this.activeOptions.hasOwnProperty(t)||(o.option=Object.keys(this.activeOptions)[0],t=o.option)),this.input.val(o.value),a.export&&this.element.val(a.export(o.value,o.option||t))),"string"==typeof t?(this.optionValue=t,(t=this.activeOptions.hasOwnProperty(t)?t:Object.keys(this.activeOptions)[0])?this._updateOptionSelectLabel(this.activeOptions[t]):this.optionSelectTrigger.hide()):t?(this.options.debug&&console.log(this.identifier,"HERE",{optionValue:t.value}),this.optionValue=t.value,this._updateOptionSelectLabel(t)):this.optionSelectTrigger.hide()):(i=r(a,this.input.val()),a.multiple?(i||(i=(a.default||[]).map(function(e){return"string"==typeof e?e:e.value}),this.value(i.join(","))),n._updateOptionSelectLabel(i)):i?n._updateOptionSelectLabel(i):"string"==typeof(o=a.options[0])?(this.value(o),n._updateOptionSelectLabel({value:o})):(this.value(o.value),n._updateOptionSelectLabel(o))),this.optionMenu=this._createMenu(a.options,a,function(e){a.multiple?(n._updateOptionSelectLabel(e),a.hasValue||n.value(e.join(","))):(n._updateOptionSelectLabel(n.activeOptions[e]),a.hasValue||n.value(n.activeOptions[e].value))}))):(this.optionSelectTrigger&&this.optionSelectTrigger.hide(),a.inputType?this.input.attr("type",a.inputType):this.input.attr("type",this.defaultInputType),!1===a.hasValue?(this.elementDiv.hide(),this.valueLabelContainer.hide()):a.valueLabel?(this.valueLabelContainer.css("pointer-events",""),this.valueLabelContainer.css("flex-grow",1),this.valueLabelContainer.css("overflow","hidden"),this.valueLabelContainer.show(),this.valueLabelContainer.empty(),this.elementDiv.hide(),a.valueLabel.call(this,this.valueLabelContainer,this.input.val())):(this.valueLabelContainer.hide(),this.elementDiv.show(),a.autoComplete&&this.input.autoComplete({search:a.autoComplete,minLength:0})),this.optionExpandButton&&(a.expand?(a.expand.icon?this.optionExpandButtonIcon.removeClass().addClass("red-ui-typedInput-icon fa "+a.expand.icon):this.optionExpandButtonIcon.removeClass().addClass("red-ui-typedInput-icon fa fa-ellipsis-h"),this.optionExpandButton.shown=!0,this.optionExpandButton.show(),this.optionExpandButton.off("click"),this.optionExpandButton.on("click",function(e){var t;e.preventDefault(),"function"==typeof a.expand?a.expand.call(n):(e=l("<div>"),t=a.expand.content.call(n,e),(e=RED.popover.panel(e)).container.css({width:n.valueLabelContainer.width()}),a.expand.minWidth&&e.container.css({minWidth:a.expand.minWidth+"px"}),e.show({target:n.optionExpandButton,onclose:t.onclose,align:"left"}))})):(this.optionExpandButton.shown=!1,this.optionExpandButton.hide()))),this._trigger("typechange",null,this.propertyType),this.input.trigger("change",[this.propertyType,this.value()]))},validate:function(){var e=this.value(),t=this.type();return(t=!this.typeMap[t]||!this.typeMap[t].validate||("function"==typeof(t=this.typeMap[t].validate)?t(e):t.test(e)))?this.uiSelect.removeClass("input-error"):this.uiSelect.addClass("input-error"),t},show:function(){this.uiSelect.show()},hide:function(){this.uiSelect.hide()},disable:function(e){void 0===e||e?this.uiSelect.attr("disabled","disabled"):this.uiSelect.attr("disabled",null)},enable:function(){this.uiSelect.attr("disabled",null)},disabled:function(){return"disabled"===this.uiSelect.attr("disabled")},focus:function(){this.input.focus()}})}(jQuery),function(r){r.widget("nodered.toggleButton",{_create:function(){var t=this,o=!1,e=(this.options.hasOwnProperty("invertState")&&(o=this.options.invertState),this.options.baseClass||"red-ui-button"),n=this.options.hasOwnProperty("enabledIcon")?this.options.enabledIcon:"fa-check-square-o",i=this.options.hasOwnProperty("disabledIcon")?this.options.disabledIcon:"fa-square-o",a=this.options.hasOwnProperty("enabledLabel")?this.options.enabledLabel:RED._("editor:workspace.enabled"),s=this.options.hasOwnProperty("disabledLabel")?this.options.disabledLabel:RED._("editor:workspace.disabled"),e=(this.element.css("display","none"),this.element.on("focus",function(){t.button.focus()}),this.button=r('<button type="button" class="red-ui-toggleButton '+e+' toggle single"></button>'),(a||s)&&(this.buttonLabel=r("<span>").appendTo(this.button).css("margin-left","5px")),this.options.class&&this.button.addClass(this.options.class),this.element.after(this.button),n&&i&&(this.buttonIcon=r('<i class="fa"></i>').prependTo(this.button)),this.button.addClass("selected"),this.buttonIcon&&this.buttonIcon.addClass(n),this.buttonLabel&&this.buttonLabel.text(a),this.button.width());this.button.removeClass("selected"),this.buttonIcon&&(this.buttonIcon.removeClass(n),t.buttonIcon.addClass(i)),this.buttonLabel&&t.buttonLabel.text(s),e=Math.max(e,this.button.width()),this.buttonIcon&&this.buttonIcon.removeClass(i),0<e&&this.button.width(Math.ceil(e)),this.button.on("click",function(e){e.stopPropagation(),t.state?t.element.prop("checked",o):t.element.prop("checked",!o),t.element.trigger("change")}),this.element.on("change",function(e){r(this).prop("checked")!==o?(t.button.addClass("selected"),t.state=!0,t.buttonIcon&&(t.buttonIcon.addClass(n),t.buttonIcon.removeClass(i)),t.buttonLabel&&t.buttonLabel.text(a)):(t.button.removeClass("selected"),t.state=!1,t.buttonIcon&&(t.buttonIcon.addClass(i),t.buttonIcon.removeClass(n)),t.buttonLabel&&t.buttonLabel.text(s))}),this.element.trigger("change")}})}(jQuery),jQuery.widget("nodered.autoComplete",{_create:function(){const o=this;this.completionMenuShown=!1,this.options.minLength=function(e,t,o,n){if(null==e)return t||0;o=null==o?Number.NEGATIVE_INFINITY:o,n=null==n?Number.POSITIVE_INFINITY:n;let i=parseInt(e);(isNaN(i)||i<o||i>n)&&(i=t||0);return i}(this.options.minLength,1,0),this.options.search=this.options.search||function(){return[]},this.element.addClass("red-ui-autoComplete"),this.element.on("keydown.red-ui-autoComplete",function(e){var t;13!==e.keyCode&&9!==e.keyCode||!o.completionMenuShown||(t=o.menu.options(),o.element.val(t[0].value),o.menu.hide(),e.preventDefault())}),this.element.on("keyup.red-ui-autoComplete",function(e){13!==e.keyCode&&9!==e.keyCode&&27!==e.keyCode&&(8!==e.keyCode&&46!==e.keyCode||o.completionMenuShown)&&o._updateCompletions(this.value)})},_showCompletionMenu:function(e){this.completionMenuShown||(this.menu=RED.popover.menu({tabSelect:!0,width:300,maxHeight:200,class:"red-ui-autoComplete-container",options:e,onselect:e=>{this.element.val(e.value),this.element.focus(),this.element.trigger("change")},onclose:()=>{this.completionMenuShown=!1,delete this.menu,this.element.focus()}}),this.menu.show({target:this.element}),this.completionMenuShown=!0)},_updateCompletions:function(e){const o=this;if(e.trim().length<this.options.minLength)this.completionMenuShown&&this.menu.hide();else if(2===this.options.search.length){const n=1+Math.floor(1e4*Math.random());this.pendingRequest=n,this.options.search(e,function(e){t(e,n)})}else t(this.options.search(e));function t(e,t){t&&t!==o.pendingRequest||(e&&0!==e.length?o.completionMenuShown?o.menu.options(e):o._showCompletionMenu(e):o.completionMenuShown&&o.menu.hide())}},_destroy:function(){this.element.removeClass("red-ui-autoComplete"),this.element.off("keydown.red-ui-autoComplete"),this.element.off("keyup.red-ui-autoComplete"),this.completionMenuShown&&this.menu.hide()}}),RED.actions=function(){var a={};function s(e){let t=a[e];return t?(t.label||(o=(o=(o=t.options)?o.label:void 0)||"action-list."+e.replace(/^.*:/,""),(n=RED._(o))===o&&(n=e.replace(/(^.+:([a-z]))|(-([a-z]))/g,function(){return 0===arguments[5]?arguments[2].toUpperCase():" "+arguments[4].toUpperCase()})),t.label=n),t.label):"";var o,n}return{add:function(e,t,o){if("function"!=typeof t)throw new Error("Action handler not a function");if(a[e])throw new Error("Cannot override existing action");a[e]={handler:t,options:o}},remove:function(e){delete a[e]},get:function(e){return a[e].handler},getLabel:s,invoke:function(){var e=Array.prototype.slice.call(arguments),t=e.shift();a.hasOwnProperty(t)&&a[t].handler.apply(null,e)},list:function(){var i=[];return Object.keys(a).forEach(function(e){var t=a[e],o=RED.keyboard.getShortcut(e),n=!1,n=o?o.user:!!RED.keyboard.getUserShortcut(e);t.label||(t.label=s(e)),i.push({id:e,scope:o?o.scope:void 0,key:o?o.key:void 0,user:n,label:t.label,options:t.options})}),i}}}(),RED.deploy=function(){var t={full:{img:"red/images/deploy-full-o.svg"},nodes:{img:"red/images/deploy-nodes-o.svg"},flows:{img:"red/images/deploy-flows-o.svg"}},c={unknown:!1,unusedConfig:!1,invalid:!1},u="full",p=!1,l=null;function s(e){u=e,$("#red-ui-header-button-deploy-icon").attr("src",t[e].img)}function f(e){var t="",o=(e.z&&(t=(o=RED.nodes.workspace(e.z))?o.label:(o=RED.nodes.subflow(e.z)).name),RED.utils.getNodeLabel(e,e.id));return{tab:t,type:e.type,label:o}}function h(e,t){return e.tab<t.tab?-1:e.tab>t.tab?1:e.type<t.type?-1:e.type>t.type?1:e.name<t.name?-1:e.name>t.name?1:0}function g(e,t){var o=$("<div>"),n=($('<p data-i18n="deploy.confirm.conflict"></p>').appendTo(o),$('<div class="red-ui-deploy-dialog-confirm-conflict-row"><img src="red/images/spin.svg"/><div data-i18n="deploy.confirm.conflictChecking"></div></div>').appendTo(o)),i=$('<div class="red-ui-deploy-dialog-confirm-conflict-row"><i class="fa fa-check"></i><div data-i18n="deploy.confirm.conflictAutoMerge"></div></div>').hide().appendTo(o),a=$('<div class="red-ui-deploy-dialog-confirm-conflict-row"><i class="fa fa-exclamation"></i><div data-i18n="deploy.confirm.conflictManualMerge"></div></div>').hide().appendTo(o),s=(o.i18n(),l=null,[{text:RED._("common.label.cancel"),click:function(){r.close()}},{id:"red-ui-deploy-dialog-confirm-deploy-review",text:RED._("deploy.confirm.button.review"),class:"primary disabled",click:function(){$("#red-ui-deploy-dialog-confirm-deploy-review").hasClass("disabled")||(RED.diff.showRemoteDiff(),r.close())}},{id:"red-ui-deploy-dialog-confirm-deploy-merge",text:RED._("deploy.confirm.button.merge"),class:"primary disabled",click:function(){$("#red-ui-deploy-dialog-confirm-deploy-merge").hasClass("disabled")||(RED.diff.mergeDiff(l),r.close())}}]),r=(t&&s.push({id:"red-ui-deploy-dialog-confirm-deploy-overwrite",text:RED._("deploy.confirm.button.overwrite"),class:"primary",click:function(){D(!0,t),r.close()}}),RED.notify(o,{modal:!0,fixed:!0,width:600,buttons:s})),d=Date.now();RED.diff.getRemoteDiff(function(e){var t=Math.max(1e3-(Date.now()-d),0);l=e,setTimeout(function(){n.hide(),0===Object.keys(e.conflicts).length?(i.show(),$("#red-ui-deploy-dialog-confirm-deploy-merge").removeClass("disabled")):a.show(),$("#red-ui-deploy-dialog-confirm-deploy-review").removeClass("disabled")},t)})}function m(e){var t;return 5<e.length&&(t=e.length-5,(e=e.slice(0,5)).push(RED._("deploy.confirm.plusNMore",{count:t}))),e}function v(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function b(){$("#red-ui-header-shade").show(),$("#red-ui-editor-shade").show(),$("#red-ui-palette-shade").show(),$("#red-ui-sidebar-shade").show()}function y(){$("#red-ui-header-shade").hide(),$("#red-ui-editor-shade").hide(),$("#red-ui-palette-shade").hide(),$("#red-ui-sidebar-shade").hide()}function w(){$(".red-ui-deploy-button-content").css("opacity",0),$(".red-ui-deploy-button-spinner").show(),$("#red-ui-header-button-deploy").addClass("disabled")}function E(){$(".red-ui-deploy-button-content").css("opacity",1),$(".red-ui-deploy-button-spinner").hide()}function r(e){const t=Date.now(),i=!$("#red-ui-header-button-deploy").hasClass("disabled");p=!0,w(),b(),$.ajax({url:"flows/state",type:"POST",data:{state:e}}).done(function(e,t,o){i&&$("#red-ui-header-button-deploy").removeClass("disabled")}).fail(function(e,t,o){if(i&&$("#red-ui-header-button-deploy").removeClass("disabled"),401===e.status)RED.notify(RED._("notification.error",{message:RED._("user.notAuthorized")}),"error");else if(e.responseText){const n={message:o?o+"":""};try{n.message=JSON.parse(e.responseText).message}finally{n.message=n.message||e.responseText}RED.notify(RED._("notification.error",n),"error")}else RED.notify(RED._("notification.error",{message:RED._("deploy.errors.noResponse")}),"error")}).always(function(){var e=Math.max(0,300-(Date.now()-t));setTimeout(function(){E(),y(),p=!1},e)})}function d(){var t=Date.now(),n=!$("#red-ui-header-button-deploy").hasClass("disabled");p=!0,w(),$.ajax({url:"flows",type:"POST",headers:{"Node-RED-Deployment-Type":"reload"}}).done(function(e,t,o){n&&$("#red-ui-header-button-deploy").removeClass("disabled"),RED.notify("<p>"+RED._("deploy.successfulRestart")+"</p>","success")}).fail(function(e,t,o){n&&$("#red-ui-header-button-deploy").removeClass("disabled"),401===e.status?RED.notify(RED._("deploy.deployFailed",{message:RED._("user.notAuthorized")}),"error"):409===e.status?g(nns,!0):e.responseText?RED.notify(RED._("deploy.deployFailed",{message:e.responseText}),"error"):RED.notify(RED._("deploy.deployFailed",{message:RED._("deploy.errors.noResponse")}),"error")}).always(function(){var e=Math.max(0,300-(Date.now()-t));setTimeout(function(){E(),p=!1},e)})}function D(a,e){if(!$("#red-ui-header-button-deploy").hasClass("disabled")&&!$("#red-ui-header-shade").is(":visible"))if(RED.user.hasPermission("flows.write")){let i=!1;if(!a){var s;const r=[],d=[],l=(RED.nodes.eachConfig(function(e){void 0===e.valid&&RED.editor.validateNode(e),e.valid||e.d||d.push(f(e)),"unknown"===e.type&&-1==r.indexOf(e.name)&&r.push(e.name)}),RED.nodes.eachNode(function(e){e.valid||e.d||d.push(f(e)),"unknown"===e.type&&-1==r.indexOf(e.name)&&r.push(e.name)}),a=0<r.length,s=0<d.length,[]);RED.nodes.eachConfig(function(e){!1!==e._def.hasUsers&&0===e.users.length&&(l.push(f(e)),i=!0)});let e=!1,t,o=[],n;if(a&&!c.unknown?(e=!0,t="<p>"+RED._("deploy.confirm.unknown")+'</p><ul class="red-ui-deploy-dialog-confirm-list"><li>'+m(r).map(v).join("</li><li>")+"</li></ul><p>"+RED._("deploy.confirm.confirm")+"</p>",o=[{text:RED._("deploy.unknownNodesButton"),class:"pull-left",click:function(){n.close(),RED.actions.invoke("core:search","type:unknown ")}},{id:"red-ui-deploy-dialog-confirm-deploy-deploy",text:RED._("deploy.confirm.button.confirm"),class:"primary",click:function(){D(!0),n.close()}}]):s&&!c.invalid&&(e=!0,d.sort(h),t="<p>"+RED._("deploy.confirm.improperlyConfigured")+'</p><ul class="red-ui-deploy-dialog-confirm-list"><li>'+m(d.map(function(e){return v((e.tab?"["+e.tab+"] ":"")+e.label+" ("+e.type+")")})).join("</li><li>")+"</li></ul><p>"+RED._("deploy.confirm.confirm")+"</p>",o=[{text:RED._("deploy.invalidNodesButton"),class:"pull-left",click:function(){n.close(),RED.actions.invoke("core:search","is:invalid ")}},{id:"red-ui-deploy-dialog-confirm-deploy-deploy",text:RED._("deploy.confirm.button.confirm"),class:"primary",click:function(){D(!0),n.close()}}]),e)return o.unshift({text:RED._("common.label.cancel"),click:function(){n.close()}}),void(n=RED.notify(t,{modal:!0,fixed:!0,buttons:o}))}const n=RED.nodes.createCompleteNodeSet(),t=Date.now(),o=(w(),{flows:n});e||(o.rev=RED.nodes.version()),p=!0,b(),$.ajax({url:"flows",type:"POST",data:JSON.stringify(o),contentType:"application/json; charset=utf-8",headers:{"Node-RED-Deployment-Type":u}}).done(function(t,e,o){if(RED.nodes.dirty(!1),RED.nodes.version(t.rev),RED.nodes.originalFlow(n),i){let e;t={type:"success",fixed:!1,timeout:6e3,buttons:[{text:RED._("deploy.unusedConfigNodesButton"),class:"pull-left",click:function(){e.close(),RED.actions.invoke("core:search","is:config is:unused ")}},{text:RED._("common.label.close"),class:"primary",click:function(){D(!0),e.close()}}]};e=RED.notify("<p>"+RED._("deploy.successfulDeploy")+"</p><p>"+RED._("deploy.unusedConfigNodes")+"</p>",t)}else RED.notify("<p>"+RED._("deploy.successfulDeploy")+"</p>","success");RED.nodes.eachNode(function(e){e.changed&&(e.dirty=!0,e.changed=!1),e.moved&&(e.dirty=!0,e.moved=!1),e.credentials&&delete e.credentials}),RED.nodes.eachConfig(function(e){e.changed=!1,e.credentials&&delete e.credentials}),RED.nodes.eachSubflow(function(e){e.changed=!1}),RED.nodes.eachWorkspace(function(e){e.changed=!1}),RED.history.markAllDirty(),RED.view.redraw(),RED.events.emit("deploy")}).fail(function(e,t,o){RED.nodes.dirty(!0),$("#red-ui-header-button-deploy").removeClass("disabled"),401===e.status?RED.notify(RED._("deploy.deployFailed",{message:RED._("user.notAuthorized")}),"error"):409===e.status?g(n,!0):e.responseText?RED.notify(RED._("deploy.deployFailed",{message:e.responseText}),"error"):RED.notify(RED._("deploy.deployFailed",{message:RED._("deploy.errors.noResponse")}),"error")}).always(function(){var e=Math.max(0,300-(Date.now()-t));setTimeout(function(){p=!1,E(),y()},e)})}else RED.notify(RED._("user.errors.deploy"),"error")}return{init:function(e){var t,o,n,i=(e=e||{}).type||"default";if("default"==i){$('<li><span class="red-ui-deploy-button-group button-group"><a id="red-ui-header-button-deploy" class="red-ui-deploy-button disabled" href="#"><span class="red-ui-deploy-button-content"><img id="red-ui-header-button-deploy-icon" src="red/images/deploy-full-o.svg"> <span>'+RED._("deploy.deploy")+'</span></span><span class="red-ui-deploy-button-spinner hide"><img src="red/images/spin.svg"/></span></a><a id="red-ui-header-button-deploy-options" class="red-ui-deploy-button" href="#"><i class="fa fa-caret-down"></i></a></span></li>').prependTo(".red-ui-header-toolbar");const a=[{id:"deploymenu-item-full",toggle:"deploy-type",icon:"red/images/deploy-full.svg",label:RED._("deploy.full"),sublabel:RED._("deploy.fullDesc"),selected:!0,onselect:function(e){e&&s("full")}},{id:"deploymenu-item-flow",toggle:"deploy-type",icon:"red/images/deploy-flows.svg",label:RED._("deploy.modifiedFlows"),sublabel:RED._("deploy.modifiedFlowsDesc"),onselect:function(e){e&&s("flows")}},{id:"deploymenu-item-node",toggle:"deploy-type",icon:"red/images/deploy-nodes.svg",label:RED._("deploy.modifiedNodes"),sublabel:RED._("deploy.modifiedNodesDesc"),onselect:function(e){e&&s("nodes")}},null];RED.settings.runtimeState&&!0===RED.settings.runtimeState.ui&&(a.push({id:"deploymenu-item-runtime-start",icon:"red/images/start.svg",label:RED._("deploy.startFlows"),sublabel:RED._("deploy.startFlowsDesc"),onselect:"core:start-flows",visible:!1}),a.push({id:"deploymenu-item-runtime-stop",icon:"red/images/stop.svg",label:RED._("deploy.stopFlows"),sublabel:RED._("deploy.stopFlowsDesc"),onselect:"core:stop-flows",visible:!1})),a.push({id:"deploymenu-item-reload",icon:"red/images/deploy-reload.svg",label:RED._("deploy.restartFlows"),sublabel:RED._("deploy.restartFlowsDesc"),onselect:"core:restart-flows"}),RED.menu.init({id:"red-ui-header-button-deploy-options",options:a})}else"simple"==i&&(t=e.label||RED._("deploy.deploy"),o="red/images/deploy-full-o.svg",e.hasOwnProperty("icon")&&(o=e.icon),$('<li><span class="red-ui-deploy-button-group button-group"><a id="red-ui-header-button-deploy" class="red-ui-deploy-button disabled" href="#"><span class="red-ui-deploy-button-content">'+(o?'<img id="red-ui-header-button-deploy-icon" src="'+o+'"> ':"")+"<span>"+t+'</span></span><span class="red-ui-deploy-button-spinner hide"><img src="red/images/spin.svg"/></span></a></span></li>').prependTo(".red-ui-header-toolbar"));$("#red-ui-header-button-deploy").on("click",function(e){e.preventDefault(),D()}),RED.actions.add("core:deploy-flows",D),"default"===i&&(RED.settings.runtimeState&&!0===RED.settings.runtimeState.ui&&(RED.actions.add("core:stop-flows",function(){r("stop")}),RED.actions.add("core:start-flows",function(){r("start")})),RED.actions.add("core:restart-flows",d),RED.actions.add("core:set-deploy-type-to-full",function(){RED.menu.setSelected("deploymenu-item-full",!0)}),RED.actions.add("core:set-deploy-type-to-modified-flows",function(){RED.menu.setSelected("deploymenu-item-flow",!0)}),RED.actions.add("core:set-deploy-type-to-modified-nodes",function(){RED.menu.setSelected("deploymenu-item-node",!0)})),RED.events.on("workspace:dirty",function(e){e.dirty?(window.onbeforeunload=function(){return RED._("deploy.confirm.undeployedChanges")},$("#red-ui-header-button-deploy").removeClass("disabled")):(window.onbeforeunload=null,$("#red-ui-header-button-deploy").addClass("disabled"))}),RED.comms.subscribe("notification/runtime-deploy",function(e,t){var o;n||(null===(o=RED.nodes.version())||p||o===t.revision||(o=$("<p>").text(RED._("deploy.confirm.backgroundUpdate")),n=RED.notify(o,{modal:!0,fixed:!0,buttons:[{text:RED._("deploy.confirm.button.ignore"),click:function(){n.close(),n=null}},{text:RED._("deploy.confirm.button.review"),class:"primary",click:function(){n.close(),g(RED.nodes.createCompleteNodeSet(),!1),n=null}}]})))})},setDeployInflight:function(e){p=e}}}(),RED.diagnostics={init:function(){!1!==RED.settings.get("diagnostics.ui",!0)&&RED.actions.add("core:show-system-info",function(){$.ajax({headers:{Accept:"application/json"},cache:!1,url:"diagnostics",success:function(e){var t=JSON.stringify(e||{},"",4);"{}"===t&&(t="{\n\n}"),RED.editor.editJSON({title:RED._("diagnostics.title"),value:t,requireValid:!0,readOnly:!0,toolbarButtons:[{text:RED._("clipboard.export.copy"),icon:"fa fa-copy",click:function(){RED.clipboard.copyText(t,$(this),RED._("clipboard.copyMessageValue"))}},{text:RED._("clipboard.download"),icon:"fa fa-download",click:function(){var e=document.createElement("a");e.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),e.setAttribute("download","system-info.json"),e.style.display="none",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}]})},error:function(e,t,o){console.log("Unexpected error loading system info:",e.status,t,o)}})})}},RED.diff=function(){var s=!1;function p(e,t,o){var D,n,e=$('<div class="red-ui-diff-panel"></div>').appendTo(e),i=$('<div class="red-ui-diff-panel-headers"></div>').appendTo(e),a=("merge"===o.mode&&e.addClass("red-ui-diff-panel-merge"),n=e,D=t,(n=$('<ol class="red-ui-diff-list"></ol>').appendTo(n)).editableList({addButton:!1,height:"auto",scrollOnAdd:!1,addItem:function(e,t,o){var n,i,a,s,r,d=o.diff,l=o.remoteDiff,c=o.tab.n,u=o.def,p=D.conflicts,f=$("<div>",{class:"red-ui-diff-list-flow"}).appendTo(e),h=(f.addClass("collapsed"),$("<div>",{class:"red-ui-diff-list-flow-title"}).appendTo(f)),g=$("<div>").appendTo(f),m=$("<div>",{class:"red-ui-diff-list-node-cell"}).appendTo(h),v=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-local"}).appendTo(h),b=(l&&(n=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-remote"}).appendTo(h)),$('<span class="red-ui-diff-list-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(m),R(c,u).appendTo(m),(o.newTab||o.tab).n),m=$("<span>",{class:"red-ui-diff-list-flow-title-meta"}).appendTo(m),y=("tab"===b.type?m.text(b.label||b.id):"subflow"===c.type?m.text(b.name||b.id):m.text(RED._("diff.globalNodes")),{local:{addedCount:0,deletedCount:0,changedCount:0,unchangedCount:0},remote:{addedCount:0,deletedCount:0,changedCount:0,unchangedCount:0},conflicts:0}),w=((o.newTab||o.remoteTab)&&(b={node:d.newConfig.all[c.id],all:d.newConfig.all,diff:d},l&&(r={node:l.newConfig.all[c.id]||null,all:l.newConfig.all,diff:l}),void 0!==c.type&&(m=$("<div>",{class:"red-ui-diff-list-node red-ui-diff-list-node-props collapsed"}).appendTo(g),w=$("<div>",{class:"red-ui-diff-list-node-header"}).appendTo(m),i=$("<div>",{class:"red-ui-diff-list-node-cell"}).appendTo(w),a=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-local"}).appendTo(w),0,d.newConfig.all[c.id]?d.added[c.id]?(a.addClass("red-ui-diff-status-added"),$('<span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(a)):d.changed[c.id]?(a.addClass("red-ui-diff-status-changed"),$('<span class="red-ui-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(a)):(a.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(a)):a.addClass("red-ui-diff-empty"),l&&(s=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-remote"}).appendTo(w),l.newConfig.all[c.id]?l.added[c.id]?(s.addClass("red-ui-diff-status-added"),$('<span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(s)):l.changed[c.id]?(s.addClass("red-ui-diff-status-changed"),$('<span class="red-ui-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(s)):(s.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(s)):(s.addClass("red-ui-diff-empty"),l.deleted[c.id]&&0)),$('<span class="red-ui-diff-list-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(i),$("<span>").text(RED._("diff.flowProperties")).appendTo(i),w.on("click",function(e){e.preventDefault(),$(this).parent().toggleClass("collapsed")}),_(u,c,b,r).appendTo(m),i="",p[c.id]?(y.conflicts++,a.hasClass("red-ui-diff-empty")||$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(a),s.hasClass("red-ui-diff-empty")||$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(s),m.addClass("red-ui-diff-list-node-conflict")):i=D.resolutions[c.id],k(c,m,a,s,!0,!p[c.id],i,D))),0),u=0,E={};o.tab.nodes.forEach(function(e){E[e.id]=!0,x(e,y,D).appendTo(g)}),o.newTab&&(w=o.newTab.nodes.length,o.newTab.nodes.forEach(function(e){E[e.id]||(E[e.id]=!0,x(e,y,D).appendTo(g))})),o.remoteTab&&(u=o.remoteTab.nodes.length,o.remoteTab.nodes.forEach(function(e){E[e.id]||x(e,y,D).appendTo(g)})),h.on("click",function(e){h.parent().toggleClass("collapsed"),$(this).parent().hasClass("collapsed")&&($(this).parent().find(".red-ui-diff-list-node").addClass("collapsed"),$(this).parent().find(".red-ui-debug-msg-element").addClass("collapsed"))}),d.deleted[c.id]?$('<span class="red-ui-diff-status-deleted"><span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.flowDeleted"></span></span></span>').appendTo(v):o.newTab?d.added[c.id]?$('<span class="red-ui-diff-status-added"><span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.flowAdded"></span></span></span>').appendTo(v):(c.id&&(d.changed[c.id]?y.local.changedCount++:y.local.unchangedCount++),b=$("<span>",{class:"red-ui-diff-list-flow-stats"}).appendTo(v),$('<span class="red-ui-diff-status"></span>').text(RED._("diff.nodeCount",{count:w})).appendTo(b),0<y.conflicts+y.local.addedCount+y.local.changedCount+y.local.deletedCount&&($('<span class="red-ui-diff-status"> [ </span>').appendTo(b),0<y.conflicts&&$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i> '+y.conflicts+"</span></span>").appendTo(b),0<y.local.addedCount&&$('<span class="red-ui-diff-status-added"><span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> '+y.local.addedCount+"</span></span>").appendTo(b),0<y.local.changedCount&&$('<span class="red-ui-diff-status-changed"><span class="red-ui-diff-status"><i class="fa fa-square"></i> '+y.local.changedCount+"</span></span>").appendTo(b),0<y.local.deletedCount&&$('<span class="red-ui-diff-status-deleted"><span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> '+y.local.deletedCount+"</span></span>").appendTo(b),$('<span class="red-ui-diff-status"> ] </span>').appendTo(b))):v.addClass("red-ui-diff-empty"),l&&(l.deleted[c.id]?$('<span class="red-ui-diff-status-deleted"><span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.flowDeleted"></span></span></span>').appendTo(n):o.remoteTab?l.added[c.id]?$('<span class="red-ui-diff-status-added"><span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.flowAdded"></span></span></span>').appendTo(n):(c.id&&(l.changed[c.id]?y.remote.changedCount++:y.remote.unchangedCount++),r=$("<span>",{class:"red-ui-diff-list-flow-stats"}).appendTo(n),$('<span class="red-ui-diff-status"></span>').text(RED._("diff.nodeCount",{count:u})).appendTo(r),0<y.conflicts+y.remote.addedCount+y.remote.changedCount+y.remote.deletedCount&&($('<span class="red-ui-diff-status"> [ </span>').appendTo(r),0<y.conflicts&&$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i> '+y.conflicts+"</span></span>").appendTo(r),0<y.remote.addedCount&&$('<span class="red-ui-diff-status-added"><span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> '+y.remote.addedCount+"</span></span>").appendTo(r),0<y.remote.changedCount&&$('<span class="red-ui-diff-status-changed"><span class="red-ui-diff-status"><i class="fa fa-square"></i> '+y.remote.changedCount+"</span></span>").appendTo(r),0<y.remote.deletedCount&&$('<span class="red-ui-diff-status-deleted"><span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> '+y.remote.deletedCount+"</span></span>").appendTo(r),$('<span class="red-ui-diff-status"> ] </span>').appendTo(r))):n.addClass("red-ui-diff-empty"),i="",0<y.conflicts?h.addClass("red-ui-diff-list-node-conflict"):i=D.resolutions[c.id],c.id&&(m=!(0<y.conflicts&&(d.deleted[c.id]||l.deleted[c.id])),k(c,h,v,n,!1,m,i,D))),0===f.find(".red-ui-diff-list-node").length&&f.addClass("red-ui-diff-list-flow-empty"),e.i18n()}}),n),s=t.localDiff,r=t.remoteDiff,d=(t.conflicts,s.currentConfig),l=s.newConfig;return void 0!==r?(e.addClass("red-ui-diff-three-way"),n=o.oldRevTitle||RED._("diff.local"),t=o.newRevTitle||RED._("diff.remote"),$("<div></div>").text(n).appendTo(i),$("<div></div>").text(t).appendTo(i)):e.removeClass("red-ui-diff-three-way"),{list:a,finish:function(){var e,t={diff:s,def:{category:"config",color:"#f0f0f0"},tab:{n:{},nodes:d.globals},newTab:{n:{},nodes:l.globals}},o=(void 0!==r&&(t.remoteTab={n:{},nodes:r.newConfig.globals},t.remoteDiff=r),a.editableList("addItem",t),{});for(e in d.tabOrder.forEach(function(e){var t=d.tabs[e],t={diff:s,def:RED.nodes.getType("tab"),tab:t};l.tabs.hasOwnProperty(e)&&(t.newTab=l.tabs[e]),void 0!==r&&(t.remoteTab=r.newConfig.tabs[e],t.remoteDiff=r),o[e]=!0,a.editableList("addItem",t)}),l.tabOrder.forEach(function(e){o[e]||(o[e]=!0,e=l.tabs[e],e={diff:s,def:RED.nodes.getType("tab"),tab:e,newTab:e},void 0!==r&&(e.remoteDiff=r),a.editableList("addItem",e))}),void 0!==r&&r.newConfig.tabOrder.forEach(function(e){o[e]||(e=r.newConfig.tabs[e],e={diff:s,remoteDiff:r,def:RED.nodes.getType("tab"),tab:e,remoteTab:e},a.editableList("addItem",e))}),d.subflows)d.subflows.hasOwnProperty(e)&&(o[e]=!0,t={diff:s,def:{defaults:{},icon:"subflow.svg",category:"subflows",color:"#DDAA99"},tab:d.subflows[e]},l.subflows.hasOwnProperty(e)&&(t.newTab=l.subflows[e]),void 0!==r&&(t.remoteTab=r.newConfig.subflows[e],t.remoteDiff=r),a.editableList("addItem",t));for(e in l.subflows)l.subflows.hasOwnProperty(e)&&!o[e]&&(o[e]=!0,t={diff:s,def:{defaults:{},icon:"subflow.svg",category:"subflows",color:"#DDAA99"},tab:l.subflows[e],newTab:l.subflows[e]},void 0!==r&&(t.remoteDiff=r),a.editableList("addItem",t));if(void 0!==r)for(e in r.newConfig.subflows)r.newConfig.subflows.hasOwnProperty(e)&&!o[e]&&(t={diff:s,remoteDiff:r,def:{defaults:{},icon:"subflow.svg",category:"subflows",color:"#DDAA99"},tab:r.newConfig.subflows[e],remoteTab:r.newConfig.subflows[e]},a.editableList("addItem",t))}}}function E(e,i){var t=$("<div>",{class:"red-ui-diff-list-wires"}),a=$("<ol></ol>"),s=0;return e.forEach(function(e,t){var n,o=$("<li>").appendTo(a);e&&0<e.length?($("<span>").text(t+1).appendTo(o),n=$("<ul>").appendTo(o),e.forEach(function(e){s++;var t=$("<li>").appendTo(n),o=i[e];o?g(o,RED.nodes.getType(o.type)||{}).appendTo(t):t.text(e)})):o.text("none")}),0===s?t.text("none"):a.appendTo(t),t}function R(e,t){var o=$("<div>",{class:"red-ui-diff-list-node-icon"}),n=RED.utils.getNodeColor(e.type,t),t=RED.utils.getNodeIcon(t,e),e=("tab"===e.type&&(n="#C0DEED"),o.css("backgroundColor",n),$("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(o));return RED.utils.createIconElement(t,e,!1),o}function g(e,t){var o=$("<div>",{class:"red-ui-diff-list-node-title"}),t=(R(e,t).appendTo(o),e.label||e.name||e.id);return $("<div>",{class:"red-ui-diff-list-node-description"}).text(t).appendTo(o),o}function x(t,e,o){var n,i,a=o.localDiff,s=o.remoteDiff,r=o.conflicts[t.id],d=!0,l=(a.added[t.id]&&(e.local.addedCount++,d=!1),s&&s.added[t.id]&&(e.remote.addedCount++,d=!1),a.deleted[t.id]&&(e.local.deletedCount++,d=!1),s&&s.deleted[t.id]&&(e.remote.deletedCount++,d=!1),a.changed[t.id]&&(e.local.changedCount++,d=!!0),s&&s.changed[t.id]&&(e.remote.changedCount++,d=!!0),RED.nodes.getType(t.type)),c=(void 0===l&&(l=/^subflow:/.test(t.type)?{icon:"subflow.svg",category:"subflows",color:"#DDAA99",defaults:{name:{value:""}}}:"group"===t.type?RED.group.def:{}),$("<div>",{class:"red-ui-diff-list-node collapsed"})),u=$("<div>",{class:"red-ui-diff-list-node-header"}).appendTo(c),p=$("<div>",{class:"red-ui-diff-list-node-cell"}).appendTo(u),f=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-local"}).appendTo(u),h=(s&&(n=$("<div>",{class:"red-ui-diff-list-node-cell red-ui-diff-list-node-remote"}).appendTo(u)),$('<span class="red-ui-diff-list-chevron"><i class="fa fa-angle-down"></i></span>').appendTo(p),d?(e.local.unchangedCount++,g(t,l).appendTo(p),f.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(f),s&&(e.remote.unchangedCount++,n.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(n)),c.addClass("red-ui-diff-status-unchanged")):a.added[t.id]?(f.addClass("red-ui-diff-status-added"),n&&n.addClass("red-ui-diff-empty"),$('<span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(f),g(t,l).appendTo(p)):s&&s.added[t.id]?(f.addClass("red-ui-diff-empty"),n.addClass("red-ui-diff-status-added"),$('<span class="red-ui-diff-status"><i class="fa fa-plus-square"></i> <span data-i18n="diff.type.added"></span></span>').appendTo(n),g(t,l).appendTo(p)):(g(t,l).appendTo(p),a.moved[t.id]?(d=a.newConfig.all[t.id],a.deleted[t.z]||t.z===d.z||""===t.z||a.newConfig.all[t.z]?(f.addClass("red-ui-diff-status-moved"),p="",p=t.z===d.z?RED._("diff.type.movedFrom",{id:a.currentConfig.all[t.id].z||"global"}):RED._("diff.type.movedTo",{id:d.z||"global"}),$('<span class="red-ui-diff-status"><i class="fa fa-caret-square-o-right"></i> '+p+"</span>").appendTo(f)):f.addClass("red-ui-diff-empty"),0):a.deleted[t.z]?(f.addClass("red-ui-diff-empty"),0):a.deleted[t.id]?(f.addClass("red-ui-diff-status-deleted"),$('<span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.deleted"></span></span>').appendTo(f),0):a.changed[t.id]?a.newConfig.all[t.id].z!==t.z?f.addClass("red-ui-diff-empty"):(f.addClass("red-ui-diff-status-changed"),$('<span class="red-ui-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(f),0):a.newConfig.all[t.id].z!==t.z?f.addClass("red-ui-diff-empty"):(e.local.unchangedCount++,f.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(f)),s&&(s.moved[t.id]?(d=s.newConfig.all[t.id],s.deleted[t.z]||t.z===d.z||""===t.z||s.newConfig.all[t.z]?(n.addClass("red-ui-diff-status-moved"),p="",p=t.z===d.z?RED._("diff.type.movedFrom",{id:s.currentConfig.all[t.id].z||"global"}):RED._("diff.type.movedTo",{id:d.z||"global"}),$('<span class="red-ui-diff-status"><i class="fa fa-caret-square-o-right"></i> '+p+"</span>").appendTo(n)):n.addClass("red-ui-diff-empty")):s.deleted[t.z]?n.addClass("red-ui-diff-empty"):s.deleted[t.id]?(n.addClass("red-ui-diff-status-deleted"),$('<span class="red-ui-diff-status"><i class="fa fa-minus-square"></i> <span data-i18n="diff.type.deleted"></span></span>').appendTo(n)):s.changed[t.id]?s.newConfig.all[t.id].z!==t.z?n.addClass("red-ui-diff-empty"):(n.addClass("red-ui-diff-status-changed"),$('<span class="red-ui-diff-status"><i class="fa fa-square"></i> <span data-i18n="diff.type.changed"></span></span>').appendTo(n)):s.newConfig.all[t.id].z!==t.z?n.addClass("red-ui-diff-empty"):(e.remote.unchangedCount++,n.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"><i class="fa fa-square-o"></i> <span data-i18n="diff.type.unchanged"></span></span>').appendTo(n)))),{node:a.newConfig.all[t.id],all:a.newConfig.all,diff:a}),d=(s&&(i={node:s.newConfig.all[t.id]||null,all:s.newConfig.all,diff:s}),"");return r?(e.conflicts++,f.hasClass("red-ui-diff-empty")||$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(f),n.hasClass("red-ui-diff-empty")||$('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span></span>').prependTo(n),c.addClass("red-ui-diff-list-node-conflict")):d=o.resolutions[t.id],k(t,c,f,n,!1,!r,d,o),u.on("click",function(e){$(this).parent().toggleClass("collapsed"),0===$(this).siblings(".red-ui-diff-list-node-properties").length&&_(l,t,h,i).appendTo(c)}),c}function _(t,n,i,a){var s,r,d,l,c,u,p,f={},h=i.node,e=(a&&(s=a.node),$("<div>",{class:"red-ui-diff-list-node-properties"})),o=$("<table>").appendTo(e),g=$("<colgroup><col/><col/></colgroup>").appendTo(o),m=(void 0!==s&&$("<col/>").appendTo(g),$("<tbody>").appendTo(o)),v=!1,b=!1,y=!1,w=$("<tr>").appendTo(m),g=($("<td>",{class:"red-ui-diff-list-cell-label"}).text("id").appendTo(w),r=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-local"}).appendTo(w),h?(r.addClass("red-ui-diff-status-unchanged"),$('<span class="red-ui-diff-status"></span>').appendTo(r),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(r),f["local.id"]=RED.utils.createObjectElement(h.id).appendTo(u)):r.addClass("red-ui-diff-empty"),void 0!==s&&((p=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-remote"}).appendTo(w)).addClass("red-ui-diff-status-unchanged"),s?($('<span class="red-ui-diff-status"></span>').appendTo(p),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(p),f["remote.id"]=RED.utils.createObjectElement(s.id).appendTo(u)):p.addClass("red-ui-diff-empty")),n.hasOwnProperty("x")&&(!h||h.x===n.x&&h.y===n.y&&h.w===n.w&&h.h===n.h||(v=!0,0),!s||s.x===n.x&&s.y===n.y&&s.w===n.w&&s.h===n.h||(b=!0,0),(b&&v&&(h.x!==s.x||h.y!==s.y)||!v&&b&&i.diff.deleted[n.id]||v&&!b&&a.diff.deleted[n.id])&&(y=!0),w=$("<tr>").appendTo(m),$("<td>",{class:"red-ui-diff-list-cell-label"}).text("position").appendTo(w),r=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-local"}).appendTo(w),h?(r.addClass("red-ui-diff-status-"+(v?"changed":"unchanged")),$('<span class="red-ui-diff-status">'+(v?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(r),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(r),g={x:h.x,y:h.y},h.hasOwnProperty("w")&&(g.w=h.w,g.h=h.h),f["local.position"]=RED.utils.createObjectElement(g,{path:"position",exposeApi:!0,ontoggle:function(e,t){f["remote."+e]&&f["remote."+e].prop("expand")(e,t)}}).appendTo(u)):r.addClass("red-ui-diff-empty"),void 0!==s&&((p=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-remote"}).appendTo(w)).addClass("red-ui-diff-status-"+(b?"changed":"unchanged")),s?($('<span class="red-ui-diff-status">'+(b?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(p),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(p),o={x:s.x,y:s.y},s.hasOwnProperty("w")&&(o.w=s.w,o.h=s.h),f["remote.position"]=RED.utils.createObjectElement(o,{path:"position",exposeApi:!0,ontoggle:function(e,t){f["local."+e]&&f["local."+e].prop("expand")(e,t)}}).appendTo(u)):p.addClass("red-ui-diff-empty"))),v=b=y=!1,n.hasOwnProperty("wires")&&(d=JSON.stringify(n.wires),h&&(l=JSON.stringify(h.wires),d!==l&&(v=!0,0)),s&&(c=JSON.stringify(s.wires),d!==c&&(b=!0,0)),(b&&v&&l!==c||!v&&b&&i.diff.deleted[n.id]||v&&!b&&a.diff.deleted[n.id])&&(y=!0),w=$("<tr>").appendTo(m),$("<td>",{class:"red-ui-diff-list-cell-label"}).text("wires").appendTo(w),r=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-local"}).appendTo(w),h?(y?(r.addClass("red-ui-diff-status-conflict"),$('<span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(r)):(r.addClass("red-ui-diff-status-"+(v?"changed":"unchanged")),$('<span class="red-ui-diff-status">'+(v?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(r)),E(h.wires,i.all).appendTo(r)):r.addClass("red-ui-diff-empty"),void 0!==s&&(p=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-remote"}).appendTo(w),s?(y?(p.addClass("red-ui-diff-status-conflict"),$('<span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(p)):(p.addClass("red-ui-diff-status-"+(b?"changed":"unchanged")),$('<span class="red-ui-diff-status">'+(b?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(p)),E(s.wires,a.all).appendTo(p)):p.addClass("red-ui-diff-empty"))),Object.keys(n).filter(function(e){return!("inputLabels"==e||"outputLabels"==e||"z"==e||"wires"==e||"x"===e||"y"===e||"w"===e||"h"===e||"id"===e||"type"===e||t.defaults&&t.defaults.hasOwnProperty(e))}));return t.defaults&&(g=g.concat(Object.keys(t.defaults))),"tab"!==n.type&&"group"!==n.type&&(g=g.concat(["inputLabels","outputLabels"])),(h&&h.hasOwnProperty("icon")||s&&s.hasOwnProperty("icon"))&&-1===g.indexOf("icon")&&g.unshift("icon"),g.forEach(function(o){y=b=v=!1,d=JSON.stringify(n[o]),h&&(l=JSON.stringify(h[o]),d!==l&&(v=!0,0)),s&&(c=JSON.stringify(s[o]),d!==c&&(b=!0,0)),(b&&v&&l!==c||!v&&b&&i.diff.deleted[n.id]||v&&!b&&a.diff.deleted[n.id])&&(y=!0),w=$("<tr>").appendTo(m);var e=$("<td>",{class:"red-ui-diff-list-cell-label"}).text(o).appendTo(w);r=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-local"}).appendTo(w),h?(y?(r.addClass("red-ui-diff-status-conflict"),$('<span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(r)):(r.addClass("red-ui-diff-status-"+(v?"changed":"unchanged")),$('<span class="red-ui-diff-status">'+(v?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(r)),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(r),f["local."+o]=RED.utils.createObjectElement(h[o],{path:o,exposeApi:!0,ontoggle:function(e,t){f["remote."+o]&&f["remote."+o].prop("expand")(e,t)}}).appendTo(u)):r.addClass("red-ui-diff-empty"),void 0!==s&&(p=$("<td>",{class:"red-ui-diff-list-cell red-ui-diff-list-node-remote"}).appendTo(w),s?(y?(p.addClass("red-ui-diff-status-conflict"),$('<span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span>').appendTo(p)):(p.addClass("red-ui-diff-status-"+(b?"changed":"unchanged")),$('<span class="red-ui-diff-status">'+(b?'<i class="fa fa-square"></i>':"")+"</span>").appendTo(p)),u=$('<span class="red-ui-diff-list-element"></span>').appendTo(p),f["remote."+o]=RED.utils.createObjectElement(s[o],{path:o,exposeApi:!0,ontoggle:function(e,t){f["local."+o]&&f["local."+o].prop("expand")(e,t)}}).appendTo(u)):p.addClass("red-ui-diff-empty")),h&&s&&"string"==typeof h[o]&&(/\n/.test(h[o])||/\n/.test(s[o]))&&$('<button class="red-ui-button red-ui-button-small red-ui-diff-text-diff-button"><i class="fa fa-file-o"> <i class="fa fa-caret-left"></i> <i class="fa fa-caret-right"></i> <i class="fa fa-file-o"></i></button>').on("click",function(){C(h[o],s[o])}).appendTo(e)}),e}function k(o,n,e,t,i,a,s,r){function d(e){var t;void 0!==o.type&&(u?(t="red-ui-diff-selectbox-tab-"+o.id.replace(/\./g,"-"),$("."+t+"-"+this.value).prop("checked",!0),"local"===this.value?($("."+t+"-"+this.value).closest(".red-ui-diff-list-node").addClass("red-ui-diff-select-local"),$("."+t+"-"+this.value).closest(".red-ui-diff-list-node").removeClass("red-ui-diff-select-remote")):($("."+t+"-"+this.value).closest(".red-ui-diff-list-node").removeClass("red-ui-diff-select-local"),$("."+t+"-"+this.value).closest(".red-ui-diff-list-node").addClass("red-ui-diff-select-remote"))):(t="red-ui-diff-selectbox-"+(i?o.id:o.z).replace(/\./g,"-"),$("#"+t+"-local").prop("checked",!1),$("#"+t+"-remote").prop("checked",!1),(t=$("#"+t+"-local").closest(".red-ui-diff-list-flow").find(".red-ui-diff-list-flow-title")).removeClass("red-ui-diff-select-local"),t.removeClass("red-ui-diff-select-remote"))),"local"===this.value?(n.removeClass("red-ui-diff-select-remote"),n.addClass("red-ui-diff-select-local")):"remote"===this.value&&(n.addClass("red-ui-diff-select-remote"),n.removeClass("red-ui-diff-select-local")),w(r)}var l="red-ui-diff-selectbox-"+o.id.replace(/\./g,"-")+(i?"-props":""),c="",u=((o.z||i)&&(c="red-ui-diff-selectbox-tab-"+(i?o.id:o.z).replace(/\./g,"-")),!i&&("tab"===o.type||"subflow"===o.type)),p=$("<label>",{class:"red-ui-diff-selectbox",for:l+"-local"}).on("click",function(e){e.stopPropagation()}).appendTo(e),f=$("<input>",{class:"red-ui-diff-selectbox-input "+c+"-local",id:l+"-local",type:"radio",value:"local",name:l}).data("node-id",o.id).on("change",d).appendTo(p),h=$("<label>",{class:"red-ui-diff-selectbox",for:l+"-remote"}).on("click",function(e){e.stopPropagation()}).appendTo(t),c=$("<input>",{class:"red-ui-diff-selectbox-input "+c+"-remote",id:l+"-remote",type:"radio",value:"remote",name:l}).data("node-id",o.id).on("change",d).appendTo(h);"local"===s?f.prop("checked",!0):"remote"===s&&c.prop("checked",!0),(a||e.hasClass("red-ui-diff-empty")||t.hasClass("red-ui-diff-empty"))&&(p.hide(),h.hide())}function w(e){var t=0,o=($(".red-ui-diff-selectbox>input:checked").each(function(){e.conflicts[$(this).data("node-id")]&&t++,e.resolutions[$(this).data("node-id")]=$(this).val()}),Object.keys(e.conflicts).length);o-t==0?$("#red-ui-diff-dialog-toolbar-resolved-conflicts").html('<span class="red-ui-diff-status-added"><span class="red-ui-diff-status"><i class="fa fa-check"></i></span></span> '+RED._("diff.unresolvedCount",{count:o-t})):$("#red-ui-diff-dialog-toolbar-resolved-conflicts").html('<span class="red-ui-diff-status-conflict"><span class="red-ui-diff-status"><i class="fa fa-exclamation"></i></span></span> '+RED._("diff.unresolvedCount",{count:o-t})),o===t&&($("#red-ui-diff-view-diff-merge").removeClass("disabled"),$("#red-ui-diff-view-resolve-diff").removeClass("disabled"))}function t(i){$.ajax({headers:{Accept:"application/json"},cache:!1,url:"flows",success:function(e){var t=RED.nodes.createCompleteNodeSet(),o=RED.nodes.originalFlow(),n=e.flows,t=D(o,t),o=D(o,n);o.rev=e.rev,i(T(t,o))}})}function r(e){var o,n,i,a;void 0===e?t(r):(o=e,n={mode:"merge"},s||(n=n||{},o.localDiff,i=o.remoteDiff,a=o.conflicts,e={title:n.title||RED._("diff.reviewChanges"),width:1/0,overlay:!0,buttons:[{text:RED._("merge"===n.mode?"common.label.cancel":"common.label.close"),click:function(){RED.tray.close()}}],resize:function(e){},open:function(e){var e=e.find(".red-ui-tray-body"),t=($('<div class="red-ui-diff-dialog-toolbar"><span><span id="red-ui-diff-dialog-toolbar-resolved-conflicts"></span></span> </div>').prependTo(e),p($('<div class="red-ui-diff-container"></div>').appendTo(e),o,n));t.list.hide(),i?($("#red-ui-diff-view-diff-merge").show(),0===Object.keys(a).length?$("#red-ui-diff-view-diff-merge").removeClass("disabled"):$("#red-ui-diff-view-diff-merge").addClass("disabled")):$("#red-ui-diff-view-diff-merge").hide(),w(o),setTimeout(function(){t.finish(),t.list.show()},300),$("#red-ui-sidebar-shade").show()},close:function(){s=!1,$("#red-ui-sidebar-shade").hide()},show:function(){}},"merge"===n.mode&&e.buttons.push({id:"red-ui-diff-view-diff-merge",text:RED._("deploy.confirm.button.merge"),class:"primary disabled",click:function(){$("#red-ui-diff-view-diff-merge").hasClass("disabled")||(w(o),c(o),RED.tray.close())}}),RED.tray.show(e)))}function d(e){var t=[],o={},n={},i=[],a={};return e.forEach(function(e){"tab"===(a[e.id]=e).type?(t.push(e.id),o[e.id]={n:e,nodes:[]}):"subflow"===e.type&&(n[e.id]={n:e,nodes:[]})}),e.forEach(function(e){"tab"!==e.type&&"subflow"!==e.type&&(o[e.z]?o[e.z].nodes:n[e.z]?n[e.z].nodes:i).push(e)}),{all:a,tabOrder:t,tabs:o,subflows:n,globals:i}}function D(e,t){var o=d(e),n=d(t),i={},a={},s={},r={};return Object.keys(o.all).forEach(function(e){RED.nodes.workspace(e)||RED.nodes.subflow(e)||RED.nodes.node(e);n.all.hasOwnProperty(e)?JSON.stringify(o.all[e])!==JSON.stringify(n.all[e])&&(s[e]=!0,o.all[e].z!==n.all[e].z&&(r[e]=!0)):a[e]=!0}),Object.keys(n.all).forEach(function(e){o.all.hasOwnProperty(e)||(i[e]=!0)}),{currentConfig:o,newConfig:n,added:i,deleted:a,changed:s,moved:r}}function T(e,t){var o,n,i,a,s={},r={},d={localDiff:e,remoteDiff:t,conflicts:s,resolutions:r},l={};for(o in e.currentConfig.all)e.currentConfig.all.hasOwnProperty(o)&&(l[o]=!0,i=e.newConfig.all[o],e.changed[o]&&t.deleted[o]||e.deleted[o]&&t.changed[o]?s[o]=!0:e.changed[o]&&t.changed[o]&&(a=t.newConfig.all[o],JSON.stringify(i)!==JSON.stringify(a)&&(s[o]=!0)),s[o]||(t.added[o]||t.changed[o]||t.deleted[o]?r[o]="remote":r[o]="local"));for(o in e.added)e.added.hasOwnProperty(o)&&(n=e.newConfig.all[o],t.deleted[n.z]?s[o]=!0:r[o]="local");for(o in t.added)t.added.hasOwnProperty(o)&&(n=t.newConfig.all[o],e.deleted[n.z]?s[o]=!0:r[o]="remote");return d}function l(e){e.localDiff.currentConfig;var t,o=e.localDiff,n=e.remoteDiff,i=e.conflicts,a=e.resolutions;for(t in i)if(i.hasOwnProperty(t)&&!a.hasOwnProperty(t))throw console.log(e),new Error("No resolution for conflict on node",t);var s,r=[],d={},l={};for(t in o.newConfig.all)o.newConfig.all.hasOwnProperty(t)&&(s=RED.nodes.node(t),"local"===a[t]?(s&&(d[t]=s.changed),r.push(o.newConfig.all[t])):"remote"===a[t]?!n.deleted[t]&&n.newConfig.all.hasOwnProperty(t)&&(s&&(d[t]=s.changed),l[t]=1,r.push(n.newConfig.all[t])):console.log("Unresolved",t));for(t in n.added)n.added.hasOwnProperty(t)&&((s=RED.nodes.node(t))&&(d[t]=s.changed),o.added.hasOwnProperty(t)||(l[t]=2,r.push(n.newConfig.all[t])));return{config:r,nodeChangedStates:d,localChangedStates:l}}function c(e){var t,o=RED.workspaces.active(),n=l(e),i=n.config,a=n.nodeChangedStates,s=n.localChangedStates,n=RED.nodes.dirty(),r={t:"replace",config:RED.nodes.createCompleteNodeSet(),changed:a,dirty:n,rev:RED.nodes.version()},d=(RED.history.push(r),RED.nodes.originalFlow());for(t in e.remoteDiff.added)e.remoteDiff.added.hasOwnProperty(t)&&e.remoteDiff.newConfig.all.hasOwnProperty(t)&&d.push(JSON.parse(JSON.stringify(e.remoteDiff.newConfig.all[t])));RED.nodes.clear();r=RED.nodes.import(i);RED.nodes.originalFlow(d),r.nodes.forEach(function(e){(a[e.id]||s[e.id])&&(e.changed=!0)}),RED.nodes.version(e.remoteDiff.rev),n&&RED.nodes.dirty(!0),RED.view.redraw(!0),RED.palette.refresh(),RED.workspaces.refresh(),RED.workspaces.show(o,!0),RED.sidebar.config.refresh()}function C(m,v){var e={title:RED._("diff.compareChanges"),width:1/0,overlay:!0,buttons:[{text:RED._("common.label.close"),click:function(){RED.tray.close()}}],resize:function(e){},open:function(e){for(var t,e=e.find(".red-ui-tray-body"),e=$('<div class="red-ui-diff-text"></div>').appendTo(e),e=$("<table>",{class:"red-ui-diff-text-content"}).appendTo(e),o=($('<colgroup><col width="50"><col width="50%"><col width="50"><col width="50%"></colgroup>').appendTo(e),$("<tbody>").appendTo(e)),n=function(e,t,o){var n,i,a=e.split(/\r?\n/),s=t.split(/\r?\n/),r=a.length,d=s.length,l={a:[],b:[]},c=[];for(n=0;n<r+1;n++)for(c[n]=[],i=0;i<d+1;i++)c[n][i]=0;for(n=r-1;0<=n;n--)for(i=d-1;0<=i;i--)1!==y(a[n],s[i],o)?c[n][i]=c[n+1][i+1]+1:c[n][i]=Math.max(c[n+1][i],c[n][i+1]);i=n=0;for(;n<r&&i<d;){var u,p=y(a[n],s[i],o);1!==p?((u=0)===p?u=0:2==p&&(u=3),l.a.push({i:n+1,j:i+1,line:a[n],type:u}),l.b.push({i:i+1,j:n+1,line:s[i],type:u}),n++,i++):c[n+1][i]>=c[n][i+1]?(l.a.push({i:n+1,line:a[n],type:1}),n++):(l.b.push({i:i+1,line:s[i],type:4}),i++)}for(;n<r||i<d;)n==r?(l.b.push({i:i+1,line:s[i],type:4}),i++):i==d&&(l.a.push({i:n+1,line:a[n],type:1}),n++);return l}(m||"",v||""),i=0,a=0,s=Math.max(n.a.length,n.b.length),r=[],d=[],l=0,c=0,u=0;u<s;u++){n[u];var p=i<n.a.length?n.a[i]:{type:2,line:""},f=a<n.b.length?n.b[a]:{type:2,line:""};0===p.type&&0!==f.type?(p={type:2,line:""},a++):0===f.type&&0!==p.type?(f={type:2,line:""},i++):(i++,a++),r.push({a:p,b:f}),void 0===t?(t={start:u,end:u},c=(l=0)===p.type&&0===f.type?0:1):0===p.type&&0===f.type?0===c?(t.end=u,l++):1===c?(t.end=u,c=2,l=0):2===c&&(t.end=u,8===++l&&(t.end-=5,d.push(t),t={start:u-5,end:u-5},l=c=0)):(t.end=u,l++,0===c?(3<t.end&&(t.end-=3,t.empty=!0,d.push(t),t={start:u-3,end:u-3}),c=1):2===c&&(c=1))}0===c&&(t.empty=!0),t.end=s,d.push(t),console.table(d);for(var h=0;h<d.length;h++)if((t=d[h]).empty)(function(n,i,a){diffRow=$('<tr class="red-ui-diff-text-header red-ui-diff-text-expand">');var e=$('<td colspan="4"> <i class="fa fa-arrows-v"></i> </td>').appendTo(diffRow),s=$("<span></span>").appendTo(e);i<a.length-1&&s.text("@@ -"+(a[i-1].a.i+1)+" +"+(a[i-1].b.i+1));return diffRow.on("click",function(e){if(20<i-n){var t=$(this).offset();if(0<n){for(var o=n;o<n+10;o++)b(a[o]).addClass("unchanged").insertBefore($(this));n+=10}if(i<a.length-1){for(o=i-1;i-11<o;o--)b(a[o]).addClass("unchanged").insertAfter($(this));i-=10}i<a.length-1&&s.text("@@ -"+(a[i-1].a.i+1)+" +"+(a[i-1].b.i+1));t=$(this).offset().top-t.top;$(".red-ui-diff-text").scrollTop($(".red-ui-diff-text").scrollTop()+t)}else{for(o=n;o<i;o++)b(a[o]).addClass("unchanged").insertBefore($(this));$(this).remove()}}),diffRow})(t.start,t.end,r).appendTo(o);else for(u=t.start;u<t.end;u++){var g=b(r[u]).appendTo(o);u===t.start?g.addClass("start-block"):u===t.end-1&&g.addClass("end-block")}},close:function(){s=!1},show:function(){}};RED.tray.show(e)}function b(e){var t=$("<tr>"),o=e.a,e=e.b,n=$('<td class="lineno">').text(2===o.type?"":o.i).appendTo(t),i=$('<td class="linetext">').text(o.line).appendTo(t);return 2===o.type?(n.addClass("blank"),i.addClass("blank")):4===o.type?(n.addClass("added"),i.addClass("added")):1===o.type&&(n.addClass("removed"),i.addClass("removed")),n=$('<td class="lineno">').text(2===e.type?"":e.i).appendTo(t),i=$('<td class="linetext">').text(e.line).appendTo(t),2===e.type?(n.addClass("blank"),i.addClass("blank")):4===e.type?(n.addClass("added"),i.addClass("added")):1===e.type&&(n.addClass("removed"),i.addClass("removed")),t}function y(e,t,o){return o?e===t?0:e.trim()===t.trime()?2:1:e===t?0:1}function a(e,y){var u=$("<div></div>");return e.forEach(function(f){var h,r,d,l,t,c,e,o,n=f.hunks,i=f.binary,a=$("<table>",{class:"red-ui-diff-text-content"}).appendTo(u),g=($('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(a),$("<tbody>").appendTo(a)),s=$('<tr class="red-ui-diff-text-file-header">').appendTo(g),a=$('<td colspan="3"></td>').appendTo(s),m=($('<i class="red-ui-diff-list-chevron fa fa-angle-down"></i>').appendTo(a),s.on("click",function(e){s.toggleClass("collapsed");var t=s.hasClass("collapsed");s.nextUntil(".red-ui-diff-text-file-header").toggle(!t)}),$('<span class="filename"></span>').text(f.file).appendTo(a),0),v=0,b={};y.project.files&&y.project.files.flow===f.file?(y.unmerged&&$('<span style="float: right;"><span id="red-ui-diff-dialog-toolbar-resolved-conflicts"></span></span>').appendTo(a),e=$('<tr class="red-ui-diff-text-header">').appendTo(g),r=$('<td class="red-ui-diff-flow-diff" colspan="3"></td>').appendTo(e),e=y.project.name,d=y.project.files.flow,c="projects/"+e+"/files/"+y.commonRev+"/"+d,l="projects/"+e+"/files/"+y.oldRev+"/"+d,o="projects/"+e+"/files/"+y.newRev+"/"+d,t=[$.Deferred(),$.Deferred(),$.Deferred()],y.commonRev?(c="projects/"+e+"/files/"+y.commonRev+"/"+d,$.ajax({dataType:"json",url:c}).then(function(e){t[0].resolve(e)}).fail(function(){t[0].resolve(null)})):t[0].resolve(null),$.ajax({dataType:"json",url:l}).then(function(e){t[1].resolve(e)}).fail(function(){t[1].resolve({content:"[]"})}),$.ajax({dataType:"json",url:o}).then(function(e){t[2].resolve(e)}).fail(function(){t[2].resolve({content:"[]"})}),$.when.apply($,t).always(function(e,t,o){var n,i,a;if(e)try{n=JSON.parse(e.content||"[]")}catch(e){return console.log(RED._("diff.commonVersionError"),c),void console.log(e)}try{i=JSON.parse(t.content||"[]")}catch(e){return console.log(RED._("diff.oldVersionError"),l),void console.log(e)}n=n||i;try{a=JSON.parse(o.content||"[]")}catch(e){return console.log(RED._("diff.newVersionError"),a),void console.log(e)}var e=D(n,i),t=D(n,a),s=(y.currentDiff=T(e,t),p(r,y.currentDiff,{title:d,mode:y.commonRev?"merge":"view",oldRevTitle:y.oldRevTitle,newRevTitle:y.newRevTitle}));s.list.hide(),w(y.currentDiff),setTimeout(function(){s.finish(),s.list.show()},300)})):i?(e=$('<tr class="red-ui-diff-text-header">').appendTo(g),o=$('<td colspan="3"></td>').appendTo(e),$("<span></span>").text(RED._("diff.noBinaryFileShowed")).appendTo(o)):(y.unmerged&&(h=$('<span style="float: right;">'+RED._("diff.conflictHeader",{resolved:v,unresolved:m})+"</span>").appendTo(a)),n.forEach(function(l){var e=$('<tr class="red-ui-diff-text-header">').appendTo(g),e=$('<td colspan="3"></td>').appendTo(e),c=($("<span></span>").text(l.header).appendTo(e),l.conflict),u=l.localStartLine,p=l.remoteStartLine;c&&m++,l.lines.forEach(function(e,t){var o,n,t=l.diffStart+t,i=c&&/^\+\+(<<<<<<<|=======$|>>>>>>>)/.test(e),a=$("<tr>").appendTo(g),s=$('<td class="lineno">').appendTo(a),r=(i?s.attr("colspan",2):o=$('<td class="lineno">').appendTo(a),$('<td class="linetext">').appendTo(a)),d=c?2:1;i?(a.addClass("mergeHeader"),/^\+\+=======$/.test(e)?(l.changeSeparator=t,a.addClass("mergeHeader-separator")):((n=/^..<<<<<<</.test(e))?($("<span>").text("<<<<<<< Local Changes").appendTo(r),l.localChangeStart=t):(l.remoteChangeEnd=t,$("<span>").text(">>>>>>> Remote Changes").appendTo(r)),a.addClass("mergeHeader-"+(n?"ours":"theirs")),$('<button class="red-ui-button red-ui-button-small" style="float: right; margin-right: 20px;"><i class="fa fa-angle-double-'+(n?"down":"up")+'"></i> use '+(n?"local":"remote")+" changes</button>").appendTo(r).on("click",function(e){var t,o;e.preventDefault(),v++,n?((o=(t=a.nextUntil(".mergeHeader-separator")).last().next()).nextUntil(".mergeHeader").remove(),o.next().remove()):((o=(t=a.prevUntil(".mergeHeader-separator")).last().prev()).prevUntil(".mergeHeader").remove(),o.prev().remove()),o.remove(),a.remove(),t.find(".linetext").addClass("added"),h.empty(),$("<span>"+RED._("diff.conflictHeader",{resolved:v,unresolved:m})+"</span>").appendTo(h),b[f.file]=b[f.file]||{},b[f.file][l.localChangeStart]={changeStart:l.localChangeStart,separator:l.changeSeparator,changeEnd:l.remoteChangeEnd,selection:n?"A":"B"},y.resolveConflict&&y.resolveConflict({conflicts:m,resolved:v,resolutions:b})}))):(i=e[0],c&&!y.unmerged&&" "===i&&(i=e[1]),$('<span class="prefix">').text(i).appendTo(r),t=!1,c&&y.unmerged?($('<span class="prefix">').text(e[1]).appendTo(r),"+"===e[0]&&(s.text(u++),t=!0),"+"===e[1]&&(o.text(p++),t=!0)):"+"===e[0]||c&&"+"===e[1]?(s.addClass("added"),o.addClass("added"),r.addClass("added"),o.text(p++),t=!0):("-"===e[0]||c&&"-"===e[1])&&(s.addClass("removed"),o.addClass("removed"),r.addClass("removed"),s.text(u++),t=!0),t||(r.addClass("unchanged"),0<u&&"\\"!==e[0]&&""!==e&&s.text(u++),0<p&&"\\"!==e[0]&&""!==e&&o.text(p++)),$("<span>").text(e.substring(d)).appendTo(r))})}))}),u}function u(e){for(var t,o,n=Array.isArray(e)?e:e.split("\n"),i=/^diff (?:(?:--git a\/(.*) b\/(.*))|(?:--cc (.*)))$/,a=/^\+\+\+ b\/(.*)\t?/,s=/^Binary files /,r=/^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/,d=/^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/,l=[],c=0;c<n.length;c++){var u=n[c],p=i.exec(u);p?(o&&(t.hunks.push(o),l.push(t)),o=null,t={file:p[1]||p[3],hunks:[]}):s.test(u)?t&&(t.binary=!0):(p=a.exec(u))?t.file=p[1]:(p=r.exec(u))?(o&&t.hunks.push(o),o={header:u,localStartLine:p[2],localLength:p[4]||1,remoteStartLine:p[6],remoteLength:p[8]||1,lines:[],conflict:!1}):(p=d.exec(u))?(o&&t.hunks.push(o),o={header:u,localStartLine:p[2],localLength:p[4]||1,remoteStartLine:p[6],remoteLength:p[8]||1,diffStart:parseInt(p[10]),lines:[],conflict:!0}):o&&o.lines.push(u)}return o&&t.hunks.push(o),l.push(t),l}return{init:function(){RED.actions.add("core:show-remote-diff",r)},getRemoteDiff:t,showRemoteDiff:r,showUnifiedDiff:function(t){var o,e=t.diff,n=t.title,i=u(e),e=(t.unmerged&&(t.resolveConflict=function(e){(o=e).conflicts===e.resolved&&$("#red-ui-diff-view-resolve-diff").removeClass("disabled")}),{title:n||RED._("diff.compareChanges"),width:1/0,overlay:!0,buttons:[{text:RED._(t.unmerged?"common.label.cancel":"common.label.close"),click:function(){t.oncancel&&t.oncancel(),RED.tray.close()}}],resize:function(e){},open:function(e){e=e.find(".red-ui-tray-body"),e=$('<div class="red-ui-diff-text"></div>').appendTo(e);a(i,t).appendTo(e)},close:function(){s=!1},show:function(){}});t.unmerged&&e.buttons.push({id:"red-ui-diff-view-resolve-diff",text:RED._("diff.saveConflict"),class:"primary disabled",click:function(){var e;$("#red-ui-diff-view-resolve-diff").hasClass("disabled")||(t.currentDiff&&(e=l(t.currentDiff),(o={resolutions:{}}).resolutions[t.project.files.flow]=JSON.stringify(e.config,"",4)),t.onresolve&&t.onresolve(o),RED.tray.close())}}),RED.tray.show(e)},showCommitDiff:function(o){var n=function(e){for(var t={},o=e.split("\n"),n=[],i=0;i<o.length;i++)if(/^commit /.test(o[i]))t.sha=o[i].substring(7);else if(/^Author: /.test(o[i])){t.author=o[i].substring(8);var a=/^(.*) <(.*)>$/.exec(t.author);a&&(t.authorName=a[1],t.authorEmail=a[2])}else if(/^Date: /.test(o[i]))t.date=o[i].substring(8);else if(/^ /.test(o[i]))t.title?(4!==o[i].length||0<n.length)&&n.push(o[i].substring(4)):t.title=o[i].substring(4);else if(/^diff /.test(o[i])){t.files=u(o.slice(i));break}return t.comment=n.join("\n"),t}(o.commit),e={title:RED._("diff.viewCommitDiff"),width:1/0,overlay:!0,buttons:[{text:RED._("common.label.close"),click:function(){RED.tray.close()}}],resize:function(e){},open:function(e){var e=e.find(".red-ui-tray-body"),e=$('<div class="red-ui-diff-text"></div>').appendTo(e),t=$("<table>",{class:"red-ui-diff-text-content"}).appendTo(e),t=($('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(t),$("<tbody>").appendTo(t)),t=$('<tr class="red-ui-diff-text-commit-header">').appendTo(t),t=$('<td colspan="3"></td>').appendTo(t),t=($("<h3>").text(n.title).appendTo(t),$('<div class="commit-body"></div>').text(n.comment).appendTo(t),$('<div class="commit-summary"></div>').appendTo(t));$('<div style="float: right">').text("Commit "+n.sha).appendTo(t),$("<div>").text((n.authorName||n.author)+" - "+o.date).appendTo(t),n.files&&a(n.files,o).appendTo(e)},close:function(){s=!1},show:function(){}};RED.tray.show(e)},mergeDiff:c}}(),RED.keyboard=function(){var d,u,n=/Mac/i.test(window.navigator.platform),t=!0,p={},a={left:37,up:38,right:39,down:40,escape:27,enter:13,backspace:8,delete:46,space:32,";":186,"=":187,"+":187,",":188,"-":189,".":190,"/":191,"\\":220,"'":222,"?":191,"[":219,"]":221,"{":219,"}":221},o={16:!0,17:!0,18:!0,91:!0,93:!0},f={},h={},g={59:186,61:187,173:189};function m(e){return RED.settings.get("editor.keymap",{})[e]}function v(e){for(var t,o=e.toLowerCase().split("-"),n={},i=0;i<o.length;i++)switch(o[i]){case"ctrl":case"cmd":n.ctrl=!0,n.meta=!0;break;case"alt":n.alt=!0;break;case"shift":n.shift=!0;break;case"":t=a["-"];break;default:if(a.hasOwnProperty(o[i]))t=a[o[i]];else{if(1<o[i].length)return null;t=o[i].toUpperCase().charCodeAt(0)}}return[t,n]}function b(e,t){for(var o=e.target,n=0;"BODY"!==o.nodeName&&o.id!==t.scope;)o=o.parentElement,n++;return n="BODY"===o.nodeName&&"*"!==t.scope?-1:n}function r(e,t,o,n){var i=o,a=n,s=("function"!=typeof o&&"string"!=typeof o||(i={},a=o),[]),r=0;if("string"==typeof t){if("string"==typeof a){if(n||h.hasOwnProperty(a)||(h[a]={scope:e,key:t,user:!1}),!n)if(m(a))return;f[a]={scope:e,key:t},"boolean"==typeof n&&(f[a].user=n)}for(var d=t.split(" "),r=0;r<d.length;r++){var l=v(d[r]);if(!l)return;s.push(l)}}else s.push([t,i]);var c=p;for(r=0;r<s.length;r++)t=s[r][0],(i=s[r][1]).ctrl&&(c.ctrl=c.ctrl||{},c=c.ctrl),i.shift&&(c.shift=c.shift||{},c=c.shift),i.alt&&(c.alt=c.alt||{},c=c.alt),c[t]=c[t]||{},c=c[t];c.handlers=c.handlers||[],c.handlers.push({scope:e,ondown:a}),c.scope=e,c.ondown=a}function s(e,t){var o=t||{},n=[],i=0;if("string"==typeof e)for(var a=e.split(" "),i=0;i<a.length;i++){var s=v(a[i]);if(!s)return void console.log("Unrecognised key specifier:",e);n.push(s)}else n.push([e,o]);var r=p;for(i=0;i<n.length;i++){if(e=n[i][0],!(r=(r=(r=(o=n[i][1]).ctrl?r.ctrl:r)&&o.shift?r.shift:r)&&o.alt?r.alt:r)[e])return;r=r[e]}"string"==typeof r.ondown&&("boolean"==typeof t&&t?f[r.ondown]={user:t}:delete f[r.ondown]),delete r.scope,delete r.ondown,delete r.handlers}d3.select(window).on("keydown",function(){var e;t&&!o[d3.event.keyCode]&&(e=function e(t){var o=u||p,n=((o=(o=(t.ctrlKey||t.metaKey)&&t.ctrlKey!==t.metaKey?o.ctrl:o)&&t.shiftKey?o.shift:o)&&t.altKey&&(o=o.alt),g[t.keyCode]||t.keyCode);if(o&&o[n]){var i=o[n];if(!i.handlers){if(u)return u=null,e(t);if(0<Object.keys(i).length)for(var a in i)if(-1<b(t,i[a])){u=i,t.preventDefault();break}return null}for(var s,r=1/0,d=0,l=i.handlers.length,d=0;d<l;d++){var c=b(t,i.handlers[d]);-1<c&&c<r&&(r=c,s=i.handlers[d])}return u=null,i=s}if(u)return u=null,e(t)}(d3.event))&&e.ondown&&("string"==typeof e.ondown?RED.actions.invoke(e.ondown):e.ondown(),d3.event.preventDefault())});function l(e){e.preventDefault();var t,o,n,i,a=$(this),s=a.data("data");a.hasClass("keyboard-shortcut-entry-expanded")||(c(),e=a.find(".keyboard-shortcut-entry-key"),i=a.find(".keyboard-shortcut-entry-scope"),a.addClass("keyboard-shortcut-entry-expanded"),(t=$('<input type="text">').attr("placeholder",RED._("keyboard.unassigned")).val(s.key||"").appendTo(e)).on("change paste keyup",function(e){if(13===e.keyCode&&!$(this).hasClass("input-error"))return c();if(27===e.keyCode)return c(!0);var e=$(this).val(),t=""===(e=e.trim())||RED.keyboard.validateKey(e);t&&""!==e&&(t=!d.has(o.val()+":"+e.toLowerCase())),$(this).toggleClass("input-error",!t),n.attr("disabled",!t)}),(o=$('<select><option value="*" data-i18n="keyboard.global"></option><option value="red-ui-workspace" data-i18n="keyboard.workspace"></option></select>').appendTo(i)).i18n(),"workspace"===s.scope&&(s.scope="red-ui-workspace"),o.val(s.scope||"*"),o.on("change",function(){t.trigger("change")}),e=$('<div class="keyboard-shortcut-edit button-group-vertical"></div>').appendTo(i),n=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-check"></i></button>').appendTo(e),i=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-reply"></i></button>').appendTo(e),n.on("click",function(e){e.stopPropagation(),c()}),i.on("click",function(e){e.stopPropagation(),a.empty(),a.removeClass("keyboard-shortcut-entry-expanded");e=RED.settings.get("editor.keymap",{}),e[s.id]=null,RED.settings.set("editor.keymap",e),RED.keyboard.revertToDefault(s.id),e=RED.keyboard.getShortcut(s.id),e={id:s.id,scope:e?e.scope:void 0,key:e?e.key:void 0,user:e?e.user:void 0,label:s.label,options:s.options};y(a,e)}),t.trigger("focus"))}function c(e){var t,o,n,i,a,s,r=$(".keyboard-shortcut-entry-expanded");1===r.length&&(t=r.data("data"),o=r.find(".keyboard-shortcut-entry-key input"),n=r.find(".keyboard-shortcut-entry-scope select"),e||(e=o.val().trim(),i=n.val(),(""===e||RED.keyboard.validateKey(e))&&(!(a=RED.keyboard.getShortcut(t.id))&&e||a&&(a.scope!==i||a.key!==e))&&(a=r.find(".keyboard-shortcut-entry-key"),s=r.find(".keyboard-shortcut-entry-scope"),a.empty(),s.empty(),t.key&&(d.delete(t.scope+":"+t.key),RED.keyboard.remove(t.key,!0)),r.find(".keyboard-shortcut-entry-text i").css("opacity",1),""===e?(a.parent().addClass("keyboard-shortcut-entry-unassigned"),a.append($("<span>").text(RED._("keyboard.unassigned"))),delete t.key,delete t.scope):(a.parent().removeClass("keyboard-shortcut-entry-unassigned"),a.append(RED.keyboard.formatKey(e)),$("<span>").text(i).appendTo(s),t.key=e,t.scope=i,d.add(t.scope+":"+t.key),RED.keyboard.add(t.scope,t.key,t.id,!0)),a=RED.settings.get("editor.keymap",{}),s=RED.keyboard.getShortcut(t.id),a[t.id]={scope:s.scope,key:s.key},RED.settings.set("editor.keymap",a))),o.remove(),n.remove(),$(".keyboard-shortcut-edit").remove(),r.removeClass("keyboard-shortcut-entry-expanded"))}function y(e,t){var o=$('<div class="keyboard-shortcut-entry">').appendTo(e),n=(e.data("data",t),t.label),n=$("<div>").addClass("keyboard-shortcut-entry-text").text(n).appendTo(o),n=$('<i class="fa fa-user"></i>').prependTo(n),n=(t.user||n.css("opacity",0),$('<div class="keyboard-shortcut-entry-key">').appendTo(o)),n=(t.key?n.append(RED.keyboard.formatKey(t.key)):(o.addClass("keyboard-shortcut-entry-unassigned"),n.append($("<span>").text(RED._("keyboard.unassigned")))),$('<div class="keyboard-shortcut-entry-scope">').appendTo(o));$("<span>").text("*"===t.scope?"global":t.scope||"").appendTo(n),e.on("click",l)}function w(){var e=$('<div id="red-ui-settings-tab-keyboard"></div>'),o=($('<div class="keyboard-shortcut-entry keyboard-shortcut-list-header"><div class="keyboard-shortcut-entry-key keyboard-shortcut-entry-text"><input autocomplete="off" name="keyboard-filter" id="red-ui-settings-tab-keyboard-filter" type="text" data-i18n="[placeholder]keyboard.filterActions"></div><div class="keyboard-shortcut-entry-key" data-i18n="keyboard.shortcut"></div><div class="keyboard-shortcut-entry-scope" data-i18n="keyboard.scope"></div></div>').appendTo(e),e.find("#red-ui-settings-tab-keyboard-filter").searchBox({delay:100,change:function(){var t=$(this).val().trim().toLowerCase();""===t?o.editableList("filter",null):(t=t.replace(/\s/g,""),o.editableList("filter",function(e){return-1<e.label.toLowerCase().indexOf(t)}))}}),$('<ol class="keyboard-shortcut-list"></ol>').css({position:"absolute",top:"32px",bottom:"0",left:"0",right:"0"}).appendTo(e).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){y(e,o)}})),t=RED.actions.list();return t.sort(function(e,t){e=e.label,t=t.label;return e.localeCompare(t)}),d=new Set,t.forEach(function(e){e.key&&d.add(e.scope+":"+e.key),o.editableList("addItem",e)}),e}return{init:function(a){"localStorage"in window&&null!==window.localStorage&&(null!==(e=localStorage.getItem("keymap"))&&(localStorage.removeItem("keymap"),RED.settings.set("editor.keymap",JSON.parse(e))));var e,s=RED.settings.get("editor.keymap",{});$.getJSON("red/keymap.json",function(e){var t,o,n,i=function(e,t){var o,n,i={};for(o in e)if(e.hasOwnProperty(o)){var a,s=e[o];for(a in s)s.hasOwnProperty(a)&&(i[s[a]]?i[s[a]].push({scope:o,key:a,user:!1}):i[s[a]]=[{scope:o,key:a,user:!1}])}for(n in t)t.hasOwnProperty(n)&&(t[n].key?(i[n]=[{scope:t[n].scope||"*",key:t[n].key,user:!1}],"workspace"===i[n][0].scope&&(i[n][0].scope="red-ui-workspace")):delete i[n]);return i}(e,RED.settings.theme("keymap",{}));for(t in i)i.hasOwnProperty(t)&&(s.hasOwnProperty(t)||i[t].forEach(function(e){r(e.scope,e.key,t,!1)}),h[t]=i[t][0]);for(t in s)s.hasOwnProperty(t)&&s[t]&&((o=s[t]).hasOwnProperty("key")&&r(n="workspace"===(n=o.scope)?"red-ui-workspace":n,o.key,t,!0));a()}),RED.userSettings.add({id:"keyboard",title:RED._("keyboard.keyboard"),get:w,focus:function(){setTimeout(function(){$("#red-ui-settings-tab-keyboard-filter").trigger("focus")},200)},close:function(){RED.menu.refreshShortcuts()}})},add:r,remove:s,getShortcut:function(e){return f[e]},getUserShortcut:m,revertToDefault:function(e){var t=f[e];t&&s(t.key),h.hasOwnProperty(e)&&r((t=h[e]).scope,t.key,e,!1)},formatKey:function(e,t){var o=n?e.replace(/ctrl-?/,"&#8984;"):e;return o=(o=(o=(o=(o=(o=n?o.replace(/alt-?/,"&#8997;"):e).replace(/shift-?/,"&#8679;")).replace(/left/,"&#x2190;")).replace(/up/,"&#x2191;")).replace(/right/,"&#x2192;")).replace(/down/,"&#x2193;"),t?o:'<span class="help-key-block"><span class="help-key">'+o.split(" ").join('</span> <span class="help-key">')+"</span></span>"},validateKey:function(e){var t=(e=e.trim()).split(" ");for(i=0;i<t.length;i++)if(!v(t[i]))return!1;return!0},disable:function(){t=!1},enable:function(){t=!0}}}(),RED.workspaces=function(){var a,s=0,i=0,t=[],n=[],o=0;let r,d;function l(e){o!==t.length&&t.splice(o),t.push(e),o=t.length}function c(o){n=n.filter(function(e){return e!==o&&(!Array.isArray(e)||(-1<(t=e.indexOf(o))&&e.splice(t,1),0!==e.length));var t})}function u(e,t,o){if(e)e.closeable||(e.hideable=!0),a.addTab(e,o),JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}")[e.id]&&a.hideTab(e.id),a.resize();else{for(var n=RED.nodes.id();i+=1,0!==$("#red-ui-workspace-tabs li[flowname='"+RED._("workspace.defaultName",{number:i})+"']").size(););e={type:"tab",id:n,disabled:!1,info:"",label:RED._("workspace.defaultName",{number:i}),env:[],hideable:!0},RED.nodes.addWorkspace(e,o),a.addTab(e,o),a.activateTab(n),t||(RED.history.push({t:"add",workspaces:[e],dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0))}return $("#red-ui-tab-"+e.id.replace(".","-")).attr("flowname",e.label),RED.view.focus(),e}function p(e){var t;1!==h&&(t=RED.nodes.getWorkspaceOrder(),e._index=t.indexOf(e.id),w(e),(t=RED.nodes.removeWorkspace(e.id)).t="delete",t.dirty=RED.nodes.dirty(),t.workspaces=[e],RED.history.push(t),RED.nodes.dirty(!0),RED.sidebar.config.refresh())}function f(e){var t=RED.nodes.workspace(e);t?RED.editor.editFlow(t):(t=RED.nodes.subflow(e))&&RED.editor.editSubflow(t)}var h=0;function e(){a=RED.tabs.create({id:"red-ui-workspace-tabs",onchange:function(e){var t={old:s};e?($("#red-ui-workspace-chart").show(),s=e.id,window.location.hash="flow/"+e.id,$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!e.disabled)):($("#red-ui-workspace-chart").hide(),s=0,window.location.hash=""),t.workspace=s,RED.events.emit("workspace:change",t),RED.sidebar.config.refresh(),RED.view.focus()},onclick:function(e){e.id!==s&&l(s),RED.view.focus()},ondblclick:function(e){"subflow"!=e.type?f(e.id):RED.editor.editSubflow(RED.nodes.subflow(e.id))},onadd:function(e){"tab"===e.type&&h++,$('<span class="red-ui-workspace-disabled-icon"><i class="fa fa-ban"></i> </span>').prependTo("#red-ui-tab-"+e.id.replace(".","-")+" .red-ui-tab-label"),e.disabled&&$("#red-ui-tab-"+e.id.replace(".","-")).addClass("red-ui-workspace-disabled"),RED.menu.setDisabled("menu-item-workspace-delete",0===s||h<=1),1===h&&($("#red-ui-workspace .red-ui-tabs").show(),$("#red-ui-workspace-chart").show(),$("#red-ui-workspace-footer").children().show())},onremove:function(e){"tab"===e.type?h--:n.push(e.id),RED.menu.setDisabled("menu-item-workspace-delete",0===s||h<=1),0===h&&g()},onreorder:function(e,t){RED.history.push({t:"reorder",workspaces:{from:e,to:t},dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),E(t)},onselect:function(e){RED.view.select(!1),0===e.length?($("#red-ui-workspace-chart svg").css({"pointer-events":"auto",filter:"none"}),$("#red-ui-workspace-toolbar").css({"pointer-events":"auto",filter:"none"}),$("#red-ui-palette-container").css({"pointer-events":"auto",filter:"none"}),$(".red-ui-sidebar-shade").hide()):(RED.view.select(!1),$("#red-ui-workspace-chart svg").css({"pointer-events":"none",filter:"opacity(60%)"}),$("#red-ui-workspace-toolbar").css({"pointer-events":"none",filter:"opacity(60%)"}),$("#red-ui-palette-container").css({"pointer-events":"none",filter:"opacity(60%)"}),$(".red-ui-sidebar-shade").show())},onhide:function(e){n.push(e.id);var t=JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");t[e.id]=!0,RED.settings.setLocal("hiddenTabs",JSON.stringify(t)),RED.events.emit("workspace:hide",{workspace:e.id})},onshow:function(e){c(e.id);var t=JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");delete t[e.id],RED.settings.setLocal("hiddenTabs",JSON.stringify(t)),RED.events.emit("workspace:show",{workspace:e.id})},minimumActiveTabWidth:150,scrollable:!0,addButton:"core:add-flow",addButtonCaption:RED._("workspace.addFlow"),menu:function(){var e=[{id:"red-ui-tabs-menu-option-search-flows",label:RED._("workspace.listFlows"),onselect:"core:list-flows"},{id:"red-ui-tabs-menu-option-search-subflows",label:RED._("workspace.listSubflows"),onselect:"core:list-subflows"},null,{id:"red-ui-tabs-menu-option-add-flow",label:RED._("workspace.addFlow"),onselect:"core:add-flow"},{id:"red-ui-tabs-menu-option-add-flow-right",label:RED._("workspace.addFlowToRight"),onselect:"core:add-flow-to-right"},null,{id:"red-ui-tabs-menu-option-add-hide-flows",label:RED._("workspace.hideFlow"),onselect:"core:hide-flow"},{id:"red-ui-tabs-menu-option-add-hide-other-flows",label:RED._("workspace.hideOtherFlows"),onselect:"core:hide-other-flows"},{id:"red-ui-tabs-menu-option-add-show-all-flows",label:RED._("workspace.showAllFlows"),onselect:"core:show-all-flows"},{id:"red-ui-tabs-menu-option-add-hide-all-flows",label:RED._("workspace.hideAllFlows"),onselect:"core:hide-all-flows"},{id:"red-ui-tabs-menu-option-add-show-last-flow",label:RED._("workspace.showLastHiddenFlow"),onselect:"core:show-last-hidden-flow"}];let o=new Set;for(let t=0;t<n.length;t++){let e=n[t];(e=Array.isArray(e)?e:[e]).forEach(e=>{RED.nodes.workspace(e)&&o.add(e)})}var t=o.size;return 0<t&&e.unshift({label:RED._("workspace.hiddenFlows",{count:t}),onselect:"core:list-hidden-flows"}),e}}),h=0}function g(){$("#red-ui-workspace .red-ui-tabs").hide(),$("#red-ui-workspace-chart").hide(),$("#red-ui-workspace-footer").children().hide()}function m(e){f(e||s)}function v(e){y(e,!1)}function b(e){y(e,!0)}function y(e,t){var o,n=RED.nodes.workspace(e||s);n&&n.disabled!==t&&(o={disabled:n.disabled},n.disabled=t,$("#red-ui-tab-"+n.id.replace(".","-")).toggleClass("red-ui-workspace-disabled",!!n.disabled),e&&e!==s||$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!n.disabled),t={t:"edit",changes:o,node:n,dirty:RED.nodes.dirty()},n.changed=!0,RED.history.push(t),RED.events.emit("flows:change",n),RED.nodes.dirty(!0),RED.sidebar.config.refresh(),(e=RED.view.selection()).nodes||e.links||n.id!==s||RED.sidebar.info.refresh(n),o.hasOwnProperty("disabled")&&(RED.nodes.eachNode(function(e){e.z===n.id&&(e.dirty=!0)}),RED.view.redraw()))}function w(e){e?(a.contains(e.id)&&a.removeTab(e.id),e.id===s&&(s=0)):p(RED.nodes.workspace(s))}function E(e){var t=e.filter(function(e){return void 0!==RED.nodes.workspace(e)}),o=RED.nodes.getWorkspaceOrder();JSON.stringify(t)!==JSON.stringify(o)&&(RED.nodes.setWorkspaceOrder(t),RED.events.emit("flows:reorder",t)),a.order(e)}return{init:function(){$('<ul id="red-ui-workspace-tabs"></ul>').appendTo("#red-ui-workspace"),$('<div id="red-ui-workspace-tabs-shade" class="hide"></div>').appendTo("#red-ui-workspace"),$('<div id="red-ui-workspace-chart" tabindex="1"></div>').appendTo("#red-ui-workspace"),$('<div id="red-ui-workspace-toolbar"></div>').appendTo("#red-ui-workspace"),$('<div id="red-ui-workspace-footer" class="red-ui-component-footer"></div>').appendTo("#red-ui-workspace"),$('<div id="red-ui-editor-shade" class="hide"></div>').appendTo("#red-ui-workspace"),e(),RED.events.on("sidebar:resize",a.resize),RED.actions.add("core:show-next-tab",function(){var e=s;a.nextTab(),e!==s&&l(e)}),RED.actions.add("core:show-previous-tab",function(){var e=s;a.previousTab(),e!==s&&l(e)}),RED.menu.setAction("menu-item-workspace-delete",function(){p(RED.nodes.workspace(s))}),$(window).on("resize",function(){a.resize()}),RED.actions.add("core:add-flow",function(e){u(void 0,void 0,e?e.index:void 0)}),RED.actions.add("core:add-flow-to-right",function(e){u(void 0,void 0,a.activeIndex()+1)}),RED.actions.add("core:edit-flow",m),RED.actions.add("core:remove-flow",w),RED.actions.add("core:enable-flow",v),RED.actions.add("core:disable-flow",b),RED.actions.add("core:hide-flow",function(){var e=a.selection(),t=(0===e.length&&(e=[{id:s}]),[]);e.forEach(function(e){RED.workspaces.hide(e.id),n.pop(),t.push(e.id)}),0<t.length&&n.push(t),a.clearSelection()}),RED.actions.add("core:hide-other-flows",function(){var e=a.selection(),t=(0===e.length&&(e=[{id:s}]),new Set(e.map(function(e){return e.id}))),e=a.listTabs(),o=[];e.forEach(function(e){t.has(e)||(RED.workspaces.hide(e),n.pop(),o.push(e))}),0<o.length&&n.push(o)}),RED.actions.add("core:hide-all-flows",function(){var e=a.listTabs();e.forEach(function(e){RED.workspaces.hide(e),n.pop()}),0<e.length&&n.push(e),a.clearSelection()}),RED.actions.add("core:show-all-flows",function(){a.listTabs().forEach(function(e){RED.workspaces.show(e,null,!0)})}),RED.actions.add("core:show-last-hidden-flow",function(){var e,t=n.pop();t&&("string"==typeof t?RED.workspaces.show(t):(e=t.pop(),t.forEach(function(e){RED.workspaces.show(e,null,!0)}),setTimeout(function(){RED.workspaces.show(e)},150)))}),RED.actions.add("core:list-modified-nodes",function(){RED.actions.invoke("core:search","is:modified ")}),RED.actions.add("core:list-hidden-flows",function(){RED.actions.invoke("core:search","is:hidden ")}),RED.actions.add("core:list-flows",function(){RED.actions.invoke("core:search","type:tab ")}),RED.actions.add("core:list-subflows",function(){RED.actions.invoke("core:search","type:subflow ")}),RED.actions.add("core:go-to-previous-location",function(){0<o&&(o===t.length&&t.push(s),RED.workspaces.show(t[--o],!0))}),RED.actions.add("core:go-to-next-location",function(){o<t.length-1&&RED.workspaces.show(t[++o],!0)}),g()},add:u,remove:w,delete:p,order:E,edit:m,contains:function(e){return a.contains(e)},count:function(){return h},active:function(){return s},selection:function(){return a.selection()},hide:function(e){e=e||s,a.contains(e)&&a.hideTab(e)},isHidden:function(e){return n.includes(e)},show:function(e,t,o,n){if(!a.contains(e)){var i=RED.nodes.subflow(e);if(!i)return;u({type:"subflow",id:e,icon:"red/images/subflow_tab.svg",label:i.name,closeable:!0},null,a.activeIndex()+1),c(e)}if(o?a.showTab(e):(t||s===e||l(s),a.activateTab(e)),n){i=e.replace(".","-");r&&r.length&&(clearInterval(d),d=null,r.removeClass("highlighted"),r=null);let t=$("#red-ui-tab-"+i);t&&t.length&&(d=setInterval(function(e){e>=Date.now()?(e=t.hasClass("highlighted"),t.toggleClass("highlighted",!e)):(clearInterval(d),d=null,r=null,t.removeClass("highlighted"))},100,Date.now()+2200),(r=t).addClass("highlighted"))}},refresh:function(){RED.nodes.eachWorkspace(function(e){a.renameTab(e.id,e.label),$("#red-ui-tab-"+e.id.replace(".","-")).attr("flowname",e.label)}),RED.nodes.eachSubflow(function(e){a.contains(e.id)&&a.renameTab(e.id,e.name)}),RED.sidebar.config.refresh()},resize:function(){a.resize()},enable:v,disable:b}}(),RED.statusBar=function(){var o,n,i={};return{init:function(){o=$('<span class="red-ui-statusbar-bucket red-ui-statusbar-bucket-left">').appendTo("#red-ui-workspace-footer"),n=$('<span class="red-ui-statusbar-bucket red-ui-statusbar-bucket-right">').appendTo("#red-ui-workspace-footer")},add:function(e){i[e.id]=e;var t=$('<span class="red-ui-statusbar-widget"></span>');t.prop("id",e.id),e.element.appendTo(t),"left"===e.align?o.append(t):"right"===e.align&&n.prepend(t)}}}(),RED.view=function(){var X,Y,Z,u,w=5e3,Q=5e3,h=.75,R=1,I=100,N=30,p=650,l=1e3,c=0,f=[],d=0,n={},E=20,ee=!1,te=!1,P=null,y=[],oe=[],ne=[],ie=[],x={},g=null,D=null,_=[],ae={},k=null,T=null,se=null,C=null,re=0,j=null,de=[0,0],A=null,M=0,L=null,S=null,le=null,ce=null,s=!1,ue=null,pe=null,fe=0,he=0,ge=[],O=null,me=-1,ve=!1,be=[];let r;var ye="";let we;var z,Ee,m,De,Re,xe,_e,$e,ke,Te,B,Ce,a,je,t,Le={red:"#c00",green:"#5a8",yellow:"#F9DF31",blue:"#53A3F3",grey:"#d3d3d3",gray:"#d3d3d3"},G=1,F=0,U=(Ce=new Set,a=[],je={add:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)je.add(e[t]);else if(!Ce.has(e.id)){a.push({n:e}),Ce.add(e.id);for(var o=RED.nodes.getNodeLinks(e.id,G).concat(RED.nodes.getNodeLinks(e.id,F)),t=0,n=o.length;t<n;t++){var i=o[t];(i.source===e&&Ce.has(i.target.id)||i.target===e&&Ce.has(i.source.id))&&V.add(i)}}},remove:function(e,t){if(Ce.has(e.id)){if(Ce.delete(e.id),void 0!==t&&a[t].n===e)a.splice(t,1);else for(var o=0;o<a.length;o++)if(a[o].n===e){a.splice(o,1);break}for(var n=RED.nodes.getNodeLinks(e.id,G).concat(RED.nodes.getNodeLinks(e.id,F)),o=0,i=n.length;o<i;o++)V.remove(n[o])}},clear:function(){Ce.clear(),a=[]},length:function(){return a.length},get:function(e){return a[e]},forEach:function(e){a.forEach(e)},nodes:function(){return a.map(function(e){return e.n})},has:function(e){return Ce.has(e.id)}}),V=(t=new Set,{add:function(e){t.add(e),e.selected=!0},remove:function(e){t.delete(e),e.selected=!1},clear:function(){t.forEach(function(e){e.selected=!1}),t.clear()},length:function(){return t.size},forEach:function(e){t.forEach(e)},has:function(e){return t.has(e)},toArray:function(){return Array.from(t)}});function Se(){for(var e=[],t=0;t<w;t+=+E)e.push(t);De.selectAll("line.red-ui-workspace-chart-grid-h").remove(),De.selectAll("line.red-ui-workspace-chart-grid-h").data(e).enter().append("line").attr({class:"red-ui-workspace-chart-grid-h",x1:0,x2:w,y1:function(e){return e},y2:function(e){return e}}),De.selectAll("line.red-ui-workspace-chart-grid-v").remove(),De.selectAll("line.red-ui-workspace-chart-grid-v").data(e).enter().append("line").attr({class:"red-ui-workspace-chart-grid-v",y1:0,y2:w,x1:function(e){return e},x2:function(e){return e}})}function Oe(e){me=-1;for(var t=0;t<e.length;t++){var o=e[t];o.el=_e.append("svg:path").attr("class","red-ui-flow-drag-line"),("link out"===o.node.type&&o.portType===F||"link in"===o.node.type&&o.portType===G)&&(o.el.attr("class","red-ui-flow-link-link red-ui-flow-drag-line"),o.virtualLink=!0,me=o.portType===F?G:F),B.push(o)}-1!==me&&y.forEach(function(e){"link in"!==e.type&&"link out"!==e.type||(e.dirty=!0)})}function Ie(){for(-1!==me&&y.forEach(function(e){"link in"!==e.type&&"link out"!==e.type||(e.dirty=!0)}),me=-1;B.length;){var e=B.pop();e.el&&e.el.remove()}}function J(){for(var e=RED.workspaces.active(),n=(0!==e?((y=RED.nodes.filterNodes({z:e})).forEach(function(e,t){e._index=t}),oe=RED.nodes.filterLinks({source:{z:e},target:{z:e}}),ne=RED.nodes.junctions(e)||[],(_=RED.nodes.groups(e)||[]).forEach(function(e,t){e._index=t,e.g?(e._root=e.g,e._depth=1):(e._root=e.id,e._depth=0)})):(y=[],oe=[],ne=[],_=[]),!1);n=!1,_.forEach(function(e){var t,o;e.g&&(t=RED.nodes.group(e.g))&&(o=t._depth,e._depth!==o+1&&(e._depth=o+1,n=!0),e._root!==t._root&&(e._root=t._root,n=!0))}),n;);_.sort(function(e,t){return e._root===t._root?e._depth-t._depth:e._index-t._index}),Te.selectAll(".red-ui-flow-group").data(_,function(e){return e.id}).sort(function(e,t){return e._root===t._root?e._depth-t._depth:e._index-t._index})}function Ne(e,t,o,n,i){var a,s,r,d,l,c=n-t,u=o-e,p=Math.sqrt(c*c+u*u),f=h;return 0<u*i?p<I&&(f=.75-(I-p)/I*.75):f=.4-.2*Math.max(0,(I-Math.min(Math.abs(u),Math.abs(c)))/I),0<u*i?"M "+e+" "+t+" C "+(e+i*(I*f))+" "+(t+0*N)+" "+(o-i*f*I)+" "+(n-0*N)+" "+o+" "+n:(p=Math.floor(o-u/2),u=Math.floor(n-c/2),a=N/2,d=(n+(u=0==c?n+N:u))/2,s=e+i*I*f,r=0<c?Math.min(d-c/2,t+a):Math.max(d-c/2,t-a),i=o-i*I*f,f=0<c?Math.max(d,n-a):Math.min(d,n+a),d=0<c?1:-1,(l=[[l=(e+s)/2,t],[s,0<c?Math.max(t,r-a):Math.min(t,r+a)],[l,0<c?Math.min(u,r+a):Math.max(u,r-a)],[i,0<c?Math.max(u,f-a):Math.min(u,f+a)],[(o+i)/2,n]])[2][1]===r+d*a&&(Math.abs(c)<10*a&&(l[1][1]=r-d*a/2,l[3][1]=f-d*a/2),l[2][0]=s),"M "+e+" "+t+" C "+l[0][0]+" "+l[0][1]+" "+l[1][0]+" "+l[1][1]+" "+s+" "+r+" S "+l[2][0]+" "+l[2][1]+" "+p+" "+u+" S "+l[3][0]+" "+l[3][1]+" "+i+" "+f+" S "+l[4][0]+" "+l[4][1]+" "+o+" "+n)}function Pe(){var e,t;RED.view.DEBUG&&console.warn("canvasMouseDown",{mouse_mode:M,point:d3.mouse(this),event:d3.event}),RED.contextMenu.hide(),M===RED.state.SELECTING_NODE?d3.event.stopPropagation():1===d3.event.button?(M=RED.state.PANNING,A=[d3.event.pageX,d3.event.pageY],ge=[z.scrollLeft(),z.scrollTop()]):2!==d3.event.button&&(T||k||se||d3.event.shiftKey||(V.clear(),W()),0===M&&L&&(L.remove(),L=null),!d3.event.touches&&0!==d3.event.button||(0!==M&&M!==RED.state.QUICK_JOINING||!d3.event.metaKey&&!d3.event.ctrlKey||d3.event.altKey||d3.event.shiftKey?0!==M||d3.event.metaKey||d3.event.ctrlKey||(d3.event.altKey?d3.event.altKey&&(q(),M=d3.event.shiftKey?RED.state.SLICING_JUNCTION:RED.state.SLICING,e=d3.mouse(this),S=m.append("path").attr("class","nr-ui-view-slice").attr("d",`M${e[0]} `+e[1]),le=e,RED.view.redraw()):d||(e=d3.mouse(this),L=m.append("rect").attr("ox",e[0]).attr("oy",e[1]).attr("rx",1).attr("ry",1).attr("x",e[0]).attr("y",e[1]).attr("width",0).attr("height",0).attr("class","nr-ui-view-lasso"),d3.event.preventDefault())):(d3.event.stopPropagation(),q(),t=Nt((e=d3.mouse(this))[0],e[1]),Ae({position:e,group:t=0<B.length?t||RED.nodes.group(B[0].node.g):t}))))}function Ae(e){function l(){var e,t,o;O&&(O.el||(O.el=_e.append("svg:path").attr("class","red-ui-flow-drag-line")),e=O.portType===F&&O.node.outputs||1,t=O.port,o=O.portType===F?1:-1,O.el.attr("d",Ne(O.node.x+o*O.node.w/2,O.node.y+(-(e-1)/2*13+13*t),p[0]-o*I/2,p[1],o)))}var t,c,u,p=(e=e||{}).position||be,f=e.splice,o=e.spliceMultiple,h=e.group,g=e.touchTrigger,e=(h&&!h.active&&(v(h,!1),b(h),RED.view.redraw()),p[0]),n=p[1],i=$("#red-ui-workspace-chart").offset(),a=e*R+i.left-$("#red-ui-workspace-chart").scrollLeft(),i=n*R+i.top-$("#red-ui-workspace-chart").scrollTop(),s=(RED.settings.get("editor").view["view-snap-grid"]&&(p[0]=Math.round(p[0]/E)*E,p[1]=Math.round(p[1]/E)*E),$("#red-ui-main-container").position());M!==RED.state.QUICK_JOINING&&(M=RED.state.QUICK_JOINING,$(window).on("keyup",it)),ce&&ce.remove(),(ce=m.append("g").attr("transform","translate("+(p[0]-I/2)+","+(p[1]-N/2)+")")).append("rect").attr("class","red-ui-flow-node-placeholder").attr("rx",5).attr("ry",5).attr("width",I).attr("height",N).attr("fill","none"),0<B.length&&(t=B[0].virtualLink?{type:"link in"===B[0].node.type?"link out":"link in"}:B[0].portType===F?{input:!0}:{output:!0},O={node:B[0].node,port:B[0].port,portType:B[0].portType},B[0].virtualLink&&(O.virtualLink=!0),Ie()),(f||o)&&(t={input:!0,output:!0,spliceMultiple:o});O&&l(),RED.typeSearch.show({x:a-s.left-I/2-(e-p[0]),y:i-s.top+N/2+5-(n-p[1]),disableFocus:g,filter:t,move:function(e,t){var o;ce&&(o=d3.transform(ce.attr("transform")).translate,ce.attr("transform","translate("+(o[0]+e)+","+(o[1]+t)+")"),p[0]+=e,p[1]+=t,l())},cancel:function(){O&&(O.el&&O.el.remove(),O=null),ce&&ce.remove(),K(),W(),Ie(),H()},add:function(e,t){var o;if(g&&(t=!1,K()),/^_action_:/.test(e))n=e.substring(9),ce.remove(),RED.actions.invoke(n);else{if("junction"===e)i={t:"add",junctions:[o={_def:{defaults:{}},type:"junction",z:RED.workspaces.active(),id:RED.nodes.id(),x:0,y:0,w:0,h:0,outputs:1,inputs:1,dirty:!0}]};else{var n=qt(e);if(!n)return;o=n.node,i=n.historyEvent}t&&(M=RED.state.QUICK_JOINING),o.x=p[0],o.y=p[1];var i,a,s,r,d,e=RED.utils.getMessageProperty(RED.settings.get("editor"),"view.view-node-show-label");void 0===e||o._def.hasOwnProperty("showLabel")&&!o._def.showLabel||o._def.defaults.hasOwnProperty("l")||(o.l=e),O?(n=null,(e=O).portType===F&&(0<o.inputs||e.virtualLink)?(n=e.node,r=e.port,d=o):e.portType===G&&(0<o.outputs||e.virtualLink)&&(n=o,d=e.node,r=0),null!==n?(e.virtualLink?(i={t:"multi",events:[i]},a=$.extend(!0,{},{v:n.links}).v,s=$.extend(!0,{},{v:d.links}).v,n.links.push(d.id),d.links.push(n.id),n.dirty=!0,d.dirty=!0,i.events.push({t:"edit",node:n,dirty:RED.nodes.dirty(),changed:n.changed,changes:{links:a}}),i.events.push({t:"edit",node:d,dirty:RED.nodes.dirty(),changed:d.changed,changes:{links:s}}),n.changed=!0,d.changed=!0):(RED.nodes.addLink(a={source:n,sourcePort:r,target:d}),i.links=[a]),t?(O.node=o,O.port=0):(O.el.remove(),O=null,M===RED.state.QUICK_JOINING&&(e.portType===F&&0<o.outputs?Oe([{node:o,port:0,portType:F}]):!O&&e.portType===G&&0<o.inputs?Oe([{node:o,port:0,portType:G}]):K()))):(Ie(),K())):t?0<o.outputs?O={node:o,port:0,portType:F}:0<o.inputs?O={node:o,port:0,portType:G}:K():M===RED.state.QUICK_JOINING&&(0<o.outputs?Oe([{node:o,port:0,portType:F}]):0<o.inputs?Oe([{node:o,port:0,portType:G}]):K()),"junction"===o.type?RED.nodes.addJunction(o):RED.nodes.add(o),RED.editor.validateNode(o),h&&(RED.group.addToGroup(h,o),(i="multi"!==i.t?{t:"multi",events:[i]}:i).events.push({t:"addToGroup",group:h,nodes:o})),f&&(K(),RED.nodes.removeLink(f),s={source:f.source,sourcePort:f.sourcePort,target:o},n={source:o,sourcePort:0,target:f.target},RED.nodes.addLink(s),RED.nodes.addLink(n),i.links=(i.links||[]).concat([s,n]),i.removedLinks=[f]),RED.history.push(i),RED.nodes.dirty(!0),q(),o.selected=!0,h&&(v(h,!1),b(h)),U.add(o),J(),W(),H(),void 0!==c&&(r=c+u/2,(d=o.x-o.w/2-r)!=2*E&&(o.x=o.x+2*E-d,o.dirty=!0,o.x=Math.ceil(o.x/E)*E,H())),t?(void 0===c&&setTimeout(function(){RED.typeSearch.refresh({filter:{input:!0}})},100),c=o.x,u=o.w,p[0]=o.x+o.w/2+I/2+2*E,ce.attr("transform","translate("+(p[0]-I/2)+","+(p[1]-N/2)+")"),l()):ce.remove()}}}),J(),W(),H()}function Me(){var c,e;if(M===RED.state.PANNING)l=[d3.event.pageX,d3.event.pageY],d3.event.touches&&(l=[(b=d3.event.touches.item(0)).pageX,b.pageY]),b=[A[0]-l[0],A[1]-l[1]],z.scrollLeft(ge[0]+b[0]),z.scrollTop(ge[1]+b[1]);else if(A=d3.touches(this)[0]||d3.mouse(this),L)l=parseInt(L.attr("ox")),b=parseInt(L.attr("oy")),e=parseInt(L.attr("x")),t=parseInt(L.attr("y")),l=A[0]<l?l-(e=A[0]):A[0]-e,b=A[1]<b?b-(t=A[1]):A[1]-t,L.attr("x",e).attr("y",t).attr("width",l).attr("height",b);else if(M===RED.state.SLICING||M===RED.state.SLICING_JUNCTION)S&&20<Math.max(1,Math.abs(le[0]-A[0]))*Math.max(1,Math.abs(le[1]-A[1]))&&(e=S.attr("d"),e+=" L"+A[0]+" "+A[1],S.attr("d",e),le=A);else if(M===RED.state.SELECTING_NODE)d3.event.stopPropagation();else if(M==RED.state.QUICK_JOINING||M==RED.state.IMPORT_DRAGGING||M==RED.state.DETACHED_DRAGGING||T||se||0!==V.length()){if(M==RED.state.JOINING||M===RED.state.QUICK_JOINING){if(0===B.length&&null!==C){if(d3.event.shiftKey){var t,o=[],n=[];for(0<V.length()?V.forEach(function(e){(C===F&&e.source===T&&e.sourcePort===re||C===G&&e.target===T)&&n.push(e)}):(t=C===F?{source:T,sourcePort:re}:{target:T},n=RED.nodes.filterLinks(t)),y=0;y<n.length;y++){var i=n[y];RED.nodes.removeLink(i),o.push({link:i,node:C===F?i.target:i.source,port:C===F?0:i.sourcePort,portType:C===F?G:F})}0===o.length?(K(),H()):(Oe(o),M=0,J(),H(),M=RED.state.JOINING)}else T&&!O&&Oe([{node:T,port:re,portType:C}]);V.clear()}for(u=A,y=0;y<B.length;y++){var a=B[y],s=a.portType===F&&a.node.outputs||1,r=a.port,d=a.portType===F?1:-1;a.el.attr("d",Ne(a.node.x+d*a.node.w/2,a.node.y+(-(s-1)/2*13+13*r),u[0],u[1],d))}d3.event.preventDefault()}else if(M==RED.state.MOVING){u=d3.mouse(document.body),isNaN(u[0])&&(u=d3.touches(document.body)[0]);var l=(de[0]-u[0])*(de[0]-u[0])+(de[1]-u[1])*(de[1]-u[1]);(3<l&&!pe||pe&&10<l)&&(M=RED.state.MOVING_ACTIVE,he=0,te=!1,1===U.length()&&(c=U.get(0),te=c.n.hasOwnProperty("_def")&&(c.n.hasOwnProperty("inputs")&&0<c.n.inputs||!c.n.hasOwnProperty("inputs")&&0<c.n._def.inputs)&&(c.n.hasOwnProperty("outputs")&&0<c.n.outputs||!c.n.hasOwnProperty("outputs")&&0<c.n._def.outputs)&&0===RED.nodes.filterLinks({source:c.n}).length&&0===RED.nodes.filterLinks({target:c.n}).length))}else if(M==RED.state.MOVING_ACTIVE||M==RED.state.IMPORT_DRAGGING||M==RED.state.DETACHED_DRAGGING){for(var u=A,p=0,f=0,h=w,g=Q,m=0;m<U.length();m++)c=U.get(m),d3.event.shiftKey&&(c.n.ox=c.n.x,c.n.oy=c.n.y),c.n.x=u[0]+c.dx,c.n.y=u[1]+c.dy,c.n.dirty=!0,g="group"===c.n.type?(!1!==c.n.groupMoved&&(c.n.groupMoved=!0),RED.group.markDirty(c.n),p=Math.min(c.n.x-5,p),f=Math.min(c.n.y-5,f),h=Math.max(c.n.x+c.n.w+5,h),Math.max(c.n.y+c.n.h+5,g)):(p=Math.min(c.n.x-c.n.w/2-5,p),f=Math.min(c.n.y-c.n.h/2-5,f),h=Math.max(c.n.x+c.n.w/2+5,h),Math.max(c.n.y+c.n.h/2+5,g));if(0!==p||0!==f)for(y=0;y<U.length();y++)(c=U.get(y)).n.x-=p,c.n.y-=f;if(h!==w||g!==Q)for(y=0;y<U.length();y++)(c=U.get(y)).n.x-=h-w,c.n.y-=g-Q;var v=[0,0];if(ee!=d3.event.shiftKey&&0<U.length()){for(var b,y=0;c=U.get(y++),y<U.length()&&"group"===c.n.type;);if("group"===c.n.type?(v[0]=c.n.x-E*Math.floor(c.n.x/E)-E/2,v[1]=c.n.y-E*Math.floor(c.n.y/E)-E/2):(b=RED.view.tools.calculateGridSnapOffsets(c.n),v[0]=b.x,v[1]=b.y),0!==v[0]||0!==v[1])for(y=0;y<U.length();y++)(c=U.get(y)).n.x-=v[0],c.n.y-=v[1],c.n.x==c.n.ox&&c.n.y==c.n.oy&&(c.dirty=!1)}1===U.length()&&"group"!==U.get(0).n.type&&(c=U.get(0),te&&(Y=Y||setTimeout(function(){for(var e,t=[],o=1/0,n=null,i=c.n.x,a=c.n.y,t=Ee[0][0].getIntersectionList?((e=Ee[0][0].createSVGRect()).x=i*R,e.y=a*R,e.width=1,e.height=1,Ee[0][0].getIntersectionList(e,Ee[0][0])):RED.view.getLinksAtPoint(i*R,a*R),s=0;s<t.length;s++)if(d3.select(t[s]).classed("red-ui-flow-link-background"))for(var r=t[s].getTotalLength(),d=0;d<r;d+=10){var l=t[s].getPointAtLength(d),l=(l.x-i)*(l.x-i)+(l.y-a)*(l.y-a);l<200&&l<o&&(o=l,n=t[s])}X&&X!==n&&d3.select(X.parentNode).classed("red-ui-flow-link-splice",!1),n?d3.select(n.parentNode).classed("red-ui-flow-link-splice",!0):d3.select(".red-ui-flow-link-splice").classed("red-ui-flow-link-splice",!1),X=n,Y=null},100)),"subflow"!==c.n.type&&!c.n.g&&_&&(Z=Z||setTimeout(function(){D=Nt(c.n.x,c.n.y);for(var e=0;e<_.length;e++){var t=_[e];t===D?(t.hovered=!0,t.dirty=!0):t.hovered&&(t.hovered=!1,t.dirty=!0)}Z=null},50)))}0!==M&&H()}}function ze(){0!==M&&0!==d3.event.buttons&&d3.select(document).on("mouseup.red-ui-workspace-tracker",function(){d3.select(document).on("mouseup.red-ui-workspace-tracker",null),Be.call(this)})}function Be(){var a,s,r,d;if(be=[d3.event.offsetX/R,d3.event.offsetY/R],RED.view.DEBUG&&console.warn("canvasMouseUp",{mouse_mode:M,point:d3.mouse(this),event:d3.event}),2!==d3.event.button)if(M===RED.state.PANNING)K();else if(M===RED.state.SELECTING_NODE)d3.event.stopPropagation();else if(M!==RED.state.QUICK_JOINING){if(T&&M==RED.state.JOINING){for(var e=[],t=0;t<B.length;t++)B[t].link&&e.push(B[t].link);0<e.length&&(f={t:"delete",links:e,dirty:RED.nodes.dirty()},RED.history.push(f),RED.nodes.dirty(!0)),Ie()}if(L?(a=parseInt(L.attr("x")),s=parseInt(L.attr("y")),r=a+parseInt(L.attr("width")),d=s+parseInt(L.attr("height")),o=g,d3.event.shiftKey||(q(),o&&a<o.x+o.w&&r>o.x&&s<o.y+o.h&&d>o.y&&(b(o),g.selected=!0)),_.forEach(function(e){if(!e.selected&&e.x>a&&e.x+e.w<r&&e.y>s&&e.y+e.h<d&&(!g||RED.group.contains(g,e))){for(;e.g&&(!g||e.g!==g.id);)e=RED.nodes.group(e.g);e.selected||v(e,!0)}}),y.forEach(function(e){if(!e.selected&&e.x>a&&e.x<r&&e.y>s&&e.y<d&&(!g||RED.group.contains(g,e)))if(!e.g||g&&e.g===g.id)e.selected=!0,e.dirty=!0,U.add(e);else{for(var t=RED.nodes.group(e.g);t.g&&(!g||t.g!==g.id);)t=RED.nodes.group(t.g);t.selected||v(t,!0)}}),ne.forEach(function(e){e.selected||e.x>a&&e.x<r&&e.y>s&&e.y<d&&(e.selected=!0,e.dirty=!0,U.add(e))}),oe.forEach(function(e){var t,o,n,i;e.selected||(t=e.source.y,o=e.target.y,n=e.source.x+e.source.w/2+10,i=e.target.x-e.target.w/2-10,a<n&&n<r&&s<t&&t<d&&a<i&&i<r&&s<o&&o<d&&V.add(e))}),P&&(P.in.forEach(function(e){e.selected=e.x>a&&e.x<r&&e.y>s&&e.y<d,e.selected&&(e.dirty=!0,U.add(e))}),P.out.forEach(function(e){e.selected=e.x>a&&e.x<r&&e.y>s&&e.y<d,e.selected&&(e.dirty=!0,U.add(e))}),P.status&&(P.status.selected=P.status.x>a&&P.status.x<r&&P.status.y>s&&P.status.y<d,P.status.selected&&(P.status.dirty=!0,U.add(P.status)))),W(),L.remove(),L=null):M!=RED.state.DEFAULT||null!=k||d3.event.ctrlKey||d3.event.metaKey?M==RED.state.SLICING?(Ye(),S.remove(),S=null,RED.view.redraw(!0)):M==RED.state.SLICING_JUNCTION&&(RED.actions.invoke("core:split-wires-with-junctions"),S.remove(),S=null):(q(),W()),M==RED.state.MOVING_ACTIVE&&0<U.length()){var o=null;if(D){for(var n=0;n<U.length();n++){var i=U.get(n);RED.group.addToGroup(D,i.n)}(o=D).hovered=!1,b(D),g.selected=!0,D=null}for(var l,c,u=[],n=0;n<U.length();n++)(i=U.get(n)).ox===i.n.x&&i.oy===i.n.y||(u.push({n:i.n,ox:i.ox,oy:i.oy,moved:i.n.moved}),i.n.dirty=!0,i.n.moved=!0);0<u.length&&M==RED.state.MOVING_ACTIVE&&(f={t:"move",nodes:u,dirty:RED.nodes.dirty()},X&&(l=d3.select(X).data()[0],RED.nodes.removeLink(l),p={source:l.source,sourcePort:l.sourcePort,target:U.get(0).n},c={source:U.get(0).n,sourcePort:0,target:l.target},RED.nodes.addLink(p),RED.nodes.addLink(c),f.links=[p,c],f.removedLinks=[l],J()),o&&(f.addToGroup=o),RED.nodes.dirty(!0),RED.history.push(f))}if(M==RED.state.MOVING||M==RED.state.MOVING_ACTIVE||M==RED.state.DETACHED_DRAGGING){if(M===RED.state.DETACHED_DRAGGING){for(u=[],n=0;n<U.length();n++)(i=U.get(n)).ox===i.n.x&&i.oy===i.n.y||(u.push({n:i.n,ox:i.ox,oy:i.oy,moved:i.n.moved}),i.n.dirty=!0,i.n.moved=!0);var p=RED.history.peek(),f={t:"move",nodes:u,dirty:RED.nodes.dirty()};("multi"===p.t?p.events:RED.history).push(f)}for(t=0;t<U.length();t++){var h=U.get(t);delete h.ox,delete h.oy}}M==RED.state.IMPORT_DRAGGING&&("cut"===we&&(we="copy"),J(),RED.nodes.dirty(!0)),K(),H()}}function Ge(){R<2&&e(R+.1)}function Fe(){.3<R&&e(R-.1)}function Ue(){e(1)}function Ve(){RED.actions.invoke("core:search",$(this).data("term"))}function Je(){RED.actions.invoke("core:search-previous")}function qe(){RED.actions.invoke("core:search-next")}function e(e){var t=[z.width(),z.height()],o=[z.scrollLeft(),z.scrollTop()],n=[(o[0]+t[0]/2)/R,(o[1]+t[1]/2)/R],t=(R=e,[(o[0]+t[0]/2)/R,(o[1]+t[1]/2)/R]),t=[(t[0]-n[0])*R,(t[1]-n[1])*R];z.scrollLeft(o[0]-t[0]),z.scrollTop(o[1]-t[1]),RED.view.navigator.resize(),H(),RED.settings.get("editor.view.view-store-zoom")&&RED.settings.setLocal("zoom-level",e.toFixed(1))}function We(){if(M!==RED.state.MOVING&&M!==RED.state.MOVING_ACTIVE){if(M===RED.state.DETACHED_DRAGGING){for(var e=0;e<U.length();e++){var t=U.get(e);t.n.x=t.ox,t.n.y=t.oy}q(),RED.history.pop(),M=0}else M===RED.state.IMPORT_DRAGGING?(q(),RED.history.pop(),M=0):M===RED.state.SLICING||M===RED.state.SLICING_JUNCTION?(S&&(S.remove(),S=null,K()),q()):L?(L.remove(),L=null):(g?Ot:q)();H()}}function Ke(){var e;M===RED.state.SELECTING_NODE&&u.single||(V.clear(),g?(e=g,q(),b(e),RED.group.getNodes(e,!1).forEach(function(e){"group"===e.type?v(e,!0,!0):(U.add(e),e.selected=!0,e.dirty=!0)}),g.selected=!0):(q(),Ot(),_.forEach(function(e){e.g?(e.selected=!1,e.dirty=!0):(v(e,!0),e.selected||(e.selected=!0,e.dirty=!0))}),y.forEach(function(e){M===RED.state.SELECTING_NODE&&u.filter&&!u.filter(e)||e.g||e.selected||(e.selected=!0,e.dirty=!0,U.add(e))}),ne.forEach(function(e){e.selected||(e.selected=!0,e.dirty=!0,U.add(e))}),M!==RED.state.SELECTING_NODE&&P&&(P.in.forEach(function(e){e.selected||(e.selected=!0,e.dirty=!0,U.add(e))}),P.out.forEach(function(e){e.selected||(e.selected=!0,e.dirty=!0,U.add(e))}),P.status&&!P.status.selected&&(P.status.selected=!0,P.status.dirty=!0,U.add(P.status)))),M!==RED.state.SELECTING_NODE&&W(),H())}function q(){RED.view.DEBUG&&console.warn("clearSelection",M,"movingSet.length():",U.length());for(var e=0;e<U.length();e++){var t=U.get(e);t.n.dirty=!0,t.n.selected=!1}U.clear(),V.clear(),g&&(g.active=!1,g.dirty=!0,g=null),_.forEach(function(e){e.selected=!1,e.dirty=!0})}var He=null;function W(){var e={},t=RED.workspaces.active(),o=RED.workspaces.selection();if(0!==t)if(0===o.length){e=Jt(),oe=RED.nodes.filterLinks({source:{z:t},target:{z:t}});RED.nodes.getWorkspaceOrder();var n={};ie=[],Object.keys(x).forEach(function(e){x[e].dirty=!0}),x={};for(var i=0;i<U.length();i++){var a,s,r=U.get(i);("link out"===r.n.type&&"return"!==r.n.mode||"link in"===r.n.type)&&r.n.z===t&&(a=r.n,x[a.id]=a,s={},a.links.forEach(function(e){e=RED.nodes.node(e);e&&("link out"===a.type?e.z===a.z?n[a.id+":"+e.id]||(oe.push({source:a,sourcePort:0,target:e,link:!0}),n[a.id+":"+e.id]=!0,(x[e.id]=e).dirty=!0):(s[e.z]=s[e.z]||[],s[e.z].push(e)):e.z===a.z?n[e.id+":"+a.id]||(oe.push({source:e,sourcePort:0,target:a,link:!0}),n[e.id+":"+a.id]=!0,(x[e.id]=e).dirty=!0):(s[e.z]=s[e.z]||[],s[e.z].push(e)))}),0<Object.keys(s).length&&ie.push({refresh:Math.floor(1e4*Math.random()),node:a,links:s}))}0===ie.length&&0<V.length()&&V.forEach(function(e){e.link&&(oe.push(e),x[e.source.id]=e.source,e.source.dirty=!0,x[e.target.id]=e.target,e.target.dirty=!0)})}else e.flows=o;o=t+":"+JSON.stringify(e,function(e,t){return"nodes"===e||"flows"===e?t.map(function(e){return e.id}):"link"===e?t.source.id+":"+t.sourcePort+":"+t.target.id:"links"===e?t.map(function(e){return e.source.id+":"+e.sourcePort+":"+e.target.id}):t});o!==He&&(He=o,RED.events.emit("view:selection-changed",e))}function Xe(){var e;0<U.length()&&("subflow"===(e=U.get(0).n).type?RED.editor.editSubflow(P):"group"===e.type?RED.editor.editGroup(e):RED.editor.edit(e))}function Ye(e){if(M!==RED.state.SELECTING_NODE){dt&&(dt.remove(),dt=null);var t=RED.workspaces.selection();if(0<t.length){var o=0;if(t.forEach(function(e){"tab"===e.type&&o++}),o!==RED.workspaces.count()){for(var n={t:"delete",dirty:RED.nodes.dirty(),nodes:[],links:[],groups:[],junctions:[],workspaces:[],subflows:[]},i=RED.nodes.getWorkspaceOrder().slice(0),a=0;a<t.length;a++){var s,r=t[a];r._index=i.indexOf(r.id),RED.workspaces.remove(r),"tab"===r.type?(n.workspaces.push(r),s=RED.nodes.removeWorkspace(r.id)):(s=RED.subflow.removeSubflow(r.id),n.subflows=n.subflows.concat(s.subflows)),n.nodes=n.nodes.concat(s.nodes),n.links=n.links.concat(s.links),n.groups=n.groups.concat(s.groups),n.junctions=n.junctions.concat(s.junctions)}RED.history.push(n),RED.nodes.dirty(!0),J(),W(),H()}}else if(0<U.length()||0<V.length()){function d(e){e&&(Array.isArray(e)?e:[e]).forEach(function(e){u.push(e),V.remove(e)})}var l,c=[],u=[],p=[],f=[],h=[],g=[],m=[],v=[],b=(e&&(0<(b=(e=RED.nodes.detachNodes(U.nodes())).newLinks).length&&v.push({t:"add",links:b}),d(e.removedLinks)),RED.nodes.dirty()),y=[];if(0<U.length()){for(a=0;a<U.length();a++)"group"===(R=U.get(a).n).type&&y.push(R);for(a=0;a<y.length;a++)y[a].nodes.forEach(function(e){"group"===e.type&&-1===y.indexOf(e)&&y.push(e)});for(var w,E,D,R,a=0;a<U.length();a++)(R=U.get(a).n).selected=!1,"group"!==R.type&&"subflow"!==R.type&&"junction"!==R.type?(R.x<0&&(R.x=25),w=RED.nodes.remove(R.id),c.push(R),c=c.concat(w.nodes),d(w.links),R.g&&(w=RED.nodes.group(R.g),-1===y.indexOf(w)&&(E=w.nodes.indexOf(R),w.nodes.splice(E,1),RED.group.markDirty(w)))):"junction"===R.type?(D=RED.nodes.removeJunction(R),f.push(R),u=u.concat(D.links)):("out"===R.direction?h.push(R):"in"===R.direction?g.push(R):"status"===R.direction&&(l=R),R.dirty=!0);for(a=y.length-1;0<=a;a--){var x=y[a];p.push(x),RED.nodes.removeGroup(x)}0<h.length&&(D=RED.subflow.removeOutput(h))&&d(D.links),1==g.length&&(D=RED.subflow.removeInput())&&d(D.links),l&&(D=RED.subflow.removeStatus())&&d(D.links);e=RED.subflow.refresh(!0);e&&(m=e.instances),U.clear(),(0<c.length||0<h.length||0<g.length||l||0<p.length||0<f.length)&&RED.nodes.dirty(!0)}0<V.length()&&V.forEach(function(e){var t,o;e.link?(t=e.source.id,o=e.target.id,t=e.target.links.indexOf(t),o=e.source.links.indexOf(o),v.push({t:"edit",node:e.source,changed:e.source.changed,changes:{links:$.extend(!0,{},{v:e.source.links}).v}}),v.push({t:"edit",node:e.target,changed:e.target.changed,changes:{links:$.extend(!0,{},{v:e.target.links}).v}}),e.source.changed=!0,e.target.changed=!0,e.target.links.splice(t,1),e.source.links.splice(o,1),e.source.dirty=!0,e.target.dirty=!0):(RED.nodes.removeLink(e),u.push(e))}),RED.nodes.dirty(!0);n={t:"delete",nodes:c,links:u,groups:p,junctions:f,subflowOutputs:h,subflowInputs:g,subflow:{id:P?P.id:void 0,instances:m},dirty:b};l&&(n.subflow.status=l),0<v.length?(v.unshift(n),RED.history.push({t:"multi",events:v})):RED.history.push(n),V.clear(),J(),W(),H()}}}function Ze(e){if(M!==RED.state.SELECTING_NODE){var t=[],o=RED.workspaces.selection();if(0<o.length?(t=[],o.forEach(function(e){"tab"===e.type&&(t.push(e),t=(t=t.concat(RED.nodes.groups(e.id))).concat(RED.nodes.filterNodes({z:e.id})))})):(o=RED.view.selection()).nodes&&o.nodes.forEach(function(e){t.push(e),"group"===e.type&&(t=t.concat(RED.group.getNodes(e,!0)))}),0<t.length){for(var n=[],i=0,a=0,s={},r=0;r<t.length;r++){var d=t[r];if(!s[d.id]&&(s[d.id]=!0,"subflow"!=d.type)){for(var l in"group"===d.type?a++:"junction"===d.type?0:i++,d._def.defaults)d._def.defaults.hasOwnProperty(l)&&d._def.defaults[l].type&&(l=RED.nodes.node(d[l]))&&l._def.exclusive&&n.push(RED.nodes.convertNode(l));n.push(RED.nodes.convertNode(d))}}ye=JSON.stringify(n),we=e?"cut":"copy",RED.menu.setDisabled("menu-item-edit-paste",!1),0<i?RED.notify(RED._("clipboard.nodeCopied",{count:i}),{id:"clipboard"}):0<a&&RED.notify(RED._("clipboard.groupCopied",{count:a}),{id:"clipboard"})}}}function Qe(e,t){for(var o=nt(e),n=0,i=0;i<o.length;i++){var a=ot(o[i],t)[0];n<a&&(n=a)}return{lines:o,width:n}}var et={},tt={};function ot(e,t){var o="!"+e;if(et[t]){if(tt[t][o])return tt[t][o]}else et[t]=document.createElement("span"),et[t].className=t,et[t].style.position="absolute",et[t].style.top="-1000px",document.getElementById("red-ui-editor").appendChild(et[t]),tt[t]={};et[t].textContent=e||"";var e=et[t].offsetWidth,n=et[t].offsetHeight;return tt[t][o]=[e,n],tt[t][o]}function nt(e){var t=[],o=e.split(/\\n /);if(1<o.length){for(var n=0,n=0;n<o.length-1;n++)/\\$/.test(o[n])?(t.push(o[n]+"\\n "+o[n+1]),n++):t.push(o[n]);n===o.length-1&&t.push(o[o.length-1])}else t=o;return t=t.map(function(e){return e.replace(/\\\\n /g,"\\n ").trim()})}function K(){M=0,X=C=k=j=se=T=null,te=!1,D&&(D.hovered=!1,D=null),d3.selectAll(".red-ui-flow-link-splice").classed("red-ui-flow-link-splice",!1),Y&&(clearTimeout(Y),Y=null),Z&&(clearTimeout(Z),Z=null)}function it(e){17!==e.keyCode&&"Meta"!==e.key&&91!==e.keyCode||(K(),Ie(),H(),$(window).off("keyup",it))}function at(e,t,o,n){RED.view.DEBUG&&console.warn("portMouseDown",M,e,t,o),RED.contextMenu.hide(),1!==(n=n||d3.event)&&(M===RED.state.SELECTING_NODE?n.stopPropagation():(T=e,C=t,re=o||0,M!==RED.state.QUICK_JOINING&&(M=RED.state.JOINING,document.body.style.cursor="crosshair",(n.ctrlKey||n.metaKey)&&(M=RED.state.QUICK_JOINING,Oe([{node:T,port:re,portType:C}]),$(window).on("keyup",it))),n.stopPropagation(),n.preventDefault()))}function st(e,n,i,t){if(RED.view.DEBUG&&console.warn("portMouseUp",M,e,n,i),t=t||d3.event,M===RED.state.SELECTING_NODE)t.stopPropagation();else{if(M===RED.state.QUICK_JOINING&&0<B.length){if(B[0].node===e)return;if(B[0].virtualLink&&("link in"===B[0].node.type&&"link out"!==e.type||"link out"===B[0].node.type&&"link in"!==e.type))return}if(document.body.style.cursor="",M==RED.state.JOINING||M==RED.state.QUICK_JOINING){if("undefined"!=typeof TouchEvent&&t instanceof TouchEvent){var a=!1;if(RED.nodes.eachNode(function(e){var t,o;e.z==RED.workspaces.active()&&(t=e.w/2,o=e.h/2,e.x-t<A[0]&&e.x+t>A[0]&&e.y-o<A[1]&&e.y+o>A[1]&&(a=!0,n=0<(j=e).inputs?G:F,i=0))}),!a&&P){var o=[];P.status&&o.push(P.status),P.in&&(o=o.concat(P.in)),P.out&&(o=o.concat(P.out));for(var s=0;s<o.length;s++){var r=o[s],d=r.w/2,l=r.h/2;if(r.x-d<A[0]&&r.x+d>A[0]&&r.y-l<A[1]&&r.y+l>A[1]){a=!0,n="in"===(j=r).direction?F:G,i=0;break}}}}else j=e;var c=[],u=[],p=[],f=null;for(s=0;s<B.length;s++)B[s].link&&u.push(B[s].link);var h,g,m,v,b,y,w,E,D=[];for(s=0;s<B.length;s++)n!=B[s].portType&&j!==B[s].node&&((h=B[s]).portType===F?(g=h.node,v=h.port,m=j):h.portType===G&&(g=j,m=h.node,v=i||0),b={source:g,sourcePort:v,target:m},h.virtualLink?/^link (in|out)$/.test(g.type)&&/^link (in|out)$/.test(m.type)&&g.type!==m.type&&-1===g.links.indexOf(m.id)&&-1===m.links.indexOf(g.id)&&(y=$.extend(!0,{},{v:g.links}).v,w=$.extend(!0,{},{v:m.links}).v,g.links.push(m.id),m.links.push(g.id),g.dirty=!0,m.dirty=!0,p.push(g),p.push(m),b.link=!0,oe.push(b),x[g.id]=g,x[m.id]=m,f=b,D.push({t:"edit",node:g,dirty:RED.nodes.dirty(),changed:g.changed,changes:{links:y}}),D.push({t:"edit",node:m,dirty:RED.nodes.dirty(),changed:m.changed,changes:{links:w}}),g.changed=!0,m.changed=!0):"link out"===e.type&&n===F||"link in"===e.type&&n===G||n===F&&"subflow"!==j.type&&0===j.outputs||n===G&&"subflow"!==j.type&&0===j.inputs||h.portType===G&&"subflow"===j.type&&("status"===j.direction||"out"===j.direction)||h.portType===F&&"subflow"===j.type&&"in"===j.direction||0!==RED.nodes.filterLinks({source:g,target:m,sourcePort:v}).length||(RED.nodes.addLink(b),c.push(b)));(0<c.length||0<u.length||0<p.length)&&(t=0<p.length?{t:"multi",events:D,dirty:RED.nodes.dirty()}:{t:"add",links:c,removedLinks:u,dirty:RED.nodes.dirty()},P&&(E=RED.subflow.refresh(!0))&&(t.subflow={id:P.id,changed:P.changed,instances:E.instances}),RED.history.push(t),J(),RED.nodes.dirty(!0)),M===RED.state.QUICK_JOINING?((0<c.length||0<p.length)&&(Ie(),n===G&&0<e.outputs?Oe([{node:e,port:0,portType:F}]):n===F&&0<e.inputs?Oe([{node:e,port:0,portType:G}]):K(),(k=f)?(V.clear(),V.add(f),W()):V.clear()),H()):(K(),Ie(),f&&(V.clear(),V.add(f)),(k=f)&&W(),H())}}}var o,rt=null,dt=null;function lt(e){var t=d3.select(e);if("red-ui-workspace-chart-event-layer"===t.attr("class"))return[0,0];var o=[0,0],n=("g"===e.nodeName.toLowerCase()?(n=t.attr("transform"))&&(o=d3.transform(n).translate):o=[t.attr("x")||0,t.attr("y")||0],lt(e.parentNode));return[o[0]+n[0],o[1]+n[1]]}function ct(t,o,e){var n,i=o===G?t.inputLabels:t.outputLabels;if(i&&i[e])return i[e];i=o===G?t._def.inputLabels:t._def.outputLabels;if("string"==typeof i)n=i;else if("function"==typeof i)try{n=i.call(t,e)}catch(e){console.log("Definition error: "+t.type+"."+(o===G?"inputLabels":"outputLabels"),e),n=null}else $.isArray(i)&&(n=i[e]);return n}function ut(e,t,o,n){var i,a,s,r=m.append("g").attr("transform","translate("+e+","+t+")").attr("class","red-ui-flow-port-tooltip"),e=o.indexOf("\\n "),t=(o=-1<e&&"\\"!==o[e-1]?o.substring(0,e)+"...":o).split("\n"),d=6,l=12,c=[],u=0,e=(t.forEach(function(e,t){e=ot(e||"&nbsp;","red-ui-flow-port-tooltip-label");d=Math.max(d,e[0]+14),c.push(e[1]),0===t&&(u=e[1]),l+=e[1]}),d/2-5-2),o=l/2-5-2,p=l-4,f=-l/2;return"left"===n?(i="M0 0 l -5 -5 v -"+o+" q 0 -2 -2 -2 h -"+d+" q -2 0 -2 2 v "+p+" q 0 2 2 2 h "+d+" q 2 0 2 -2 v -"+o+" l 5 -5",a=-14,s="end"):"right"===n?(i="M0 0 l 5 -5 v -"+o+" q 0 -2 2 -2 h "+d+" q 2 0 2 2 v "+p+" q 0 2 -2 2 h -"+d+" q -2 0 -2 -2 v -"+o+" l -5 -5",a=14,s="start"):"top"===n&&(i="M0 0 l 5 -5 h "+e+" q 2 0 2 -2 v -"+l+" q 0 -2 -2 -2 h -"+(d-4)+" q -2 0 -2 2 v "+l+" q 0 2 2 2 h "+e+" l 5 5",a=-d/2+6,f=-l-u+12,s="start"),r.append("path").attr("d",i),t.forEach(function(e,t){f+=c[t],r.append("svg:text").attr("class","red-ui-flow-port-tooltip-label").attr("x",a).attr("y",f).attr("text-anchor",s).text(e||" ")}),r}function pt(o,n,i,a){var e;M===RED.state.SELECTING_NODE?d3.event.stopPropagation():(clearTimeout(rt),(e=M!=RED.state.JOINING&&M!=RED.state.QUICK_JOINING||0<B.length&&B[0].portType!==i&&(!B[0].virtualLink||"link in"===B[0].node.type&&"link out"===n.type||"link out"===B[0].node.type&&"link in"===n.type))&&(i===G&&(n._def&&n._def.inputLabels||n.inputLabels)||i===F&&(n._def&&n._def.outputLabels||n.outputLabels))&&(rt=setTimeout(function(){var e,t=o&&o.node();t&&t.__data__&&t.__data__.id;t&&t.parentNode&&RED.nodes.node(t.__data__.id)&&((e=ct(n,i,a))&&(t=lt(t),rt=null,dt=ut(t[0]+(i===G?-2:12),t[1]+5,e,i===G?"left":"right")))},500)),o.classed("red-ui-flow-port-hovered",e))}function ft(e){M===RED.state.SELECTING_NODE?d3.event.stopPropagation():(clearTimeout(rt),dt&&(dt.remove(),dt=null),e.classed("red-ui-flow-port-hovered",!1))}function ht(e){for(M=RED.state.MOVING,i=0;i<U.length();i++){var t=U.get(i);t.ox=t.n.x,t.oy=t.n.y,t.dx=t.n.x-e[0],t.dy=t.n.y-e[1]}try{de=d3.mouse(document.body),isNaN(de[0])&&(de=d3.touches(document.body)[0])}catch(e){de=[0,0]}}function gt(e){if(RED.view.DEBUG&&console.warn("nodeMouseUp",M,e),M===RED.state.SELECTING_NODE)d3.event.stopPropagation();else if(pe&&T==e&&0<he&&he<p)M=RED.state.DEFAULT,"subflow"!=e.type?/^subflow:/.test(e.type)&&(d3.event.ctrlKey||d3.event.metaKey)?RED.workspaces.show(e.type.substring(8)):RED.editor.edit(e):RED.editor.editSubflow(P),he=0,d3.event.stopPropagation();else{if(M===RED.state.MOVING)if(!ve&&!e.selected&&e.g&&RED.nodes.group(e.g).selected)return q(),v(RED.nodes.group(e.g),!1),b(RED.nodes.group(e.g)),T.selected=!0,U.add(T),(t=d3.touches(this)[0]||d3.mouse(this))[0]+=e.x-e.w/2,t[1]+=e.y-e.h/2,ht(t),void W();ve=!1;var t=e._def?0<e.inputs?1:0:"in"==e.direction?0:1,o=!1;M!==RED.state.JOINING&&M!==RED.state.QUICK_JOINING||(o=!0,0<B.length&&(B[0].virtualLink?"link in"===e.type?t=1:"link out"===e.type&&(t=0):t=1===B[0].portType?F:G)),st(e,t,0),o&&d3.selectAll(".red-ui-flow-port-hovered").classed("red-ui-flow-port-hovered",!1)}}function mt(e){if(RED.view.DEBUG&&console.warn("nodeMouseDown",M,e),Ft(),RED.contextMenu.hide(),1!==d3.event.button)if(M==RED.state.IMPORT_DRAGGING||M==RED.state.DETACHED_DRAGGING){var t=RED.history.peek();if(X&&(c=d3.select(X).data()[0],RED.nodes.removeLink(c),a={source:c.source,sourcePort:c.sourcePort,target:U.get(0).n},r={source:U.get(0).n,sourcePort:0,target:c.target},RED.nodes.addLink(a),RED.nodes.addLink(r),t.links=[a,r],t.removedLinks=[c],J()),D){for(var o=0;o<U.length();o++){var n=U.get(o);RED.group.addToGroup(D,n.n)}(t.addedToGroup=D).hovered=!1,b(D),g.selected=!0,D=null}if(M==RED.state.DETACHED_DRAGGING){for(var i=[],o=0;o<U.length();o++)(n=U.get(o)).ox===n.n.x&&n.oy===n.n.y||(i.push({n:n.n,ox:n.ox,oy:n.oy,moved:n.n.moved}),n.n.dirty=!0,n.n.moved=!0);RED.history.replace({t:"multi",events:[t,{t:"move",nodes:i}],dirty:t.dirty})}W(),RED.nodes.dirty(!0),H(),"cut"===we&&(we="copy"),K(),d3.event.stopPropagation()}else if(M==RED.state.QUICK_JOINING)d3.event.stopPropagation();else{if(M===RED.state.SELECTING_NODE)return d3.event.stopPropagation(),"junction"===e.type?void 0:u.single?void u.done(e):(e.selected?(e.selected=!1,U.remove(e)):u.filter&&!u.filter(e)||(e.selected=!0,U.add(e)),e.dirty=!0,void H());T=e;var a=Date.now();if(he=a-fe,fe=a,pe=ue==T&&(d3.event.touches||0===d3.event.button)&&!d3.event.shiftKey&&!d3.event.altKey&&he<p&&"junction"!==e.type,ue=T,!e.selected&&e.g){var s,r=RED.nodes.group(e.g);if(r!==g&&(d3.event.ctrlKey||d3.event.metaKey))ve=(g&&r.g===g.id||Ot(),!0),r.selected?It(r):v(r,!0);else if(r===g)if(d3.event.shiftKey){d3.event.ctrlKey||d3.event.metaKey||(l=g,q(),b(l),g.selected=!0);for(var d=RED.nodes.getAllFlowNodes(T),n=0;n<d.length;n++)d[n].selected||(d[n].selected=!0,d[n].dirty=!0,U.add(d[n]))}else d3.event.ctrlKey||d3.event.metaKey||(l=g,q(),It(r),v(r,!1,!1),l&&(b(l),g.selected=!0)),T.selected=!0,U.add(T);else{ve=!r.selected;var l=g;r.selected||q(),l?l!==r&&l.id!==r.g?(l.active=!1,l.dirty=!0):(g=l).active=!0:pe=!1,v(r,!(g&&g===r),!!ve),g&&g===r&&(T.selected=!0,U.add(T))}2!=d3.event.button&&((s=d3.touches(this)[0]||d3.mouse(this))[0]+=e.x-e.w/2,s[1]+=e.y-e.h/2,ht(s))}else if(e.selected&&(d3.event.ctrlKey||d3.event.metaKey))T.selected=!1,U.remove(T);else{if(d3.event.shiftKey){d3.event.ctrlKey||d3.event.metaKey||q();var c=d3.event.offsetX/R-T.x;d=(T.w||10)/2-Math.abs(c)<(30<T.w?25:0<T.w?8:3)?[T].concat(c<0?RED.nodes.getAllUpstreamNodes(T):RED.nodes.getAllDownstreamNodes(T)):RED.nodes.getAllFlowNodes(T);for(n=0;n<d.length;n++)d[n].selected=!0,d[n].dirty=!0,U.add(d[n])}else e.selected||((d3.event.ctrlKey||d3.event.metaKey?Ot:q)(),T.selected=!0,U.add(T));2!=d3.event.button&&(M=RED.state.MOVING,(s=d3.touches(this)[0]||d3.mouse(this))[0]+=e.x-e.w/2,s[1]+=e.y-e.h/2,ht(s))}e.dirty=!0,W(),H(),d3.event.stopPropagation()}}function vt(e){RED.view.DEBUG&&console.warn("nodeTouchStart",M,e);var t=d3.select(this),o=d3.event.touches.item(0),n=[o.pageX,o.pageY];f=[o.pageX,o.pageY],c=0,d=setTimeout(function(){Mt(t,n)},l),mt.call(this,e),d3.event.preventDefault()}function bt(e){RED.view.DEBUG&&console.warn("nodeTouchEnd",M,e),d3.event.preventDefault(),clearTimeout(d),d=null,RED.touch.radialMenu.active()?d3.event.stopPropagation():gt.call(this,e)}function yt(o){var n,e,t;RED.view.DEBUG&&console.warn("nodeMouseOver",M,o),0===M||M===RED.state.SELECTING_NODE?(M===RED.state.SELECTING_NODE&&u&&u.filter&&!u.filter(o)||this.parentNode.classList.add("red-ui-flow-node-hovered"),clearTimeout(rt),(o.hasOwnProperty("l")?o.l:"link in"!==o.type&&"link out"!==o.type)||(n=this.parentNode,rt=setTimeout(function(){if(n&&n.parentNode&&RED.nodes.node(n.id)){var t,e;if(o._def.label){t=o._def.label;try{t=("function"==typeof t?t.call(o):t)||""}catch(e){console.log("Definition error: "+o.type+".label",e),t=o.type}}""!==t&&(e=lt(n),rt=null,dt=ut(e[0]+o.w/2,e[1]-1,t,"top"))}},500))):M!==RED.state.JOINING&&M!==RED.state.QUICK_JOINING||0<B.length&&(t=B[0].virtualLink&&B[0].portType===G||B[0].portType===F?(e=".red-ui-flow-port-input .red-ui-flow-port",G):(e=".red-ui-flow-port-output .red-ui-flow-port",F),pt(d3.select(this.parentNode).selectAll(e),o,t,0))}function wt(e){var t;RED.view.DEBUG&&console.warn("nodeMouseOut",M,e),this.parentNode.classList.remove("red-ui-flow-node-hovered"),clearTimeout(rt),dt&&(dt.remove(),dt=null),M!==RED.state.JOINING&&M!==RED.state.QUICK_JOINING||0<B.length&&(B[0].virtualLink&&B[0].portType===G||B[0].portType===F?t=".red-ui-flow-port-input .red-ui-flow-port":t=".red-ui-flow-port-output .red-ui-flow-port",ft(d3.select(this.parentNode).selectAll(t)))}function Et(e){at(this.__data__,this.__portType__,this.__portIndex__,e)}function Dt(e){at(this.__data__,this.__portType__,this.__portIndex__,e),e.preventDefault()}function Rt(e){st(this.__data__,this.__portType__,this.__portIndex__,e)}function xt(e){st(this.__data__,this.__portType__,this.__portIndex__,e),e.preventDefault()}function _t(e){pt(d3.select(this),this.__data__,this.__portType__,this.__portIndex__)}function $t(e){ft(d3.select(this),this.__data__,this.__portType__,this.__portIndex__)}function kt(e){var t,o;t=d3.select(this),this.__data__,o=void 0===(o=this.__portType__)||M!==RED.state.JOINING&&M!==RED.state.QUICK_JOINING||0<B.length&&B[0].portType!==o&&!B[0].virtualLink,t.classed("red-ui-flow-junction-hovered",o)}function Tt(e){var t;t=d3.select(this),this.__data__,t.classed("red-ui-flow-junction-hovered",!1)}function Ct(e){var t;RED.view.DEBUG&&console.warn("linkMouseDown",{mouse_mode:M,point:d3.mouse(this),event:d3.event}),RED.contextMenu.hide(),M===RED.state.SELECTING_NODE?d3.event.stopPropagation():2!==d3.event.button&&(k=e,d3.event.metaKey||d3.event.ctrlKey||q(),(d3.event.metaKey||d3.event.ctrlKey)&&V.has(k)?1!==V.length()&&V.remove(k):V.add(k),W(),H(),Ft(),d3.event.stopPropagation(),k.link||0!==U.length()||!d3.event.touches&&0!==d3.event.button||1!==V.length()||!V.has(k)||!d3.event.metaKey&&!d3.event.ctrlKey||(d3.select(this).classed("red-ui-flow-link-splice",!0),t=Nt((e=d3.mouse(this))[0],e[1]),Ae({position:e,splice:k,group:t})))}function jt(e){var t,o;M===RED.state.SELECTING_NODE?d3.event.stopPropagation():(k=e,q(),V.clear(),V.add(k),W(),H(),Ft(),d3.event.stopPropagation(),t=d3.select(document.body),e=d3.event.touches.item(0),o=[e.pageX,e.pageY],d=setTimeout(function(){d=null,Mt(t,o)},l),d3.event.preventDefault())}function Lt(e){RED.view.DEBUG&&console.warn("groupMouseUp",{mouse_mode:M,event:d3.event}),pe&&se==e&&0<he&&he<p&&(M=RED.state.DEFAULT,RED.editor.editGroup(e),d3.event.stopPropagation())}function St(e){var t,o=d3.touches(this.parentNode)[0]||d3.mouse(this.parentNode);RED.view.DEBUG&&console.warn("groupMouseDown",{mouse_mode:M,point:o,event:d3.event}),RED.contextMenu.hide(),Ft(),1!==d3.event.button&&(M!=RED.state.QUICK_JOINING&&M!==RED.state.SELECTING_NODE&&(se=e,t=Date.now(),he=t-fe,fe=t,pe=ue==e&&(d3.event.touches||0===d3.event.button)&&!d3.event.shiftKey&&!d3.event.metaKey&&!d3.event.altKey&&!d3.event.ctrlKey&&he<p,(ue=e).selected&&(d3.event.ctrlKey||d3.event.metaKey)?(e===g&&Ot(),It(e),d3.event.stopPropagation()):(e.selected?g&&e.g!==g.id&&Ot():(d3.event.ctrlKey||d3.event.metaKey||(t=g,q(),t&&e.g===t.id&&(b(t),g.selected=!0)),g&&!RED.group.contains(g,e)&&Ot(),v(e,!0)),2!=d3.event.button&&(e.nodes[0],ht(o),se.dx=se.x-o[0],se.dy=se.y-o[1])),W(),H()),d3.event.stopPropagation())}function v(e,t,o){var n;e.selected||(e.selected=!0,e.dirty=!0),!1!==o&&U.add(e),t&&(n=new Set(U.nodes()),RED.group.getNodes(e,!0).forEach(function(e){n.has(e)||U.add(e),e.dirty=!0}))}function b(e){g&&Ot(),e.active=!0,e.dirty=!0,g=e,U.remove(e)}function Ot(){g&&(g.active=!1,g.dirty=!0,It(g),v(g,!0),g=null)}function It(e){e.selected&&(e.selected=!1,e.dirty=!0);var t=new Set(e.nodes);t.add(e);for(var o=U.length()-1;0<=o;--o){var n=U.get(o);!t.has(n.n)&&n.n!==e||(n.n.selected=!1,n.n.dirty=!0,U.remove(n.n,o))}}function Nt(e,t){for(var o={},n=0;n<_.length;n++){var i=_[n];e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h&&(o[i.id]=i)}var a=Object.keys(o);return 1<a.length&&(a.forEach(function(e){o[e]&&o[e].g&&delete o[o[e].g]}),a=Object.keys(o)),0===a.length?null:o[a[a.length-1]]}function Pt(e){var t=!0,o=RED.nodes.workspace(RED.workspaces.active());return!o||o.disabled||e.d?t=!1:e._def.button.hasOwnProperty("enabled")&&(t="function"==typeof e._def.button.enabled?e._def.button.enabled.call(e):e._def.button.enabled),t}function At(t){if(M===RED.state.SELECTING_NODE)d3.event&&d3.event.stopPropagation();else{var e=RED.workspaces.active(),e=RED.nodes.workspace(e);if(!e||e.disabled||t.d)P?RED.notify(RED._("notification.warning",{message:RED._("notification.warnings.nodeActionDisabledSubflow")}),"warning"):RED.notify(RED._("notification.warning",{message:RED._("notification.warnings.nodeActionDisabled")}),"warning");else{if(t._def.button.toggle&&(t[t._def.button.toggle]=!t[t._def.button.toggle],t.dirty=!0),t._def.button.onclick)try{t._def.button.onclick.call(t)}catch(e){console.log("Definition error: "+t.type+".onclick",e)}t.dirty&&H()}d3.event&&d3.event.preventDefault()}}function Mt(e,t){var o=T,n=[];n.push({name:"delete",disabled:0===U.length()&&0===V.length(),onselect:function(){Ye()}}),n.push({name:"cut",disabled:0===U.length(),onselect:function(){Ze(!0),Ye()}}),n.push({name:"copy",disabled:0===U.length(),onselect:function(){Ze()}}),n.push({name:"paste",disabled:0===ye.length,onselect:function(){Ut(ye,{generateIds:!0,touchImport:!0})}}),n.push({name:"edit",disabled:1!=U.length(),onselect:function(){RED.editor.edit(o)}}),n.push({name:"select",onselect:function(){Ke()}}),n.push({name:"undo",disabled:0===RED.history.depth(),onselect:function(){RED.history.pop()}}),n.push({name:"add",onselect:function(){chartPos=z.offset(),Ae({position:[t[0]-chartPos.left+z.scrollLeft(),t[1]-chartPos.top+z.scrollTop()],touchTrigger:!0})}}),RED.touch.radialMenu.show(e,t,n),K()}function zt(o,e,t){var n,i,a,s=null;0===o.indexOf("font-awesome/")&&(n=o.substr(13),(s=RED.nodes.fontAwesome.getIconUnicode(n))||(n=RED.utils.getDefaultNodeIcon(t._def,t),o=RED.settings.apiRootUrl+"icons/"+n.module+"/"+n.file)),s?e.append("text").attr("xlink:href",o).attr("class","fa-lg").attr("x",15).text(s):(i=e.append("image").style("display","none").attr("xlink:href",o).attr("class","red-ui-flow-node-icon").attr("x",0).attr("width","30").attr("height","30"),(a=new Image).src=o,a.onload=function(){var e,t;o.match(/\.svg$/)||(e=Math.max(a.width,a.height),t=1,e=a.width*(t=30<e?30/e:t),t=a.height*t,i.attr("width",e),i.attr("height",t),i.attr("x",15-e/2)),i.attr("xlink:href",o),i.style("display",null)})}function Bt(e,t){var o;e.z===RED.workspaces.active()&&(t=t||document.getElementById(e.id))&&(s&&e.status&&!0!==e.d?(t.__statusGroup__.style.display="inline",o=Le[e.status.fill],null==e.status.shape&&null==o?(t.__statusShape__.style.display="none",t.__statusGroup__.setAttribute("transform","translate(-14,"+(e.h+3)+")")):(t.__statusGroup__.setAttribute("transform","translate(3,"+(e.h+3)+")"),o="red-ui-flow-node-status-"+(e.status.shape||"dot")+"-"+e.status.fill,t.__statusShape__.style.display="inline",t.__statusShape__.setAttribute("class","red-ui-flow-node-status "+o)),e.status.hasOwnProperty("text")?t.__statusLabel__.textContent=e.status.text:t.__statusLabel__.textContent=""):t.__statusGroup__.style.display="none",delete e.dirtyStatus)}function H(){RED.view.DEBUG_SYNC_REDRAW?Gt():(o&&cancelAnimationFrame(o),o=requestAnimationFrame(Gt))}function Gt(){var E,D,e,t,o,n,i;m.attr("transform","scale("+R+")"),Ee.attr("width",w*R).attr("height",Q*R),-1!==me||M!=RED.state.JOINING?(E={},P?((n=ke.selectAll(".red-ui-flow-subflow-port-output").data(P.out,function(e,t){return e.id})).exit().remove(),n.enter().insert("svg:g").attr("class","red-ui-flow-node red-ui-flow-subflow-port-output").each(function(e,t){var o=d3.select(this),n=document.createDocumentFragment(),i=(e.h=40,e.resize=!0,e.dirty=!0,document.createElementNS("http://www.w3.org/2000/svg","rect")),i=(i.__data__=e,i.setAttribute("class","red-ui-flow-subflow-port"),i.setAttribute("rx",8),i.setAttribute("ry",8),i.setAttribute("width",40),i.setAttribute("height",40),o[0][0].__mainRect__=i,d3.select(i).on("mouseup",gt).on("mousedown",mt).on("touchstart",vt).on("touchend",bt),n.appendChild(i),document.createElementNS("http://www.w3.org/2000/svg","g")),a=(i.setAttribute("x",0),i.setAttribute("y",0),o[0][0].__outputLabelGroup__=i,document.createElementNS("http://www.w3.org/2000/svg","text")),a=(a.setAttribute("class","red-ui-flow-port-label"),a.style["font-size"]="10px",a.textContent="output",i.appendChild(a),o[0][0].__outputOutput__=a,document.createElementNS("http://www.w3.org/2000/svg","text")),a=(a.setAttribute("class","red-ui-flow-port-label red-ui-flow-port-index"),a.setAttribute("x",0),a.setAttribute("y",0),a.textContent=e.i+1,i.appendChild(a),o[0][0].__outputNumber__=a,document.createElementNS("http://www.w3.org/2000/svg","path")),a=(a.setAttribute("d","M 40 1 l 0 38"),a.setAttribute("class","red-ui-flow-node-icon-shade-border"),i.appendChild(a),o[0][0].__outputBorder__=a,n.appendChild(i),document.createElementNS("http://www.w3.org/2000/svg","g")),i=(a.setAttribute("class","red-ui-flow-port-label"),a.setAttribute("transform","translate(38,0)"),a.setAttribute("style","fill : #888"),o[0][0].__textGroup__=a,n.append(a),document.createElementNS("http://www.w3.org/2000/svg","g")),a=(i.setAttribute("transform","translate(-5,15)"),document.createElementNS("http://www.w3.org/2000/svg","rect"));a.setAttribute("class","red-ui-flow-port"),a.setAttribute("rx",3),a.setAttribute("ry",3),a.setAttribute("width",10),a.setAttribute("height",10),i.appendChild(a),a.__data__=e,d3.select(a).on("mousedown",function(e,t){at(e,G,0)}).on("touchstart",function(e,t){at(e,G,0),d3.event.preventDefault()}).on("mouseup",function(e,t){st(e,G,0)}).on("touchend",function(e,t){st(e,G,0),d3.event.preventDefault()}).on("mouseover",function(e){pt(d3.select(this),e,G,0)}).on("mouseout",function(e){ft(d3.select(this))}),o[0][0].__port__=i,n.appendChild(i),o[0][0].appendChild(n)}),(e=ke.selectAll(".red-ui-flow-subflow-port-input").data(P.in,function(e,t){return e.id})).exit().remove(),(t=e.enter().insert("svg:g").attr("class","red-ui-flow-node red-ui-flow-subflow-port-input").attr("transform",function(e){return"translate("+(e.x-20)+","+(e.y-20)+")"})).each(function(e,t){e.w=40,e.h=40}),t.append("rect").attr("class","red-ui-flow-subflow-port").attr("rx",8).attr("ry",8).attr("width",40).attr("height",40).on("mouseup",gt).on("mousedown",mt).on("touchstart",vt).on("touchend",bt),t.append("g").attr("transform","translate(35,15)").append("rect").attr("class","red-ui-flow-port").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10).on("mousedown",function(e,t){at(e,F,t)}).on("touchstart",function(e,t){at(e,F,t),d3.event.preventDefault()}).on("mouseup",function(e,t){st(e,F,t)}).on("touchend",function(e,t){st(e,F,t),d3.event.preventDefault()}).on("mouseover",function(e){pt(d3.select(this),e,F,0)}).on("mouseout",function(e){ft(d3.select(this))}),t.append("svg:text").attr("class","red-ui-flow-port-label").attr("x",18).attr("y",20).style("font-size","10px").text("input"),(t=ke.selectAll(".red-ui-flow-subflow-port-status").data(P.status?[P.status]:[],function(e,t){return e.id})).exit().remove(),(o=t.enter().insert("svg:g").attr("class","red-ui-flow-node red-ui-flow-subflow-port-status").attr("transform",function(e){return"translate("+(e.x-20)+","+(e.y-20)+")"})).each(function(e,t){e.w=40,e.h=40}),o.append("rect").attr("class","red-ui-flow-subflow-port").attr("rx",8).attr("ry",8).attr("width",40).attr("height",40).on("mouseup",gt).on("mousedown",mt).on("touchstart",vt).on("touchend",bt),o.append("g").attr("transform","translate(-5,15)").append("rect").attr("class","red-ui-flow-port").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10).on("mousedown",function(e,t){at(e,G,0)}).on("touchstart",function(e,t){at(e,G,0),d3.event.preventDefault()}).on("mouseup",function(e,t){st(e,G,0)}).on("touchend",function(e,t){st(e,G,0),d3.event.preventDefault()}).on("mouseover",function(e){pt(d3.select(this),e,G,0)}).on("mouseout",function(e){ft(d3.select(this))}),o.append("svg:text").attr("class","red-ui-flow-port-label").attr("x",22).attr("y",20).style("font-size","10px").text("status"),n.each(function(e,t){if(e.dirty){d3.select(this);E[e.id]=e;var o,n=ct(P,F,e.i)||"",i=n.length<1;if(!e.resize&&this.__hideLabel__===i&&this.__label__===n||((o=Qe(n,"red-ui-flow-node-label")).lines.length===this.__labelLineCount__&&this.__label__===n||(e.resize=!0),this.__label__=n,this.__labelLineCount__=o.lines.length,e.h=i?Math.max(40,15*(e.outputs||0)):Math.max(6+24*o.lines.length,15*(e.outputs||0),40),this.__hideLabel__=i),e.resize&&(n=e.w,e.w=i?40:Math.max(40,20*Math.ceil((o.width+50+7)/20)),void 0!==n&&(e.x+=(e.w-n)/2),e.resize=!1),this.setAttribute("transform","translate("+(e.x-e.w/2)+","+(e.y-e.h/2)+")"),this.classList.toggle("red-ui-flow-node-selected",!!e.selected),M!=RED.state.MOVING_ACTIVE){if(this.classList.toggle("red-ui-flow-node-disabled",!0===e.d),this.__mainRect__.setAttribute("width",e.w),this.__mainRect__.setAttribute("height",e.h),this.__mainRect__.classList.toggle("red-ui-flow-node-highlighted",!!e.highlighted),o){for(var a=o.lines,s=o.lines.length,r=this.__textGroup__.childNodes;r.length>s;)r[r.length-1].remove();for(var d,t=0;t<s;t++)t===r.length&&((d=document.createElementNS("http://www.w3.org/2000/svg","text")).setAttribute("class","red-ui-flow-node-label-text"),d.setAttribute("x",0),d.setAttribute("y",24*t),this.__textGroup__.appendChild(d)),r[t].textContent=a[t]}this.__textGroup__.setAttribute("class","red-ui-flow-node-label"+(i?" hide":""));n=e.h/2-this.__labelLineCount__/2*24+13;this.__textGroup__.setAttribute("transform","translate(48,"+n+")"),this.__outputBorder__.setAttribute("d","M 40 1 l 0 "+(i?0:e.h-2)),this.__port__.setAttribute("transform","translate(-5,"+(e.h/2-5)+")"),this.__outputOutput__.setAttribute("transform","translate(20,"+(e.h/2-8)+")"),this.__outputNumber__.setAttribute("transform","translate(20,"+(e.h/2+7)+")")}e.dirty=!1}}),e.each(function(e,t){var o;e.dirty&&((o=d3.select(this)).classed("red-ui-flow-node-selected",function(e){return e.selected}),o.attr("transform",function(e){return"translate("+(e.x-e.w/2)+","+(e.y-e.h/2)+")"}),(E[e.id]=e).dirty=!1)}),t.each(function(e,t){var o;e.dirty&&((o=d3.select(this)).classed("red-ui-flow-node-selected",function(e){return e.selected}),o.selectAll(".red-ui-flow-port-index").text(function(e){return e.i+1}),o.attr("transform",function(e){return"translate("+(e.x-e.w/2)+","+(e.y-e.h/2)+")"}),(E[e.id]=e).dirty=!1)})):(ke.selectAll(".red-ui-flow-subflow-port-output").remove(),ke.selectAll(".red-ui-flow-subflow-port-input").remove(),ke.selectAll(".red-ui-flow-subflow-port-status").remove()),(o=ke.selectAll(".red-ui-flow-node-group").data(y,function(e){return e.id})).exit().each(function(e,t){RED.hooks.trigger("viewRemoveNode",{node:e,el:this})}).remove(),o.enter().insert("svg:g").attr("class","red-ui-flow-node red-ui-flow-node-group").classed("red-ui-flow-subflow",null!=P).each(function(e,t){this.__outputs__=[],this.__inputs__=[];var o=d3.select(this),n=document.createDocumentFragment(),i="link in"===e.type||"link out"===e.type,i=e.hasOwnProperty("l")?!e.l:i,a=(o.attr("id",e.id),e.h=N,e.resize=!0,e._def.button&&((s=document.createElementNS("http://www.w3.org/2000/svg","g")).__data__=e,s.setAttribute("transform","translate("+("right"==e._def.align?94:-25)+",2)"),s.setAttribute("class","red-ui-flow-node-button"),o[0][0].__buttonGroup__=s,(a=document.createElementNS("http://www.w3.org/2000/svg","rect")).__data__=e,a.setAttribute("class","red-ui-flow-node-button-background"),a.setAttribute("rx",5),a.setAttribute("ry",5),a.setAttribute("width",32),a.setAttribute("height",N-4),s.appendChild(a),o[0][0].__buttonGroupBackground__=a,(a=document.createElementNS("http://www.w3.org/2000/svg","rect")).__data__=e,a.setAttribute("class","red-ui-flow-node-button-button"),a.setAttribute("x","right"==e._def.align?11:5),a.setAttribute("y",4),a.setAttribute("rx",4),a.setAttribute("ry",4),a.setAttribute("width",16),a.setAttribute("height",N-12),a.setAttribute("fill",RED.utils.getNodeColor(e.type,e._def)),d3.select(a).on("mousedown",function(e){!L&&Pt(e)&&(Ft(),d3.select(this).attr("fill-opacity",.2),d3.event.preventDefault(),d3.event.stopPropagation())}).on("mouseup",function(e){!L&&Pt(e)&&(d3.select(this).attr("fill-opacity",.4),d3.event.preventDefault(),d3.event.stopPropagation())}).on("mouseover",function(e){!L&&Pt(e)&&d3.select(this).attr("fill-opacity",.4)}).on("mouseout",function(e){var t;!L&&Pt(e)&&(t=1,e._def.button.toggle&&(t=e[e._def.button.toggle]?1:.2),d3.select(this).attr("fill-opacity",t))}).on("click",At).on("touchstart",function(e){At.call(this,e),d3.event.preventDefault()}),s.appendChild(a),o[0][0].__buttonGroupButton__=a,n.appendChild(s)),document.createElementNS("http://www.w3.org/2000/svg","rect")),s=(a.__data__=e,a.setAttribute("class","red-ui-flow-node "+("unknown"==e.type?"red-ui-flow-node-unknown":"")),a.setAttribute("rx",5),a.setAttribute("ry",5),a.setAttribute("fill",RED.utils.getNodeColor(e.type,e._def)),o[0][0].__mainRect__=a,d3.select(a).on("mouseup",gt).on("mousedown",mt).on("touchstart",vt).on("touchend",bt).on("mouseover",yt).on("mouseout",wt),n.appendChild(a),e._def.icon&&(s=RED.utils.getNodeIcon(e._def,e),(a=document.createElementNS("http://www.w3.org/2000/svg","g")).__data__=e,a.setAttribute("class","red-ui-flow-node-icon-group"+("right"==e._def.align?" red-ui-flow-node-icon-group-right":"")),a.setAttribute("x",0),a.setAttribute("y",0),a.style["pointer-events"]="none",o[0][0].__iconGroup__=a,(r=document.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("x",0),r.setAttribute("y",0),r.setAttribute("class","red-ui-flow-node-icon-shade"),a.appendChild(r),o[0][0].__iconShade__=r,zt(s,d3.select(a),e),(r=document.createElementNS("http://www.w3.org/2000/svg","path")).setAttribute("d","right"!=e._def.align?"M 30 1 l 0 "+(e.h-2):"M 0 1 l 0 "+(e.h-2)),r.setAttribute("class","red-ui-flow-node-icon-shade-border"),a.appendChild(r),o[0][0].__iconShadeBorder__=r,n.appendChild(a)),document.createElementNS("http://www.w3.org/2000/svg","g")),r=(s.setAttribute("class","red-ui-flow-node-label"+(i?" hide":"")+(e._def.align?" red-ui-flow-node-label-"+e._def.align:"")),s.setAttribute("transform","translate(38,0)"),n.appendChild(s),o[0][0].__textGroup__=s,document.createElementNS("http://www.w3.org/2000/svg","g")),a=(r.setAttribute("class","red-ui-flow-node-status-group"),r.style.display="none",o[0][0].__statusGroup__=r,document.createElementNS("http://www.w3.org/2000/svg","rect")),i=(a.setAttribute("class","red-ui-flow-node-status"),a.setAttribute("x",6),a.setAttribute("y",1),a.setAttribute("width",9),a.setAttribute("height",9),a.setAttribute("rx",2),a.setAttribute("ry",2),a.setAttribute("stroke-width","3"),r.appendChild(a),o[0][0].__statusShape__=a,document.createElementNS("http://www.w3.org/2000/svg","text"));i.setAttribute("class","red-ui-flow-node-status-label"),i.setAttribute("x",20),i.setAttribute("y",10),r.appendChild(i),o[0][0].__statusLabel__=i,n.appendChild(r),o[0][0].appendChild(n),RED.hooks.trigger("viewAddNode",{node:e,el:this})}),D=!1,o.each(function(t,e){if(t._reordered&&(D=!0,delete t._reordered),t.dirty){var o=this,n=d3.select(this),i="link in"===t.type||"link out"===t.type,a=t.hasOwnProperty("l")?!t.l:i,s=(E[t.id]=t,RED.utils.getNodeLabel(t,t.type));if(!t.resize&&this.__hideLabel__===a&&this.__label__===s&&this.__outputs__.length===t.outputs||((u=Qe(s,"red-ui-flow-node-label")).lines.length===this.__labelLineCount__&&this.__label__===s||(t.resize=!0),this.__label__=s,this.__labelLineCount__=u.lines.length,t.h=a?Math.max(N,15*(t.outputs||0)):Math.max(6+24*u.lines.length,15*(t.outputs||0),30),this.__hideLabel__=a),t.resize&&(s=t.w,t.w=a?N:Math.max(I,20*Math.ceil((u.width+50+(0<t._def.inputs?7:0))/20)),void 0!==s&&(t.x+=(t.w-s)/2),t.resize=!1),t._colorChanged&&(s=RED.utils.getNodeColor(t.type,t._def),this.__mainRect__.setAttribute("fill",s),this.__buttonGroupButton__&&this.__buttonGroupButton__.settAttribute("fill",s),delete t._colorChanged),this.setAttribute("transform","translate("+(t.x-t.w/2)+","+(t.y-t.h/2)+")"),this.classList.toggle("red-ui-flow-node-selected",!!t.selected),M!=RED.state.MOVING_ACTIVE){if(this.classList.toggle("red-ui-flow-node-disabled",!0===t.d),this.__mainRect__.setAttribute("width",t.w),this.__mainRect__.setAttribute("height",t.h),this.__mainRect__.classList.toggle("red-ui-flow-node-highlighted",!!t.highlighted),u){for(var r=u.lines,d=u.lines.length,l=this.__textGroup__.childNodes;l.length>d;)l[l.length-1].remove();for(var c,e=0;e<d;e++)e===l.length&&((c=document.createElementNS("http://www.w3.org/2000/svg","text")).setAttribute("class","red-ui-flow-node-label-text"),c.setAttribute("x",0),c.setAttribute("y",24*e),this.__textGroup__.appendChild(c)),l[e].textContent=r[e]}s="";if(t._def.labelStyle){s=t._def.labelStyle;try{s=("function"==typeof s?s.call(t):s)||""}catch(e){console.log("Definition error: "+t.type+".labelStyle",e),s=""}s=" "+s}s="red-ui-flow-node-label"+(t._def.align?" red-ui-flow-node-label-"+t._def.align:"")+s+(a?" hide":""),this.__textGroup__.setAttribute("class",s);var u=t.h/2-this.__labelLineCount__/2*24+13,s=(!t._def.align&&0!==t.inputs&&0===t.outputs||"right"===t._def.align?(this.__iconGroup__&&(this.__iconGroup__.classList.add("red-ui-flow-node-icon-group-right"),this.__iconGroup__.setAttribute("transform","translate("+(t.w-30)+",0)")),this.__textGroup__.classList.add("red-ui-flow-node-label-right"),this.__textGroup__.setAttribute("transform","translate("+(t.w-38)+","+u+")")):(this.__iconGroup__&&(this.__iconGroup__.classList.remove("red-ui-flow-node-icon-group-right"),this.__iconGroup__.setAttribute("transform","")),this.__textGroup__.classList.remove("red-ui-flow-node-label-right"),this.__textGroup__.setAttribute("transform","translate(38,"+u+")")),n.selectAll(".red-ui-flow-port-input")),p=(i&&(-1!==me||x[t.id])||0!==t.inputs||s.empty()?(i&&(me===G||x[t.id])||1===t.inputs)&&s.empty()&&(u=n.append("g").attr("class","red-ui-flow-port-input"),h="link in"===t.type?u.append("circle").attr("cx",-1).attr("cy",5).attr("r",5).attr("class","red-ui-flow-port red-ui-flow-link-port"):u.append("rect").attr("class","red-ui-flow-port").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10),u[0][0].__port__=h[0][0],h[0][0].__data__=this.__data__,h[0][0].__portType__=G,h[0][0].__portIndex__=0,h.on("mousedown",function(e){at(e,G,0)}).on("touchstart",function(e){at(e,G,0),d3.event.preventDefault()}).on("mouseup",function(e){st(e,G,0)}).on("touchend",function(e){st(e,G,0),d3.event.preventDefault()}).on("mouseover",function(e){pt(d3.select(this),e,G,0)}).on("mouseout",function(e){ft(d3.select(this))}),RED.hooks.trigger("viewAddPort",{node:t,el:this,port:u[0][0],portType:"input",portIndex:0})):s.each(function(e,t){RED.hooks.trigger("viewRemovePort",{node:e,el:o,port:d3.select(this)[0][0],portType:"input",portIndex:0})}).remove(),t.outputs);for(i&&"link out"===t.type&&(p="return"===t.mode||me!==F&&!x[t.id]?0:1),t.h;this.__outputs__.length>p;){var f=this.__outputs__.pop();RED.hooks.trigger("viewRemovePort",{node:t,el:this,port:f,portType:"output",portIndex:this.__outputs__.length}),f.remove()}for(var h,g=0;g<p;g++){g===this.__outputs__.length?((v=document.createElementNS("http://www.w3.org/2000/svg","g")).setAttribute("class","red-ui-flow-port-output"),"link out"===t.type?((m=document.createElementNS("http://www.w3.org/2000/svg","circle")).setAttribute("cx",11),m.setAttribute("cy",5),m.setAttribute("r",5),m.setAttribute("class","red-ui-flow-port red-ui-flow-link-port")):((m=document.createElementNS("http://www.w3.org/2000/svg","rect")).setAttribute("rx",3),m.setAttribute("ry",3),m.setAttribute("width",10),m.setAttribute("height",10),m.setAttribute("class","red-ui-flow-port")),v.appendChild(m),(v.__port__=m).__data__=this.__data__,m.__portType__=F,m.__portIndex__=g,m.addEventListener("mousedown",Et),m.addEventListener("touchstart",Dt),m.addEventListener("mouseup",Rt),m.addEventListener("touchend",xt),m.addEventListener("mouseover",_t),m.addEventListener("mouseout",$t),this.appendChild(v),this.__outputs__.push(v),RED.hooks.trigger("viewAddPort",{node:t,el:this,port:v,portType:"output",portIndex:g})):v=this.__outputs__[g];var m,v,b=t.w-5,y=t.h/2-(p-1)/2*13;v.setAttribute("transform","translate("+b+","+(y+13*g-5)+")")}t._def.icon&&(h=n.select(".red-ui-flow-node-icon"),u=n.select(".fa-lg"),s=(h.empty()?u:h).attr("xlink:href"),(i=RED.utils.getNodeIcon(t._def,t))!==s&&((h.empty()?u:h).remove(),zt(i,n.select(".red-ui-flow-node-icon-group"),t),h=n.select(".red-ui-flow-node-icon"),u=n.select(".fa-lg")),h.attr("y",function(){return(t.h-d3.select(this).attr("height"))/2}),s=t.h,this.__iconShade__.setAttribute("d",a?`M5 0 h20 a 5 5 0 0 1 5 5 v${s-10} a 5 5 0 0 1 -5 5 h-20 a 5 5 0 0 1 -5 -5 v-${s-10} a 5 5 0 0 1 5 -5`:"right"===t._def.align?`M 0 0 h25 a 5 5 0 0 1 5 5 v${s-10} a 5 5 0 0 1 -5 5 h-25 v-`+s:`M5 0 h25 v${s} h-25 a 5 5 0 0 1 -5 -5 v-${s-10} a 5 5 0 0 1 5 -5`),this.__iconShadeBorder__.style.display=a?"none":"",this.__iconShadeBorder__.setAttribute("d","M "+(!t._def.align&&0!==t.inputs&&0===t.outputs||"right"===t._def.align?.5:29.5)+" "+(t.selected?1:.5)+" l 0 "+(t.h-(t.selected?2:1))),u.attr("y",(t.h+13)/2)),n.selectAll(".red-ui-flow-port-input").each(function(e,t){d3.select(this).attr("transform",function(e){return"translate(-5,"+(e.h/2-5)+")"})}),t._def.button&&(i=Pt(t),this.__buttonGroup__.classList.toggle("red-ui-flow-node-button-disabled",!i),RED.runtime&&void 0!==RED.runtime.started&&this.__buttonGroup__.classList.toggle("red-ui-flow-node-button-stopped",!RED.runtime.started),b="right"==t._def.align?t.w-6:-25,t._def.button.toggle&&!t[t._def.button.toggle]&&(b-="right"==t._def.align?8:-8),this.__buttonGroup__.setAttribute("transform","translate("+b+",2)"),t._def.button.toggle&&(this.__buttonGroupButton__.setAttribute("fill-opacity",t[t._def.button.toggle]?1:.2),this.__buttonGroupBackground__.setAttribute("fill-opacity",t[t._def.button.toggle]?1:.2)),"function"==typeof t._def.button.visible&&(!1===t._def.button.visible.call(t)?this.__buttonGroup__.style.display="none":this.__buttonGroup__.style.display="inherit"))}if(t.dirtyStatus&&Bt(t,this),t.dirty=!1,t.g&&!ae[t.g])for(var w=t.g;w&&!ae[w];)ae[w]=RED.nodes.group(w),w=ae[w].g}RED.hooks.trigger("viewRedrawNode",{node:t,el:this})}),D&&o.sort(function(e,t){return e._index-t._index}),(n=xe.selectAll(".red-ui-flow-junction").data(ne,e=>e.id)).enter().insert("svg:g").attr("class","red-ui-flow-junction").each(function(e,t){var o=d3.select(this),n=document.createDocumentFragment(),i=document.createElementNS("http://www.w3.org/2000/svg","rect"),a=(i.setAttribute("class","red-ui-flow-junction-background"),i.setAttribute("x",-5),i.setAttribute("y",-5),i.setAttribute("width",10),i.setAttribute("height",10),i.setAttribute("rx",3),i.setAttribute("ry",3),i.__data__=e,this.__junctionBack__=i,n.appendChild(i),document.createElementNS("http://www.w3.org/2000/svg","rect")),s=(a.setAttribute("class","red-ui-flow-junction-port red-ui-flow-junction-port-input"),a.setAttribute("x",-5),a.setAttribute("y",-5),a.setAttribute("width",10),a.setAttribute("height",10),a.setAttribute("rx",3),a.setAttribute("ry",3),a.__data__=e,a.__portType__=G,a.__portIndex__=0,this.__junctionInput__=void 0,n.appendChild(a),a.addEventListener("mouseup",Rt),a.addEventListener("mousedown",Et),this.__junctionInput__=a,n.appendChild(a),document.createElementNS("http://www.w3.org/2000/svg","rect"));s.setAttribute("class","red-ui-flow-junction-port red-ui-flow-junction-port-output"),s.setAttribute("x",-5),s.setAttribute("y",-5),s.setAttribute("width",10),s.setAttribute("height",10),s.setAttribute("rx",3),s.setAttribute("ry",3),s.__data__=e,s.__portType__=F,s.__portIndex__=0,this.__junctionOutput__=s,n.appendChild(s),s.addEventListener("mouseup",Rt),s.addEventListener("mousedown",Et),s.addEventListener("mouseover",kt),s.addEventListener("mouseout",Tt),a.addEventListener("mouseover",kt),a.addEventListener("mouseout",Tt),i.addEventListener("mouseover",kt),i.addEventListener("mouseout",Tt),d3.select(i).on("mousedown",mt).on("mouseup",gt),o[0][0].appendChild(n)}),n.exit().remove(),n.each(function(e){var t=d3.select(this);if(this.setAttribute("transform","translate("+e.x+","+e.y+")"),e.dirty&&(t.classed("red-ui-flow-junction-dragging",M===RED.state.MOVING_ACTIVE&&U.has(e)),t.classed("selected",!!e.selected),(E[e.id]=e).g&&!ae[e.g]))for(var o=e.g;o&&!ae[o];)ae[o]=RED.nodes.group(o),o=ae[o].g}),(e=Re.selectAll(".red-ui-flow-link").data(oe,function(e){return e.source.id+":"+e.sourcePort+":"+e.target.id+":"+e.target.i})).enter().insert("g",".red-ui-flow-node").attr("class","red-ui-flow-link").each(function(e,t){var d=d3.select(this),o=document.createDocumentFragment(),n=(e.added=!0,document.createElementNS("http://www.w3.org/2000/svg","path")),n=(n.__data__=e,n.setAttribute("class","red-ui-flow-link-background red-ui-flow-link-path"+(e.link?" red-ui-flow-link-link":"")),this.__pathBack__=n,o.appendChild(n),d3.select(n).on("mousedown",Ct).on("touchstart",jt).on("mousemove",function(e){if(M===RED.state.SLICING)V.add(e),d.classed("red-ui-flow-link-splice",!0),H();else if(M===RED.state.SLICING_JUNCTION&&!e.link&&!d.classed("red-ui-flow-link-splice")){for(var t,o=l.getTotalLength(),n=1/0,i=0;i<o;i++){var a=l.getPointAtLength(i),s=Math.abs(a.x-d3.event.offsetX),r=Math.abs(a.y-d3.event.offsetY),s=s*s+r*r;s<n&&(t=a,n=s)}e._sliceLocation=t,V.add(e),d.classed("red-ui-flow-link-splice",!0),H()}}),document.createElementNS("http://www.w3.org/2000/svg","path")),l=(n.__data__=e,n.setAttribute("class","red-ui-flow-link-outline red-ui-flow-link-path"),this.__pathOutline__=n,o.appendChild(n),document.createElementNS("http://www.w3.org/2000/svg","path"));l.__data__=e,l.setAttribute("class","red-ui-flow-link-line red-ui-flow-link-path"+(e.link?" red-ui-flow-link-link":P?" red-ui-flow-subflow-link":"")),this.__pathLine__=l,o.appendChild(l),d[0][0].appendChild(o)}),e.exit().remove(),e.each(function(e){var t;d3.select(this),(e.added||e.selected||E[e.source.id]||E[e.target.id])&&(t=-((e.source.outputs||1)-1)/2*13+13*(e.sourcePort||0),e.x1=e.source.x+(e.source.w/2||0),e.y1=e.source.y+t,e.x2=e.target.x-(e.target.w/2||0),e.y2=e.target.y,t=Ne(e.x1,e.y1,e.x2,e.y2,1),/NaN/.test(t)&&(t=""),this.__pathBack__.setAttribute("d",t),this.__pathOutline__.setAttribute("d",t),this.__pathLine__.setAttribute("d",t),this.__pathLine__.classList.toggle("red-ui-flow-node-disabled",!(!e.source.d&&!e.target.d)),this.__pathLine__.classList.toggle("red-ui-flow-subflow-link",!e.link&&P)),this.classList.toggle("red-ui-flow-link-selected",!!e.selected),"unknown"!=e.target.type&&e.source.type;this.classList.toggle("red-ui-flow-link-unknown",!("unknown"!=e.target.type&&"unknown"!=e.source.type)),delete e.added}),(t=Re.selectAll(".red-ui-flow-link-off-flow").data(ie,function(e){return e.node.id+":"+e.refresh})).enter().insert("g",".red-ui-flow-node").attr("class","red-ui-flow-link-off-flow").each(function(o,e){var t=d3.select(this),n=1,i="start",a=("link in"===o.node.type&&(n=-1,i="end"),30*n),s=20*n,r=(t.append("svg:path").attr("class","red-ui-flow-link-link").attr("d","M 0 0 h "+a),o.links),r=Object.keys(r),d=RED.nodes.getWorkspaceOrder(),l=(r.sort(function(e,t){return d.indexOf(e)-d.indexOf(t)}),N),c=-(r.length-1)*l/2,t=t.selectAll(".red-ui-flow-link-group").data(r);t.enter().append("g").attr("class","red-ui-flow-link-group").on("mouseover",function(){0===M&&d3.select(this).classed("red-ui-flow-link-group-active",!0)}).on("mouseout",function(){0===M&&d3.select(this).classed("red-ui-flow-link-group-active",!1)}).on("mousedown",function(){d3.event.preventDefault(),d3.event.stopPropagation()}).on("mouseup",function(e){var t;0===M&&(d3.event.stopPropagation(),t=o.links[e],RED.workspaces.show(e),t.forEach(function(e){e.selected=!0,e.dirty=!0,U.add(e),1===t.length&&RED.view.reveal(e.id)}),W(),H())}).each(function(e){var t,o=d3.select(this),e=(o.append("svg:path").attr("class","red-ui-flow-link-link").attr("d","M "+a+" 0 C "+(a+1.7*s)+" 0 "+(a+.1*s)+" "+c+" "+(a+1.5*s)+" "+c+" "),o.append("svg:path").attr("class","red-ui-flow-link-port").attr("d","M "+(a+1.5*s+17*n)+" "+(c-12)+" h "+10*-n+" a 3 3 45 0 "+(1===n?"0":"1")+" "+-3*n+" 3 v 18 a 3 3 45 0 "+(1===n?"0":"1")+" "+3*n+" 3 h "+10*n),o.append("svg:path").attr("class","red-ui-flow-link-port").attr("d","M "+(a+1.5*s+20*n)+" "+(c-12)+" h "+30*n+" M "+(a+1.5*s+20*n)+" "+(c+12)+" h "+30*n).style("stroke-dasharray","12 3 8 4 3"),o.append("rect").attr("class","red-ui-flow-port red-ui-flow-link-port").attr("x",a+1.5*s-4+4*n).attr("y",c-4).attr("rx",2).attr("ry",2).attr("width",8).attr("height",8),o.append("rect").attr("x",a+1.5*s-(-1===n?I:0)).attr("y",c-12).attr("width",I).attr("height",24).style("stroke","none").style("fill","transparent"),RED.nodes.workspace(e));e&&(t=e.label||e.id),o.append("svg:text").attr("class","red-ui-flow-port-label").attr("x",a+1.5*s+15*n).attr("y",c+1).style("font-size","10px").style("text-anchor",i).text(t),c+=l}),t.exit().remove()}),t.exit().remove(),(t=Re.selectAll(".red-ui-flow-link-off-flow")).each(function(e){var t=1;"link in"===e.node.type&&(t=-1),d3.select(this).attr("transform",function(e){return"translate("+(e.node.x+t*e.node.w/2)+","+e.node.y+")"})}),(o=Te.selectAll(".red-ui-flow-group").data(_,function(e){return e.id})).exit().each(function(e,t){document.getElementById("group_select_"+e.id).remove()}).remove(),n=o.enter().insert("svg:g").attr("class","red-ui-flow-group"),i=!1,n.each(function(e,t){i=!0;var o=d3.select(this),n=(o.attr("id",e.id),$e.append("g").attr("class","red-ui-flow-group").attr("id","group_select_"+e.id));n.append("rect").classed("red-ui-flow-group-outline-select",!0).classed("red-ui-flow-group-outline-select-background",!0).attr("rx",4).attr("ry",4).attr("x",-4).attr("y",-4),n.append("rect").classed("red-ui-flow-group-outline-select",!0).attr("rx",4).attr("ry",4).attr("x",-4).attr("y",-4),n.on("mousedown",function(){St.call(o[0][0],e)}),n.on("mouseup",function(){Lt.call(o[0][0],e)}),n.on("touchstart",function(){St.call(o[0][0],e),d3.event.preventDefault()}),n.on("touchend",function(){Lt.call(o[0][0],e),d3.event.preventDefault()}),o.append("rect").classed("red-ui-flow-group-outline",!0).attr("rx",.5).attr("ry",.5),o.append("rect").classed("red-ui-flow-group-body",!0).attr("rx",4).attr("ry",4).style({fill:e.fill||"none",stroke:e.stroke||"none"}),o.on("mousedown",St).on("mouseup",Lt),o.on("touchstart",function(){St.call(o[0][0],e),d3.event.preventDefault()}),o.on("touchend",function(){Lt.call(o[0][0],e),d3.event.preventDefault()}),o.append("svg:text").attr("class","red-ui-flow-group-label"),e.dirty=!0}),i&&o.sort(function(e,t){return e._root===t._root?e._depth-t._depth:e._index-t._index}),o[0].reverse(),o.each(function(e,t){var o,n,i,a,s,r,d,l,c,u;e.resize&&(e.minWidth=0,delete e.resize),(e.dirty||ae[e.id])&&(o=d3.select(this),u=!1,0<e.nodes.length?e.groupMoved?delete e.groupMoved:(n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=a=0,e.nodes.forEach(function(e){s="group"!==e.type?(n=Math.min(n,e.x-e.w/2-26-(e._def.button&&"right"!==e._def.align?20:0)),i=Math.min(i,e.y-e.h/2-26),a=Math.max(a,e.x+e.w/2+26+(e._def.button&&"right"==e._def.align?20:0)),Math.max(s,e.y+e.h/2+26)):(n=Math.min(n,e.x-26),i=Math.min(i,e.y-26),a=Math.max(a,e.x+e.w+26),Math.max(s,e.y+e.h+26))}),e.x=n,e.y=i,e.w=a-n,e.h=s-i,!(u=!0)===e.groupMoved&&delete e.groupMoved):(e.w=40,e.h=40,u=!0),u&&(e.minWidth||(e.style.label&&e.name?(u=Qe(e.name||"","red-ui-flow-group-label"),e.minWidth=u.width+8,e.labels=u.lines):(e.minWidth=40,e.labels=[])),e.w=Math.max(e.minWidth,e.w),e.style.label&&0<e.labels.length&&(d=e.style["label-position"]||"nw",u=16*(e.labels.length-1),"s"===d[0]&&(u+=8),e.h+=u,"n"===d[0]&&0<e.nodes.length&&(e.y-=u))),o.attr("transform","translate("+e.x+","+e.y+")"),o.selectAll(".red-ui-flow-group-outline").attr("width",e.w).attr("height",e.h),(u=document.getElementById("group_select_"+e.id)).setAttribute("transform","translate("+e.x+","+e.y+")"),e.hovered?u.classList.add("red-ui-flow-group-hovered"):u.classList.remove("red-ui-flow-group-hovered"),(l=u.children[0]).setAttribute("width",e.w+8),l.setAttribute("height",e.h+8),l.style.strokeOpacity=e.active||e.selected||e.highlighted?.8:0,l.style.strokeDasharray=e.active?"10 4":"",(l=u.children[1]).setAttribute("width",e.w+8),l.setAttribute("height",e.h+8),l.style.strokeOpacity=e.active||e.selected||e.highlighted?.8:0,l.style.strokeDasharray=e.active?"10 4":"",e.highlighted?u.classList.add("red-ui-flow-node-highlighted"):u.classList.remove("red-ui-flow-node-highlighted"),o.selectAll(".red-ui-flow-group-body").attr("width",e.w).attr("height",e.h).style("stroke",e.style.stroke||"").style("stroke-opacity",e.style.hasOwnProperty("stroke-opacity")?e.style["stroke-opacity"]:"").style("fill",e.style.fill||"").style("fill-opacity",e.style.hasOwnProperty("fill-opacity")?e.style["fill-opacity"]:""),(r=o.selectAll(".red-ui-flow-group-label")).classed("hide",!e.style.label),e.style.label&&(u="n"===(d=e.style["label-position"]||"nw")[u=l=0]?15:e.h-5-16*(e.labels.length-1),labelAnchor="w"===d[1]?(l=5,"start"):"e"===d[1]?(l=e.w-5,"end"):(l=e.w/2,"middle"),e.style.hasOwnProperty("color")?r.style("fill",e.style.color):r.style("fill",null),r.attr("transform","translate("+l+","+u+")").attr("text-anchor",labelAnchor),e.labels?(c=0,o.selectAll(".red-ui-flow-group-label-text").remove(),e.labels.forEach(function(e){r.append("tspan").classed("red-ui-flow-group-label-text",!0).text(e).attr("x",0).attr("y",c),c+=16})):o.selectAll(".red-ui-flow-group-label-text").remove()),delete ae[e.id],delete e.dirty)})):Re.selectAll(".red-ui-flow-link-selected").data(oe,function(e){return e.source.id+":"+e.sourcePort+":"+e.target.id+":"+e.target.i}).classed("red-ui-flow-link-selected",!1),RED.view.navigator.refresh(),d3.event&&d3.event.preventDefault()}function Ft(){try{var e=window.parent.window.scrollX,t=window.parent.window.scrollY;z.trigger("focus"),window.parent.window.scrollTo(e,t)}catch(e){z.trigger("focus")}}function Ut(e,t){var o,n=(t=t||{addFlow:!1,touchImport:!1,generateIds:!1,generateDefaultNames:!1}).addFlow,i=t.touchImport;if(M!==RED.state.SELECTING_NODE){if("string"==typeof e){if(""===e)return;try{o=JSON.parse(e)}catch(e){var a=new Error(RED._("clipboard.invalidFlow",{message:e.message}));throw a.code="NODE_RED",a}}else o=e;$.isArray(o)||(o=[o]),t.generateDefaultNames&&RED.actions.invoke("core:generate-node-names",o,{renameBlank:!1,renameClash:!0,generateHistory:!1});try{P&&(s=P.changed);var s,r=RED.nodes.import(o,{generateIds:t.generateIds,addFlow:n,importMap:t.importMap});if(r){var d=r.nodes,l=r.links,c=r.groups,u=r.junctions,p=r.workspaces,f=r.subflows,h=r.removedNodes,g=r.missingWorkspace,m=(n&&g&&RED.workspaces.show(g.id),d.filter(function(e){return e.hasOwnProperty("x")&&e.hasOwnProperty("y")&&e.z==RED.workspaces.active()})),v=(m=(m=m.concat(c.filter(function(e){return e.z===RED.workspaces.active()}))).concat(u.filter(function(e){return e.z===RED.workspaces.active()})),d.map(function(e){return e.changed=!0,e.id}));if(q(),U.clear(),U.add(m),0<U.length()){for(var b,y,w=(A=null==A?[0,0]:A)[0],E=A[1],D=(0<U.length()&&(w=(b=U.get(0).n).x,E=b.y),0),R=0,x=U.length(),_=0;_<x;_++)(y=U.get(_)).n.selected=!0,y.n.changed=!0,y.n.moved=!0,y.n.x-=w-A[0],y.n.y-=E-A[1],"junction"!==y.n.type&&(y.n.w=I,y.n.h=N,y.n.resize=!0),y.dx=y.n.x-A[0],y.dy=y.n.y-A[1],R="group"===y.n.type?(y.n.groupMoved=!1,D=Math.min(y.n.x-5,D),Math.min(y.n.y-5,R)):(D=Math.min(y.n.x-I/2-5,D),Math.min(y.n.y-N/2-5,R));for(_=0;_<x;_++)if((y=U.get(_)).n.x-=D,y.n.y-=R,y.dx-=D,y.dy-=R,y.n._def.onadd)try{y.n._def.onadd.call(y.n)}catch(e){console.log("Definition error: "+y.n.type+".onadd:",e)}i||(M=RED.state.IMPORT_DRAGGING,te=!1,1===U.length()&&(y=U.get(0),te=y.n.hasOwnProperty("_def")&&(y.n.hasOwnProperty("inputs")&&0<y.n.inputs||!y.n.hasOwnProperty("inputs")&&0<y.n._def.inputs)&&(y.n.hasOwnProperty("outputs")&&0<y.n.outputs||!y.n.hasOwnProperty("outputs")&&0<y.n._def.outputs)))}var k,T,C={t:"add",nodes:v,links:l,groups:c,junctions:u,workspaces:p,subflows:f,dirty:RED.nodes.dirty()},j=(0===U.length()&&RED.nodes.dirty(!0),!P||(k=RED.subflow.refresh(!0))&&(C.subflow={id:P.id,changed:s,instances:k.instances}),h&&(C={t:"multi",events:[{t:"replace",config:h},C]}),RED.history.push(C),J(),H(),[]),L=0,S=0,O=(d.forEach(function(e){e.hasOwnProperty("x")&&e.hasOwnProperty("y")?L++:S++}),c.length);u.length;0<p.length&&j.push(RED._("clipboard.flow",{count:p.length})),0<L&&j.push(RED._("clipboard.node",{count:L})),0<O&&j.push(RED._("clipboard.group",{count:O})),0<S&&j.push(RED._("clipboard.configNode",{count:S})),0<f.length&&j.push(RED._("clipboard.subflow",{count:f.length})),h&&0<h.length&&j.push(RED._("clipboard.replacedNodes",{count:h.length})),0<j.length&&(T="<ul><li>"+j.join("</li><li>")+"</li></ul>",RED.notify("<p>"+RED._("clipboard.nodesImported")+"</p>"+T,{id:"clipboard"}))}}catch(e){if("import_conflict"===e.code)throw e;"NODE_RED"!=e.code?(console.log(e.stack),RED.notify(RED._("notification.error",{message:e.toString()}),"error")):RED.notify(RED._("notification.error",{message:e.message}),"error")}}}function Vt(e){if(M!==RED.state.SELECTING_NODE){var t=RED.workspaces.selection();if(!(0<t.length)&&0<U.length()){for(var o=[],n=0;n<U.length();n++){var i=U.get(n).n;"group"!==i.type&&"subflow"!==i.type&&e!=i.d&&(o.push({t:"edit",node:i,changed:i.changed,changes:{d:i.d}}),e?i.d=!0:delete i.d,i.dirty=!0,i.dirtyStatus=!0,i.changed=!0,"junction"===i.type?RED.events.emit("junctions:change",i):RED.events.emit("nodes:change",i))}0<o.length&&(RED.history.push({t:"multi",events:o,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0))}RED.view.redraw()}}function Jt(){var e={},t=new Set,o=(0<U.length()&&U.forEach(function(e){"group"!==e.n.type&&t.add(e.n)}),_.filter(function(e){return e.selected&&!e.active}));return 0<o.length&&(1===o.length&&o[0].active||o.forEach(function(e){RED.group.getNodes(e,!0).forEach(function(e){t.delete(e)}),t.add(e)})),0<t.size&&(e.nodes=Array.from(t)),0<V.length()&&(e.links=V.toArray(),e.link=e.links[0]),e}function qt(e,t,o,n){var i=RED.nodes.dirty(),a=/^subflow:(.+)$/.exec(e),s=n?RED.nodes.subflow(n):null;if(s&&a){if(a[1]===s.id)throw new Error(RED._("notification.error",{message:RED._("notification.errors.cannotAddSubflowToItself")}));if(RED.nodes.subflowContains(a[1],s.id))throw new Error(RED._("notification.error",{message:RED._("notification.errors.cannotAddCircularReference")}))}var r={id:RED.nodes.id(),z:n||RED.workspaces.active()};if(r.type=e,r._def=RED.nodes.getType(r.type),a){n=RED.nodes.subflow(a[1]);r.name="",r.inputs=n.in.length,r.outputs=n.out.length}else{for(var d in r.inputs=r._def.inputs||0,r.outputs=r._def.outputs,r._def.defaults)r._def.defaults.hasOwnProperty(d)&&void 0!==r._def.defaults[d].value&&(r[d]=JSON.parse(JSON.stringify(r._def.defaults[d].value)));if(r._def.onadd)try{r._def.onadd.call(r)}catch(e){console.log("Definition error: "+r.type+".onadd:",e)}}r.changed=!0,r.moved=!0,r.w=RED.view.node_width,r.h=Math.max(RED.view.node_height,15*(r.outputs||0)),r.resize=!0,null!=t&&"number"==typeof t&&0<=t&&(r.x=t),null!=o&&"number"==typeof o&&0<=o&&(r.y=o);e={t:"add",nodes:[r.id],dirty:i};return s&&(a=RED.subflow.refresh(!0))&&(e.subflow={id:s.id,changed:s.changed,instances:a.instances}),{node:r,historyEvent:e}}return{init:function(){(z=$("#red-ui-workspace-chart")).on("contextmenu",function(e){return e.preventDefault(),e.stopPropagation(),RED.contextMenu.show({x:e.clientX-5,y:e.clientY-5}),!1}),Ee=d3.select("#red-ui-workspace-chart").append("svg:svg").attr("width",w).attr("height",Q).attr("pointer-events","all").style("cursor","crosshair").style("touch-action","none").on("mousedown",function(){Ft()}).on("contextmenu",function(){d3.event.preventDefault()}),(m=Ee.append("svg:g").on("dblclick.zoom",null).append("svg:g").attr("class","red-ui-workspace-chart-event-layer").on("mousemove",Me).on("mousedown",Pe).on("mouseup",Be).on("mouseenter",function(){d3.select(document).on("mouseup.red-ui-workspace-tracker",null),L?1!==d3.event.buttons&&(L.remove(),L=null):M===RED.state.PANNING&&4!==d3.event.buttons?K():S&&2!==d3.event.buttons&&(S.remove(),S=null,K())}).on("mouseleave",ze).on("touchend",function(){d3.event.preventDefault(),clearTimeout(d),d=null,RED.touch.radialMenu.active()||Be.call(this)}).on("touchcancel",function(){RED.view.DEBUG&&console.warn("eventLayer.touchcancel",M),d3.event.preventDefault(),Be.call(this)}).on("touchstart",function(){var e,t,o,n,i,a,s,r;RED.view.DEBUG&&console.warn("eventLayer.touchstart",M),1<d3.event.touches.length?(clearTimeout(d),d=null,d3.event.preventDefault(),e=d3.event.touches.item(0),t=d3.event.touches.item(1),o=e.pageY-t.pageY,n=e.pageX-t.pageX,i=z.offset(),a=[z.scrollLeft(),z.scrollTop()],f=[(t.pageX+n/2-i.left+a[0])/R,(t.pageY+o/2-i.top+a[1])/R],t.pageX,t.pageY,c=Math.sqrt(o*o+n*n)):(s=d3.select(document.body),r=[(e=d3.event.touches.item(0)).pageX,e.pageY],f=[e.pageX,e.pageY],c=0,d3.touches(this)[0],d=setTimeout(function(){d=null,Mt(s,r)},l)),d3.event.preventDefault()}).on("touchmove",function(){var e,t,o,n,i;RED.touch.radialMenu.active()||(RED.view.DEBUG&&console.warn("eventLayer.touchmove",M,T),d3.event.touches.length<2?(d?(i=(n=d3.event.touches.item(0)).pageX-f[0],e=n.pageY-f[1],64<Math.abs(i*i+e*e)&&(clearTimeout(d),d=null,T||se||(M=RED.state.PANNING,A=[n.pageX,n.pageY],ge=[z.scrollLeft(),z.scrollTop()]))):L&&d3.event.preventDefault(),Me.call(this)):(n=d3.event.touches.item(0),i=d3.event.touches.item(1),e=n.pageY-i.pageY,n=n.pageX-i.pageX,z.offset(),t=[z.scrollLeft(),z.scrollTop()],o=Math.sqrt(e*e+n*n),n=[i.pageX+n/2,i.pageY+e/2],isNaN(o)||(oldScaleFactor=R,R=Math.min(2,Math.max(.3,R+Math.floor(100*o-100*c)/1e4)),i=[f[0]*(R-oldScaleFactor),f[1]*(R-oldScaleFactor)],c=o,z.scrollLeft(t[0]+i[0]),z.scrollTop(t[1]+i[1]),H()))),d3.event.preventDefault()})).append("svg:rect").attr("class","red-ui-workspace-chart-background").attr("width",w).attr("height",Q),De=m.append("g").attr("class","red-ui-workspace-chart-grid"),Se(),Te=m.append("g"),$e=m.append("g"),Re=m.append("g"),_e=m.append("g"),xe=m.append("g"),ke=m.append("g"),B=[],RED.events.on("workspace:change",function(e){(M=0)!==e.old&&(n[e.old]={left:z.scrollLeft(),top:z.scrollTop()});var t=z.scrollLeft(),o=z.scrollTop(),e=(P=RED.nodes.subflow(e.workspace),RED.menu.setDisabled("menu-item-workspace-edit",P||0===e.workspace),RED.menu.setDisabled("menu-item-workspace-delete",0===e.workspace||1==RED.workspaces.count()||P),n[e.workspace]?(z.scrollLeft(n[e.workspace].left),z.scrollTop(n[e.workspace].top)):(z.scrollLeft(0),z.scrollTop(0)),z.scrollLeft()-t),t=z.scrollTop()-o;null!=A&&(A[0]+=e,A[1]+=t),0===RED.workspaces.selection().length&&q(),RED.nodes.eachNode(function(e){e.dirty=!0,e.dirtyStatus=!0}),W(),J(),H()}),RED.statusBar.add({id:"view-zoom-controls",align:"right",element:$('<span class="button-group"><button class="red-ui-footer-button" id="red-ui-view-zoom-out"><i class="fa fa-minus"></i></button><button class="red-ui-footer-button" id="red-ui-view-zoom-zero"><i class="fa fa-circle-o"></i></button><button class="red-ui-footer-button" id="red-ui-view-zoom-in"><i class="fa fa-plus"></i></button></span>')}),$("#red-ui-view-zoom-out").on("click",Fe),RED.popover.tooltip($("#red-ui-view-zoom-out"),RED._("actions.zoom-out"),"core:zoom-out"),$("#red-ui-view-zoom-zero").on("click",Ue),RED.popover.tooltip($("#red-ui-view-zoom-zero"),RED._("actions.zoom-reset"),"core:zoom-reset"),$("#red-ui-view-zoom-in").on("click",Ge),RED.popover.tooltip($("#red-ui-view-zoom-in"),RED._("actions.zoom-in"),"core:zoom-in"),z.on("DOMMouseScroll mousewheel",function(e){e.altKey&&(e.preventDefault(),e.stopPropagation(),((-e.originalEvent.detail||e.originalEvent.wheelDelta)<=0?Fe:Ge)())}),RED.statusBar.add({id:"view-search-tools",align:"left",hidden:!1,element:$('<span class="button-group"><button class="red-ui-footer-button" id="red-ui-view-searchtools-search"><i class="fa fa-search"></i></button></span><span class="button-group search-counter"><span class="red-ui-footer-button" id="red-ui-view-searchtools-counter">? of ?</span></span><span class="button-group"><button class="red-ui-footer-button" id="red-ui-view-searchtools-prev"><i class="fa fa-chevron-left"></i></button><button class="red-ui-footer-button" id="red-ui-view-searchtools-next"><i class="fa fa-chevron-right"></i></button></span><span class="button-group"><button class="red-ui-footer-button" id="red-ui-view-searchtools-close"><i class="fa fa-close"></i></button></span>')}),$("#red-ui-view-searchtools-search").on("click",Ve),RED.popover.tooltip($("#red-ui-view-searchtools-search"),RED._("actions.search-flows"),"core:search"),$("#red-ui-view-searchtools-prev").on("click",Je),RED.popover.tooltip($("#red-ui-view-searchtools-prev"),RED._("actions.search-prev"),"core:search-previous"),$("#red-ui-view-searchtools-next").on("click",qe),RED.popover.tooltip($("#red-ui-view-searchtools-next"),RED._("actions.search-next"),"core:search-next"),RED.popover.tooltip($("#red-ui-view-searchtools-close"),RED._("common.label.close")),z.droppable({accept:".red-ui-palette-node",drop:function(e,t){d3.event=e;e=qt($(t.draggable[0]).attr("data-palette-type"));if(e){var o=e.historyEvent,e=e.node,n=(RED.nodes.add(e),RED.utils.getMessageProperty(RED.settings.get("editor"),"view.view-node-show-label")),n=(void 0===n||e._def.hasOwnProperty("showLabel")&&!e._def.showLabel||e._def.defaults.hasOwnProperty("l")||(e.l=n),d3.touches(t.helper.get(0))[0]||d3.mouse(t.helper.get(0))),i=t.helper.width(),a=t.helper.height(),s=d3.touches(this)[0]||d3.mouse(this);try{var r="link in"===e.type||"link out"===e.type,d=e.hasOwnProperty("l")?!e.l:r,l=Qe(RED.utils.getNodeLabel(e,e.type),"red-ui-flow-node-label");d?(e.w=N,e.h=Math.max(N,15*(e.outputs||0))):(e.w=Math.max(I,20*Math.ceil((l.width+50+(0<e._def.inputs?7:0))/20)),e.h=Math.max(6+24*l.lines.length,15*(e.outputs||0),30))}catch(e){}s[1]+=this.scrollTop+(a/2-n[1]),s[0]+=this.scrollLeft+(i/2-n[0]),s[1]/=R,s[0]/=R,e.x=s[0],e.y=s[1];var r=e.w/2-5,d=(e.x<r&&(e.x=r),e.h/2-5),l=(e.y<d&&(e.y=d),w-e.w/2+5),a=(e.x>l&&(e.x=l),Q-e.h+5),n=(e.y>a&&(e.y=a),ee&&(i=RED.view.tools.calculateGridSnapOffsets(e),e.x-=i.x,e.y-=i.y),$(t.helper).data("splice")),d=(n&&(RED.nodes.removeLink(n),s={source:n.source,sourcePort:n.sourcePort,target:e},r={source:e,sourcePort:0,target:n.target},RED.nodes.addLink(s),RED.nodes.addLink(r),o.links=[s,r],o.removedLinks=[n]),$(t.helper).data("group"));d&&(RED.group.addToGroup(d,e),(o={t:"multi",events:[o]}).events.push({t:"addToGroup",group:d,nodes:e})),RED.history.push(o),RED.editor.validateNode(e),RED.nodes.dirty(!0),Ot(),q(),e.selected=!0,U.add(e),d&&(v(d,!1),b(d),g=d),J(),W(),H(),e._def.autoedit&&RED.editor.edit(e)}}}),z.on("focus",function(){$("#red-ui-workspace-tabs").addClass("red-ui-workspace-focussed")}),z.on("blur",function(){$("#red-ui-workspace-tabs").removeClass("red-ui-workspace-focussed")}),RED.actions.add("core:copy-selection-to-internal-clipboard",Ze),RED.actions.add("core:cut-selection-to-internal-clipboard",function(){Ze(!0),Ye()}),RED.actions.add("core:paste-from-internal-clipboard",function(){Ut(ye,{generateIds:"copy"===we,generateDefaultNames:"copy"===we})}),RED.actions.add("core:detach-selected-nodes",function(){var e,t,o=RED.view.selection();o.nodes&&({newLinks:e,removedLinks:t}=RED.nodes.detachNodes(o.nodes),(t.length||e.length)&&(RED.history.push({t:"multi",events:[{t:"delete",links:t},{t:"add",links:e}],dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0)),ht([o.nodes[0].x,o.nodes[0].y]),M=RED.state.DETACHED_DRAGGING,RED.view.redraw(!0))}),RED.events.on("view:selection-changed",function(e){var t=e.nodes&&0<e.nodes.length,e=t&&1<e.nodes.length;RED.menu.setDisabled("menu-item-edit-cut",!t),RED.menu.setDisabled("menu-item-edit-copy",!t),RED.menu.setDisabled("menu-item-edit-select-connected",!t),RED.menu.setDisabled("menu-item-view-tools-move-to-back",!t),RED.menu.setDisabled("menu-item-view-tools-move-to-front",!t),RED.menu.setDisabled("menu-item-view-tools-move-backwards",!t),RED.menu.setDisabled("menu-item-view-tools-move-forwards",!t),RED.menu.setDisabled("menu-item-view-tools-align-left",!e),RED.menu.setDisabled("menu-item-view-tools-align-center",!e),RED.menu.setDisabled("menu-item-view-tools-align-right",!e),RED.menu.setDisabled("menu-item-view-tools-align-top",!e),RED.menu.setDisabled("menu-item-view-tools-align-middle",!e),RED.menu.setDisabled("menu-item-view-tools-align-bottom",!e),RED.menu.setDisabled("menu-item-view-tools-distribute-horizontally",!e),RED.menu.setDisabled("menu-item-view-tools-distribute-veritcally",!e)}),RED.actions.add("core:delete-selection",Ye),RED.actions.add("core:delete-selection-and-reconnect",function(){Ye(!0)}),RED.actions.add("core:edit-selected-node",Xe),RED.actions.add("core:go-to-selection",function(){var e;0<U.length()&&(e=U.get(0).n,/^subflow:/.test(e.type)?RED.workspaces.show(e.type.substring(8)):"group"===e.type&&(b(e),H()))}),RED.actions.add("core:undo",RED.history.pop),RED.actions.add("core:redo",RED.history.redo),RED.actions.add("core:select-all-nodes",Ke),RED.actions.add("core:select-none",We),RED.actions.add("core:zoom-in",Ge),RED.actions.add("core:zoom-out",Fe),RED.actions.add("core:zoom-reset",Ue),RED.actions.add("core:enable-selected-nodes",function(){Vt(!1)}),RED.actions.add("core:disable-selected-nodes",function(){Vt(!0)}),RED.actions.add("core:toggle-show-grid",function(e){void 0===e?RED.userSettings.toggle("view-show-grid"):e?De.style("visibility","visible"):De.style("visibility","hidden")}),RED.actions.add("core:toggle-snap-grid",function(e){void 0===e?RED.userSettings.toggle("view-snap-grid"):(ee=e,H())}),RED.actions.add("core:toggle-status",function(e){void 0===e?RED.userSettings.toggle("view-node-status"):(s=e,RED.nodes.eachNode(function(e){e.dirtyStatus=!0,e.dirty=!0}),H())}),RED.view.annotations.init(),RED.view.navigator.init(),RED.view.tools.init(),RED.view.annotations.register("red-ui-flow-node-changed",{type:"badge",class:"red-ui-flow-node-changed",element:function(){var e=document.createElementNS("http://www.w3.org/2000/svg","circle");return e.setAttribute("cx",5),e.setAttribute("cy",5),e.setAttribute("r",5),e},show:function(e){return e.changed||e.moved}}),RED.view.annotations.register("red-ui-flow-node-error",{type:"badge",class:"red-ui-flow-node-error",element:function(e){var t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M 0,9 l 10,0 -5,-8 z"),t},tooltip:function(e){if(e.validationErrors&&0<e.validationErrors.length)return RED._("editor.errors.invalidProperties")+"\n - "+e.validationErrors.join("\n - ")},show:function(e){return!e.valid}}),RED.settings.get("editor.view.view-store-zoom")&&(o=parseFloat(RED.settings.getLocal("zoom-level")),isNaN(o)||(R=o));var e=null;function t(){n[RED.workspaces.active()]={left:z.scrollLeft(),top:z.scrollTop()},RED.settings.setLocal("scroll-positions",JSON.stringify(n))}if(z.on("scroll",function(){RED.settings.get("editor.view.view-store-position")&&(e&&clearTimeout(e),e=setTimeout(t,200))}),RED.settings.get("editor.view.view-store-position")){var o=RED.settings.getLocal("scroll-positions");if(o)try{n=JSON.parse(o)}catch(e){}}},state:function(e){if(null==e)return M;M=e},updateActive:J,redraw:function(e,t){e&&(J(),W()),(t?Gt:H)()},focus:Ft,importNodes:Ut,calculateTextWidth:function(e,t){for(var o=nt(e),n=0,i=0;i<o.length;i++){var a=ot(o[i],t)[0];n<a&&(n=a)}return n},select:function(e){var t;void 0!==e&&(q(),"string"==typeof e?(t=RED.nodes.node(e))&&(t.selected=!0,t.dirty=!0,U.clear(),U.add(t)):e&&e.nodes&&(J(),U.clear(),e.nodes.forEach(function(e){"group"!==e.type?(e.selected=!0,e.dirty=!0,U.add(e)):v(e,!0)}))),W(),H()},selection:Jt,clearSelection:q,createNode:qt,get node_width(){return I},get node_height(){return N},get snapGrid(){return ee},scale:function(){return R},getLinksAtPoint:function(e,t){for(var o=[],n=Ee.selectAll(".red-ui-flow-link-background")[0],i=0;i<n.length;i++){var a=n[i].getBBox();e>=a.x&&t>=a.y&&e<=a.x+a.width&&t<=a.y+a.height&&o.push(n[i])}return o},getGroupAtPoint:Nt,getActiveGroup:function(){return g},reveal:function(e,t){if(RED.nodes.workspace(e)||RED.nodes.subflow(e))RED.workspaces.show(e,null,null,!0);else{var o=RED.nodes.node(e)||RED.nodes.group(e);if(o)if(!o.z||"group"!==o.type&&"config"===o._def.category)"config"===o._def.category&&RED.sidebar.config.show(e);else{o.dirty=!0,RED.workspaces.show(o.z);var e=[z[0].clientWidth/R,z[0].clientHeight/R],n=[z.scrollLeft()/R,z.scrollTop()/R],i=o.x,a=o.y;if("group"===o.type&&(i+=o.w/2,a+=o.h/2),(i<n[0]||a<n[1]||e[0]+n[0]<i||e[1]+n[1]<a)&&(i="-="+(n[0]-i+e[0]/2)*R,n="-="+(n[1]-a+e[1]/2)*R,z.animate({scrollLeft:i,scrollTop:n},200)),!1!==t){a=o;let e=a;if(e="string"==typeof e?RED.nodes.node(a):e){const s=r&&RED.nodes.node(r);s&&(clearInterval(s.__flashTimer),delete s.__flashTimer,s.dirty=!0,s.highlighted=!1),e.__flashTimer=setInterval(function(e,t){t.dirty=!0,e>=Date.now()?t.highlighted=!t.highlighted:(clearInterval(t.__flashTimer),delete t.__flashTimer,r=null,t.highlighted=!1),RED.view.redraw()},100,Date.now()+2200,e),r=e.id,e.highlighted=!0,RED.view.redraw()}}}}},gridSize:function(e){if(void 0===e)return E;E=Math.max(5,e),Se()},getActiveNodes:function(){return y},getSubflowPorts:function(){var o=[];return P&&(ke.selectAll(".red-ui-flow-subflow-port-output").data(P.out,function(e,t){return e.id}).each(function(e,t){o.push(e)}),ke.selectAll(".red-ui-flow-subflow-port-input").data(P.in,function(e,t){return e.id}).each(function(e,t){o.push(e)}),ke.selectAll(".red-ui-flow-subflow-port-status").data(P.status?[P.status]:[],function(e,t){return e.id}).each(function(e,t){o.push(e)})),o},selectNodes:function(e){$("#red-ui-workspace-tabs-shade").show(),$("#red-ui-palette-shade").show(),$("#red-ui-sidebar-shade").show(),$("#red-ui-header-shade").show(),$("#red-ui-workspace").addClass("red-ui-workspace-select-mode"),M=RED.state.SELECTING_NODE,q(),e.selected&&e.selected.forEach(function(e){e=RED.nodes.node(e);e&&(e.selected=!0,e.dirty=!0,U.add(e))}),H();function t(){q(),$("#red-ui-workspace-tabs-shade").hide(),$("#red-ui-palette-shade").hide(),$("#red-ui-sidebar-shade").hide(),$("#red-ui-header-shade").hide(),$("#red-ui-workspace").removeClass("red-ui-workspace-select-mode"),K(),o.close()}(u=e||{}).done=function(e){t(),u.onselect&&u.onselect(e)};var e=[{text:RED._("common.label.cancel"),click:function(e){t(),u.oncancel&&u.oncancel()}}],o=(u.single||e.push({text:RED._("common.label.done"),class:"primary",click:function(e){var t=U.nodes();u.done(t)}}),RED.notify(u.prompt||RED._("workspace.selectNodes"),{modal:!1,fixed:!0,type:"compact",buttons:e}))},scroll:function(e,t){z.scrollLeft(z.scrollLeft()+e),z.scrollTop(z.scrollTop()+t)},clickNodeButton:function(e){e._def.button&&At(e)},clipboard:function(){return ye},redrawStatus:Bt,showQuickAddDialog:Ae,calculateNodeDimensions:function(t){var e=[I,N];try{var o="link in"===t.type||"link out"===t.type,n=t.hasOwnProperty("l")?!t.l:o,i=Qe(RED.utils.getNodeLabel(t,t.type),"red-ui-flow-node-label");e[1]=n?Math.max(N,15*(t.outputs||0)):Math.max(6+24*i.lines.length,15*(t.outputs||0),30),e[0]=n?N:Math.max(I,20*Math.ceil((i.width+50+(0<t._def.inputs?7:0))/20))}catch(e){console.log("Error",t)}return e},getElementPosition:lt,showTooltip:ut,dimensions:function(){return{width:w,height:Q}}}}(),RED.view.annotations=function(){var r,d,c={};function u(e,t){var n,i,a,o=c[e],s=(t.el.__annotations__=t.el.__annotations__||[],document.createElementNS("http://www.w3.org/2000/svg","g")),e=(s.setAttribute("class",o.class||""),t.el.__annotations__.push({id:e,element:s}),o.element(t.node));o.tooltip&&(e.addEventListener("mouseenter",(n=e,i=t.node,a=o.tooltip,function(){var o="function"==typeof a?a(i):a;o&&(clearTimeout(r),r=setTimeout(function(){var e=RED.view.getElementPosition(n),t=n.getBoundingClientRect();r=null,d=RED.view.showTooltip(e[0]+t.width/2,e[1],o,"top")},500))})),e.addEventListener("mouseleave",l)),s.appendChild(e),t.el.appendChild(s)}function l(){clearTimeout(r),d&&(d.remove(),d=null)}return{init:function(){RED.hooks.add("viewRedrawNode.annotations",function(e){try{e.node.__pendingAnnotation__&&(u(e.node.__pendingAnnotation__,e),delete e.node.__pendingAnnotation__);for(var t=0,o=0,n=0,i=e.el.__annotations__.length;n<i;n++){var a,s,r,d,l=e.el.__annotations__[n];c.hasOwnProperty(l.id)?(a=c[l.id],s=!0,r="badge"===a.type,void 0!==a.show&&(s="string"==typeof a.show?!!e.node[a.show]:"function"==typeof a.show?a.show(e.node):!!a.show,l.element.classList.toggle("hide",!s)),r?s&&(t+=(d=l.element.getBoundingClientRect()).width,l.element.setAttribute("transform","translate("+(e.node.w-3-t)+", -8)"),t+=4):s&&(d=l.element.getBoundingClientRect(),l.element.setAttribute("transform","translate("+(3+o)+", -12)"),o+=d.width+4)):(l.element.parentNode.removeChild(l.element),e.el.__annotations__.splice(n,1),n--,i--)}}catch(e){console.log(e)}})},register:function(t,o){if("badge"!==o.type)throw new Error("Unsupported annotation type: "+o.type);c[t]=o,RED.hooks.add("viewAddNode.annotation-"+t,function(e){o.filter&&!o.filter(e.node)||u(t,e)}),RED.view.getActiveNodes().forEach(function(e){e.__pendingAnnotation__=t}),RED.view.redraw()},unregister:function(e){delete c[e],RED.hooks.remove("*.annotation-"+e),RED.view.redraw()}}}(),RED.view.navigator=function(){var e,t,o,n,i,a,s,r,d,l=25,c=5e3/l,u=5e3/l,p=!1;function f(){var e;p&&((e=n.selectAll(".red-ui-navigator-node").data(RED.view.getActiveNodes(),function(e){return e.id})).exit().remove(),e.enter().insert("rect").attr("class","red-ui-navigator-node").attr("pointer-events","none"),e.each(function(e){d3.select(this).attr("x",function(e){return(e.x-e.w/2)/l}).attr("y",function(e){return(e.y-e.h/2)/l}).attr("width",function(e){return Math.max(9,e.w/l)}).attr("height",function(e){return Math.max(3,e.h/l)}).attr("fill",function(e){return RED.utils.getNodeColor(e.type,e._def)})}))}function h(){d||g()}function g(){o&&(a=RED.view.scale(),s=[$("#red-ui-workspace-chart").width(),$("#red-ui-workspace-chart").height()],i=[$("#red-ui-workspace-chart").scrollLeft(),$("#red-ui-workspace-chart").scrollTop()],o.attr("x",i[0]/l).attr("y",i[1]/l).attr("width",s[0]/l/a).attr("height",s[1]/l/a))}function m(){p?(p=!1,e.fadeOut(100),$("#red-ui-workspace-chart").off("scroll",h),$("#red-ui-view-navigate").removeClass("selected")):(p=!0,$("#red-ui-view-navigate").addClass("selected"),g(),f(),$("#red-ui-workspace-chart").on("scroll",h),e.fadeIn(200))}return{init:function(){$(window).on("resize",g),RED.events.on("sidebar:resize",g),RED.actions.add("core:toggle-navigator",m),e=$("<div>").css({position:"absolute",bottom:$("#red-ui-workspace-footer").height(),right:0,zIndex:1}).appendTo("#red-ui-workspace").hide(),(t=d3.select(e[0]).append("svg:svg").attr("width",c).attr("height",u).attr("pointer-events","all").attr("id","red-ui-navigator-canvas")).append("rect").attr("x",0).attr("y",0).attr("width",c).attr("height",u).style({fill:"none",stroke:"none",pointerEvents:"all"}).on("mousedown",function(){a=RED.view.scale(),s=[$("#red-ui-workspace-chart").width(),$("#red-ui-workspace-chart").height()],r=[s[0]/l/a,s[1]/l/a];var e=Math.max(0,Math.min(d3.event.offsetX+r[0]/2,c)-r[0]),t=Math.max(0,Math.min(d3.event.offsetY+r[1]/2,u)-r[1]);o.attr("x",e).attr("y",t),d=!0,$("#red-ui-workspace-chart").scrollLeft(e*l*a),$("#red-ui-workspace-chart").scrollTop(t*l*a)}).on("mousemove",function(){var e,t;d&&(0===d3.event.buttons?d=!1:(e=Math.max(0,Math.min(d3.event.offsetX+r[0]/2,c)-r[0]),t=Math.max(0,Math.min(d3.event.offsetY+r[1]/2,u)-r[1]),o.attr("x",e).attr("y",t),$("#red-ui-workspace-chart").scrollLeft(e*l*a),$("#red-ui-workspace-chart").scrollTop(t*l*a)))}).on("mouseup",function(){d=!1}),o=t.append("rect").attr("class","red-ui-navigator-border"),n=t.append("svg:g"),RED.statusBar.add({id:"view-navigator",align:"right",element:$('<button class="red-ui-footer-button-toggle single" id="red-ui-view-navigate"><i class="fa fa-map-o"></i></button>')}),$("#red-ui-view-navigate").on("click",function(e){e.preventDefault(),m()}),RED.popover.tooltip($("#red-ui-view-navigate"),RED._("actions.toggle-navigator"),"core:toggle-navigator")},refresh:f,resize:g,toggle:m}}(),RED.view.tools=function(){function t(o){var e=RED.view.selection(),n=new Set;e.nodes&&0<e.nodes.length&&(e.nodes.forEach(function(e){var t;n.has(e)||("all"===o?t=RED.nodes.getAllFlowNodes(e):"up"===o?t=[e].concat(RED.nodes.getAllUpstreamNodes(e)):"down"===o&&(t=[e].concat(RED.nodes.getAllDownstreamNodes(e))),t.forEach(function(e){n.add(e)}))}),RED.view.select({nodes:Array.from(n)}))}function e(){var n,e=RED.view.selection();e.nodes&&(n=[],e.nodes.forEach(function(e){var t=e.w/2+Math.round((e.x-e.w/2)/RED.view.gridSize())*RED.view.gridSize(),o=Math.round(e.y/RED.view.gridSize())*RED.view.gridSize();e.x===t&&e.y===o||(n.push({n:e,ox:e.x,oy:e.y,moved:e.moved}),e.x=t,e.y=o,e.dirty=!0,e.moved=!0)}),0<n.length&&(RED.history.push({t:"move",nodes:n,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0)))}var u=null,p=!1;function f(){if(p=!1,0<u.length){for(var e=[],t=0;t<u.length;t++)e.push({n:u[t].n,ox:u[t].ox,oy:u[t].oy,moved:u[t].moved}),u[t].n.moved=!0,u[t].n.dirty=!0,delete u[t].ox,delete u[t].oy;RED.view.redraw(),RED.history.push({t:"move",nodes:e,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),u=null}}function o(e,t){if(null===u){u=[];var o=RED.view.selection();if(o.nodes)for(;0<o.nodes.length;){var n=o.nodes.shift();u.push({n:n}),"group"===n.type&&(o.nodes=o.nodes.concat(n.nodes))}}if(u&&0<u.length){p||($(document).one("keyup",f),p=!0);for(var i,a=RED.view.dimensions(),s=a.width,r=a.height,d=0,l=0,c=0;c<u.length;c++)null==(i=u[c]).ox&&null==i.oy&&(i.ox=i.n.x,i.oy=i.n.y,i.moved=i.n.moved),i.n.moved=!0,i.n.dirty=!0,i.n.x+=e,i.n.y+=t,i.n.x+i.n.w/2>=s&&(i.n.x=s-i.n.w/2),i.n.y+i.n.h/2>=r&&(i.n.y=r-i.n.h/2),i.n.dirty=!0,l="group"===i.n.type?(RED.group.markDirty(i.n),d=Math.min(i.n.x-5,d),Math.min(i.n.y-5,l)):(d=Math.min(i.n.x-i.n.w/2-5,d),Math.min(i.n.y-i.n.h/2-5,l));if(0!==d||0!==l)for(n=0;n<u.length;n++)(i=u[n]).n.x-=d,i.n.y-=l;RED.view.redraw()}else RED.view.scroll(10*e,10*t)}function n(i){var e=RED.view.selection(),a=[],t=[];e.nodes&&e.nodes.forEach(function(e){"subflow"!==e.type&&"group"!==e.type?t.push(e):"group"===e.type&&(t=t.concat(RED.group.getNodes(e,!0)))}),t.forEach(function(e){var t=!1,o=void 0===e.l||e.l,n=!e._def.hasOwnProperty("showLabel")||e._def.showLabel;i?!1!==e.l&&(n||e.hasOwnProperty("l"))||(t=e.l=!0):(!n||e.hasOwnProperty("l")&&!0!==e.l)&&(n||!0!==e.l)||(t=!(e.l=!1)),t&&(a.push({t:"edit",node:e,changed:e.changed,changes:{l:o}}),e.changed=!0,e.dirty=!0,e.resize=!0)}),0<a.length&&(RED.history.push({t:"multi",events:a,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0)),RED.view.redraw()}function i(){var n={x:0,y:0},e=RED.view.getActiveGroup(),i=(e?(candidates=RED.group.getNodes(e,!1),n=e):candidates=RED.view.getActiveNodes(),[]);candidates.forEach(function(e){var t=e.x-n.x,o=e.y-n.x;i.push({node:e,delta:o*o+t*t})}),0<i.length&&(i.sort(function(e,t){return e.delta-t.delta}),(e=i[0].node)&&(RED.view.select({nodes:[e]}),RED.view.reveal(e.id,!1)))}function a(e){return RED.nodes.filterLinks({source:e}).map(function(e){return e.target})}function s(e){return RED.nodes.filterLinks({target:e}).map(function(e){return e.source})}function r(e){var t=new Set;return s(e).forEach(function(e){a(e).forEach(function(e){t.add(e)})}),a(e).forEach(function(e){s(e).forEach(function(e){t.add(e)})}),t.delete(e),Array.from(t)}function d(s){var r,e,d,t,o=RED.view.selection();o.nodes&&1===o.nodes.length?(r=o.nodes[0],d=[],(e=(e=RED.nodes.filterNodes({z:r.z})).concat(RED.view.getSubflowPorts())).forEach(function(e){if(e!==r){var t,o=e.x-r.x,n=e.y-r.y,i=n*n+o*o,a=180/Math.PI*Math.atan2(n,o);switch(a<0&&(a+=360),360<a&&(a-=360),s){case"up":if(a<210||330<a)return;t=Math.max(Math.abs(270-a)/60,.2);break;case"down":if(a<30||150<a)return;t=Math.max(Math.abs(90-a)/60,.2);break;case"left":if(a<140||220<a)return;t=Math.max(Math.abs(180-a)/40,.1);break;case"right":if(40<a&&a<320)return;t=Math.max(Math.abs(a)/40,.1)}t=Math.max(t,.1),d.push({node:e,d:i,w:t,delta:i*t})}}),0<d.length&&(d.sort(function(e,t){return e.delta-t.delta}),(t=d[0].node)&&(RED.view.select({nodes:[t]}),RED.view.reveal(t.id,!1)))):0===RED.workspaces.selection().length&&(e=RED.view.getActiveNodes(),d=[],e.forEach(function(e){var t=e.x,o=e.y;d.push({node:e,delta:o*o+t*t})}),0<d.length&&(d.sort(function(e,t){return e.delta-t.delta}),(t=d[0].node)&&(RED.view.select({nodes:[t]}),RED.view.reveal(t.id,!1))))}function l(r){var d,l,e=RED.view.selection();e.nodes&&1<e.nodes.length&&(d=[],l={minX:Number.MAX_SAFE_INTEGER,minY:Number.MAX_SAFE_INTEGER,maxX:Number.MIN_SAFE_INTEGER,maxY:Number.MIN_SAFE_INTEGER},e.nodes.forEach(function(e){"group"===e.type?(l.minX=Math.min(l.minX,e.x),l.minY=Math.min(l.minY,e.y),l.maxX=Math.max(l.maxX,e.x+e.w),l.maxY=Math.max(l.maxY,e.y+e.h)):(l.minX=Math.min(l.minX,e.x-e.w/2),l.minY=Math.min(l.minY,e.y-e.h/2),l.maxX=Math.max(l.maxX,e.x+e.w/2),l.maxY=Math.max(l.maxY,e.y+e.h/2))}),l.midX=l.minX+(l.maxX-l.minX)/2,l.midY=l.minY+(l.maxY-l.minY)/2,e.nodes.forEach(function(e){var t,o,n,i,a,s="group"===e.type;switch(r){case"top":t=e.x,o=l.minY+(s?0:e.h/2);break;case"bottom":t=e.x,o=l.maxY-(s?e.h:e.h/2);break;case"left":t=l.minX+(s?0:e.w/2),o=e.y;break;case"right":t=l.maxX-(s?e.w:e.w/2),o=e.y;break;case"middle":t=e.x,o=l.midY-(s?e.h/2:0);break;case"center":t=l.midX-(s?e.w/2:0),o=e.y}e.x===t&&e.y===o||(s?(n=RED.group.getNodes(e,!0),i=e.x-t,a=e.y-o,n.forEach(function(e){"group"!==e.type&&(d.push({n:e,ox:e.x,oy:e.y,moved:e.moved}),e.x=e.x-i,e.y=e.y-a,e.dirty=!0,e.moved=!0)})):(d.push({n:e,ox:e.x,oy:e.y,moved:e.moved}),e.x=t,e.y=o,e.dirty=!0,e.moved=!0))}),0<d.length&&(RED.history.push({t:"move",nodes:d,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0)))}function c(n){var e=RED.view.selection();if(e.nodes&&2<e.nodes.length){var t=[],i={minX:Number.MAX_SAFE_INTEGER,minY:Number.MAX_SAFE_INTEGER,maxX:Number.MIN_SAFE_INTEGER,maxY:Number.MIN_SAFE_INTEGER},a=[],s=[],o=(e.nodes.forEach(function(e){var t,o="group"===e.type?(t=e.x+e.w/2,e.y+e.h/2):(t=e.x,e.y);"h"===n?(t<i.minX&&(a=[],i.minX=t),t===i.minX&&a.push(e),t>i.maxX&&(s=[],i.maxX=t),t===i.maxX&&s.push(e)):(o<i.minY&&(a=[],i.minY=o),o===i.minY&&a.push(e),o>i.maxY&&(s=[],i.maxY=o),o===i.maxY&&s.push(e))}),a[0]),r=s[0],d=0,l=e.nodes.filter(function(e){return e.id!==o.id&&e.id!==r.id&&(d+="h"===n?e.w:e.h,!0)}).sort(function(e,t){return"h"===n?e.x-t.x:e.y-t.y}),e=o.x+o.w/2,c=o.y+o.h/2,u=("group"===o.type&&(e=o.x+o.w,c=o.y+o.h),r.x),p=r.y;"group"!==r.type&&(u-=r.w/2,p-=r.h/2);for(var f=("h"===n?u-e-d:p-c-d)/(l.length+1),h=e,g=c;0<l.length;){"h"===n?h+=f:g+=f;var m,v,b,y=l.shift(),w="group"===y.type,E=y.x,D=y.y;w||(h+=y.w/2,g+=y.h/2),("h"===n&&E!==h||"v"===n&&D!==g)&&(w?(m=RED.group.getNodes(y,!0),v="h"===n?E-h:0,b="v"===n?D-g:0,m.forEach(function(e){"group"!==e.type&&(t.push({n:e,ox:e.x,oy:e.y,moved:e.moved}),e.x=e.x-v,e.y=e.y-b,e.dirty=!0,e.moved=!0)})):(t.push({n:y,ox:y.x,oy:y.y,moved:y.moved}),"h"===n?y.x=h:y.y=g,y.dirty=!0,y.moved=!0)),w?(h+=y.w,g+=y.h):(h+=y.w/2,g+=y.h/2)}0<t.length&&(RED.history.push({t:"move",nodes:t,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0))}}function h(e){var t,o,n,i=RED.view.selection();i.nodes&&(t=[],i.nodes.forEach(function(e){"group"===e.type?t=t.concat(RED.group.getNodes(e,!0).filter(function(e){return"group"!==e.type})):"subflow"!==e.type&&t.push(e)}),0<t.length&&(i=t[0].z,o=RED.nodes.getNodeOrder(i),"forwards"===e?n=RED.nodes.moveNodesForwards(t):"backwards"===e?n=RED.nodes.moveNodesBackwards(t):"front"===e?n=RED.nodes.moveNodesToFront(t):"back"===e&&(n=RED.nodes.moveNodesToBack(t)),0<n.length&&(e=RED.nodes.getNodeOrder(i),RED.history.push({t:"reorder",nodes:{z:i,from:o,to:e},dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0))))}function g(e){let n=e||RED.view.selection().links&&RED.view.selection().links.filter(e=>!e.link);if(n&&!((n=Array.isArray(n)?n:[n]).length<1)){const p={t:"multi",events:[],dirty:RED.nodes.dirty()},f={},h={},g=RED.view.gridSize();for(let o=0;o<n.length;o++){function i(e,t,o,n,i){var a=RED.view.calculateNodeDimensions(t);t.w=a[0],t.h=a[1];const s={x:e.x||0,y:e.y||0,w:e.w||RED.view.node_width,h:e.h||RED.view.node_height};a=s.x-s.w/2;s.x=o?a-g-t.w/2:a+s.w+g+t.w/2,t.x=s.x,t.y=s.y,!1!==n&&(e=RED.view.tools.calculateGridSnapOffsets(t),t.x-=e.x,t.y-=e.y),t.y+=i||0}var a=n[o],s=a.source,r=a.target,d=a.sourcePort||0,l=s.id+":"+d;let t=f[l];if(!t){var c=RED.view.createNode("link out");t=c.node,f[l]=t;let e=0;1<s.outputs?(l=(s.outputs-1)/2+1,u=Math.abs(l-(d+1)),e=2*g*u,d+1<l&&(e=-e),i(s,t,!1,!1,e)):i(s,t,!1,RED.view.snapGrid,e),RED.nodes.add(t),RED.editor.validateNode(t),p.events.push(c.historyEvent);var u={source:s,sourcePort:a.sourcePort||0,target:t};RED.nodes.addLink(u),p.events.push({t:"add",links:[u]})}let e=h[r.id];e||(d=RED.view.createNode("link in"),e=d.node,i(r,h[r.id]=e,!0,RED.view.snapGrid,0),RED.nodes.add(e),RED.editor.validateNode(e),p.events.push(d.historyEvent),l={source:e,sourcePort:0,target:r},RED.nodes.addLink(l),p.events.push({t:"add",links:[l]})),-1==e.links.indexOf(t.id)&&e.links.push(t.id),-1==t.links.indexOf(e.id)&&t.links.push(e.id),RED.nodes.removeLink(a),p.events.push({t:"delete",links:[a]})}RED.history.push(p),RED.view.clearSelection(),RED.view.select({nodes:Object.values(h)}),t("down"),RED.nodes.dirty(!0),RED.view.redraw(!0)}}function m(e,s){s=Object.assign({renameBlank:!0,renameClash:!0,generateHistory:!0},s);let t=e;if(e?Array.isArray(e)||(t=[e]):t=RED.view.selection().nodes,t&&0<t.length){const r=s.generateHistory&&(!e||!!RED.nodes.node(e.id)),d=[],l={};let a=!1;t.forEach(e=>{var t=e._def||RED.nodes.getType(e.type);if(t&&t.defaults&&t.defaults.name){const o=RED.utils.getPaletteLabel(e.type,t),n=new RegExp("^"+o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+" (\\d+)$");if(!l.hasOwnProperty(e.type)){const i=RED.nodes.filterNodes({type:e.type});let t=0;i.forEach(e=>{var e=n.exec(e.name);e&&(e=parseInt(e[1]))>t&&(t=e)}),l[e.type]=t+1}(s.renameBlank&&""===e.name||s.renameClash&&n.test(e.name))&&(r&&d.push({t:"edit",node:e,changes:{name:e.name},dirty:RED.nodes.dirty(),changed:e.changed}),e.name=o+" "+l[e.type],e.dirty=!0,l[e.type]++,a=!0)}}),a&&(0<d.length&&RED.history.push({t:"multi",events:d}),RED.nodes.dirty(!0),RED.view.redraw())}}return{init:function(){RED.actions.add("core:show-selected-node-labels",function(){n(!0)}),RED.actions.add("core:hide-selected-node-labels",function(){n(!1)}),RED.actions.add("core:scroll-view-up",function(){RED.view.scroll(0,-RED.view.gridSize())}),RED.actions.add("core:scroll-view-right",function(){RED.view.scroll(RED.view.gridSize(),0)}),RED.actions.add("core:scroll-view-down",function(){RED.view.scroll(0,RED.view.gridSize())}),RED.actions.add("core:scroll-view-left",function(){RED.view.scroll(-RED.view.gridSize(),0)}),RED.actions.add("core:step-view-up",function(){RED.view.scroll(0,-5*RED.view.gridSize())}),RED.actions.add("core:step-view-right",function(){RED.view.scroll(5*RED.view.gridSize(),0)}),RED.actions.add("core:step-view-down",function(){RED.view.scroll(0,5*RED.view.gridSize())}),RED.actions.add("core:step-view-left",function(){RED.view.scroll(-5*RED.view.gridSize(),0)}),RED.actions.add("core:move-selection-up",function(){o(0,-1)}),RED.actions.add("core:move-selection-right",function(){o(1,0)}),RED.actions.add("core:move-selection-down",function(){o(0,1)}),RED.actions.add("core:move-selection-left",function(){o(-1,0)}),RED.actions.add("core:move-selection-forwards",function(){h("forwards")}),RED.actions.add("core:move-selection-backwards",function(){h("backwards")}),RED.actions.add("core:move-selection-to-front",function(){h("front")}),RED.actions.add("core:move-selection-to-back",function(){h("back")}),RED.actions.add("core:step-selection-up",function(){o(0,-RED.view.gridSize())}),RED.actions.add("core:step-selection-right",function(){o(RED.view.gridSize(),0)}),RED.actions.add("core:step-selection-down",function(){o(0,RED.view.gridSize())}),RED.actions.add("core:step-selection-left",function(){o(-RED.view.gridSize(),0)}),RED.actions.add("core:select-connected-nodes",function(){t("all")}),RED.actions.add("core:select-downstream-nodes",function(){t("down")}),RED.actions.add("core:select-upstream-nodes",function(){t("up")}),RED.actions.add("core:go-to-next-node",function(){var o,e;(e=RED.view.selection()).nodes&&1===e.nodes.length?(o=e.nodes[0],0<(e=RED.nodes.filterLinks({source:o})).length&&(e.sort(function(e,t){return Math.abs(e.target.y-o.y)-Math.abs(t.target.y-o.y)}),(e=e[0].target)&&(RED.view.select({nodes:[e]}),RED.view.reveal(e.id,!1)))):0===RED.workspaces.selection().length&&i()}),RED.actions.add("core:go-to-previous-node",function(){var o,e;(e=RED.view.selection()).nodes&&1===e.nodes.length?(o=e.nodes[0],0<(e=RED.nodes.filterLinks({target:o})).length&&(e.sort(function(e,t){return Math.abs(e.source.y-o.y)-Math.abs(t.source.y-o.y)}),(e=e[0].source)&&(RED.view.select({nodes:[e]}),RED.view.reveal(e.id,!1)))):0===RED.workspaces.selection().length&&i()}),RED.actions.add("core:go-to-next-sibling",function(){var o,e;(e=RED.view.selection()).nodes&&1===e.nodes.length?0<(e=r(o=e.nodes[0])).length&&((e=e.filter(function(e){return e.y>o.y})).sort(function(e,t){return Math.abs(e.y-o.y)-Math.abs(t.y-o.y)}),(e=e[0])&&(RED.view.select({nodes:[e]}),RED.view.reveal(e.id,!1))):0===RED.workspaces.selection().length&&i()}),RED.actions.add("core:go-to-previous-sibling",function(){var o,e;(e=RED.view.selection()).nodes&&1===e.nodes.length?0<(e=r(o=e.nodes[0])).length&&((e=e.filter(function(e){return e.y<o.y})).sort(function(e,t){return Math.abs(e.y-o.y)-Math.abs(t.y-o.y)}),(e=e[0])&&(RED.view.select({nodes:[e]}),RED.view.reveal(e.id,!1))):0===RED.workspaces.selection().length&&i()}),RED.actions.add("core:go-to-nearest-node-on-left",function(){d("left")}),RED.actions.add("core:go-to-nearest-node-on-right",function(){d("right")}),RED.actions.add("core:go-to-nearest-node-above",function(){d("up")}),RED.actions.add("core:go-to-nearest-node-below",function(){d("down")}),RED.actions.add("core:align-selection-to-grid",e),RED.actions.add("core:align-selection-to-left",function(){l("left")}),RED.actions.add("core:align-selection-to-right",function(){l("right")}),RED.actions.add("core:align-selection-to-top",function(){l("top")}),RED.actions.add("core:align-selection-to-bottom",function(){l("bottom")}),RED.actions.add("core:align-selection-to-middle",function(){l("middle")}),RED.actions.add("core:align-selection-to-center",function(){l("center")}),RED.actions.add("core:distribute-selection-horizontally",function(){c("h")}),RED.actions.add("core:distribute-selection-vertically",function(){c("v")}),RED.actions.add("core:wire-series-of-nodes",function(){var e=RED.view.selection();if(e.nodes&&1<e.nodes.length){for(var t=0,o=[];t<e.nodes.length-1;){var n=e.nodes[t],i=e.nodes[t+1];0<n.outputs&&0<i.inputs&&0===RED.nodes.filterLinks({source:n,target:i,sourcePort:0}).length&&(RED.nodes.addLink(n={source:n,target:i,sourcePort:0}),o.push(n)),t++}0<o.length&&(RED.history.push({t:"add",links:o,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0))}}),RED.actions.add("core:wire-node-to-multiple",function(){var e=RED.view.selection();if(e.nodes&&1<e.nodes.length){var t=e.nodes[0];if(0!==t.outputs){for(var o=1,n=[];o<e.nodes.length;){var i=e.nodes[o];0<i.inputs&&0===RED.nodes.filterLinks({source:t,target:i,sourcePort:Math.min(t.outputs-1,o-1)}).length&&(i={source:t,target:i,sourcePort:Math.min(t.outputs-1,o-1)},RED.nodes.addLink(i),n.push(i)),o++}0<n.length&&(RED.history.push({t:"add",links:n,dirty:RED.nodes.dirty()}),RED.nodes.dirty(!0),RED.view.redraw(!0))}}}),RED.actions.add("core:split-wire-with-link-nodes",function(){g()}),RED.actions.add("core:split-wires-with-junctions",function(){{var t=void 0,r,d,l,c,o;let e=t||RED.view.selection().links&&RED.view.selection().links.filter(e=>!e.link);e&&0!==(e=Array.isArray(e)?e:[e]).length&&(r=new Set,d=[],l=[],c={},e.forEach(function(e){var t=e.source.id+":"+e.sourcePort;c[t]=c[t]||[],c[t].push(e),c[e.target.id]=c[e.target.id]||[],c[e.target.id].push(e)}),(t=Object.keys(c)).sort(function(e,t){return c[t].length-c[e].length}),o=RED.nodes.dirty(),t.forEach(function(o){var n=c[o],i={_def:{defaults:{}},type:"junction",z:RED.workspaces.active(),id:RED.nodes.id(),x:0,y:0,w:0,h:0,outputs:1,inputs:1,dirty:!0},n=n.filter(function(e){return!r.has(e)});if(0!==n.length){let t=0;n.forEach(function(e){e._sliceLocation?(i.x+=e._sliceLocation.x,i.y+=e._sliceLocation.y,delete e._sliceLocation,t++):(i.x+=e.source.x+e.source.w/2+e.target.x-e.target.w/2,i.y+=e.source.y+e.target.y,t+=2)}),i.x=Math.round(i.x/t),i.y=Math.round(i.y/t),RED.view.snapGrid&&(a=RED.view.gridSize(),i.x=a*Math.round(i.x/a),i.y=a*Math.round(i.y/a));var a,s=new Set;RED.nodes.addJunction(i),l.push(i);let e;e=o===n[0].source.id+":"+n[0].sourcePort?{source:n[0].source,sourcePort:n[0].sourcePort,target:i}:{source:i,sourcePort:0,target:n[0].target},d.push(e),RED.nodes.addLink(e),n.forEach(function(e){r.add(e),RED.nodes.removeLink(e);let t;t=o===e.target.id?{source:e.source,sourcePort:e.sourcePort,target:i}:{source:i,sourcePort:0,target:e.target},d.push(t),RED.nodes.addLink(t),s.add(e.source.g||"__NONE__"),s.add(e.target.g||"__NONE__")}),1!==s.size||"__NONE__"!==(a=s.values().next().value)&&RED.group.addToGroup(RED.nodes.group(a),i)}}),0<l.length&&(RED.history.push({dirty:o,t:"add",links:d,junctions:l,removedLinks:Array.from(r)}),RED.nodes.dirty(!0),RED.view.select({nodes:l})),RED.view.redraw(!0))}}),RED.actions.add("core:generate-node-names",m)},alignSelectionToGrid:e,moveSelection:o,calculateGridSnapOffsets:function(e,t){t=t||{align:"nearest"};const o={x:0,y:0};var n=RED.view.gridSize(),i=e.x-(n*Math.round((e.x-e.w/2)/n)+e.w/2),a=e.x-(n*Math.round((e.x+e.w/2)/n)-e.w/2);return o.x=a,"right"!==t.align&&("left"===t.align||Math.abs(i)<Math.abs(a))&&(o.x=i),o.y=e.y-n*Math.round(e.y/n),o}}}(),RED.sidebar=function(){var a,s={},o=null;var i={};function t(e){e?($("#red-ui-main-container").removeClass("red-ui-sidebar-closed"),a.resize()):$("#red-ui-main-container").addClass("red-ui-sidebar-closed"),RED.events.emit("sidebar:resize")}function r(e,t){(e=":first"===e?o||RED.settings.get("editor.sidebar.order",["info","help","version-control","debug"])[0]:e)&&(!n(e)&&s[e]&&a.addTab(s[e]),a.activateTab(e),t||RED.menu.isSelected("menu-item-sidebar")||RED.menu.setSelected("menu-item-sidebar",!0))}function n(e){return a.contains(e)}return i.dragging=!1,{init:function(){var e;$("#red-ui-sidebar-separator").draggable({axis:"x",start:function(e,t){i.closing=!1,i.opening=!1;var o=$("#red-ui-editor").width();i.start=t.position.left,i.chartWidth=$("#red-ui-workspace").width(),i.chartRight=o-$("#red-ui-workspace").width()-$("#red-ui-workspace").offset().left-2,i.dragging=!0,RED.menu.isSelected("menu-item-sidebar")||(i.opening=!0,$("#red-ui-sidebar").addClass("closing"),$("#red-ui-workspace").css("right",7),$("#red-ui-editor-stack").css("right",8),$("#red-ui-sidebar").width(0),RED.menu.setSelected("menu-item-sidebar",!0),RED.events.emit("sidebar:resize")),i.width=$("#red-ui-sidebar").width()},drag:function(e,t){var o=t.position.left-i.start,n=i.width-o,t=(i.opening&&(n-=3),150<n&&i.chartWidth+o<200&&(t.position.left=200+i.start-i.chartWidth,o=t.position.left-i.start,n=i.width-o),n<150?(i.closing||($("#red-ui-sidebar").addClass("closing"),i.closing=!0),i.opening||(t.position.left=i.width-((n=150)-i.start),o=t.position.left-i.start)):150<n&&(i.closing||i.opening)&&(i.closing=!1,$("#red-ui-sidebar").removeClass("closing")),i.chartRight-o);$("#red-ui-workspace").css("right",t),$("#red-ui-editor-stack").css("right",1+t),$("#red-ui-sidebar").width(n),a.resize(),RED.events.emit("sidebar:resize")},stop:function(e,t){i.dragging=!1,i.closing&&($("#red-ui-sidebar").removeClass("closing"),RED.menu.setSelected("menu-item-sidebar",!1),$("#red-ui-sidebar").width()<180&&($("#red-ui-sidebar").width(180),$("#red-ui-workspace").css("right",187),$("#red-ui-editor-stack").css("right",188))),$("#red-ui-sidebar-separator").css("left","auto"),$("#red-ui-sidebar-separator").css("right",$("#red-ui-sidebar").width()+2+"px"),RED.events.emit("sidebar:resize")}}),(e=$('<div class="red-ui-sidebar-control-right"><i class="fa fa-chevron-right"</div>').appendTo($("#red-ui-sidebar-separator"))).on("click",function(){e.hide(),RED.menu.toggleSelected("menu-item-sidebar")}),$("#red-ui-sidebar-separator").on("mouseenter",function(){i.dragging||(RED.menu.isSelected("menu-item-sidebar")?e.find("i").addClass("fa-chevron-right").removeClass("fa-chevron-left"):e.find("i").removeClass("fa-chevron-right").addClass("fa-chevron-left"),e.toggle("slide",{direction:"right"},200))}),$("#red-ui-sidebar-separator").on("mouseleave",function(){i.dragging||(e.stop(!1,!0),e.hide())}),a=RED.tabs.create({element:$('<ul id="red-ui-sidebar-tabs"></ul>').appendTo("#red-ui-sidebar"),onchange:function(e){$("#red-ui-sidebar-content").children().hide(),$("#red-ui-sidebar-footer").children().hide(),e.onchange&&e.onchange.call(e),$(e.wrapper).show(),e.toolbar&&$(e.toolbar).show(),RED.settings.setLocal("last-sidebar-tab",e.id)},onremove:function(e){$(e.wrapper).hide(),e.onremove&&e.onremove.call(e)},collapsible:!0,onreorder:function(e){RED.settings.set("editor.sidebar.order",e)},order:RED.settings.get("editor.sidebar.order",["info","help","version-control","debug"])}),$('<div id="red-ui-sidebar-content"></div>').appendTo("#red-ui-sidebar"),$('<div id="red-ui-sidebar-footer" class="red-ui-component-footer"></div>').appendTo("#red-ui-sidebar"),$('<div id="red-ui-sidebar-shade" class="hide"></div>').appendTo("#red-ui-sidebar"),RED.actions.add("core:toggle-sidebar",function(e){void 0===e?RED.menu.toggleSelected("menu-item-sidebar"):t(e)}),RED.popover.tooltip($("#red-ui-sidebar-separator").find(".red-ui-sidebar-control-right"),RED._("keyboard.toggleSidebar"),"core:toggle-sidebar"),o=RED.settings.getLocal("last-sidebar-tab"),RED.sidebar.info.init(),RED.sidebar.help.init(),RED.sidebar.config.init(),RED.sidebar.context.init(),$("#red-ui-editor").width()<600&&RED.menu.setSelected("menu-item-sidebar",!1)},addTab:function(e,t,o,n){var i;"string"==typeof e?i={id:t.id,label:e,name:e,content:t,closeable:o,visible:n}:"object"==typeof e&&(i=e),delete i.closeable,i.wrapper=$("<div>",{style:"height:100%"}).appendTo("#red-ui-sidebar-content"),i.wrapper.append(i.content),i.wrapper.hide(),i.enableOnEdit||(i.shade=$("<div>",{class:"red-ui-sidebar-shade hide"}).appendTo(i.wrapper)),i.toolbar&&($("#red-ui-sidebar-footer").append(i.toolbar),$(i.toolbar).hide()),i.id,RED.menu.addItem("menu-item-view-menu",{id:"menu-item-view-menu-"+i.id,label:i.name,onselect:function(){r(i.id)},group:"sidebar-tabs"}),i.iconClass=i.iconClass||"fa fa-square-o",!1!==(s[i.id]=i).visible&&a.addTab(s[i.id])},removeTab:function(e){a.removeTab(e),$(s[e].wrapper).remove(),s[e].footer&&s[e].footer.remove(),delete s[e],RED.menu.removeItem("menu-item-view-menu-"+e)},show:r,containsTab:n,toggleSidebar:t}}(),RED.palette=function(){var n,w=["config","unknown","deprecated"],E=["subflows","common","function","network","input","output","sequence","parser","storage","analysis","social","advanced"],D={};function R(e,t,o,n){0===$("#red-ui-palette-base-category-"+t).length&&i(e,t,n+":palette.label."+t),$("#red-ui-palette-container-"+t).show(),0===$("#red-ui-palette-"+o).length&&$("#red-ui-palette-base-category-"+t).append('<div id="red-ui-palette-'+o+'"></div>')}function i(e,t,o){var o=((o=RED._(o,{defaultValue:t}))||t).replace(/_/g," "),n=$('<div id="red-ui-palette-container-'+t+'" class="red-ui-palette-category hide"><div id="red-ui-palette-header-'+t+'" class="red-ui-palette-header"><i class="expanded fa fa-angle-down"></i><span>'+o+'</span></div><div class="red-ui-palette-content" id="red-ui-palette-base-category-'+t+'"><div id="red-ui-palette-'+t+'"></div><div id="red-ui-palette-'+t+'-input"></div><div id="red-ui-palette-'+t+'-output"></div><div id="red-ui-palette-'+t+'-function"></div></div></div>').appendTo("#red-ui-palette-container");n.data("category",e),n.data("label",o),D[t]={container:n,close:function(){n.removeClass("red-ui-palette-open"),n.addClass("red-ui-palette-closed"),$("#red-ui-palette-base-category-"+t).slideUp(),$("#red-ui-palette-header-"+t+" i").removeClass("expanded")},open:function(){n.addClass("red-ui-palette-open"),n.removeClass("red-ui-palette-closed"),$("#red-ui-palette-base-category-"+t).slideDown(),$("#red-ui-palette-header-"+t+" i").addClass("expanded")},toggle:function(){n.hasClass("red-ui-palette-open")?D[t].close():D[t].open()}},$("#red-ui-palette-header-"+t).on("click",function(e){D[t].toggle()})}function x(t,e,o,n){e.attr("data-palette-label",o);for(var i=(o=RED.utils.sanitize(o)).split(/([ -]|\\n )/),a=[],s="",r=0;r<i.length;r++){var d=i[r];if("\\n "===d)a.push(s),s="";else{var l=0==r?"":" ";if(RED.view.calculateTextWidth(s+l+d,"red-ui-palette-label")<82)s+=l+d;else for(0<r&&a.push(s);;){if(!(82<=RED.view.calculateTextWidth(d,"red-ui-palette-label"))){s=d;break}for(var c=d.length;0<c;c--){var u=d.substring(0,c);if(RED.view.calculateTextWidth(u,"red-ui-palette-label")<82){a.push(u),d=d.substring(c);break}}}}}a.push(s);var p=a.join("<br/>"),f=8+20*a.length;e.css({height:f+"px"}),e.find(".red-ui-palette-label").html(p).attr("dir",RED.text.bidi.resolveBaseTextDir(p)),e.find(".red-ui-palette-port").css({top:f/2-5+"px"});try{var h,g,m,v="<p><b>"+RED.text.bidi.enforceTextDirectionWithUCC(o)+"</b></p>",b=((h=$("<div></div>").append($(v+(n||RED.nodes.getNodeHelp(t)||"<p>"+RED._("palette.noInfo")+"</p>").trim()).filter(function(e){return 1==this.nodeType&&"P"==this.nodeName||3==this.nodeType&&0<this.textContent.trim().length}).slice(0,2))).find("a").each(function(){var e=$(this).text();$(this).before(e),$(this).remove()}),RED.nodes.getType(t));b&&(g="",b&&!/^subflow:/.test(t)&&(g=b.set.module+" : "),g+=t,/^subflow:/.test(t)&&$('<button type="button" onclick="RED.workspaces.show(\''+t.substring(8).replace(/'/g,"\\'")+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-pencil"></i></button>').appendTo(h),m=t.replace(/'/g,"\\'"),$('<button type="button" onclick="RED.search.show(\'type:'+m+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-search"></i></button>').appendTo(h),$('<button type="button" onclick="RED.sidebar.help.show(\''+m+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-book"></i></button>').appendTo(h),$("<p>",{style:"font-size: 0.8em"}).text(g).appendTo(h))}catch(e){console.log("Error generating pop-over label for ",t),console.log(e.toString()),h="<p><b>"+o+"</b></p><p>"+RED._("palette.noInfo")+"</p>"}e.data("popover").setContent(h)}function _(e){return $(".red-ui-palette-node[data-palette-type='"+e+"']")}function k(e){return e.replace(/[\x00-\x2c\x2e-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]/g,"_")}function a(o,n){var e,t,i,a,s,r,p,f,h,g,m,d,l,c,v,b,u,y;_(o).length||(u=n.category,-1===w.indexOf(u)&&(t=(e=k(u)).split("-")[0],i=$("<div>",{class:"red-ui-palette-node"}).attr("data-palette-type",o).data("category",t),a=RED.utils.getPaletteLabel(o,n),$("<div/>",{class:"red-ui-palette-label"+(!n.align&&0!==n.inputs&&0===n.outputs||"right"===n.align?" red-ui-palette-label-right":"")}).appendTo(i),n.icon&&(s=RED.utils.getNodeIcon(n),(y=$("<div/>",{class:"red-ui-palette-icon-container"+(!n.align&&0!==n.inputs&&0===n.outputs||"right"===n.align?" red-ui-palette-icon-container-right":"")}).appendTo(i)).attr("data-palette-icon",s),RED.utils.createIconElement(s,y,!0)),i.css("backgroundColor",RED.utils.getNodeColor(o,n)),0<n.outputs&&((s=document.createElement("div")).className="red-ui-palette-port red-ui-palette-port-output",i.append(s)),0<n.inputs&&((y=document.createElement("div")).className="red-ui-palette-port red-ui-palette-port-input",i.append(y)),R(u,t,e,-1!==E.indexOf(t)?"node-red":n.set.id),$("#red-ui-palette-"+e).append(i),i.on("mousedown",function(e){e.preventDefault()}),s=RED.popover.create({target:i,trigger:"hover",interactive:!0,width:"300px",content:"hi",delay:{show:750,hide:50}}),i.data("popover",s),r=$("#red-ui-workspace-chart"),p=$("#red-ui-workspace-chart>svg").get(0),$(i).draggable({helper:"clone",appendTo:"#red-ui-editor",revert:"invalid",revertDuration:200,containment:"#red-ui-main-container",start:function(){v=$("#red-ui-palette").width(),b=$("#red-ui-palette").parent().position().top+$("#red-ui-palette-container").position().top,c=null,(l=RED.view.getActiveGroup())&&document.getElementById("group_select_"+l.id).classList.add("red-ui-flow-group-active-hovered"),RED.view.focus()},stop:function(){d3.select(".red-ui-flow-link-splice").classed("red-ui-flow-link-splice",!1),c&&document.getElementById("group_select_"+c.id).classList.remove("red-ui-flow-group-hovered"),l&&document.getElementById("group_select_"+l.id).classList.remove("red-ui-flow-group-active-hovered"),m&&(clearTimeout(m),m=null),d&&(clearTimeout(d),d=null)},drag:function(e,u){var t=_(o);u.originalPosition.left=t.offset().left,h=u.position.left-v+u.helper.width()/2+r.scrollLeft(),g=u.position.top-b+u.helper.height()/2+r.scrollTop()+10,d=d||setTimeout(function(){var e=h/RED.view.scale(),t=g/RED.view.scale(),e=RED.view.getGroupAtPoint(e,t);e!==c&&(c&&document.getElementById("group_select_"+c.id).classList.remove("red-ui-flow-group-hovered"),e&&document.getElementById("group_select_"+e.id).classList.add("red-ui-flow-group-hovered"),(c=e)?$(u.helper).data("group",c):$(u.helper).removeData("group")),d=null},200),0<n.inputs&&0<n.outputs&&(m=m||setTimeout(function(){for(var e,t=[],o=1/0,n=null,t=p.getIntersectionList?((e=p.createSVGRect()).x=h,e.y=g,e.width=1,e.height=1,p.getIntersectionList(e,p)):RED.view.getLinksAtPoint(h,g),i=h/RED.view.scale(),a=g/RED.view.scale(),s=0;s<t.length;s++){var r=d3.select(t[s]);if(r.classed("red-ui-flow-link-background")&&!r.classed("red-ui-flow-link-link"))for(var d=t[s].getTotalLength(),l=0;l<d;l+=10){var c=t[s].getPointAtLength(l),c=(c.x-i)*(c.x-i)+(c.y-a)*(c.y-a);c<200&&c<o&&(o=c,n=t[s])}}f&&f!==n&&d3.select(f.parentNode).classed("red-ui-flow-link-splice",!1),n?d3.select(n.parentNode).classed("red-ui-flow-link-splice",!0):d3.select(".red-ui-flow-link-splice").classed("red-ui-flow-link-splice",!1),f!==n&&(n?$(u.helper).data("splice",d3.select(n).data()[0]):$(u.helper).removeData("splice")),f=n,m=null},200))}}),y=null,0===o.indexOf("subflow:")&&(i.on("dblclick",function(e){RED.workspaces.show(o.substring(8)),e.preventDefault()}),u=RED.nodes.subflow(o.substring(8)),y=RED.utils.renderMarkdown(u.info||"")),x(o,i,a,y),1===$("#red-ui-palette-container-"+t).find(".red-ui-palette-node").length&&D[t].open()))}function s(e){var e=_(e),t=e.closest(".red-ui-palette-category");e.remove(),0===t.find(".red-ui-palette-node").length&&t.find("i").hasClass("expanded")&&(t.find(".red-ui-palette-content").slideToggle(),t.find("i").toggleClass("expanded"))}function r(e){for(var e=_(e),e=(e.hide(),e.closest(".red-ui-palette-category")),t=e.find(".red-ui-palette-node"),o=0,n=0;n<t.length;n++)"none"===$(t[n]).css("display")&&(o+=1);o===t.length&&e.hide()}function d(e){e=_(e);e.closest(".red-ui-palette-category").show(),e.show()}function l(e){var t=_("subflow:"+e.id),o=t.find(".red-ui-palette-port-input"),n=t.find(".red-ui-palette-port-output");t.find(".red-ui-palette-label").attr("class","red-ui-palette-label"+(!e._def.align&&0!==e.in.length&&0===e.out.length||"right"===e._def.align?" red-ui-palette-label-right":""));t.find(".red-ui-palette-icon-container").attr("class","red-ui-palette-icon-container"+(!e._def.align&&0!==e.in.length&&0===e.out.length||"right"===e._def.align?" red-ui-palette-icon-container-right":"")),0===o.length&&0<e.in.length?((a=document.createElement("div")).className="red-ui-palette-port red-ui-palette-port-input",t.append(a)):0!==o.length&&0===e.in.length&&o.remove(),0===n.length&&0<e.out.length?((a=document.createElement("div")).className="red-ui-palette-port red-ui-palette-port-output",t.append(a)):0!==n.length&&0===e.out.length&&n.remove();var i,o=t.attr("data-palette-label"),a=t.attr("data-palette-info"),a=(o===e.name&&a===e.info||(t.attr("data-palette-info",e.info),x(e.type+":"+e.id,t,e.name,RED.utils.renderMarkdown(e.info||""))),n=t,o=e,o=RED.utils.getNodeIcon(o._def),(n=n.find(".red-ui-palette-icon-container")).attr("data-palette-icon")!==o&&(n.attr("data-palette-icon",o),RED.utils.createIconElement(o,n,!0)),t.data("category")),o=e.category||"subflows";a!==o&&(R(o,n=k(o),n,"node-red"),a=t.closest(".red-ui-palette-category"),(i=$("#red-ui-palette-"+n)).append(t),1===i.find(".red-ui-palette-node").length&&D[n].open(),t.data("category",o),0===a.find(".red-ui-palette-node").length&&a.find("i").hasClass("expanded")&&(a.find(".red-ui-palette-content").slideToggle(),a.find("i").toggleClass("expanded"))),t.css("backgroundColor",e.color)}return{init:function(){$('<img src="red/images/spin.svg" class="red-ui-palette-spinner hide"/>').appendTo("#red-ui-palette"),$('<div id="red-ui-palette-search" class="red-ui-palette-search hide"><input type="text" data-i18n="[placeholder]palette.filter"></input></div>').appendTo("#red-ui-palette"),$('<div id="red-ui-palette-container" class="red-ui-palette-scroll hide"></div>').appendTo("#red-ui-palette"),$('<div class="red-ui-component-footer"></div>').appendTo("#red-ui-palette"),$('<div id="red-ui-palette-shade" class="hide"></div>').appendTo("#red-ui-palette"),$("#red-ui-palette > .red-ui-palette-spinner").show(),RED.events.on("registry:node-type-added",function(e){var t=RED.nodes.getType(e);a(e,t),t.onpaletteadd&&"function"==typeof t.onpaletteadd&&t.onpaletteadd.call(t)}),RED.events.on("registry:node-type-removed",function(e){s(e)}),RED.events.on("registry:node-set-enabled",function(e){for(var t=0;t<e.types.length;t++){d(e.types[t]);var o=RED.nodes.getType(e.types[t]);o&&o.onpaletteadd&&"function"==typeof o.onpaletteadd&&o.onpaletteadd.call(o)}}),RED.events.on("registry:node-set-disabled",function(e){for(var t=0;t<e.types.length;t++){r(e.types[t]);var o=RED.nodes.getType(e.types[t]);o&&o.onpaletteremove&&"function"==typeof o.onpaletteremove&&o.onpaletteremove.call(o)}}),RED.events.on("registry:node-set-removed",function(e){if(e.added)for(var t=0;t<e.types.length;t++){s(e.types[t]);var o=RED.nodes.getType(e.types[t]);o&&o.onpaletteremove&&"function"==typeof o.onpaletteremove&&o.onpaletteremove.call(o)}}),RED.events.on("subflows:change",l),$("#red-ui-palette-search input").searchBox({delay:100,change:function(){var e,n=$(this).val(),i=new RegExp(n.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");for(e in $("#red-ui-palette-container .red-ui-palette-node").each(function(e,t){var o=$(t).attr("data-palette-label"),t=$(t).attr("data-palette-type");""===n||i.test(t)||i.test(o)?$(this).show():$(this).hide()}),D)D.hasOwnProperty(e)&&(0===D[e].container.find(".red-ui-palette-node").filter(function(){return"none"!==$(this).css("display")}).length?(D[e].close(),D[e].container.slideUp()):(D[e].open(),D[e].container.show()))}}),n=$('<div class="red-ui-sidebar-control-left"><i class="fa fa-chevron-left"></i></div>').appendTo($("#red-ui-palette")),RED.popover.tooltip(n,RED._("keyboard.togglePalette"),"core:toggle-palette"),n.on("click",function(){RED.menu.toggleSelected("menu-item-palette")}),$("#red-ui-palette").on("mouseenter",function(){n.toggle("slide",{direction:"left"},200)}),$("#red-ui-palette").on("mouseleave",function(){n.stop(!1,!0),n.hide()});var e=[],t=(RED.settings.paletteCategories?e=RED.settings.paletteCategories:RED.settings.theme("palette.categories")&&(e=RED.settings.theme("palette.categories")),Array.isArray(e)||(e=[]),{}),e=(e.forEach(function(e){t[e]=!0,i(e,k(e),"palette.label."+k(e))}),E.forEach(function(e){t[e]||i(e,k(e),"palette.label."+k(e))}),$('<span class="button-group"></span>').appendTo("#red-ui-palette .red-ui-component-footer")),o=$('<button type="button" class="red-ui-footer-button"><i class="fa fa-angle-double-up"></i></button>').appendTo(e);o.on("click",function(e){for(var t in e.preventDefault(),D)D.hasOwnProperty(t)&&D[t].close()}),RED.popover.tooltip(o,RED._("palette.actions.collapse-all")),(o=$('<button type="button" class="red-ui-footer-button"><i class="fa fa-angle-double-down"></i></button>').appendTo(e)).on("click",function(e){for(var t in e.preventDefault(),D)D.hasOwnProperty(t)&&D[t].open()}),RED.popover.tooltip(o,RED._("palette.actions.expand-all")),RED.actions.add("core:toggle-palette",function(e){void 0===e?RED.menu.toggleSelected("menu-item-palette"):(e?($("#red-ui-main-container").removeClass("red-ui-palette-closed"),n.find("i").removeClass("fa-chevron-right").addClass("fa-chevron-left")):($("#red-ui-main-container").addClass("red-ui-palette-closed"),n.hide(),n.find("i").addClass("fa-chevron-right").removeClass("fa-chevron-left")),setTimeout(function(){$(window).trigger("resize")},200))})},add:a,remove:s,hide:r,show:d,refresh:function(){RED.nodes.eachSubflow(l)},getCategories:function(){var o=[];return $("#red-ui-palette-container .red-ui-palette-category").each(function(e,t){o.push({id:$(t).data("category"),label:$(t).data("label")})}),o}}}(),RED.sidebar.info=function(){var n,i,w,a,E,D,R,x,_,s,r,k={property:!1};function d(){var e;i&&(e=$(n).parent().height()-s.outerHeight(),i.resize(e))}function l(){RED.sidebar.show("info")}function o(e){if(void 0===e)T();else{$(w).empty();var t=$('<table class="red-ui-info-table"></table>').appendTo(w),o=$("<tbody>").appendTo(t);if(null===e)RED.sidebar.info.outliner.select(null),E.empty(),D.text(""),R.hide(),x.hide();else if(Array.isArray(e)){RED.sidebar.info.outliner.select(e),E.empty(),RED.utils.createNodeIcon({type:"_selection_"}).appendTo(E),D.text("Selection"),R.hide(),x.hide(),_=null;var n={nodes:0,flows:0,subflows:0,groups:0},i=(e.forEach(function(e){"tab"===e.type?(n.flows++,n.nodes+=RED.nodes.filterNodes({z:e.id}).length):"subflow"===e.type?n.subflows++:"group"===e.type?n.groups++:n.nodes++}),r=$('<tr class="red-ui-help-info-row"><td>'+RED._("sidebar.info.selection")+"</td><td></td></tr>").appendTo(o),$("<div>").appendTo($(r.children()[1])));0<n.flows&&$("<div>").text(RED._("clipboard.flow",{count:n.flows})).appendTo(i),0<n.subflows&&$("<div>").text(RED._("clipboard.subflow",{count:n.subflows})).appendTo(i),0<n.nodes&&$("<div>").text(RED._("clipboard.node",{count:n.nodes})).appendTo(i),0<n.groups&&$("<div>").text(RED._("clipboard.group",{count:n.groups})).appendTo(i)}else{RED.sidebar.info.outliner.select(e);var t=/^subflow(:(.+))?$/.exec(e.type),a=(t&&((y=t[2]?RED.nodes.subflow(t[2]):e).id,b=y.instances.length),E.empty(),RED.utils.createNodeIcon(e).appendTo(E),RED.utils.getNodeLabel(e,e.type+": "+e.id)),s=a.indexOf("\\n"),s=(-1<s&&(a=a.substring(0,s)+"..."),D.text(a),R.show(),_=e,r=$('<tr class="red-ui-help-info-row"><td></td><td></td></tr>').appendTo(o),"node");if("subflow"===e.type||t?s="subflow":"tab"===e.type?s="flow":"group"===e.type&&(s="group"),$(r.children()[0]).text(RED._("sidebar.info."+s)),RED.utils.createObjectElement(e.id,{sourceId:e.id}).appendTo(r.children()[1]),"tab"===e.type||"subflow"===e.type)x.hide();else if("group"===e.type){x.hide();var r=$('<tr class="red-ui-help-info-row"><td>&nbsp;</td><td></td></tr>').appendTo(o),d={nodes:0,groups:0},i=(RED.group.getNodes(e,!0).forEach(function(e){"group"===e.type?d.groups++:d.nodes++}),$("<div>").appendTo($(r.children()[1])));0<d.nodes&&$("<div>").text(RED._("clipboard.node",{count:d.nodes})).appendTo(i),0<d.groups&&$("<div>").text(RED._("clipboard.group",{count:d.groups})).appendTo(i)}else if("junction"===e.type)x.hide();else{x.show(),t||(r=$('<tr class="red-ui-help-info-row"><td>'+RED._("sidebar.info.type")+"</td><td></td></tr>").appendTo(o),$(r.children()[1]).text(("unknown"===e.type?e._orig:e).type),"unknown"===e.type&&$('<span style="float: right; font-size: 0.8em"><i class="fa fa-warning"></i></span>').prependTo($(r.children()[1])));var l=0;if(!t&&"subflow"!=e.type&&"group"!=e.type){var c,u,p,f,h,g,m,a=$('<tr class="red-ui-help-property-expand blank"><td colspan="2"></td></tr>').appendTo(o);if("unknown"===e.type?(c={},Object.keys(e._orig).forEach(function(e){"type"!==e&&(c[e]={})})):e._def&&(c=e._def.defaults,r=$('<tr class="red-ui-help-info-property-row'+(k.property?"":" hide")+'"><td>'+RED._("sidebar.info.module")+"</td><td></td></tr>").appendTo(o),$(r.children()[1]).text(RED.nodes.getType(e.type).set.module),l++),c)for(var v in c)"name"!=v&&"info"!=v&&c.hasOwnProperty(v)&&(u=e[v],l++,r=$('<tr class="red-ui-help-info-property-row'+(k.property?"":" hide")+'"><td></td><td></td></tr>').appendTo(o),$(r.children()[0]).text(v),c[v].type&&!c[v]._type.array?(p=RED.nodes.node(u))?(v=RED.utils.getNodeLabel(p,u),f=r.children()[1],h=$("<span>",{class:""}).appendTo(f),h=$("<div>",{class:"red-ui-palette-node red-ui-palette-node-small"}).appendTo(h),m=RED.utils.getNodeColor(p.type,p._def),g=RED.utils.getNodeIcon(p._def),h.css({backgroundColor:m,cursor:"pointer"}),m=$("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(h),$("<div/>",{class:"red-ui-palette-icon",style:"background-image: url("+g+")"}).appendTo(m),$("<span></span>").css({verticalAlign:"top",marginLeft:"6px"}).text(v).appendTo(f),h.on("dblclick",function(){RED.editor.editConfig("",p.type,p.id)})):RED.utils.createObjectElement(void 0).appendTo(r.children()[1]):RED.utils.createObjectElement(u,{sourceId:e.id}).appendTo(r.children()[1]));0<l&&$('<a href="#" class="node-info-property-header'+(k.property?" expanded":"")+'"><span class="red-ui-help-property-more">'+RED._("sidebar.info.showMore")+'</span><span class="red-ui-help-property-less">'+RED._("sidebar.info.showLess")+'</span> <i class="fa fa-caret-down"></i></a>').appendTo(a.children()[0])}"tab"!==e.type&&t&&($('<tr class="blank"><th colspan="2">'+RED._("sidebar.info.subflow")+"</th></tr>").appendTo(o),$('<tr class="node-info-subflow-row"><td>'+RED._("common.label.name")+'</td><td><span class="red-ui-text-bidi-aware" dir="'+RED.text.bidi.resolveBaseTextDir(y.name)+'">'+RED.utils.sanitize(y.name)+"</span></td></tr>").appendTo(o))}t&&(r=$('<tr class="red-ui-help-info-row"><td>'+RED._("subflow.category")+"</td><td></td></tr>").appendTo(o),s=y.category||"subflows",$(r.children()[1]).text(RED._("palette.label."+s,{defaultValue:s})),$('<tr class="node-info-subflow-row"><td>'+RED._("sidebar.info.instances")+"</td><td>"+b+"</td></tr>").appendTo(o),y.meta&&(r=$('<tr class="red-ui-help-info-row"><td>'+RED._("subflow.module")+"</td><td></td></tr>").appendTo(o),$(r.children()[1]).text(y.meta.module||""),r=$('<tr class="red-ui-help-info-row"><td>'+RED._("subflow.version")+"</td><td></td></tr>").appendTo(o),$(r.children()[1]).text(y.meta.version||"")));var i="",s=(e._def&&e._def.info&&(t="function"==typeof(a=e._def.info)?a.call(e):a,i+=RED.utils.renderMarkdown(t)),e.info&&(i+=RED.utils.renderMarkdown(e.info||"")),$("<div>").css("padding","0 6px 6px").appendTo(w)),b=i,y=s;(b=function(e){return $(e).find("a").each(function(e){var t=$(this).attr("href");/^https?:/.test(t)&&$(this).attr("target","_blank")}),e}($('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir="'+RED.text.bidi.resolveBaseTextDir(b)+'">'+b+"</span></div>")).appendTo(y)).find(".red-ui-text-bidi-aware").contents().filter(function(){return 3===this.nodeType&&""!==this.textContent.trim()}).wrap("<span></span>"),b.find("H3").wrapInner('<a class="red-ui-help-info-header expanded" href="#"></a>').find("a").prepend('<i class="fa fa-angle-right">').on("click",function(e){e.preventDefault();for(var t=$(this).hasClass("expanded"),o=$(this).parent().next();1===o.length&&"H3"!==o[0].nodeName;)o.toggle(!t),o=o.next();$(this).toggleClass("expanded",!t)}),$(".red-ui-sidebar-info-stack").scrollTop(0),$(".node-info-property-header").on("click",function(e){e.preventDefault(),k.property=!k.property,$(this).toggleClass("expanded",k.property),$(".red-ui-help-info-property-row").toggle(k.property)})}}}t=!0,p=15e3,f=-1,RED.actions.add("core:toggle-show-tips",function(e){void 0===e?RED.userSettings.toggle("view-show-tips"):((t=e)?m:v)()});var c,u,t,p,f,h={start:m,stop:v,next:function(){clearInterval(u),c=!0,e()},enabled:function(){return t}};function e(){for(var e,t=Math.floor(Math.random()*f),o=RED._("infotips:info.tip"+t);e=/({{(.*?)}})/.exec(o);){var n=RED.keyboard.getShortcut(e[2]);if(!n)return;o=o.replace(e[1],RED.keyboard.formatKey(n.key))}for(;e=/(\[([a-z]*?)\])/.exec(o);)o=o.replace(e[1],RED.keyboard.formatKey(e[2]));r.html(o).fadeIn(200),c&&(c=null,u=setInterval(g,p))}function g(){r.fadeOut(300,function(){e()})}function m(){if($(".red-ui-sidebar-info").addClass("show-tips"),d(),t&&!c&&!u){if(-1===f)for(;f++,RED._("infotips:info.tip"+f)!=="info.tip"+f;);c=setTimeout(e,1e3)}}function v(){$(".red-ui-sidebar-info").removeClass("show-tips"),d(),clearInterval(u),clearTimeout(c),c=u=null}function T(e){var t;(e=void 0===e?RED.view.selection():e).nodes?1==e.nodes.length?"subflow"===(t=e.nodes[0]).type&&t.direction?o(RED.nodes.subflow(t.z)):o(t):o(e.nodes):e.flows||e.subflows?o(e.flows):(t=RED.workspaces.active(),(e=RED.nodes.workspace(t)||RED.nodes.subflow(t))?o(e):(t=RED.nodes.workspace(RED.workspaces.active()))&&t.info?o(t):o(null))}return RED.events.on("view:selection-changed",T),{init:function(){(n=document.createElement("div")).className="red-ui-sidebar-info",RED.actions.add("core:show-info-tab",l);var e=$("<div>",{class:"red-ui-sidebar-info-stack"}).appendTo(n),t=$("<div>").css({overflow:"hidden",height:"calc(70%)"}).appendTo(e),o=$("<div>").css({overflow:"hidden",height:"100%",display:"flex","flex-direction":"column"}).appendTo(e),o=(a=$("<div>",{class:"red-ui-palette-header red-ui-info-header"}).css({flex:"0 0 auto"}).appendTo(o),E=$("<span>").appendTo(a),D=$("<span>").appendTo(a),x=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-book"></button>').css({position:"absolute",top:"12px",right:"32px"}).on("click",function(e){e.preventDefault(),e.stopPropagation(),_&&RED.sidebar.help.show(_.type)}).appendTo(a),RED.popover.tooltip(x,RED._("sidebar.help.showHelp")),R=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-search"></button>').css({position:"absolute",top:"12px",right:"8px"}).on("click",function(e){e.preventDefault(),e.stopPropagation(),_&&(RED.sidebar.info.outliner.reveal(_),RED.view.reveal(_.id))}).appendTo(a),RED.popover.tooltip(R,RED._("sidebar.help.showInOutline")),w=$("<div>").css({flex:"1 1 auto","overflow-y":"auto"}).appendTo(o),(i=RED.panels.create({container:e})).ratio(.6),RED.sidebar.info.outliner.build().appendTo(t),RED.sidebar.addTab({id:"info",label:RED._("sidebar.info.label"),name:RED._("sidebar.info.name"),iconClass:"fa fa-info",action:"core:show-info-tab",content:n,pinned:!0,enableOnEdit:!0}),RED.events.on("sidebar:resize",d),$(window).on("resize",d),$(window).on("focus",d),s=$('<div class="red-ui-help-tips"></div>').appendTo(n),r=$('<div class="red-ui-help-tip"></div>').appendTo(s),$('<div class="red-ui-help-tips-buttons"></div>').appendTo(s));$('<a href="#" class="red-ui-footer-button"><i class="fa fa-refresh"></a>').appendTo(o).on("click",function(e){e.preventDefault(),h.next()}),$('<a href="#" class="red-ui-footer-button"><i class="fa fa-times"></a>').appendTo(o).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:toggle-show-tips"),RED.notify(RED._("sidebar.info.showTips"))}),h.enabled()?h.start():h.stop()},show:l,refresh:o,clear:function(){o(null)},set:function(e,t){console.warn("Deprecated use of RED.sidebar.info.set - use RED.sidebar.help.set instead"),RED.sidebar.help.set(e,t)}}}(),RED.sidebar.info.outliner=function(){var a,o,s,n,i,r,t,d,l={},c={};function u(){var e=[{label:RED._("menu.label.flows"),expanded:!0,children:[]},{id:"__subflow__",label:RED._("menu.label.subflows"),children:[f("__subflow__")]},{id:"__global__",flow:"__global__",label:RED._("sidebar.info.globalConfig"),types:{},children:[f("__global__")]}];return r=e[0],t=e[1],d={__global__:e[2]},e}var e,p={};function f(e){var t={empty:!0,element:$('<div class="red-ui-info-outline-item red-ui-info-outline-item-empty">').text(RED._("sidebar.info.empty"))};return p[e]=t}function h(e){var t=$("<div>",{class:"red-ui-node-list-item red-ui-info-outline-item"});return RED.utils.createNodeIcon(e,!0).appendTo(t),t.find(".red-ui-node-label").addClass("red-ui-info-outline-item-label"),g(e,t),t}function g(t,o){var e,n=$("<div>",{class:"red-ui-info-outline-item-controls red-ui-info-outline-item-hover-controls"}).appendTo(o);"subflow"===t.type&&$('<button type="button" class="red-ui-info-outline-item-control-users red-ui-button red-ui-button-small"><i class="fa fa-toggle-right"></i></button>').text(t.instances.length).appendTo(n).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.search.show("type:subflow:"+t.id)}),"config"===t._def.category&&"group"!==t.type&&(e=$('<button type="button" class="red-ui-info-outline-item-control-users red-ui-button red-ui-button-small"><i class="fa fa-toggle-right"></i></button>').text(t.users.length).appendTo(n).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.search.show("uses:"+t.id)}),RED.popover.tooltip(e,function(){return RED._("editor.nodesUse",{count:t.users.length})})),t._def.button&&(e=$('<button type="button" class="red-ui-info-outline-item-control-action red-ui-button red-ui-button-small"><i class="fa fa-toggle-right"></i></button>').appendTo(n).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.view.clickNodeButton(t)}),RED.popover.tooltip(e,RED._("sidebar.info.triggerAction"))),"tab"===t.type&&$('<button type="button" class="red-ui-info-outline-item-control-hide red-ui-button red-ui-button-small"><i class="fa fa-eye"></i><i class="fa fa-eye-slash"></i></button>').appendTo(n).on("click",function(e){e.preventDefault(),e.stopPropagation();e=!o.hasClass("red-ui-info-outline-item-hidden");o.toggleClass("red-ui-info-outline-item-hidden",e),e?RED.workspaces.hide(t.id):RED.workspaces.show(t.id,null,!0)}),"subflow"!==t.type?(e=$('<button type="button" class="red-ui-info-outline-item-control-disable red-ui-button red-ui-button-small"><i class="fa fa-circle-thin"></i><i class="fa fa-ban"></i></button>').appendTo(n).on("click",function(e){var o,n;e.preventDefault(),e.stopPropagation(),"tab"===t.type?t.disabled?RED.workspaces.enable(t.id):RED.workspaces.disable(t.id):"group"===t.type?(e=RED.group.getNodes(t,!0),o={t:"multi",events:[],dirty:RED.nodes.dirty()},e.forEach(function(e){var t;"group"!==e.type&&(void 0===n&&(n=!e.d),!!e.d!==n&&(t={t:"edit",node:e,changed:e.changed,changes:{d:e.d}},e.d?delete e.d:e.d=!0,e.dirty=!0,e.dirtyStatus=!0,e.changed=!0,RED.events.emit("nodes:change",e),o.events.push(t))),0<o.events.length&&(RED.history.push(o),RED.nodes.dirty(!0),RED.view.redraw())})):(e={t:"edit",node:t,changed:t.changed,changes:{d:t.d},dirty:RED.nodes.dirty()},t.d?delete t.d:t.d=!0,t.dirty=!0,t.dirtyStatus=!0,t.changed=!0,RED.events.emit("nodes:change",t),RED.history.push(e),RED.nodes.dirty(!0),RED.view.redraw())}),RED.popover.tooltip(e,function(){return"group"===t.type?RED._("common.label.enable")+" / "+RED._("common.label.disable"):RED._("common.label."+("tab"===t.type&&t.disabled||"tab"!==t.type&&t.d?"enable":"disable"))})):$('<div class="red-ui-info-outline-item-control-spacer">').appendTo(n),n.find("button").on("dblclick",function(e){e.preventDefault(),e.stopPropagation()})}function m(e){l={};var t,o=u();i.empty(),e=e,(t=$("<div>",{class:"red-ui-info-outline-item red-ui-info-outline-item-flow"})).css("width","calc(100% - 40px)"),$("<div>",{class:"red-ui-search-result-description red-ui-info-outline-item-label"}).appendTo(t).text(e.name),e=$("<div>",{class:"red-ui-info-outline-item-controls"}).appendTo(t),e=$('<button class="red-ui-button red-ui-button-small" style="position:absolute;right:5px;top: 3px;"><i class="fa fa-ellipsis-h"></i></button>').appendTo(e).on("click",function(e){e.preventDefault(),RED.projects.editProject()}),RED.popover.tooltip(e,RED._("sidebar.project.showProjectSettings")),t.appendTo(i),n.show(),a.treeList("data",o)}function v(){a.treeList("data",u())}function b(e){e=l[e.workspace];e&&e.element.removeClass("red-ui-info-outline-item-hidden")}function y(e){e=l[e.workspace];e&&e.element.addClass("red-ui-info-outline-item-hidden")}function w(e){var t,o,n,i,a;l[e.id]={id:e.id,element:(t=e,o=$("<div>",{class:"red-ui-info-outline-item red-ui-info-outline-item-flow"}),n=$("<div>",{class:"red-ui-search-result-description red-ui-info-outline-item-label"}).appendTo(o),i="string"==typeof t?t:t.label,-1<(a=i.indexOf("\\n"))&&(i=i.substring(0,a)+"..."),n.text(i),g(t,o),o),children:[],deferBuild:!0,icon:"red-ui-icons red-ui-icons-flow",gutter:T(e)},c[e.id]?(l[e.id].children=c[e.id],delete c[e.id]):l[e.id].children.push(f(e.id)),r.treeList.addChild(l[e.id]),l[e.id].element.toggleClass("red-ui-info-outline-item-disabled",!!e.disabled),l[e.id].treeList.container.toggleClass("red-ui-info-outline-item-disabled",!!e.disabled),L()}function E(e){var t=l[e.id],o=e.label||e.id,n=o.indexOf("\\n");-1<n&&(o=o.substring(0,n)+"..."),t.element.find(".red-ui-info-outline-item-label").text(o),t.element.toggleClass("red-ui-info-outline-item-disabled",!!e.disabled),t.treeList.container.toggleClass("red-ui-info-outline-item-disabled",!!e.disabled),L()}function D(e){var o={};e.forEach(function(e,t){o[e]=t}),r.treeList.sortChildren(function(e,t){return"__global__"===e.id?-1:"__global__"===t.id?1:o[e.id]-o[t.id]})}function R(e){l[e.id]={id:e.id,element:h(e),children:[],deferBuild:!0,gutter:T(e)},c[e.id]?(l[e.id].children=c[e.id],delete c[e.id]):l[e.id].children.push(f(e.id)),p.__subflow__&&(p.__subflow__.treeList.remove(),delete p.__subflow__),t.treeList.addChild(l[e.id]),L()}function x(t){l[t.id].treeList.replaceElement(h(t)),RED.nodes.eachNode(function(e){e.type=="subflow:"+t.id&&l[e.id].treeList.replaceElement(h(e))}),L()}function _(e){var t=l[e.id],o=e.g||e.z||"__global__",n=RED.utils.getNodeLabel(e,e.name||e.type+": "+e.id);n?t.element.find(".red-ui-info-outline-item-label").text(n):t.element.find(".red-ui-info-outline-item-label").html("&nbsp;"),o!==(t.parent.id||t.parent.parent.flow)&&(n=t.parent,t.treeList.remove(!0),0===n.children.length&&(n.config?(n.treeList.remove(),delete d[n.parent.id||n.parent.parent.id].types[e.type],0===n.parent.children.length&&("__global__"===n.parent.id?n.parent.treeList.addChild(f(n.parent.id)):(delete d[n.parent.parent.id],n.parent.treeList.remove(),0===n.parent.parent.children.length&&n.parent.parent.treeList.addChild(f(n.parent.parent.id))))):n.treeList.addChild(f(n.id))),"config"===e._def.category&&"group"!==e.type?(C(o,e.type),d[o].types[e.type].treeList.addChild(l[e.id])):(p[o]&&(p[o].treeList.remove(),delete p[o]),l[o].treeList.addChild(t))),t.element.toggleClass("red-ui-info-outline-item-disabled",!!e.d),"config"===e._def.category&&"group"!==e.type&&t.element.find(".red-ui-info-outline-item-control-users").text(e.users.length),L()}function k(e){var t=l[e.id],o=(t.treeList.remove(),delete l[e.id],/^subflow:/.test(e.type)&&(o=e.type.substring(8),l[o]&&l[o].element.find(".red-ui-info-outline-item-control-users").text(RED.nodes.subflow(o).instances.length)),p[e.id]&&delete p[e.id],t.parent);0===o.children.length&&(o.config?(o.treeList.remove(),delete d[o.parent.id||e.z].types[e.type],0===o.parent.children.length&&("__global__"===o.parent.id?o.parent.treeList.addChild(f(o.parent.id)):(delete d[e.z],o.parent.treeList.remove(),0===o.parent.parent.children.length&&o.parent.parent.treeList.addChild(f(o.parent.parent.id))))):o.treeList.addChild(f(o.id)))}function T(t){var e=$("<span>",{class:"red-ui-info-outline-gutter red-ui-treeList-gutter-float"}),o=$('<button type="button" class="red-ui-info-outline-item-control-reveal red-ui-button red-ui-button-small"><i class="fa fa-search"></i></button>').appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation(),RED.view.reveal(t.id)});return RED.popover.tooltip(o,RED._("sidebar.info.find")),e}function C(e,t){p[e]&&(p[e].treeList.remove(),delete p[e]),d[e]||(d[e]={config:!0,flow:e,types:{},label:RED._("menu.label.displayConfig"),children:[]},l[e].treeList.insertChildAt(d[e],0)),d[e].types[t]||(d[e].types[t]={config:!0,label:t,children:[]},d[e].treeList.addChild(d[e].types[t]))}function j(e){l[e.id]={id:e.id,element:h(e),gutter:T(e)},"group"===e.type&&(l[e.id].children=[],l[e.id].deferBuild=!0,c[e.id]&&(l[e.id].children=c[e.id],delete c[e.id]));var t=e.g||e.z||"__global__";"config"!==e._def.category||"group"===e.type?l[t]?(p[t]&&(p[t].treeList.remove(),delete p[t]),l[t].treeList?l[t].treeList.addChild(l[e.id]):l[t].children.push(l[e.id])):(c[t]=c[t]||[],c[t].push(l[e.id])):(C(t,e.type),d[t].types[e.type].treeList.addChild(l[e.id])),l[e.id].element.toggleClass("red-ui-info-outline-item-disabled",!!e.d),/^subflow:/.test(e.type)&&(t=e.type.substring(8),l[t]&&l[t].element.find(".red-ui-info-outline-item-control-users").text(RED.nodes.subflow(t).instances.length)),L()}function L(){e&&clearTimeout(e),s&&(e=setTimeout(function(){o.searchBox("change")},100))}return{build:function(){var e=$("<div>",{class:"red-ui-info-outline"}).css({height:"100%"}),t=$("<div>",{class:"red-ui-sidebar-header red-ui-info-toolbar"}).appendTo(e);return o=$('<input type="text" data-i18n="[placeholder]menu.label.search">').appendTo(t).searchBox({style:"compact",delay:500,change:function(){var e=$(this).val(),t=RED.search.search(e);if(e){s=e;for(var o={},n=0,i=t.length;n<i;n++)o[t[n].node.id]=!0;a.treeList("filter",function(e){return 0===e.depth||e.id&&l[e.id]&&o[e.id]},!0)}else{s=null,a.treeList("filter",null);e=a.treeList("selected");e.id&&a.treeList("show",e.id)}},options:RED.search.getSearchOptions()}),n=$('<div class="red-ui-treeList-label red-ui-info-outline-project"><span class="red-ui-treeList-icon"><i class="fa fa-archive"></i></span></div>').hide().appendTo(e),i=$("<span>").appendTo(n),(a=$("<div>").css({width:"100%"}).appendTo(e).treeList({data:u()})).on("treelistselect",function(e,t){t=RED.nodes.node(t.id)||RED.nodes.group(t.id)||RED.nodes.workspace(t.id)||RED.nodes.subflow(t.id);t?RED.sidebar.info.refresh(t):RED.sidebar.info.refresh(null)}),a.on("treelistconfirm",function(e,t){t=RED.nodes.node(t.id);t&&("config"===t._def.category?RED.editor.editConfig("",t.type,t.id):RED.editor.edit(t))}),RED.events.on("projects:load",m),RED.events.on("flows:add",w),RED.events.on("flows:remove",k),RED.events.on("flows:change",E),RED.events.on("flows:reorder",D),RED.events.on("subflows:add",R),RED.events.on("subflows:remove",k),RED.events.on("subflows:change",x),RED.events.on("nodes:add",j),RED.events.on("nodes:remove",k),RED.events.on("nodes:change",_),RED.events.on("groups:add",j),RED.events.on("groups:remove",k),RED.events.on("groups:change",_),RED.events.on("workspace:show",b),RED.events.on("workspace:hide",y),RED.events.on("workspace:clear",v),e},search:function(e){o.searchBox("value",e)},select:function(e){e?Array.isArray(e)?a.treeList("select",e.map(function(e){return l[e.id]}),!1):a.treeList("select",l[e.id],!1):a.treeList("clearSelection")},reveal:function(e){a.treeList("show",l[e.id])}}}(),RED.sidebar.help=function(){var n,i,a,s,t,r,d,l;function c(){var e=$(n).parent().height()-i.outerHeight();s.resize(e)}function u(){l=l||setTimeout(function(){l=null;var a=RED.nodes.registry.getModuleList(),e=Object.keys(a),s=(e.sort(),{label:RED._("sidebar.help.nodeHelp"),children:[],expanded:!0}),t=RED.tourGuide.list().map(function(e){return{icon:"fa fa-play-circle-o",label:e.label,tour:e.path}}),t=[{label:"Node-RED",children:[{id:"changelog",label:RED._("sidebar.help.changeLog"),content:w},{label:RED._("tourGuide.welcomeTours"),children:t}]},s],o=RED.nodes.registry.getNodeTypes().filter(function(e){return/subflow/.test(e)});0<o.length&&(s.children.push({label:RED._("menu.label.subflows"),children:[]}),o.forEach(function(e){var t=RED.nodes.getType(e);s.children[0].children.push({id:"node-type:"+e,nodeType:e,subflowLabel:t.label().toLowerCase(),element:m({_def:t,type:t.label()})})})),e.forEach(function(e){var t=a[e];const o=[],n=t.sets,i=Object.keys(n);i.forEach(function(e){const t=n[e];t.types.forEach(function(e){if($("script[data-help-name='"+e+"']").length){const t={_def:RED.nodes.getType(e),type:e};t.name=g(t),o.push({id:"node-type:"+e,nodeType:e,palleteLabel:t.name,element:m(t)})}})}),0<o.length&&(o.sort(function(e,t){return e.nodeType.localeCompare(t.nodeType)}),s.children.push({id:e,icon:"fa fa-cube",label:e,children:o}))}),r.treeList("data",t)},500)}function p(e){var t=r.treeList("get","node-type:subflow:"+e.id);t.subflowLabel=e._def.label().toLowerCase(),t.treeList.replaceElement(m({_def:e._def,type:e._def.label()}))}function f(){var e=$("#red-ui-sidebar-help-show-toc");e.hasClass("selected")&&(e.removeClass("selected"),t=s.ratio(),d.css({transition:"height 0.2s"}),s.ratio(0),setTimeout(function(){d.css({transition:""})},250))}function h(){var e=$("#red-ui-sidebar-help-show-toc");e.hasClass("selected")||(e.addClass("selected"),d.css({transition:"height 0.2s"}),s.ratio(Math.max(.3,Math.min(t,.7))),setTimeout(function(){d.css({transition:""});var e=r.treeList("selected");e.id&&r.treeList("show",e)},250))}function g(e){let t=e.name;if(!t&&e._def&&e._def.paletteLabel)try{t=("function"==typeof e._def.paletteLabel?e._def.paletteLabel.call(e._def):e._def.paletteLabel)||""}catch(e){}return t||e.type}function m(e){var t=$("<div>",{class:"red-ui-node-list-item"}),o=RED.utils.createNodeIcon(e).appendTo(t);return $("<div>",{class:"red-ui-node-label"}).text(g(e)).appendTo(o),t}function v(t){a.empty();var e=/^subflow(:(.+))?$/.exec(t);if(e&&e[2])var e=RED.nodes.subflow(e[2]),o=RED.utils.renderMarkdown(e.info||"")||'<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+"</span>",n=e.name||t;else{o=RED.nodes.getNodeHelp(t)||'<span class="red-ui-help-info-none">'+RED._("sidebar.info.none")+"</span>";e=RED.nodes.registry.getNodeType(t);if("function"==typeof(n=e&&e.paletteLabel?e.paletteLabel:t))try{n=e.paletteLabel.call(e)}catch(e){n=t}}y(n,o),.7<s.ratio()&&s.ratio(.7),r.treeList("show","node-type:"+t),r.treeList("select","node-type:"+t,!1)}function b(e,t){!1!==t&&RED.sidebar.show("help"),e&&v(e),c()}function y(e,t){a.empty(),e&&$("<h1>",{class:"red-ui-help-title"}).text(e).appendTo(a);e=$('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir="'+RED.text.bidi.resolveBaseTextDir(t)+'">'+t+"</span></div>"),$(e).find("a").each(function(e){var t=$(this).attr("href");/^https?:/.test(t)&&$(this).attr("target","_blank")});t=e.appendTo(a);t.find(".red-ui-text-bidi-aware").contents().filter(function(){return 3===this.nodeType&&""!==this.textContent.trim()}).wrap("<span></span>");t.find("H3").wrapInner('<a class="red-ui-help-info-header expanded" href="#"></a>').find("a").prepend('<i class="fa fa-angle-right">').on("click",function(e){e.preventDefault();for(var t=$(this).hasClass("expanded"),o=$(this).parent().next();1===o.length&&"H3"!==o[0].nodeName;)o.toggle(!t),o=o.next();$(this).toggleClass("expanded",!t)}),a.parent().scrollTop(0)}function w(a){$.get("red/about",function(i){i=RED.utils.sanitize(i),RED.tourGuide.load("./tours/welcome.js",function(e,t){var o,n='<div><img width="50px" src="red/images/node-red-icon.svg" /></div>';t&&(o=RED.settings.version.split("."),(t=t.version.split("."))[0]===o[0]&&t[1]===o[1]&&(n='<div><button type="button" onclick="RED.actions.invoke(\'core:show-welcome-tour\')" class="red-ui-button">'+RED._("tourGuide.takeATour")+"</button></div>")),a('<div style="text-align:center;">'+n+"</div>"+RED.utils.renderMarkdown(i))})})}return RED.events.on("view:selection-changed",function(e){!(e=void 0===e?RED.view.selection():e).nodes||1!=e.nodes.length||"subflow"===(e=e.nodes[0]).type&&e.direction||"group"!==e.type&&"junction"!==e.type&&v(e.type)}),RED.actions.add("core:show-about",function(){r.treeList("show","changelog"),r.treeList("select","changelog"),b()}),RED.actions.add("core:show-welcome-tour",function(o,n){n=n||function(){},RED.tourGuide.load("./tours/welcome.js",function(e,t){if(e)console.warn("Failed to load welcome tour",e),n();else{e=RED.settings.version.split("."),t=t.version.split(".");if(t[0]!==e[0]||t[1]!==e[1])n();else{if(o){if(o===RED.settings.version)return void n();t=o.split(".");if(e[0]<t[0]||e[0]===t[0]&&e[1]<t[1])return void n();if(e[0]===t[0]&&e[1]===t[1]){if(3===t.length&&3===e.length)return void n();if(4===e.length&&(3===t.length||e[3]<t[3]))return void n()}}RED.tourGuide.run("./tours/welcome.js",function(e){RED.settings.set("editor.tours.welcome",RED.settings.version),n()})}}})}),{init:function(){(n=document.createElement("div")).className="red-ui-sidebar-info",i=$("<div>",{class:"red-ui-sidebar-header red-ui-info-toolbar"}).appendTo(n),$('<span class="button-group"><a id="red-ui-sidebar-help-show-toc" class="red-ui-button red-ui-button-small selected" href="#"><i class="fa fa-list-ul"></i></a></span>').appendTo(i);var o,e=i.find("#red-ui-sidebar-help-show-toc"),e=(RED.popover.tooltip(e,RED._("sidebar.help.showTopics")),e.on("click",function(e){e.preventDefault(),($(this).hasClass("selected")?f:h)()}),$("<div>",{class:"red-ui-sidebar-help-stack"}).appendTo(n)),t=(d=$("<div>",{class:"red-ui-sidebar-help-toc"}).appendTo(e),$("<div>").css({"overflow-y":"auto"}).appendTo(e));(s=RED.panels.create({container:e})).ratio(.3),helpSearch=$('<input type="text" data-i18n="[placeholder]sidebar.help.search">').appendTo(i).searchBox({style:"compact",delay:100,change:function(){const t=$(this).val().toLowerCase();var e;t?(h(),r.treeList("filter",function(e){return 0===e.depth||(e.nodeType&&-1<e.nodeType.toLowerCase().indexOf(t)||e.subflowLabel&&-1<e.subflowLabel.toLowerCase().indexOf(t)||e.palleteLabel&&-1<e.palleteLabel.toLowerCase().indexOf(t))},!0)):(r.treeList("filter",null),(e=r.treeList("selected")).id&&r.treeList("show",e.id))}}),a=$("<div>",{class:"red-ui-help"}).css({padding:"6px"}).appendTo(t),$('<span class="red-ui-help-info-none">'+RED._("sidebar.help.noHelp")+"</span>").appendTo(a),(r=$("<div>").css({width:"100%"}).appendTo(d).treeList({data:[]})).on("treelistselect",function(e,t){(o=t).tour?RED.tourGuide.run(t.tour):t.nodeType?v(t.nodeType):t.content&&(a.empty(),"string"==typeof t.content?y(t.label,t.content):"function"==typeof t.content&&(0===t.content.length?y(t.label,t.content()):(y(t.label,'<div class="red-ui-component-spinner red-ui-component-spinner-contain"><img src="red/images/spin.svg" /></div>'),t.content(function(e){o===t&&(a.empty(),y(t.label,e))}))))}),RED.sidebar.addTab({id:"help",label:RED._("sidebar.help.label"),name:RED._("sidebar.help.name"),iconClass:"fa fa-book",action:"core:show-help-tab",content:n,pinned:!0,enableOnEdit:!0,onchange:function(){c()}}),$(window).on("resize",c),$(window).on("focus",c),RED.events.on("registry:node-type-added",u),RED.events.on("registry:node-type-removed",u),RED.events.on("subflows:change",p),RED.actions.add("core:show-help-tab",b)},show:b,set:function(e,t){$(a).empty(),y(t,e),f(),b()}}}(),RED.sidebar.config=function(){let r,d;var l=document.createElement("div"),e=(l.className="red-ui-sidebar-node-config",l.id="red-ui-sidebar-node-config",l.tabIndex=0,$('<div class="red-ui-sidebar-header"><span class="button-group"><a class="red-ui-sidebar-header-button-toggle selected" id="red-ui-sidebar-config-filter-all" href="#"><span data-i18n="sidebar.config.filterAll"></span></a><a class="red-ui-sidebar-header-button-toggle" id="red-ui-sidebar-config-filter-unused" href="#"><span data-i18n="sidebar.config.filterUnused"></span></a> </span></div>').appendTo(l),$('<div><a class="red-ui-footer-button" id="red-ui-sidebar-config-collapse-all" href="#"><i class="fa fa-angle-double-up"></i></a> <a class="red-ui-footer-button" id="red-ui-sidebar-config-expand-all" href="#"><i class="fa fa-angle-double-down"></i></a></div>')),i=$("<div>").appendTo(l),a=$("<div>").appendTo(l),s=$("<div>").appendTo(l),n=!1,c={};function u(e,t,o){var n,i,a;return e=e.replace(/\./i,"-"),c[e]?c[e].label!==o&&(c[e].list.parent().find(".red-ui-palette-node-config-label").text(o),c[e].label=o):(t=$('<div class="red-ui-palette-category red-ui-sidebar-config-category" id="red-ui-sidebar-config-category-'+e+'"></div>').appendTo(t),n=$('<div class="red-ui-sidebar-config-tray-header red-ui-palette-header"><i class="fa fa-angle-down expanded"></i></div>').appendTo(t),(o?$('<span class="red-ui-palette-node-config-label"/>').text(o):$('<span class="red-ui-palette-node-config-label" data-i18n="sidebar.config.'+e+'">')).appendTo(n),$('<span class="red-ui-sidebar-node-config-filter-info"></span>').appendTo(n),(category=$('<ul class="red-ui-palette-content red-ui-sidebar-node-config-list"></ul>').appendTo(t)).on("click",function(e){$(l).find(".red-ui-palette-node").removeClass("selected")}),t.i18n(),i=n.find("i"),a={label:o,list:category,size:function(){return a.list.find("li:not(.red-ui-palette-node-config-none)").length},open:function(e){i.hasClass("expanded")||(i.addClass("expanded"),e?a.list.show():a.list.slideDown())},close:function(e){i.hasClass("expanded")&&(i.removeClass("expanded"),e?a.list.hide():a.list.slideUp())},isOpen:function(){return i.hasClass("expanded")}},n.on("click",function(e){a.isOpen()?a.close():a.open()}),c[e]=a),c[e]}function p(e,t){var o,a,e=u(e.replace(/\./i,"-")),s=e.list;t.sort(function(e,t){return e.type<t.type?-1:e.type>t.type?1:0}),n?(o=t.length,0<(o-=(t=t.filter(function(e){return!1!==e._def.hasUsers&&0===e.users.length})).length)?s.parent().find(".red-ui-sidebar-node-config-filter-info").text(RED._("sidebar.config.filtered",{count:o})).show():s.parent().find(".red-ui-sidebar-node-config-filter-info").hide()):s.parent().find(".red-ui-sidebar-node-config-filter-info").hide(),s.empty(),0===t.length?($('<li class="red-ui-palette-node-config-none" data-i18n="sidebar.config.none">NONE</li>').i18n().appendTo(s),e.close(!0)):(a="",t.forEach(function(t){var e=RED.utils.getNodeLabel(t,t.id),o=(t.type!=a&&($('<li class="red-ui-palette-node-config-type">'+t.type+"</li>").appendTo(s),a=t.type),$('<li class="red-ui-palette-node_id_'+t.id.replace(/\./g,"-")+'"></li>').appendTo(s)),n=$('<div class="red-ui-palette-node-config red-ui-palette-node"></div>').appendTo(o),e=(o.data("node",t.id),n.data("node",t.id),$('<div class="red-ui-palette-label"></div>').text(e).appendTo(n)),i=(t.d&&(n.addClass("red-ui-palette-node-config-disabled"),$('<i class="fa fa-ban"></i>').prependTo(e)),!1!==t._def.hasUsers&&(o=$("<div/>",{class:"red-ui-palette-icon-container red-ui-palette-icon-container-right"}).appendTo(n),0===t.users.length?o.text(0):$('<a href="#"/>').on("click",function(e){e.stopPropagation(),e.preventDefault(),RED.search.show(t.id)}).text(t.users.length).appendTo(o),RED.popover.tooltip(o,RED._("editor.nodesUse",{count:t.users.length})),0===t.users.length&&n.addClass("red-ui-palette-node-config-unused")),n.on("click",function(e){e.stopPropagation(),RED.view.select(!1),e.metaKey?$(this).toggleClass("selected"):($(l).find(".red-ui-palette-node").removeClass("selected"),$(this).addClass("selected")),RED.sidebar.info.refresh(t)}),n.on("dblclick",function(e){e.stopPropagation(),RED.editor.editConfig("",t.type,t.id)}),t.users.map(function(e){return e.id}));n.on("mouseover",function(e){RED.nodes.eachNode(function(e){-1!=i.indexOf(e.id)&&(e.highlighted=!0,e.dirty=!0)}),RED.view.redraw()}),n.on("mouseout",function(e){RED.nodes.eachNode(function(e){e.highlighted&&(e.highlighted=!1,e.dirty=!0)}),RED.view.redraw()})}),e.open(!0))}function t(){var e,t={global:!0},o=(u("global",i),RED.nodes.eachWorkspace(function(e){t[e.id.replace(/\./g,"-")]=!0,u(e.id,a,e.label)}),RED.nodes.eachSubflow(function(e){t[e.id.replace(/\./g,"-")]=!0,u(e.id,s,e.name)}),$(".red-ui-sidebar-config-category").each(function(){var e=$(this).attr("id").substring("red-ui-sidebar-config-category-".length);t[e]||($(this).remove(),delete c[e])}),[]),n={};for(e in RED.nodes.eachConfig(function(e){e.z?(n[e.z.replace(/\./g,"-")]=n[e.z.replace(/\./g,"-")]||[],n[e.z.replace(/\./g,"-")].push(e)):e.z||o.push(e)}),t)t.hasOwnProperty(e)&&p(e,n[e]||[]);p("global",o)}return{init:function(){RED.sidebar.addTab({id:"config",label:RED._("sidebar.config.label"),name:RED._("sidebar.config.name"),content:l,toolbar:e,iconClass:"fa fa-cog",action:"core:show-config-tab",onchange:function(){t()}}),RED.actions.add("core:show-config-tab",function(){RED.sidebar.show("config")}),RED.actions.add("core:select-all-config-nodes",function(){$(l).find(".red-ui-palette-node").addClass("selected")}),RED.actions.add("core:delete-config-selection",function(){var a,e=[];$(l).find(".red-ui-palette-node.selected").each(function(){e.push($(this).parent().data("node"))}),0<e.length&&(a={t:"delete",nodes:[],changes:{},dirty:RED.nodes.dirty()},e.forEach(function(e){var t=RED.nodes.node(e);try{t._def.oneditdelete&&t._def.oneditdelete.call(t)}catch(e){console.log("oneditdelete",t.id,t.type,e.toString())}a.nodes.push(t);for(var o=0;o<t.users.length;o++){var n,i=t.users[o];for(n in a.changes[i.id]={changed:i.changed,valid:i.valid},i._def.defaults)i._def.defaults.hasOwnProperty(n)&&i[n]==e&&(a.changes[i.id][n]=e,i[n]="",i.changed=!0,i.dirty=!0);RED.editor.validateNode(i)}RED.nodes.remove(e)}),RED.nodes.dirty(!0),RED.view.redraw(!0),RED.history.push(a))}),RED.events.on("view:selection-changed",function(){$(l).find(".red-ui-palette-node").removeClass("selected")}),$("#red-ui-sidebar-config-collapse-all").on("click",function(e){for(var t in e.preventDefault(),c)c.hasOwnProperty(t)&&c[t].close()}),$("#red-ui-sidebar-config-expand-all").on("click",function(e){for(var t in e.preventDefault(),c)c.hasOwnProperty(t)&&0<c[t].size()&&c[t].open()}),$("#red-ui-sidebar-config-filter-all").on("click",function(e){e.preventDefault(),n&&($(this).addClass("selected"),$("#red-ui-sidebar-config-filter-unused").removeClass("selected"),n=!n,t())}),$("#red-ui-sidebar-config-filter-unused").on("click",function(e){e.preventDefault(),n||($(this).addClass("selected"),$("#red-ui-sidebar-config-filter-all").removeClass("selected"),n=!n,t())}),RED.popover.tooltip($("#red-ui-sidebar-config-filter-all"),RED._("sidebar.config.showAllConfigNodes")),RED.popover.tooltip($("#red-ui-sidebar-config-filter-unused"),RED._("sidebar.config.showAllUnusedConfigNodes"))},show:function(s){"boolean"==typeof s&&(s?$("#red-ui-sidebar-config-filter-unused"):$("#red-ui-sidebar-config-filter-all")).trigger("click"),t(),"string"==typeof s&&($("#red-ui-sidebar-config-filter-all").trigger("click"),s=s.replace(/\./g,"-"),setTimeout(function(){var t,e=$(".red-ui-palette-node_id_"+s),o=e.position().top,n=e.height(),i=$(".red-ui-sidebar-node-config"),a=i.height();a<o+n?i.animate({scrollTop:"-="+(a-(o+n)-30)},150):o<0&&i.animate({scrollTop:"+="+(o-10)},150),t=e,r&&r.length&&(clearInterval(d),d=null,r.children("div").removeClass("highlighted"),r=null),t&&t.children("div").length&&(d=setInterval(function(e){e>=Date.now()?(e=t.children("div").hasClass("highlighted"),t.children("div").toggleClass("highlighted",!e)):(clearInterval(d),d=null,r=null,t.children("div").removeClass("highlighted"))},100,Date.now()+2200),(r=t).children("div").addClass("highlighted"))},100)),RED.sidebar.show("config")},refresh:t}}(),RED.sidebar.context=function(){var i,a,s,r,d,l,c,u,p;function f(e,t){u=e,t||r.prop("checked")?e?g(d,"context/node/"+e.id,e.id):g(d):($(d.table).empty(),(e?$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.refresh"></td></tr>'):$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.none"></td></tr>')).appendTo(d.table).i18n(),d.timestamp.html("&nbsp;"))}function h(e,t){p=e,t||s.prop("checked")?e?g(l,"context/flow/"+e.id,e.id):g(l):($(l.table).empty(),$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.refresh"></td></tr>').appendTo(l.table).i18n(),l.timestamp.html("&nbsp;"))}function g(e,t,o){var a,p,f,h,g,n=e.table;o?(a=e,p=t,f=o,h=RED.settings.context.stores,g=a.table,$.getJSON(p,function(e){$(g).empty();var t,o={};for(t in e)if(e.hasOwnProperty(t))for(var n in e[t])e[t].hasOwnProperty(n)&&(o.hasOwnProperty(n)||(o[n]=[]),e[t][n].store=t,o[n].push(e[t][n]));for(var c=Object.keys(o),i=(c.sort(),c.length),u=0;u<i;u++)o[c[u]].forEach(function(i){var a=c[u],s=(o[a].length,$('<tr class="red-ui-help-info-row"><td class="red-ui-sidebar-context-property"></td><td></td></tr>').appendTo(g)),r=($(s.children()[0]).text(a),$('<span class="button-group"></span>')),e=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-refresh"></i></button>').appendTo(r).on("click",function(e){e.preventDefault(),e.stopPropagation(),$.getJSON(p+"/"+a+"?store="+i.store,function(e){e.msg===d&&e.format===l||(d=e.msg,l=e.format,r.detach(),$(s.children()[1]).empty(),RED.utils.createObjectElement(RED.utils.decodeObject(d,l),{typeHint:e.format,sourceId:f+"."+a,tools:r,path:""}).appendTo(s.children()[1]))})}),e=(RED.popover.tooltip(e,RED._("sidebar.context.refrsh")),$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-trash"></i></button>').appendTo(r).on("click",function(e){e.preventDefault(),e.stopPropagation();var n=RED.popover.create({trigger:"modal",target:s,direction:"left",content:function(){var e=$("<div>"),t=($('<p data-i18n="sidebar.context.deleteConfirm"></p>').appendTo(e),$("<p>").appendTo(e)),o=$('<span class="button-group"></span>').appendTo(t);return $('<button class="red-ui-button" data-i18n="common.label.cancel"></button>').appendTo(o).on("click",function(e){e.preventDefault(),n.close()}),o=$('<span class="button-group"></span>').appendTo(t),$('<button class="red-ui-button primary" data-i18n="common.label.delete"></button>').appendTo(o).on("click",function(e){e.preventDefault(),n.close(),$.ajax({url:p+"/"+a+"?store="+i.store,type:"DELETE"}).done(function(e,t,o){$.getJSON(p+"/"+a+"?store="+i.store,function(e){"undefined"===e.format?(s.remove(),0===g.children().length&&$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.empty"></td></tr>').appendTo(g).i18n()):(d=e.msg,l=e.format,r.detach(),$(s.children()[1]).empty(),RED.utils.createObjectElement(RED.utils.decodeObject(d,l),{typeHint:e.format,sourceId:f+"."+a,tools:r,path:""}).appendTo(s.children()[1]))})}).fail(function(e,t,o){})}),e.i18n()}});n.open()})),d=(RED.popover.tooltip(e,RED._("sidebar.context.delete")),i.msg),l=i.format;RED.utils.createObjectElement(RED.utils.decodeObject(d,l),{typeHint:i.format,sourceId:f+"."+a,tools:r,path:""}).appendTo(s.children()[1]),1<h.length&&$("<span>",{class:"red-ui-sidebar-context-property-storename"}).text(i.store).appendTo($(s.children()[0]))});0===i&&$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.empty"></td></tr>').appendTo(g).i18n(),$(a.timestamp).text((new Date).toLocaleString())})):($(n).empty(),$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.none"></td></tr>').appendTo(n).i18n())}function m(){RED.sidebar.show("context")}return{init:function(){(i=$("<div>").css({position:"relative",height:"100%"})).className="red-ui-sidebar-context";var e=$("<div></div>"),t=$("<div>",{class:"red-ui-sidebar-context-stack"}).appendTo(i),t=(a=RED.stack.create({container:t}),(d=a.add({title:RED._("sidebar.context.node"),collapsible:!0})).expand(),d.content.css({height:"100%"}),d.timestamp=$('<div class="red-ui-sidebar-context-updated">&nbsp;</div>').appendTo(d.content),$('<table class="red-ui-info-table"></table>').appendTo(d.content)),o=(d.table=$("<tbody>").appendTo(t),$('<div style="float: right"></div>').appendTo(d.header)),n=RED.settings.get("editor.context.nodeRefresh",!1),n=(r=$('<input type="checkbox">').prop("checked",n).appendTo(o).toggleButton({baseClass:"red-ui-sidebar-header-button red-ui-button-small",enabledLabel:"",disabledLabel:""}).on("change",function(){var e=$(this).prop("checked");RED.settings.set("editor.context.flowRefresh",e)}),RED.popover.tooltip(r.next(),RED._("sidebar.context.autoRefresh")),$('<button class="red-ui-button red-ui-button-small" style="margin-left: 5px"><i class="fa fa-refresh"></i></button>').appendTo(o).on("click",function(e){e.stopPropagation(),e.preventDefault(),f(u,!0)})),t=(RED.popover.tooltip(n,RED._("sidebar.context.refrsh")),(l=a.add({title:RED._("sidebar.context.flow"),collapsible:!0})).expand(),l.content.css({height:"100%"}),l.timestamp=$('<div class="red-ui-sidebar-context-updated">&nbsp;</div>').appendTo(l.content),$('<table class="red-ui-info-table"></table>').appendTo(l.content)),n=(l.table=$("<tbody>").appendTo(t),o=$('<div style="float: right"></div>').appendTo(l.header),RED.settings.get("editor.context.flowRefresh",!1)),n=(s=$('<input type="checkbox">').prop("checked",n).appendTo(o).toggleButton({baseClass:"red-ui-sidebar-header-button red-ui-button-small",enabledLabel:"",disabledLabel:""}).on("change",function(){var e=$(this).prop("checked");RED.settings.set("editor.context.flowRefresh",e)}),RED.popover.tooltip(s.next(),RED._("sidebar.context.autoRefresh")),$('<button class="red-ui-button red-ui-button-small" style="margin-left: 5px"><i class="fa fa-refresh"></i></button>').appendTo(o).on("click",function(e){e.stopPropagation(),e.preventDefault(),h(p,!0)})),t=(RED.popover.tooltip(n,RED._("sidebar.context.refrsh")),(c=a.add({title:RED._("sidebar.context.global"),collapsible:!0})).expand(),c.content.css({height:"100%"}),c.timestamp=$('<div class="red-ui-sidebar-context-updated">&nbsp;</div>').appendTo(c.content),$('<table class="red-ui-info-table"></table>').appendTo(c.content));c.table=$("<tbody>").appendTo(t),o=$('<div style="float: right"></div>').appendTo(c.header),$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-refresh"></i></button>').appendTo(o).on("click",function(e){e.stopPropagation(),e.preventDefault(),g(c,"context/global","global")}),RED.popover.tooltip(o,RED._("sidebar.context.refrsh")),RED.actions.add("core:show-context-tab",m),RED.sidebar.addTab({id:"context",label:RED._("sidebar.context.label"),name:RED._("sidebar.context.name"),iconClass:"fa fa-database",content:i,toolbar:e,enableOnEdit:!0,action:"core:show-context-tab"}),RED.events.on("view:selection-changed",function(e){f(e.nodes&&1===e.nodes.length&&e.nodes[0])}),RED.events.on("workspace:change",function(e){h(RED.nodes.workspace(e.workspace))}),$(c.table).empty(),$('<tr class="red-ui-help-info-row red-ui-search-empty blank" colspan="2"><td data-i18n="sidebar.context.refresh"></td></tr>').appendTo(c.table).i18n(),c.timestamp.html("&nbsp;")}}}(),RED.palette.editor=function(){var l,c,u,y,p,i,f=[],h=[],w={},E={},D={},t={},g="",n=/^(\d+)(\.(\d+))?(\.(\d+))?(-([0-9A-Za-z-]+))?(\.([0-9A-Za-z-.]+))?$/,z=/^\d+$/;function o(e){this.number=0,this.text=e,z.test(e)?(this.number=parseInt(e),this.type="N"):this.type=null==e||e.length<1?"E":"T"}function R(e){e=e.match(n);this.parts=[new o(e[1]),new o(e[3]),new o(e[5]),new o(e[7]),new o(e[9])]}function s(e,t){e=(e=Date.now()-e)<300?300:0;setTimeout(function(){t()},e)}function m(e,t,n,i){n.show();var a=Date.now();$.ajax({url:"nodes/"+e,type:"PUT",data:JSON.stringify({enabled:t}),contentType:"application/json; charset=utf-8"}).done(function(e,t,o){s(a,function(){n.hide(),i()})}).fail(function(e,t,o){s(a,function(){n.hide(),i(e)})})}function v(e,t,o,n){e={module:e};t&&(e.version=t),o&&(e.url=o),$.ajax({url:"nodes",type:"POST",data:JSON.stringify(e),contentType:"application/json; charset=utf-8"}).done(function(e,t,o){n()}).fail(function(e,t,o){n(e)})}function b(e){t.hasOwnProperty(e)||(t[e]=setTimeout(function(){delete t[e],a(e)},100))}function a(e){if(D.hasOwnProperty(e)){var t=D[e].info,o=D[e].elements;if(o){var n,i=0,a=0,s=0;for(n in o.errorList.empty(),D[e].totalUseCount=0,D[e].setUseCount={},t.sets)if(t.sets.hasOwnProperty(n)){var r,d=0,l=t.sets[n],c=o.sets[n];l.err&&(s++,r=l.err,l.err.message?r=l.err.message:l.err.code&&(r=l.err.code),$("<li>").text(r).appendTo(o.errorList)),l.enabled&&(i+=l.types.length),a+=l.types.length;for(var u=0;u<t.sets[n].types.length;u++){var p,f=t.sets[n].types[u],h=(d+=E[f]||0,c.swatches[f]);!l.enabled||(p=RED.nodes.getType(f))&&p.color&&(h.css({background:RED.utils.getNodeColor(f,p)}),h.css({border:"1px solid "+function(e){if(n=/^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)[,)]/.exec(e)){var t=parseInt(n[1]),o=parseInt(n[2]),n=parseInt(n[3]);if(160<(299*t+587*o+114*n)/1e3)return"rgb("+Math.floor(.8*t)+","+Math.floor(.8*o)+","+Math.floor(.8*n)+")"}return e}(h.css("backgroundColor"))}))}D[e].setUseCount[n]=d,D[e].totalUseCount+=d,0<d?(c.enableButton.text(RED._("palette.editor.inuse")),c.enableButton.addClass("disabled")):(c.enableButton.removeClass("disabled"),l.enabled?c.enableButton.text(RED._("palette.editor.disable")):c.enableButton.text(RED._("palette.editor.enable"))),c.setRow.toggleClass("red-ui-palette-module-set-disabled",!l.enabled)}0===s?o.errorRow.hide():o.errorRow.show(),o.setCount.text(RED._("palette.editor.nodeCount",{count:a,label:i===a?a:i+" / "+a})),0<D[e].totalUseCount?(o.enableButton.text(RED._("palette.editor.inuse")),o.enableButton.addClass("disabled"),o.removeButton.hide()):(o.enableButton.removeClass("disabled"),t.local&&o.removeButton.css("display","inline-block"),0===i?o.enableButton.text(RED._("palette.editor.enableall")):o.enableButton.text(RED._("palette.editor.disableall")),o.container.toggleClass("disabled",0===i))}t.pending_version?(o.versionSpan.html(t.version+' <i class="fa fa-long-arrow-right"></i> '+t.pending_version).appendTo(o.metaRow),o.updateButton.text(RED._("palette.editor.updated")).addClass("disabled").css("display","inline-block")):w.hasOwnProperty(e)&&N&&(v=w[e].version,b=t.version,v=new R(v),b=new R(b),0<v.compare(b))&&RED.utils.checkModuleAllowed(e,null,P,A)?(o.updateButton.show(),o.updateButton.text(RED._("palette.editor.update",{version:w[e].version}))):o.updateButton.hide()}else{D[e]={info:RED.nodes.registry.getModule(e)};var g,m=[e];for(g in D[e].info.sets)D[e].info.sets.hasOwnProperty(g)&&(m.push(g),m=m.concat(D[e].info.sets[g].types));D[e].index=m.join(",").toLowerCase(),y.editableList("addItem",D[e])}var v,b}o.prototype.compare=function(e){switch(this.type+e.type){case"EE":return 0;case"NT":case"TE":case"EN":return-1;case"NN":return this.number-e.number;case"TT":return this.text.localeCompare(e.text);case"ET":case"TN":case"NE":return 1}};var r,d=[],x=!(R.prototype.compare=function(e){for(var t=0,o=0,n=this.parts.length;0==t&&o<n;o++)t=this.parts[o].compare(e.parts[o]);return t}),_=j;function k(e,t,o,n){d.push(e||n),e?x=!0:(n.modules&&(n.modules=n.modules.filter(function(e){return!!RED.utils.checkModuleAllowed(e.id,e.version,O,I)&&((w[e.id]=e).index=[e.id],e.keywords&&(e.index=e.index.concat(e.keywords)),e.types&&(e.index=e.index.concat(e.types)),e.updated_at?e.timestamp=new Date(e.updated_at).getTime():e.timestamp=0,e.index=e.index.join(",").toLowerCase(),!0)}),f=f.concat(n.modules)),u.searchBox("count",f.length)),1<i&&$(".red-ui-palette-module-shade-status").html(RED._("palette.editor.loading")+"<br>"+d.length+"/"+i),d.length===i&&(x&&RED.notify(RED._("palette.editor.errors.catalogLoadFailed",{url:t}),"error",!1,8e3),e=250-(Date.now()-r),setTimeout(function(){$("#red-ui-palette-module-install-shade").hide()},Math.max(e,0)))}function T(){var e,t;0===f.length&&(f=[],w={},p.editableList("empty"),$(".red-ui-palette-module-shade-status").text(RED._("palette.editor.loading")),e=RED.settings.theme("palette.catalogues")||["https://catalogue.nodered.org/catalogue.json"],x=!(d=[]),i=e.length,1<e.length&&$(".red-ui-palette-module-shade-status").html(RED._("palette.editor.loading")+"<br>0/"+e.length),$("#red-ui-palette-module-install-shade").show(),r=Date.now(),t=0,e.forEach(function(n,e){$.getJSON(n,{_:(new Date).getTime()},function(e){for(var t in k(null,n,0,e),D)D.hasOwnProperty(t)&&a(t)}).fail(function(e,t,o){console.warn("Error loading catalog",n,":",o),k(e,n)}).always(function(){++t===i&&u.searchBox("change")})}))}function C(){if(p.editableList("empty"),""===u.searchBox("value").trim())p.editableList("addItem",{count:f.length});else{h.sort(_);for(var e=0;e<Math.min(10,h.length);e++)p.editableList("addItem",h[e]);0===h.length&&p.editableList("addItem",{}),10<h.length&&p.editableList("addItem",{start:10,more:h.length-10})}}function j(e,t){var o=u.searchBox("value").trim();if(""===o)return L(e,t);o=e.info.index.indexOf(o)-t.info.index.indexOf(o);return 0==o?L(e,t):o}function L(e,t){return e.info.id.localeCompare(t.info.id)}function B(e,t){return-1*(e.info.timestamp-t.info.timestamp)}var S,O=["*"],I=[],N=!0,P=["*"],A=[];function G(){return T(),l.activateTab("nodes"),S}function M(n,t,i){var e,a;!1===RED.settings.get("externalModules.palette.allowInstall",!0)?i(new Error("Palette not editable")):(e=[{text:RED._("common.label.cancel"),click:function(){a.close()}}],n.url&&e.push({text:RED._("palette.editor.confirm.button.review"),class:"primary red-ui-palette-module-install-confirm-button-install",click:function(){var e=n.url||"";window.open(e)}}),e.push({text:RED._("palette.editor.confirm.button.install"),class:"primary red-ui-palette-module-install-confirm-button-install",click:function(){var o=RED.utils.addSpinnerOverlay(t,!0),e=$('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(o);$('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(e).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.eventLog.startEvent(RED._("palette.editor.confirm.button.install")+" : "+n.id+" "+n.version),v(n.id,n.version,n.pkg_url,function(e){var t;o.remove(),e&&e.responseJSON&&(t=RED.notify(RED._("palette.editor.errors.installFailed",{module:n.id,message:e.responseJSON.message}),{type:"error",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.close"),click:function(){t.close()}},{text:RED._("eventLog.view"),click:function(){t.close(),RED.actions.invoke("core:show-event-log")}}]})),i(e)}),a.close()}}),a=RED.notify(RED._("palette.editor.confirm.install.body",{module:n.id}),{modal:!0,fixed:!0,buttons:e}))}return{init:function(){var a,s,t,o,e,n,i,r,d;!1!==RED.settings.get("externalModules.palette.allowInstall",!0)&&(n=RED.settings.get("externalModules.palette.allowList"),e=RED.settings.get("externalModules.palette.denyList"),(n||e)&&(O=n,I=e),O=RED.utils.parseModuleList(O),I=RED.utils.parseModuleList(I),n=RED.settings.get("externalModules.palette.allowUpdateList"),e=RED.settings.get("externalModules.palette.denyUpdateList"),(n||e)&&(P=n,A=e),P=RED.utils.parseModuleList(P),A=RED.utils.parseModuleList(A),N=RED.settings.get("externalModules.palette.allowUpdate",!0),S=$('<div id="red-ui-settings-tab-palette"></div>'),o=$('<div id="red-ui-palette-editor"><ul id="red-ui-palette-editor-tabs"></ul></div>').appendTo(S),l=RED.tabs.create({element:S.find("#red-ui-palette-editor-tabs"),onchange:function(e){o.find(".red-ui-palette-editor-tab").hide(),e.content.show(),c&&c.searchBox("value",""),u&&u.searchBox("value",""),"install"===e.id?u&&u.trigger("focus"):c&&c.trigger("focus")},minimumActiveTabWidth:110}),n=o,n=$("<div>",{class:"red-ui-palette-editor-tab"}).appendTo(n),l.addTab({id:"nodes",label:RED._("palette.editor.tab-nodes"),content:n}),e=$("<div>",{class:"red-ui-palette-search"}).appendTo(n),c=$('<input type="text" data-i18n="[placeholder]palette.filter"></input>').appendTo(e).searchBox({delay:200,change:function(){var e,t,o;e=$(this).val(),g=e.toLowerCase(),t=y.editableList("filter"),o=y.editableList("length"),""===e?c.searchBox("count"):c.searchBox("count",t+" / "+o)}}),y=$("<ol>",{id:"red-ui-palette-module-list",style:"position: absolute;top: 35px;bottom: 0;left: 0;right: 0px;"}).appendTo(n).editableList({addButton:!1,scrollOnAdd:!1,sort:function(e,t){return e.info.name.localeCompare(t.info.name)},filter:function(e){return""===g||(""===g||-1<e.index.indexOf(g))},addItem:function(o,e,s){var t,n,i,a,r,d,l,c,u,p,f=s.info;f?(l=$("<div>",{class:"red-ui-palette-module-header"}).appendTo(o),t=$('<div class="red-ui-palette-module-meta red-ui-palette-module-name"><i class="fa fa-cube"></i></div>').appendTo(l),$("<span>").text(f.name).appendTo(t),t=$('<div class="red-ui-palette-module-meta red-ui-palette-module-version"><i class="fa fa-tag"></i></div>').appendTo(l),t=$("<span>").text(f.version).appendTo(t),n=$('<div class="red-ui-palette-module-meta red-ui-palette-module-errors"><i class="fa fa-warning"></i></div>').hide().appendTo(l),i=$('<ul class="red-ui-palette-module-error-list"></ul>').appendTo(n),l=$("<div>",{class:"red-ui-palette-module-meta"}).appendTo(l),a=$('<a href="#" class="red-ui-button red-ui-button-small red-ui-palette-module-set-button"><i class="fa fa-angle-right red-ui-palette-module-node-chevron"></i> </a>').appendTo(l),r=$("<span>").appendTo(a),l=$("<div>",{class:"red-ui-palette-module-button-group"}).appendTo(l),(p=$('<a href="#" class="red-ui-button red-ui-button-small"></a>').text(RED._("palette.editor.update")).appendTo(l)).attr("id","up_"+Math.floor(1e9*Math.random())),p.on("click",function(e){var n,t,i,a,s,r;e.preventDefault(),$(this).hasClass("disabled")||(t=w[(n=f).name].version,i=w[f.name].pkg_url,a=o,!(s=function(e){})===RED.settings.get("externalModules.palette.allowInstall",!0)?s(new Error("Palette not editable")):r=RED.notify(RED._("palette.editor.confirm.update.body",{module:n.name}),{modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){r.close()}},{text:RED._("palette.editor.confirm.button.update"),class:"primary red-ui-palette-module-install-confirm-button-update",click:function(){var o=RED.utils.addSpinnerOverlay(a,!0),e=$('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(o);$('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(e).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.eventLog.startEvent(RED._("palette.editor.confirm.button.install")+" : "+n.name+" "+t),v(n.name,t,i,function(e){var t;o.remove(),e&&e.responseJSON&&(t=RED.notify(RED._("palette.editor.errors.updateFailed",{module:n.name,message:e.responseJSON.message}),{type:"error",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.close"),click:function(){t.close()}},{text:RED._("eventLog.view"),click:function(){t.close(),RED.actions.invoke("core:show-event-log")}}]})),s(e)}),r.close()}}]}))}),(d=$('<a href="#" class="red-ui-button red-ui-button-small"></a>').text(RED._("palette.editor.remove")).appendTo(l)).attr("id","up_"+Math.floor(1e9*Math.random())),d.on("click",function(e){var i,t,a;e.preventDefault(),i=f,t=o,!(e=function(e){})===RED.settings.get("externalModules.palette.allowInstall",!0)?e(new Error("Palette not editable")):a=RED.notify(RED._("palette.editor.confirm.remove.body",{module:i.name}),{modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){a.close()}},{text:RED._("palette.editor.confirm.button.remove"),class:"primary red-ui-palette-module-install-confirm-button-remove",click:function(){var n,o=RED.utils.addSpinnerOverlay(t,!0),e=$('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(o);$('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(e).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.eventLog.startEvent(RED._("palette.editor.confirm.button.remove")+" : "+i.name),e=i.name,n=function(e){var t;o.remove(),e&&e.responseJSON&&(t=RED.notify(RED._("palette.editor.errors.removeFailed",{module:i.name,message:e.responseJSON.message}),{type:"error",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.close"),click:function(){t.close()}},{text:RED._("eventLog.view"),click:function(){t.close(),RED.actions.invoke("core:show-event-log")}}]}))},$.ajax({url:"nodes/"+e,type:"DELETE"}).done(function(e,t,o){n()}).fail(function(e,t,o){n(e)}),a.close()}}]})}),f.local||d.hide(),l=$('<a href="#" class="red-ui-button red-ui-button-small"></a>').text(RED._("palette.editor.disableall")).appendTo(l),c=$("<div>",{class:"red-ui-palette-module-content"}).appendTo(o),u=$('<div class="red-ui-palette-module-shade hide"><img src="red/images/spin.svg" class="red-ui-palette-spinner"/></div>').appendTo(o),s.elements={updateButton:p,removeButton:d,enableButton:l,errorRow:n,errorList:i,setCount:r,container:o,shade:u,versionSpan:t,sets:{}},a.on("click",function(e){e.preventDefault(),o.hasClass("expanded")?(o.removeClass("expanded"),c.slideUp()):(o.addClass("expanded"),c.slideDown())}),(p=Object.keys(f.sets)).sort(function(e,t){return e.toLowerCase().localeCompare(t.toLowerCase())}),p.forEach(function(o){var n=f.sets[o],i=$("<div>",{class:"red-ui-palette-module-set"}).appendTo(c),e=$("<div>",{class:"red-ui-palette-module-set-button-group"}).appendTo(i),a={},e=(n.types.forEach(function(e){var t=$("<div>",{class:"red-ui-palette-module-type"}).appendTo(i);a[e]=$("<span>",{class:"red-ui-palette-module-type-swatch"}).appendTo(t),$("<span>",{class:"red-ui-palette-module-type-node"}).text(e).appendTo(t)}),$('<a href="#" class="red-ui-button red-ui-button-small"></a>').appendTo(e));e.on("click",function(e){var t;e.preventDefault(),0===s.setUseCount[o]&&(e=RED.nodes.registry.getNodeSet(n.id),u.show(),t=!e.enabled,m(n.id,t,u,function(e){e&&e.responseJSON&&RED.notify(RED._("palette.editor.errors."+(t?"enable":"disable")+"Failed",{module:id,message:e.responseJSON.message}))}))}),s.elements.sets[n.name]={setRow:i,enableButton:e,swatches:a}}),l.on("click",function(e){e.preventDefault(),0===s.totalUseCount&&m(f.name,o.hasClass("disabled"),u,function(e){e&&e.responseJSON&&RED.notify(RED._("palette.editor.errors.installFailed",{module:id,message:e.responseJSON.message}))})}),b(f.name)):$("<div>",{class:"red-ui-search-empty"}).text(RED._("search.empty")).appendTo(o)}}),e=o,e=$("<div>",{class:"red-ui-palette-editor-tab hide"}).appendTo(e),l.addTab({id:"install",label:RED._("palette.editor.tab-install"),content:e}),n=$("<div>",{class:"red-ui-palette-editor-toolbar"}).appendTo(e),i=$("<div>",{class:"red-ui-palette-search"}).appendTo(e),u=$('<input type="text" data-i18n="[placeholder]palette.search"></input>').appendTo(i).searchBox({delay:300,change:function(){var t=$(this).val().trim().toLowerCase();0<t.length?(h=f.filter(function(e){return-1<e.index.indexOf(t)}).map(function(e){return{info:e}}),C(),u.searchBox("count",h.length+" / "+f.length)):(u.searchBox("count",f.length),p.editableList("empty"),p.editableList("addItem",{count:f.length}))}}),$("<span>").text(RED._("palette.editor.sort")+" ").appendTo(n),i=$('<span class="button-group"></span>').appendTo(n),r=$('<a href="#" class="red-ui-palette-editor-install-sort-option red-ui-sidebar-header-button-toggle selected"><i class="fa fa-sort-amount-desc"></i></a>').appendTo(i),d=$('<a href="#" class="red-ui-palette-editor-install-sort-option red-ui-sidebar-header-button-toggle" data-i18n="palette.editor.sortAZ"></a>').appendTo(i),i=$('<a href="#" class="red-ui-palette-editor-install-sort-option red-ui-sidebar-header-button-toggle" data-i18n="palette.editor.sortRecent"></a>').appendTo(i),[{button:r,func:j},{button:d,func:L},{button:i,func:B}].forEach(function(t){t.button.on("click",function(e){e.preventDefault(),$(this).hasClass("selected")||($(".red-ui-palette-editor-install-sort-option").removeClass("selected"),$(this).addClass("selected"),_=t.func,C())})}),r=$("<span>").appendTo(n),(d=$('<a href="#" class="red-ui-sidebar-header-button"><i class="fa fa-refresh"></i></a>').appendTo(r)).on("click",function(e){e.preventDefault(),f=[],w={},T()}),RED.popover.tooltip(d,RED._("palette.editor.refresh")),p=$("<ol>",{style:"position: absolute;top: 79px;bottom: 0;left: 0;right: 0px;"}).appendTo(e).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(t,e,o){if(o.count)$("<div>",{class:"red-ui-search-empty"}).text(RED._("palette.editor.moduleCount",{count:o.count})).appendTo(t);else if(o.more)t.addClass("red-ui-palette-module-more"),i=$("<div>",{class:"red-ui-palette-module-header palette-module"}).appendTo(t),$('<a href="#"></a>').text(RED._("palette.editor.more",{count:o.more})).appendTo(i).on("click",function(e){e.preventDefault(),p.editableList("removeItem",o);for(var t=o.start;t<Math.min(o.start+10,o.start+o.more);t++)p.editableList("addItem",h[t]);10<o.more&&p.editableList("addItem",{start:o.start+10,more:o.more-10})});else if(o.info){var n=o.info,i=$("<div>",{class:"red-ui-palette-module-header"}).appendTo(t),a=$('<div class="red-ui-palette-module-meta red-ui-palette-module-name"><i class="fa fa-cube"></i></div>').appendTo(i),a=($("<span>").text(n.name||n.id).appendTo(a),$('<a target="_blank" class="red-ui-palette-module-link"><i class="fa fa-external-link"></i></a>').attr("href",n.url).appendTo(a),$('<div class="red-ui-palette-module-meta"></div>').appendTo(i)),a=($("<div>",{class:"red-ui-palette-module-description"}).text(n.description).appendTo(a),$('<div class="red-ui-palette-module-meta"></div>').appendTo(i)),s=($('<span class="red-ui-palette-module-version"><i class="fa fa-tag"></i> '+n.version+"</span>").appendTo(a),$('<span class="red-ui-palette-module-updated"><i class="fa fa-calendar"></i> '+function(e){if(new Date,new Date(e),(e=(Date.now()-new Date(e).getTime())/1e3)<60)return RED._("palette.editor.times.seconds");if((e=Math.floor(e/60))<10)return RED._("palette.editor.times.minutes");if(e<60)return RED._("palette.editor.times.minutesV",{count:e});if((e=Math.floor(e/60))<24)return RED._("palette.editor.times.hoursV",{count:e});if((e=Math.floor(e/24))<7)return RED._("palette.editor.times.daysV",{count:e});if((e=Math.floor(e/7))<4)return RED._("palette.editor.times.weeksV",{count:e});var t=Math.floor(e/4);return e%=4,t<12?RED._("palette.editor.times.monthsV",{count:t}):(e=Math.floor(t/12),0===(t%=12)?RED._("palette.editor.times.yearsV",{count:e}):RED._("palette.editor.times.year"+(1<e?"s":"")+"MonthsV",{y:e,count:t}))}(n.updated_at)+"</span>").appendTo(a),!1);if(n.types&&0<n.types.length)for(e=0;e<n.types.length;e++){var r=RED.nodes.registry.getNodeSetForType(n.types[e]);if(r){s=r.module;break}}a=$("<div>",{class:"red-ui-palette-module-meta"}).appendTo(i),i=$("<div>",{class:"red-ui-palette-module-button-group"}).appendTo(a),a=$('<a href="#" class="red-ui-button red-ui-button-small"></a>').text(RED._("palette.editor.install")).appendTo(i);a.on("click",function(e){e.preventDefault(),$(this).hasClass("disabled")||M(n,t,function(e){})}),D.hasOwnProperty(n.id)?(a.addClass("disabled"),a.text(RED._("palette.editor.installed"))):s&&(a.addClass("disabled"),a.text(RED._("palette.editor.conflict")),RED.popover.create({target:a,content:RED._("palette.editor.conflictTip",{module:s}),trigger:"hover",direction:"bottom",delay:{show:750,hide:50}})),o.elements={installButton:a}}else $("<div>",{class:"red-ui-search-empty"}).text(RED._("search.empty")).appendTo(t)}}),!1!==RED.settings.get("externalModules.palette.allowUpload",!0)&&(i=$('<span class="button-group">').prependTo(n),r=$('<button type="button" class="red-ui-sidebar-header-button red-ui-palette-editor-upload-button"><label><i class="fa fa-upload"></i><form id="red-ui-palette-editor-upload-form" enctype="multipart/form-data"><input name="tarball" type="file" accept=".tgz"></label></button>').appendTo(i),(a=r.find('input[type="file"]')).on("change",function(e){0<this.files.length&&(t.text(this.files[0].name),s.slideDown(200))}),s=$('<div class="red-ui-palette-editor-upload"></div>').appendTo(e),d=$("<div>").appendTo(s),n=$('<div class="placeholder-input"><i class="fa fa-upload"></i> </div>').appendTo(d),t=$("<span></span>").appendTo(n),i=$('<div class="red-ui-palette-editor-upload-buttons"></div>').appendTo(d),$('<button class="editor-button"></button>').text(RED._("common.label.cancel")).appendTo(i).on("click",function(e){e.preventDefault(),s.slideUp(200),a.val("")}),$('<button class="editor-button primary"></button>').text(RED._("common.label.upload")).appendTo(i).on("click",function(e){e.preventDefault();var n=RED.utils.addSpinnerOverlay(s,!0),e=$('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(n),e=($('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(e).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.eventLog.startEvent(RED._("palette.editor.confirm.button.install")+" : "+a[0].files[0].name),new FormData),i=(e.append("tarball",a[0].files[0]),a[0].files[0].name);$.ajax({url:"nodes",data:e,cache:!1,contentType:!1,processData:!1,method:"POST"}).always(function(e,t,o){n.remove(),a.val(""),s.slideUp(200)}).fail(function(e,t,o){e.responseJSON&&(t=e.responseJSON.message);var n=RED.notify(RED._("palette.editor.errors.installFailed",{module:i,message:t}),{type:"error",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.close"),click:function(){n.close()}},{text:RED._("eventLog.view"),click:function(){n.close(),RED.actions.invoke("core:show-event-log")}}]});a.val(""),s.slideUp(200)})}),RED.popover.tooltip(r,RED._("palette.editor.upload"))),$('<div id="red-ui-palette-module-install-shade" class="red-ui-palette-module-shade hide"><div class="red-ui-palette-module-shade-status"></div><img src="red/images/spin.svg" class="red-ui-palette-spinner"/></div>').appendTo(e),RED.userSettings.add({id:"palette",title:RED._("palette.editor.palette"),get:G,close:function(){S.detach()},focus:function(){l.resize(),setTimeout(function(){c.trigger("focus")},200)}}),RED.actions.add("core:manage-palette",function(){RED.userSettings.show("palette")}),RED.events.on("registry:module-updated",function(e){b(e.module)}),RED.events.on("registry:node-set-enabled",function(e){b(e.module)}),RED.events.on("registry:node-set-disabled",function(e){b(e.module)}),RED.events.on("registry:node-type-added",function(e){/^subflow:/.test(e)||b(RED.nodes.registry.getNodeSetForType(e).module)}),RED.events.on("registry:node-type-removed",function(e){/^subflow:/.test(e)||b(RED.nodes.registry.getNodeSetForType(e).module)}),RED.events.on("registry:node-set-added",function(e){b(e.module);for(var t=0;t<h.length;t++)if(h[t].info.id===e.module){var o=h[t].elements.installButton;o.addClass("disabled"),o.text(RED._("palette.editor.installed"));break}}),RED.events.on("registry:node-set-removed",function(e){if(!RED.nodes.registry.getModule(e.module)){var t=D[e.module];if(t){y.editableList("removeItem",t),delete D[e.module];for(var o=0;o<h.length;o++)if(h[o].info.id===e.module){var n=h[o].elements.installButton;n.removeClass("disabled"),n.text(RED._("palette.editor.install"));break}}}}),RED.events.on("nodes:add",function(e){/^subflow:/.test(e.type)||(E[e.type]=(E[e.type]||0)+1,1===E[e.type]&&b(RED.nodes.registry.getNodeSetForType(e.type).module))}),RED.events.on("nodes:remove",function(e){E.hasOwnProperty(e.type)&&(E[e.type]--,0===E[e.type]&&(delete E[e.type],b(RED.nodes.registry.getNodeSetForType(e.type).module)))}))},install:M}}(),RED.editor=function(){var l=[],c=!1,o={},m={},v={},u={};function w(e){var t,o,n,i,a=e.valid,s=e.changed;if(e.valid=!0,0===e.type.indexOf("subflow:"))o=(t=RED.nodes.subflow(e.type.substring(8))).valid,i=t.changed,void 0===o&&(o=w(t),i=t.changed),n=p(e,e._def.defaults,e),e.valid=o&&0===n.length,e.changed=e.changed||i,e.validationErrors=n;else if(e._def)n=p(e,e._def.defaults,e),e._def._creds&&(n=n.concat(p(e,e._def.credentials,e._def._creds))),e.valid=0===n.length,e.validationErrors=n;else if("subflow"==e.type){for(var r=RED.nodes.filterNodes({z:e.id}),d=0;d<r.length;d++)o=r[d].valid,i=r[d].changed,void 0===o&&(o=w(r[d]),i=r[d].changed),e.valid=e.valid&&o,e.changed=e.changed||i;for(var l=RED.nodes.filterNodes({type:"subflow:"+e.id}),c={},d=0;d<l.length;d++)l[d].valid=e.valid,l[d].changed=l[d].changed||e.changed,l[d].dirty=!0,c[l[d].z]=!0;Object.keys(c).forEach(function(e){e=RED.nodes.subflow(e);e&&w(e)})}return a===e.valid&&s===e.changed||(e.dirty=!0,(t=RED.nodes.subflow(e.z))&&w(t)),e.valid}function p(e,t,o){var n,i,a=[];for(n in t)t.hasOwnProperty(n)&&("string"==typeof(i=s(e,t,n,o[n]))?a.push(i):i||a.push(n));return a}function s(t,e,o,n){var i=!0;if(/^\$\([a-zA-Z_][a-zA-Z0-9_]*\)$/.test(n))return!0;if(/^\$\{[a-zA-Z_][a-zA-Z0-9_]*\}$/.test(n))return!0;var a=null;if("label"in e[o]&&"string"==typeof e[o].label&&(a=e[o].label),"required"in e[o]&&e[o].required&&!(i=""!==n)&&a)return RED._("validator.errors.missing-required-prop",{prop:a});if(i&&"validate"in e[o])try{var s={};if(a&&(s.label=a),i=e[o].validate.call(t,n,s),2===e[o].validate.length&&"string"==typeof i)return i;i=!!i}catch(e){return console.log("Validation error:",t.type,t.id,"property: "+o,"value:",n,e),RED._("validator.errors.validation-error",{prop:o,node:t.type,id:t.id,error:e.message})}if(i&&e[o].type&&RED.nodes.getType(e[o].type)&&!("validate"in e[o])){if(n&&"_ADD_"!=n){s=RED.nodes.node(n);if(s){if(null==s.valid||s.valid)return!0;if(a)return RED._("validator.errors.invalid-config",{prop:a})}else if(a)return RED._("validator.errors.missing-config",{prop:a});return!1}if(!(i=e[o].hasOwnProperty("required")&&!e[o].required)&&a)return RED._("validator.errors.missing-required-prop",{prop:a})}return i}function b(e,t){for(var o in e._def.defaults)e._def.defaults.hasOwnProperty(o)&&n(e,e._def.defaults,o,t);if(e._def.credentials)for(o in e._def.credentials)e._def.credentials.hasOwnProperty(o)&&n(e,e._def.credentials,o,t)}function n(e,t,o,n){var i,a,n=$("#"+n+"-"+o);0<n.length&&(i=n.val(),t[o].hasOwnProperty("format")&&""!==t[o].format&&"DIV"===n[0].nodeName&&(i=n.text()),"string"!=typeof(e=s(e,t,o,i))&&e?(n.removeClass("input-error"),(a=n.data("tooltip"))&&(n.data("tooltip",null),a.delete())):(n.addClass("input-error"),"string"==typeof e&&((a=n.data("tooltip"))?a.setContent(e):(a=RED.popover.tooltip(n,e),n.data("tooltip",a)))))}function f(t,o){t.resize=!0,t.dirty=!0,t.dirtyStatus=!0;var n=[];o&&RED.nodes.eachLink(function(e){e.source===t&&o.hasOwnProperty(e.sourcePort)&&("-1"===o[e.sourcePort]?n.push(e):e.sourcePort=o[e.sourcePort])}),t.hasOwnProperty("__outputs")&&(t.outputs<t.__outputs&&RED.nodes.eachLink(function(e){e.source===t&&e.sourcePort>=t.outputs&&-1===n.indexOf(e)&&n.push(e)}),delete t.__outputs),t.inputs=Math.min(1,Math.max(0,parseInt(t.inputs))),isNaN(t.inputs)&&(t.inputs=0),0===t.inputs&&(n=n.concat(RED.nodes.filterLinks({target:t})));for(var e=0;e<n.length;e++)RED.nodes.removeLink(n[e]);return n}function y(e,t,o,n){o=$("#"+o+"-"+t);0!==o.length&&("checkbox"===o.attr("type")?o.prop("checked",e[t]):(null==(e=e[t])&&(e=""),void 0!==n&&n[t].hasOwnProperty("format")&&""!==n[t].format&&"DIV"===o[0].nodeName?(o.html(RED.text.format.getHtml(e,n[t].format,{},!1,"en")),RED.text.format.attach(o[0],n[t].format,{},!1,"en")):(o.val(e),"INPUT"!==o[0].nodeName&&"TEXTAREA"!==o[0].nodeName||RED.text.bidi.prepareInput(o))))}function E(t,e,o,n){$("#"+n+"-"+o).on("change keyup paste",function(e){$(this).attr("skipValidation")||b(t,n)})}function D(e,t,o,n){for(var i in t)t.hasOwnProperty(i)&&("password"==t[i].type?o[i]?$("#"+n+"-"+i).val(o[i]):o["has_"+i]?$("#"+n+"-"+i).val("__PWRD__"):$("#"+n+"-"+i).val(""):y(o,i,n,t),E(e,0,i,n))}function R(d,l,c,u,p,f,h){function t(){var e,t,o,n,i=$("<ul></ul>").appendTo(d),a=$("<div></div>").appendTo(d),s=RED.tabs.create({element:i,onchange:function(e){a.children().hide(),e.content.show(),e.onchange&&e.onchange.call(e),g&&RED.tray.resize()},collapsible:!0,menu:!1}),r=[];for(e in l=l.slice(),v)v.hasOwnProperty(e)&&v[e](c)&&l.push(e);for(o in l.forEach(function(t){try{var e,o,n=m[t];n?("function"==typeof n&&(n=n.call(n,c)),e=$("<div>",{class:"red-ui-tray-content"}).appendTo(a).hide(),n.create.call(n,e),o={id:t,label:n.label,name:n.name,iconClass:n.iconClass,content:e,onchange:function(){n.show&&n.show.call(n)}},s.addTab(o),r.push(n)):console.warn("Unregisted edit pane:",t)}catch(e){console.log(t,e)}}),u.defaults)u.defaults.hasOwnProperty(o)&&(u.defaults[o].type?u.defaults[o]._type.array||((t=RED.nodes.getType(u.defaults[o].type))&&"config"===t.category?t.exclusive?function(t,o,n,i){var a=$("#"+i+"-"+o),e=(a.val(t[o]),a.attr("type","hidden"),$("<a>",{id:i+"-edit-"+o,class:"red-ui-button"}));a.after(e),t[o]?e.text(RED._("editor.configEdit")):e.text(RED._("editor.configAdd")),e.on("click",function(e){k(o,n,a.val()||"_ADD_",i,t),e.preventDefault()})}(c,o,u.defaults[o].type,p):function(t,o,n,i,e){var a,s,r,d=$("#"+i+"-"+o);0!==d.length&&(r=d.width(),a=d.attr("style"),r=null!==(a=/(^|\s|;)width\s*:\s*([^;]+)/i.exec(a))?a[2].trim():"70%",a=$("<div></div>").css({width:r,display:"inline-flex"}),s=$('<select id="'+i+"-"+o+'"></select>').appendTo(a),d.replaceWith(a),s.css({"flex-grow":1}),_(o,n,t[o],i,e),$('<a id="'+i+"-lookup-"+o+'" class="red-ui-button"><i class="fa fa-pencil"></i></a>').css({"margin-left":"10px"}).appendTo(a),$("#"+i+"-lookup-"+o).on("click",function(e){k(o,n,s.find(":selected").val(),i,t),e.preventDefault()}),r="",e=RED.nodes.node(t[o]),RED.nodes.getType(n),e&&(r=RED.utils.getNodeLabel(e,e.id)),d.val(r))}(c,o,u.defaults[o].type,p,u.defaults[o].filter):(console.log("Unknown type:",u.defaults[o].type),y(c,o,p,u.defaults))):y(c,o,p,u.defaults),E(c,u.defaults,o,p));if(/^subflow:/.test(u.type)||D(c,u.credentials,c.credentials,p),u.oneditprepare)try{u.oneditprepare.call(c)}catch(e){console.log("oneditprepare",c.id,c.type,e.toString()),console.log(e.stack)}for(o in u.defaults)u.defaults.hasOwnProperty(o)&&((n=$("#"+p+"-"+o)).attr("skipValidation",!0),void 0!==n.data("noderedTypedInput")?n.trigger("change",[n.typedInput("type"),n.typedInput("value")]):n.trigger("change"),n.removeAttr("skipValidation"));if(u.credentials)for(o in u.credentials)u.credentials.hasOwnProperty(o)&&((n=$("#"+p+"-"+o)).attr("skipValidation",!0),void 0!==n.data("noderedTypedInput")?n.trigger("change",[n.typedInput("type"),n.typedInput("value")]):n.trigger("change"),n.removeAttr("skipValidation"));b(c,p),g=!0,f&&s.activateTab(f),h&&h(r)}var e,o,n,i,a,g=!1;u.credentials||/^subflow:/.test(u.type)||"group"===c.type||"tab"===c.type?c.credentials?(D(c,u.credentials,c.credentials,p),t()):(e=c.type,/^subflow:/.test(e)&&(e="subflow"),e=e,o=c.id,n=function(e){e&&(c.credentials=e,c.credentials._=$.extend(!0,{},e)),t()},a=setTimeout(function(){i=RED.notify($('<p data-i18n="[prepend]editor.loadCredentials"> <img src="red/images/spin.svg"/></p>').i18n(),{fixed:!0})},800),e="credentials/"+e.replace(/\s+/g,"-")+"/"+o,$.ajax({url:e,dataType:"json",success:function(e){i&&(i.close(),i=null),clearTimeout(a),n(e)},error:function(e,t,o){i&&(i.close(),i=null),clearTimeout(a),RED.notify(RED._("editor.errors.credentialLoadFailed"),"error"),n(null)},timeout:3e4})):t()}function x(){for(var e=l.length-1;e<l.length;e++){var t=l[e];if(n=t.type,"group"===t.type)n=RED._("group.editGroup",{name:RED.utils.sanitize(t.name||t.id)});else if("_expression"===t.type)n=RED._("expressionEditor.title");else if("_js"===t.type)n=RED._("jsEditor.title");else if("_text"===t.type)n=RED._("textEditor.title");else if("_json"===t.type)n=RED._("jsonEditor.title");else if("_markdown"===t.type)n=RED._("markdownEditor.title");else if("_buffer"===t.type)n=RED._("bufferEditor.title");else if("subflow"===t.type)n=RED._("subflow.editSubflow",{name:RED.utils.sanitize(t.name)});else if(0===t.type.indexOf("subflow:"))var o=RED.nodes.subflow(t.type.substring(8)),n=RED._("subflow.editSubflowInstance",{name:RED.utils.sanitize(o.name)});else if(void 0!==t._def){if(void 0!==t._def.paletteLabel)try{n=RED.utils.sanitize(("function"==typeof t._def.paletteLabel?t._def.paletteLabel.call(t._def):t._def.paletteLabel)||"")}catch(e){console.log("Definition error: "+t.type+".paletteLabel",e)}e===l.length-1&&(n=RED.nodes.node(t.id)?RED._("editor.editNode",{type:RED.utils.sanitize(n)}):RED._("editor.addNewConfig",{type:RED.utils.sanitize(n)}))}}return n}function h(t,e){if(t._def.oneditsave){var o={};for(var n in t._def.defaults)t._def.defaults.hasOwnProperty(n)&&("string"==typeof t[n]||"number"==typeof t[n]?o[n]=t[n]:o[n]=$.extend(!0,{},{v:t[n]}).v);try{!0===t._def.oneditsave.call(t)&&(e.changed=!0)}catch(e){console.warn("oneditsave",t.id,t.type,e.toString())}for(n in t._def.defaults)t._def.defaults.hasOwnProperty(n)&&(null===o[n]||"string"==typeof o[n]||"number"==typeof o[n]?o[n]!==t[n]&&(e.changes[n]=o[n],e.changed=!0):"group"===t.type&&"nodes"===n||JSON.stringify(o[n])!==JSON.stringify(t[n])&&(e.changes[n]=o[n],e.changed=!0))}}function g(e,t){return e.__label__<t.__label__?-1:e.__label__>t.__label__?1:0}function _(e,o,t,n,i){if(n){var a=$("#"+n+"-edit-"+e);if(a.length)t?a.text(RED._("editor.configEdit")):a.text(RED._("editor.configAdd")),$("#"+n+"-"+e).val(t);else{var s=$("#"+n+"-"+e),a=RED.nodes.getType(o);s.children().remove();var r=(r=RED.nodes.workspace(RED.workspaces.active()))||RED.nodes.subflow(RED.workspaces.active()),d=[],n=("function"!=typeof i&&(i=null),RED.nodes.eachConfig(function(e){var t;e.type!=o||e.z&&e.z!==r.id||i&&!i.call(null,e)||(t=RED.utils.getNodeLabel(e,e.id),e.__label__=t+(e.d?" ["+RED._("workspace.disabled")+"]":""),d.push(e))}),g);"function"==typeof a.sort&&(n=a.sort);try{d.sort(n)}catch(e){console.log("Definition error: "+a.type+".sort",e)}d.forEach(function(e){$('<option value="'+e.id+'"'+(t==e.id?" selected":"")+"></option>").text(RED.text.bidi.enforceTextDirectionWithUCC(e.__label__)).appendTo(s),delete e.__label__});e=o;if(void 0!==a.paletteLabel)try{e=RED.utils.sanitize(("function"==typeof a.paletteLabel?a.paletteLabel.call(a):a.paletteLabel)||o)}catch(e){console.log("Definition error: "+o+".paletteLabel",e)}s.append('<option value="_ADD_"'+(""===t?" selected":"")+">"+RED._("editor.addNewType",{type:e})+"</option>"),window.setTimeout(function(){s.trigger("change")},50)}}}function k(f,h,e,g,m){if(!c){c=!0;var v="_ADD_"==e,r=RED.nodes.getType(h),b=RED.nodes.node(e),y=[],e="",t=RED.nodes.subflow(RED.workspaces.active());if(t&&(e=t.id),null==b){for(var o in b={id:RED.nodes.id(),_def:r,type:h,z:e,users:[]},r.defaults)r.defaults[o].value&&(b[o]=JSON.parse(JSON.stringify(r.defaults[o].value)));b._=r._}l.push(b),RED.view.state(RED.state.EDITING);t={title:x(),resize:function(e){$(".red-ui-tray-content").height(e.height-50);var e=$("#node-config-dialog-edit-form"),t={width:e.width(),height:e.height()};y.forEach(function(e){e.resize&&e.resize.call(e,t)})},open:function(e,i){e.find(".red-ui-tray-header");var a=e.find(".red-ui-tray-body"),s=e.find(".red-ui-tray-footer"),e=$('<div class="red-ui-tray-footer-left"></div>').appendTo(s),e=($('<input id="node-config-input-node-disabled" type="checkbox">').prop("checked",!!b.d).appendTo(e).toggleButton({enabledIcon:"fa-circle-thin",disabledIcon:"fa-ban",invertState:!0}),!1!==r.hasUsers&&$('<span><i class="fa fa-info-circle"></i> <span id="red-ui-editor-config-user-count"></span></span>').css("margin-left","10px").appendTo(e),s.append('<span class="red-ui-tray-footer-right"><span id="red-ui-editor-config-scope-warning" data-i18n="[title]editor.errors.scopeChange"><i class="fa fa-warning"></i></span><select id="red-ui-editor-config-scope"></select></span>'),["editor-tab-properties"]);b._def.defaults&&b._def.defaults.hasOwnProperty("info")||e.push("editor-tab-description"),R(a,e,b,r,"node-config-input",null,function(e){y=e,b._def.exclusive?$("#red-ui-editor-config-scope").hide():$("#red-ui-editor-config-scope").show(),$("#red-ui-editor-config-scope-warning").hide();var o={},t=(b.users.forEach(function(e){o[e.z]=!0}),Object.keys(o).length),n=$("#red-ui-editor-config-scope").empty();n.off("change"),n.append('<option value=""'+(b.z?"":" selected")+' data-i18n="sidebar.config.global"></option>'),n.append('<option disabled data-i18n="sidebar.config.flows"></option>'),RED.nodes.eachWorkspace(function(e){var t=e.label;o[e.id]&&(t="* "+t),$('<option value="'+e.id+'"'+(e.id==b.z?" selected":"")+"></option>").text(t).appendTo(n)}),n.append('<option disabled data-i18n="sidebar.config.subflows"></option>'),RED.nodes.eachSubflow(function(e){var t=e.name;o[e.id]&&(t="* "+t),$('<option value="'+e.id+'"'+(e.id==b.z?" selected":"")+"></option>").text(t).appendTo(n)}),0<t&&n.on("change",function(){var e=$(this).val();""!==e&&(!o[e]||1<t)?$("#red-ui-editor-config-scope-warning").show():$("#red-ui-editor-config-scope-warning").hide()}),!1!==r.hasUsers&&$("#red-ui-editor-config-user-count").text(RED._("editor.nodesUse",{count:b.users.length})).parent().show(),a.i18n(),s.i18n(),c=!1,i()})},close:function(){RED.workspaces.refresh(),y.forEach(function(e){e.close&&e.close.call(e)}),l.pop()},show:function(){b&&(RED.sidebar.info.refresh(b),RED.sidebar.help.show(h,!1))}};t.buttons=[{id:"node-config-dialog-cancel",text:RED._("common.label.cancel"),click:function(){var t=h,o=b.id,e=RED.nodes.getType(t);if(e.oneditcancel&&e.oneditcancel){var n=RED.nodes.node(o);if(n)try{e.oneditcancel.call(n,!1)}catch(e){console.log("oneditcancel",n.id,n.type,e.toString())}else try{e.oneditcancel.call({id:o},!0)}catch(e){console.log("oneditcancel",o,t,e.toString())}}RED.tray.close()}},{id:"node-config-dialog-ok",text:v?RED._("editor.configAdd"):RED._("editor.configUpdate"),class:"primary",click:function(){var e,t,o,n,i={changes:{},changed:!1,outputMap:null},a=f,s=(b.id,h),r=v,d=RED.nodes.getType(s);if(d.oneditsave)try{d.oneditsave.call(b)}catch(e){console.warn("oneditsave",b.id,b.type,e.toString())}for(e in d.defaults)!d.defaults.hasOwnProperty(e)||null!=(n="checkbox"===(n=$("#node-config-input-"+e)).attr("type")?n.prop("checked"):"format"in d.defaults[e]&&""!==d.defaults[e].format&&"DIV"===n[0].nodeName?n.text():n.val())&&n!==b[e]&&(b._def.defaults[e].type&&("_ADD_"==n&&(n=""),(t=RED.nodes.node(b[e]))&&((o=t.users).splice(o.indexOf(b),1),RED.events.emit("nodes:change",t)),(t=RED.nodes.node(n))&&(t.users.push(b),RED.events.emit("nodes:change",t))),b[e]=n);y.forEach(function(e){e.apply&&e.apply.call(e,i)}),b.label=d.label;for(var l=$("#red-ui-editor-config-scope").val(),c=(b.z=l,$("#node-config-input-node-disabled").prop("checked")?!0!==b.d&&(b.d=!0):!0===b.d&&delete b.d,l&&(b.users=b.users.filter(function(e){var t,o=!0;for(t in e._def.defaults)e._def.defaults.hasOwnProperty(t)&&e._def.defaults[t].type===b.type&&e[t]===b.id&&e.z!==l&&(o=!1,e[t]=null,e.dirty=!0,e.changed=!0,w(e));return o})),r&&RED.nodes.add(b),w(b),{}),u=(c[b.id]=!0,b.users.slice());0<u.length;){var p=u.pop();c[p.id]||(c[p.id]=!0,p.users&&(u=u.concat(p.users)),w(p))}RED.nodes.dirty(!0),RED.view.redraw(!0),r||(RED.events.emit("editor:save",b),RED.events.emit("nodes:change",b)),RED.tray.close(function(){var e=null;m&&"function"==typeof m._def.defaults[a].filter&&(e=function(e){return m._def.defaults[a].filter.call(m,e)}),_(a,s,b.id,g,e)})}}],v||t.buttons.unshift({class:"leftButton",text:RED._("editor.configDelete"),click:function(){var t=f,e=b.id,o=h,n=RED.nodes.getType(o);try{n.ondelete&&(console.log("Deprecated API warning: config node type ",o," has an ondelete function - should be oneditdelete"),n.ondelete.call(b)),n.oneditdelete&&n.oneditdelete.call(b)}catch(e){console.log("oneditdelete",b.id,b.type,e.toString())}for(var i={t:"delete",nodes:[b],changes:{},dirty:RED.nodes.dirty()},a=0;a<b.users.length;a++){var s,r=b.users[a];for(s in i.changes[r.id]={changed:r.changed,valid:r.valid},r._def.defaults)r._def.defaults.hasOwnProperty(s)&&r[s]==e&&(i.changes[r.id][s]=e,r[s]="",r.changed=!0,r.dirty=!0);w(r)}RED.nodes.remove(e),RED.nodes.dirty(!0),RED.view.redraw(!0),RED.history.push(i),RED.tray.close(function(){var e=null;m&&"function"==typeof m._def.defaults[t].filter&&(e=function(e){return m._def.defaults[t].filter.call(m,e)}),_(t,o,"",g,e)})}}),RED.tray.show(t)}}function t(e,t){o.hasOwnProperty(e)?(0<l.length&&(t.parent=l[l.length-1].id),l.push({type:e}),t.title=t.title||x(),t.onclose=function(){l.pop()},o[e].show(t)):console.log("Unknown type editor:",e)}return{init:function(){window.ace&&window.ace.config.set("basePath","vendor/ace"),RED.tray.init(),RED.actions.add("core:confirm-edit-tray",function(){$(document.activeElement).blur(),$("#node-dialog-ok").trigger("click"),$("#node-config-dialog-ok").trigger("click")}),RED.actions.add("core:cancel-edit-tray",function(){$(document.activeElement).blur(),$("#node-dialog-cancel").trigger("click"),$("#node-config-dialog-cancel").trigger("click")}),RED.editor.codeEditor.init()},generateViewStateId:function(o,n,i){try{const s="object"==typeof(n=n||{}).options?n.options:{};let t;if(!1===(t=n.hasOwnProperty("stateId")||s.hasOwnProperty("stateId")?n.stateId:t))return!1;if(!t){let e;var a=RED.view.selection();if("node"===o&&n.id)e=n.id;else{if(!a.nodes||!a.nodes.length)return!1;e=a.nodes[0].id}const r=[e],d=$(n.element||s.element);d.length&&(r.push(d.closest(".form-row").index()),r.push(d.index())),"typedInput"==o&&(r.push(d.closest("li").index()),!i&&n.propertyType&&(i=n.propertyType)),t=r.join("/")}return t&&i&&(t+="/"+i),t}catch(e){return!1}},edit:function(s,i){var r,a,e,d,o,t,n;c||(r=s,a=!(c=!0),e=!1,d=[],l.push(s),RED.view.state(RED.state.EDITING),o=s.type,"subflow:"==s.type.substring(0,8)&&(o="subflow"),t={title:x(),buttons:[{id:"node-dialog-delete",class:"leftButton",text:RED._("common.label.delete"),click:function(){var e=RED.nodes.dirty(),t=[],o=[],n=RED.nodes.remove(r.id),t=(t.push(r),{t:"delete",nodes:t=t.concat(n.nodes),links:o=o.concat(n.links),changes:{},dirty:e});RED.nodes.dirty(!0),RED.view.redraw(!0),RED.history.push(t),RED.tray.close()}},{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){if(r._def){if(r._def.oneditcancel)try{r._def.oneditcancel.call(r)}catch(e){console.log("oneditcancel",r.id,r.type,e.toString())}for(var e in r._def.defaults){var t;r._def.defaults.hasOwnProperty(e)&&(t=r._def.defaults[e]).type&&(t=RED.nodes.getType(t.type))&&t.exclusive&&(""===(t=$("#node-input-"+e).val()||"")||r[e]||RED.nodes.remove(t))}}RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){var e,t,o,n={changes:{},changed:!1,outputMap:null},i=RED.nodes.dirty(),a=(h(r,n),d.forEach(function(e){e.apply&&e.apply.call(e,n)}),f(r,n.outputMap));$("#node-input-node-disabled").prop("checked")?!0!==s.d&&(n.changes.d=s.d,n.changed=!0,s.d=!0):!0===s.d&&(n.changes.d=s.d,n.changed=!0,delete s.d),s.resize=!0,n.changed&&(e=r.changed,r.changed=!0,RED.nodes.dirty(!0),o=RED.nodes.subflow(RED.workspaces.active()),t=null,o&&(t=[],RED.nodes.eachNode(function(e){e.type=="subflow:"+RED.workspaces.active()&&(t.push({id:e.id,changed:e.changed}),e.changed=!0,e.dirty=!0,f(e))})),o={t:"edit",node:r,changes:n.changes,links:a,dirty:i,changed:e},n.outputMap&&(o.outputMap=n.outputMap),t&&(o.subflow={instances:t}),RED.history.push(o)),r.dirty=!0,w(r),RED.events.emit("editor:save",r),RED.events.emit("nodes:change",r),RED.tray.close()}}],resize:function(e){u[o]=e.width,$(".red-ui-tray-content").height(e.height-50);var e=$(".red-ui-tray-content form").height(e.height-50-40),t={width:e.width(),height:e.height()};d.forEach(function(e){e.resize&&e.resize.call(e,t)})},open:function(e,t){r.hasOwnProperty("outputs")&&(r.__outputs=r.outputs);var o=e.find(".red-ui-tray-footer"),n=e.find(".red-ui-tray-body"),e=(n.parent().css("overflow","hidden"),$('<div class="red-ui-tray-footer-left"></div>').appendTo(o)),e=($('<input id="node-input-node-disabled" type="checkbox">').prop("checked",!!s.d).appendTo(e).toggleButton({enabledIcon:"fa-circle-thin",disabledIcon:"fa-ban",invertState:!0}),["editor-tab-properties"]);/^subflow:/.test(s.type)&&e.push("editor-tab-envProperties"),s._def.defaults&&s._def.defaults.hasOwnProperty("info")||(e.push("editor-tab-description"),a=!0,s.infoEditor&&(s.infoEditor__orig=s.infoEditor,delete s.infoEditor,a=!1)),e.push("editor-tab-appearance"),R(n,e,s,s._def,"node-input",i,function(e){d=e,n.i18n(),o.i18n(),c=!1,t()})},close:function(){RED.view.state()!=RED.state.IMPORT_DRAGGING&&RED.view.state(RED.state.DEFAULT),r&&(r.infoEditor__orig&&(r.infoEditor=r.infoEditor__orig,delete r.infoEditor__orig),a&&delete r.infoEditor,e||RED.sidebar.info.refresh(r)),RED.workspaces.refresh(),d.forEach(function(e){e.close&&e.close.call(e)}),RED.view.redraw(!0),l.pop()},show:function(){r&&(RED.sidebar.info.refresh(r),RED.sidebar.help.show(r.type,!1),"BODY"===document.activeElement.tagName&&$("#red-ui-editor-stack").trigger("focus"))}},u.hasOwnProperty(o)&&(t.width=u[o]),"subflow"===o&&(n=r.type.substring(8),t.buttons.unshift({class:"leftButton",text:RED._("subflow.edit"),click:function(){RED.workspaces.show(n),e=!0,$("#node-dialog-ok").trigger("click")}})),RED.tray.show(t))},editConfig:k,editFlow:function(i,a){var s,e;c||(c=!0,s=[],RED.view.state(RED.state.EDITING),e={title:RED._("workspace.editFlow",{name:RED.utils.sanitize(i.label)}),buttons:[{id:"node-dialog-delete",class:"leftButton"+(1===RED.workspaces.count()?" disabled":""),text:RED._("common.label.delete"),click:function(){RED.workspaces.delete(i),RED.tray.close()}},{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){RED.tray.close()}},{id:"node-dialog-ok",class:"primary",text:RED._("common.label.done"),click:function(){var t={changes:{},changed:!1,outputMap:null},e=RED.nodes.dirty(),o=(s.forEach(function(e){e.apply&&e.apply.call(e,t)}),$("#node-input-disabled").prop("checked"));i.disabled!==o&&(t.changes.disabled=i.disabled,t.changed=!0,i.disabled=o,$("#red-ui-tab-"+i.id.replace(".","-")).toggleClass("red-ui-workspace-disabled",!!i.disabled),i.id===RED.workspaces.active()&&$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!i.disabled)),t.changed&&(o={t:"edit",changes:t.changes,node:i,dirty:e},i.changed=!0,RED.history.push(o),RED.nodes.dirty(!0),t.changes.hasOwnProperty("disabled")&&(RED.nodes.eachNode(function(e){e.z===i.id&&(e.dirty=!0)}),RED.view.redraw()),RED.workspaces.refresh(),RED.events.emit("flows:change",i)),RED.tray.close()}}],resize:function(e){$(".red-ui-tray-content").height(e.height-50);var e=$(".red-ui-tray-content form").height(e.height-50-40),t={width:e.width(),height:e.height()};s.forEach(function(e){e.resize&&e.resize.call(e,t)})},open:function(e,t){var o=e.find(".red-ui-tray-footer"),n=e.find(".red-ui-tray-body"),e=(n.parent().css("overflow","hidden"),$('<div class="red-ui-tray-footer-left"></div>').appendTo(o));i.hasOwnProperty("disabled")||(i.disabled=!1),$('<input id="node-input-disabled" type="checkbox">').prop("checked",i.disabled).appendTo(e).toggleButton({enabledIcon:"fa-circle-thin",disabledIcon:"fa-ban",invertState:!0}),R(n,["editor-tab-flow-properties","editor-tab-envProperties"],i,{},"node-input",a,function(e){s=e,n.i18n(),o.i18n(),c=!1,t()})},close:function(){RED.view.state()!=RED.state.IMPORT_DRAGGING&&RED.view.state(RED.state.DEFAULT),s.forEach(function(e){e.close&&e.close.call(e)});var e=RED.view.selection();e.nodes||e.links||i.id!==RED.workspaces.active()||RED.sidebar.info.refresh(i)}},RED.tray.show(e))},editSubflow:function(a,s){var r,d,e;c||(c=!0,r=a,d=[],l.push(a),RED.view.state(RED.state.EDITING),e={title:x(),buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){RED.tray.close()}},{id:"node-dialog-ok",class:"primary",text:RED._("common.label.done"),click:function(){var t,e,o={changes:{},changed:!1,outputMap:null},n=RED.nodes.dirty(),i=(d.forEach(function(e){e.apply&&e.apply.call(e,o)}),$("#subflow-input-name").val()),i=(i!=r.name&&(o.changes.name=r.name,r.name=i,o.changed=!0),r.env),a=RED.subflow.exportSubflowTemplateEnv($("#node-input-env-container").editableList("items"));a&&0<a.length&&a.forEach(function(e){"cred"===e.type&&(r.credentials=r.credentials||{_:{}},r.credentials[e.name]=e.value,r.credentials["has_"+e.name]=""!==e.value,"__PWRD__"!==e.value&&(o.changed=!0),delete e.value)}),e=a,JSON.stringify(i)!==JSON.stringify(e)&&(r.env=a,o.changes.env=r.env,o.changed=!0),o.changed&&(i=r.changed,r.changed=!0,w(r),t=[],RED.nodes.eachNode(function(e){e.type=="subflow:"+r.id&&(t.push({id:e.id,changed:e.changed}),e._def.color=r.color,e.changed=!0,e.dirty=!0,f(e),w(e))}),RED.events.emit("subflows:change",r),RED.nodes.dirty(!0),e={t:"edit",node:r,changes:o.changes,dirty:n,changed:i,subflow:{instances:t}},RED.history.push(e)),r.dirty=!0,RED.tray.close()}}],resize:function(e){$(".red-ui-tray-content").height(e.height-50);var e=$(".red-ui-tray-content form").height(e.height-50-40),t={width:e.width(),height:e.height()};d.forEach(function(e){e.resize&&e.resize.call(e,t)})},open:function(e,t){var o=e.find(".red-ui-tray-footer"),n=$("<div/>",{class:"red-ui-tray-footer-left"}).appendTo(o),i=e.find(".red-ui-tray-body");i.parent().css("overflow","hidden"),$('<span style="margin-left: 10px"><i class="fa fa-info-circle"></i> <i id="red-ui-editor-subflow-user-count"></i></span>').appendTo(n),r&&RED.sidebar.info.refresh(r);R(i,["editor-tab-properties","editor-tab-subflow-module","editor-tab-description","editor-tab-appearance"],a,a._def,"node-input",s,function(e){d=e,$("#subflow-input-name").val(a.name),RED.text.bidi.prepareInput($("#subflow-input-name")),i.i18n(),o.i18n(),c=!1,t()})},close:function(){RED.view.state()!=RED.state.IMPORT_DRAGGING&&RED.view.state(RED.state.DEFAULT),RED.sidebar.info.refresh(r),RED.workspaces.refresh(),d.forEach(function(e){e.close&&e.close.call(e)}),l.pop(),r=null},show:function(){}},RED.tray.show(e))},editGroup:function(i,a){var n,s,e;c||(c=!0,n=i,l.push(i),RED.view.state(RED.state.EDITING),s=[],e={title:x(),buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){RED.tray.close()}},{id:"node-dialog-ok",class:"primary",text:RED._("common.label.done"),click:function(){var e,t={changes:{},changed:!1,outputMap:null},o=RED.nodes.dirty();h(n,t),s.forEach(function(e){e.apply&&e.apply.call(e,t)}),t.changed&&(e=n.changed,n.changed=!0,RED.nodes.dirty(!0),o={t:"edit",node:n,changes:t.changes,dirty:o,changed:e},RED.history.push(o),RED.events.emit("groups:change",n)),n.dirty=!0,RED.tray.close(),RED.view.redraw(!0)}}],resize:function(e){u.group=e.width,$(".red-ui-tray-content").height(e.height-50);var e=$(".red-ui-tray-content form").height(e.height-50-40),t={width:e.width(),height:e.height()};s.forEach(function(e){e.resize&&e.resize.call(e,t)})},open:function(e,t){var o=e.find(".red-ui-tray-footer"),n=($("<div/>",{class:"red-ui-tray-footer-left"}).appendTo(o),e.find(".red-ui-tray-body"));n.parent().css("overflow","hidden");R(n,["editor-tab-properties","editor-tab-envProperties","editor-tab-description"],i,i._def,"node-input",a,function(e){s=e,n.i18n(),c=!1,t()})},close:function(){RED.view.state()!=RED.state.IMPORT_DRAGGING&&RED.view.state(RED.state.DEFAULT),RED.sidebar.info.refresh(n),s.forEach(function(e){e.close&&e.close.call(e)}),l.pop(),n=null},show:function(){}},u.hasOwnProperty("group")&&(e.width=u.group),RED.tray.show(e))},editJavaScript:function(e){t("_js",e)},editExpression:function(e){t("_expression",e)},editJSON:function(e){t("_json",e)},editMarkdown:function(e){t("_markdown",e)},editText:function(e){"markdown"==e.mode?t("_markdown",e):t("_text",e)},editBuffer:function(e){t("_buffer",e)},buildEditForm:function(e,t,o,a,n){return(t=$('<form id="'+t+'" class="form-horizontal" autocomplete="off"></form>').appendTo(e)).html($("script[data-template-name='"+o+"']").html()),a=a||"node-red",t.find("[data-i18n]").each(function(){for(var e=$(this).attr("data-i18n").split(";"),t=0;t<e.length;t++){var o,n,i=e[t];-1===i.indexOf(":")&&(n="",0===i.indexOf("[")&&(n=(o=i.split("]"))[0]+"]",i=o[1]),e[t]=n+a+":"+i)}$(this).attr("data-i18n",e.join(";"))}),$('<span style="position: absolute; top: -2000px;"><input id="red-ui-trap-password" type="password"/></span>').prependTo(t),$('<span style="position: absolute; top: -2000px;"><input id="red-ui-trap-username" type="text"/></span>').prependTo(t),$('<span style="position: absolute; top: -2000px;"><input id="red-ui-trap-user" type="text"/></span>').prependTo(t),t.on("submit",function(e){e.preventDefault()}),t.find("input").attr("autocomplete","off"),t},validateNode:w,updateNodeProperties:f,showIconPicker:function(){RED.editor.iconPicker.show.apply(null,arguments)},showTypeEditor:t,registerTypeEditor:function(e,t){o[e]=t},createEditor:function(e){return RED.editor.codeEditor.create(e)},get customEditTypes(){return o},registerEditPane:function(e,t,o){o&&(v[e]=o),m[e]=t}}}(),function(){function w(e,t,o,n){var i,a=$("<div>",{class:"red-ui-editor-node-label-form-row"});return void 0===e?($("<span>").text(RED._("editor.noDefaultLabel")).appendTo(a),a.addClass("red-ui-editor-node-label-form-none")):(a.addClass(""),e="red-ui-editor-node-label-form-"+e+"-"+t,$("<label>",{for:e}).text(t+1+".").appendTo(a),i=$("<input>",{type:"text",id:e,placeholder:n}).val(o).appendTo(a),$('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-times"></i></button>').appendTo(a).on("click",function(e){e.preventDefault(),i.val("")})),a}RED.editor.registerEditPane("editor-tab-appearance",function(y){return{label:RED._("editor-tab.appearance"),name:RED._("editor-tab.appearance"),iconClass:"fa fa-object-group",create:function(e){this.content=e;var t,o,n,i,a,s,r,d,e=this.content,l=y,e=$('<form class="dialog-form form-horizontal" autocomplete="off"></form>').appendTo(e),c=("subflow"===l.type&&(n=$("<div/>",{class:"form-row"}).appendTo(e),$("<label/>",{for:"subflow-appearance-input-category","data-i18n":"editor:subflow.category"}).appendTo(n),o=$("<select/>",{id:"subflow-appearance-input-category"}).css({width:"250px"}).appendTo(n),$("<input/>",{type:"text",id:"subflow-appearance-input-custom-category"}).css({display:"none","margin-left":"10px",width:"calc(100% - 250px)"}).appendTo(n),(n=RED.palette.getCategories()).sort(function(e,t){return e.label.localeCompare(t.label)}),n.forEach(function(e){o.append($("<option/>").val(e.id).text(e.label))}),o.append($("<option/>").attr("disabled",!0).text("---")),o.append($("<option/>").val("_custom_").text(RED._("palette.addCategory"))),$("#subflow-appearance-input-category").on("change",function(){"_custom_"===$(this).val()?($("#subflow-appearance-input-category").width(120),$("#subflow-appearance-input-custom-category").show()):($("#subflow-appearance-input-category").width(250),$("#subflow-appearance-input-custom-category").hide())}),$("#subflow-appearance-input-category").val(l.category||"subflows"),l.id,$("#red-ui-editor-subflow-user-count").text(RED._("subflow.subflowInstances",{count:l.instances.length})).show()),$('<div class="form-row"><label for="node-input-show-label-btn" data-i18n="editor.label"></label><span style="margin-right: 2px;"/><input type="checkbox" id="node-input-show-label"/></div>').appendTo(e),$("#node-input-show-label").toggleButton({enabledLabel:RED._("editor.show"),disabledLabel:RED._("editor.hide")}),l.hasOwnProperty("l")||(l.l=!l._def.hasOwnProperty("showLabel")||l._def.showLabel),$("#node-input-show-label").prop("checked",l.l).trigger("change"),"subflow"===l.type&&(n=l.color||"#DDAA99",v=$("<div/>",{class:"form-row"}).appendTo(e),$("<label/>").text(RED._("editor.color")).appendTo(v),RED.editor.colorPicker.create({id:"red-ui-editor-node-color",value:n,defaultValue:"#DDAA99",palette:["#DDAA99","#3FADB5","#87A980","#A6BBCF","#AAAA66","#C0C0C0","#C0DEED","#C7E9C0","#D7D7A0","#D8BFD8","#DAC4B4","#DEB887","#DEBD5C","#E2D96E","#E6E0F8","#E7E7AE","#E9967A","#F3B567","#FDD0A2","#FDF0C2","#FFAAAA","#FFCC66","#FFF0F0","#FFFFFF"],sortPalette:function(e,t){return e.l-t.l}}).appendTo(v),$("#red-ui-editor-node-color").on("change",function(e){var t=$(this).val(),o=(a.css("backgroundColor",t),RED.utils.getDarkerColor(t));o!==t&&a.css("border-color",o)})),l._def.defaults&&l._def.defaults.hasOwnProperty("icon")||(n=$('<div class="form-row"></div>').appendTo(e),$('<label data-i18n="editor.settingIcon">').appendTo(n),i=$('<button type="button" class="red-ui-button red-ui-editor-node-appearance-button">').appendTo(n),$('<i class="fa fa-caret-down"></i>').appendTo(i),a=$("<div>",{class:"red-ui-search-result-node"}).appendTo(i),v=RED.utils.getNodeColor(l.type,l._def),s=RED.utils.getNodeIcon(l._def,l),a.css("backgroundColor",v),(r=RED.utils.getDarkerColor(v))!==v&&a.css("border-color",r),d=$("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(a),RED.utils.createIconElement(s,d,!0),i.on("click",function(e){e.preventDefault();var e=$("#red-ui-editor-node-icon").val()||"",e=e?RED.utils.separateIconPath(e):RED.utils.getDefaultNodeIcon(l._def,l),t=RED.utils.getNodeColor(l.type,l._def);"subflow"===l.type&&(t=$("#red-ui-editor-node-color").val()),RED.editor.iconPicker.show(i,t,e,!1,function(e){$("#red-ui-editor-node-icon").val(e||"");e=RED.utils.getNodeIcon(l._def,{type:l.type,icon:e});RED.utils.createIconElement(e,d,!0)})}),RED.popover.tooltip(i,function(){return $("#red-ui-editor-node-icon").val()||RED._("editor.default")}),$('<input type="hidden" id="red-ui-editor-node-icon">').val(l.icon).appendTo(n)),$('<div class="form-row"><span data-i18n="editor.portLabels"></span></div>').appendTo(e),l.inputs||l._def.inputs||0),u=l.outputs||l._def.outputs||0,p=("subflow"===l.type&&(c=l.in.length,u=l.out.length),l.inputLabels||[]),f=l.outputLabels||[],h=l._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel"),g=l._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel"),m=($('<div class="form-row"><span style="margin-left: 50px;" data-i18n="editor.labelInputs"></span><div id="red-ui-editor-node-label-form-inputs"></div></div>').appendTo(e),$("#red-ui-editor-node-label-form-inputs"));if(0<c)for(t=0;t<c;t++)w("input",t,p[t],h).appendTo(m);else w().appendTo(m);$('<div class="form-row"><span style="margin-left: 50px;" data-i18n="editor.labelOutputs"></span><div id="red-ui-editor-node-label-form-outputs"></div></div>').appendTo(e);var v,b=$("#red-ui-editor-node-label-form-outputs");if(0<u)for(t=0;t<u;t++)w("output",t,f[t],g).appendTo(b);else w().appendTo(b);"subflow"===y.type?this.defaultIcon="node-red/subflow.svg":(v=RED.utils.getDefaultNodeIcon(y._def,y),this.defaultIcon=v.module+"/"+v.file,y.icon&&y.icon!==this.defaultIcon?this.isDefaultIcon=!1:this.isDefaultIcon=!0)},resize:function(e){},close:function(){},show:function(){this.content;var e,t=y,o=t._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel"),n=t._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel"),i=$("#red-ui-editor-node-label-form-inputs"),a=$("#red-ui-editor-node-label-form-outputs"),s=$("#node-input-inputs").val();void 0===s?e="subflow"===t.type?t.in.length:t.inputs||t._def.inputs||0:(e=Math.min(1,Math.max(0,parseInt(s))),isNaN(e)&&(e=0));var r,d,l,c,u=i.children(),p=u.length;if(1===p&&$(u[0]).hasClass("red-ui-editor-node-label-form-none")&&p--,p<e)for(0===p&&$(u[0]).remove(),d=p;d<e;d++)w("input",d,"",o).appendTo(i);else if(e<p){for(d=e;d<p;d++)$(u[d]).remove();0===e&&w().appendTo(i)}if(void 0===(s=$("#node-input-outputs").val())?"subflow"===t.type?r=t.out.length:e=t.outputs||t._def.outputs||0:isNaN(s)?(l=JSON.parse(s),t=Object.keys(l),u=a.children(),1===(p=u.length)&&$(u[0]).hasClass("red-ui-editor-node-label-form-none")&&p--,r=0,c=[],t.forEach(function(e){var t=$("#red-ui-editor-node-label-form-output-"+e).parent();0===t.length&&-1!==l[e]?(0===p&&($(u[0]).remove(),p=-1),t=w("output",e,"",n)):t.detach(),-1!==l[e]&&(r++,c.push({i:parseInt(l[e]),r:t}))}),c.sort(function(e,t){return e.i-t.i}),c.forEach(function(e,t){e.r.find("label").text(t+1+"."),e.r.appendTo(a)}),0===c.length&&w("output",d,"").appendTo(a)):r=Math.max(0,parseInt(s)),u=a.children(),1===(p=u.length)&&$(u[0]).hasClass("red-ui-editor-node-label-form-none")&&p--,p<r)for(0===p&&$(u[0]).remove(),d=p;d<r;d++)w("output",d,"").appendTo(a);else if(r<p){for(d=r;d<p;d++)$(u[d]).remove();0===r&&w().appendTo(a)}},apply:function(e){!function(o,e,n){var t=$("#red-ui-editor-node-label-form-inputs").children().find("input"),i=$("#red-ui-editor-node-label-form-outputs").children().find("input"),a=!1,s=!1,r=t.map(function(){var e=$(this).val();return a=a||""!==e,e}).toArray().slice(0,o.inputs);(void 0===o.inputLabels&&a||void 0!==o.inputLabels&&JSON.stringify(r)!==JSON.stringify(o.inputLabels))&&(e.inputLabels=o.inputLabels,o.inputLabels=r,s=!0);a=!1,r=new Array(o.outputs),i.each(function(){var e,t=$(this).attr("id").substring("red-ui-editor-node-label-form-output-".length);n&&n.hasOwnProperty(t)&&-1===(t=parseInt(n[t]))||(e=$(this).val(),a=a||""!==e,"subflow"!==o.type||o.outputLabels&&o.outputLabels[t]===e||(o.out[t].dirty=!0),r[t]=e)}),(void 0===o.outputLabels&&a||void 0!==o.outputLabels&&JSON.stringify(r)!==JSON.stringify(o.outputLabels))&&(e.outputLabels=o.outputLabels,o.outputLabels=r,s=!0,"subflow"===o.type&&RED.view.redraw());return s}(y,e.changes,e.outputMap)||(e.changed=!0),y._def.defaults&&y._def.defaults.hasOwnProperty("icon")||(t=$("#red-ui-editor-node-icon").val()||"",this.isDefaultIcon?""!==t&&t!==this.defaultIcon?(e.changes.icon=y.icon,y.icon=t,e.changed=!0):(o=(o=RED.utils.getDefaultNodeIcon(y._def,y)).module+"/"+o.file,this.defaultIcon!==o&&(e.changes.icon=y.icon,y.icon=o,e.changed=!0)):(y.icon&&t!==y.icon||!y.icon&&""!==t)&&(e.changes.icon=y.icon,y.icon=t,e.changed=!0)),"subflow"===y.type&&((o="subflows"===(o="_custom_"===(o=$("#subflow-appearance-input-category").val().trim())&&""===(o=$("#subflow-appearance-input-custom-category").val().trim())?y.category:o)?"":o)!=y.category&&(e.changes.category=y.category,y.category=o,e.changed=!0),y.color!==(t=$("#red-ui-editor-node-color").val())&&(e.changes.color=y.color,y.color=t,e.changed=!0,RED.utils.clearNodeColorCache(),"subflow"===y.type&&(RED.nodes.getType("subflow:"+y.id).color=t)));var t,o=!y._def.hasOwnProperty("showLabel")||y._def.showLabel;$("#node-input-show-label").prop("checked")?o?(y.hasOwnProperty("l")&&!y.l&&(e.changes.l=y.l,e.changed=!0),delete y.l):(y.l||(e.changes.l=y.l,e.changed=!0),y.l=!0):o?(!1!==y.l&&(e.changes.l=y.l,e.changed=!0),y.l=!1):(y.hasOwnProperty("l")&&y.l&&(e.changes.l=y.l,e.changed=!0),delete y.l)}}})}(),RED.editor.registerEditPane("editor-tab-description",function(n){return{label:RED._("editor-tab.description"),name:RED._("editor-tab.description"),iconClass:"fa fa-file-text-o",create:function(e){var t,o;this.editor=(e=e,t=n,e=$('<form class="dialog-form form-horizontal" autocomplete="off"></form>').appendTo(e),$("<div></div>").appendTo(e),e=$('<div class="form-row node-text-editor-row" style="position:relative; padding-top: 4px; height: 100%"></div>').appendTo(e),o="node-info-input-info-editor-"+Math.floor(1e3*Math.random()),$('<div style="height: 100%" class="node-text-editor" id="'+o+'" ></div>').appendTo(e),e=RED.editor.createEditor({id:o,mode:"ace/mode/markdown",stateId:RED.editor.generateViewStateId("node",t,"nodeinfo"),value:t.info||""}),t.infoEditor=e)},resize:function(e){this.editor.resize()},close:function(){this.editor.destroy(),this.editor=null},show:function(){this.editor.focus()},apply:function(e){var t=n.info,o=this.editor.getValue();t?""===o.trim()?(e.changed=!0,e.changes.info=t,delete n.info):o!==t&&(e.changed=!0,e.changes.info=t,n.info=o):""!==o.trim()&&(e.changed=!0,e.changes.info=void 0,n.info=o)}}}),RED.editor.registerEditPane("editor-tab-envProperties",function(i){return{label:RED._("editor-tab.envProperties"),name:RED._("editor-tab.envProperties"),iconClass:"fa fa-list",create:function(e){e=$('<form class="dialog-form form-horizontal"></form>').appendTo(e),e=$('<div class="form-row node-input-env-container-row"></div>').appendTo(e);this.list=$("<ol></ol>").appendTo(e),RED.editor.envVarList.create(this.list,i)},resize:function(e){this.list.editableList("height",e.height)},close:function(){},apply:function(t){var e,o=i.env,n=[];/^subflow:/.test(i.type)&&(n=RED.subflow.exportSubflowInstanceEnv(i)),this.list.editableList("items").each(function(e,t){var t=t.data("data");t.nameField&&t.valueField&&""!==(t={name:t.nameField.val(),value:t.valueField.typedInput("value"),type:t.valueField.typedInput("type")}).name.trim()&&n.push(t)}),n&&0<n.length&&n.forEach(function(e){"cred"===e.type&&(i.credentials=i.credentials||{_:{}},i.credentials[e.name]=e.value,i.credentials["has_"+e.name]=""!==e.value,"__PWRD__"!==e.value&&(t.changed=!0),delete e.value)}),o||0!==n.length?(e=n,JSON.stringify(o)!==JSON.stringify(e)&&(t.changes.env=i.env,0===n.length?delete i.env:i.env=n,t.changed=!0)):delete i.env}}}),RED.editor.registerEditPane("editor-tab-flow-properties",function(o){return{label:RED._("editor-tab.properties"),name:RED._("editor-tab.properties"),iconClass:"fa fa-cog",create:function(e){e=$('<form id="dialog-form" class="form-horizontal"></form>').appendTo(e);$('<div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></div>').appendTo(e),$('<div class="form-row node-text-editor-row"><label for="node-input-info" data-i18n="editor:workspace.info" style="width:300px;"></label><div style="min-height:150px;" class="node-text-editor" id="node-input-info"></div></div>').appendTo(e);this.tabflowEditor=RED.editor.createEditor({id:"node-input-info",mode:"ace/mode/markdown",value:""}),$('<input type="text" style="display: none;" />').prependTo(e),e.on("submit",function(e){e.preventDefault()}),$("#node-input-name").val(o.label),RED.text.bidi.prepareInput($("#node-input-name")),this.tabflowEditor.getSession().setValue(o.info||"",-1)},resize:function(e){$("#node-input-info").css("height",e.height-70+"px"),this.tabflowEditor.resize()},close:function(){this.tabflowEditor.destroy()},apply:function(e){var t=$("#node-input-name").val(),t=(o.label!=t&&(e.changes.label=o.label,e.changed=!0,o.label=t),this.tabflowEditor.getValue());o.info!==t&&(e.changes.info=o.info,e.changed=!0,o.info=t),$("#red-ui-tab-"+o.id.replace(".","-")).toggleClass("red-ui-workspace-disabled",!!o.disabled),$("#red-ui-workspace").toggleClass("red-ui-workspace-disabled",!!o.disabled)}}}),RED.editor.registerEditPane("editor-tab-properties",function(d){return{label:RED._("editor-tab.properties"),name:RED._("editor-tab.properties"),iconClass:"fa fa-cog",create:function(e){var t,o=d.type,n=("subflow"===d.type?o="subflow-template":"subflow:"==d.type.substring(0,8)&&(o="subflow"),t="node-red"===d._def.set.module?"node-red":d._def.set.id,"dialog-form");this.inputClass="node-input","config"===d._def.category&&"group"!==o&&(this.inputClass="node-config-input",n="node-config-dialog-edit-form"),RED.editor.buildEditForm(e,n,o,t,d)},resize:function(e){if(d&&d._def.oneditresize)try{d._def.oneditresize.call(d,e)}catch(e){console.log("oneditresize",d.id,d.type,e.toString())}},close:function(){},apply:function(t){var e,o,n;if(d._def.defaults)for(o in d._def.defaults)if(d._def.defaults.hasOwnProperty(o)){var i,a,s,r=$("#"+this.inputClass+"-"+o);if("checkbox"===r.attr("type")?e=r.prop("checked"):"select"===r.prop("nodeName")&&"multiple"===r.attr("multiple")?null==(e=r.val())&&(e=[]):e="format"in d._def.defaults[o]&&""!==d._def.defaults[o].format&&"DIV"===r[0].nodeName?r.text():r.val(),null!=e){if("outputs"===o){if(""===e.trim())continue;isNaN(e)?(t.outputMap=JSON.parse(e),i=0,a=!1,Object.keys(t.outputMap).forEach(function(e){isNaN(e)?(i++,delete t.outputMap[e]):(t.outputMap[e]=t.outputMap[e]+"","-1"!==t.outputMap[e]?(i++,t.outputMap[e]!==e?a=!0:delete t.outputMap[e]):a=!0)}),e=i,a&&(t.changed=!0)):e=parseInt(e)}d._def.defaults[o].type&&"_ADD_"==e&&(e=""),!function(e,t){try{return e==t?1:JSON.stringify(e)===JSON.stringify(t)}catch(e){}}(d[o],e)&&(d._def.defaults[o].type&&((r=RED.nodes.node(d[o]))&&((s=r.users).splice(s.indexOf(d),1),RED.events.emit("nodes:change",r)),(r=RED.nodes.node(e))&&(r.users.push(d),RED.events.emit("nodes:change",r))),t.changes[o]=d[o],d[o]=e,t.changed=!0)}}d._def.credentials&&(n=d._def.credentials,n=function(e,t,o){var n,i=!1;e.credentials?e.credentials._||(e.credentials._={}):e.credentials={_:{}};for(n in t)if(t.hasOwnProperty(n)){var a=$("#"+o+"-"+n);if(0<a.length){a=a.val();if("password"==t[n].type){if(e.credentials["has_"+n]=""!==a,"__PWRD__"==a)continue;i=!0}(e.credentials[n]=a)!=e.credentials._[n]&&(i=!0)}}return i}(d,n,this.inputClass),t.changed=t.changed||n)}}}),function(){function n(t,o){var n;t.on("change keyup paste",function(){n=n||setTimeout(function(){var e=o(t.val());t.toggleClass("input-error",!!e),n=null})})}RED.editor.registerEditPane("editor-tab-subflow-module",function(i){return{label:RED._("editor-tab.module"),name:RED._("editor-tab.module"),iconClass:"fa fa-cube",create:function(e){var t=i,o=($('<form class="dialog-form form-horizontal" autocomplete="off"><div class="form-row"><label for="subflow-input-module-module" data-i18n="[append]editor:subflow.module"><i class="fa fa-cube"></i> </label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-module" data-i18n="[placeholder]common.label.name"></div><div class="form-row"><label for="subflow-input-module-type" data-i18n="[append]editor:subflow.type"> </label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-type"></div><div class="form-row"><label for="subflow-input-module-version" data-i18n="[append]editor:subflow.version"></label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-version" data-i18n="[placeholder]editor:subflow.versionPlaceholder"></div><div class="form-row"><label for="subflow-input-module-desc" data-i18n="[append]editor:subflow.desc"></label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-desc"></div><div class="form-row"><label for="subflow-input-module-license" data-i18n="[append]editor:subflow.license"></label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-license"></div><div class="form-row"><label for="subflow-input-module-author" data-i18n="[append]editor:subflow.author"></label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-author" data-i18n="[placeholder]editor:subflow.authorPlaceholder"></div><div class="form-row"><label for="subflow-input-module-keywords" data-i18n="[append]editor:subflow.keys"></label><input style="width: calc(100% - 110px)" type="text" id="subflow-input-module-keywords" data-i18n="[placeholder]editor:subflow.keysPlaceholder"></div></form>').appendTo(e),t.meta||{});["module","type","version","author","desc","keywords","license"].forEach(function(e){$("#subflow-input-module-"+e).val(o[e]||"")}),$("#subflow-input-module-type").attr("placeholder",t.id),n($("#subflow-input-module-module"),function(e){var t=(e=e.trim()).length<215;return t=(t=t&&!/^[._]/.test(e))&&!/[A-Z]/.test(e),(t=e!==encodeURIComponent(e)?!!(e=/^@([^\/]+)\/([^\/]+)$/.exec(e))&&(t&&e[1]===encodeURIComponent(e[1])&&e[2]===encodeURIComponent(e[2])):t)?"":"Invalid module name"}),n($("#subflow-input-module-version"),function(e){return""===(e=e.trim())||/^(\d|[1-9]\d*)\.(\d|[1-9]\d*)\.(\d|[1-9]\d*)(-(0|[1-9A-Za-z-][0-9A-Za-z-]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9A-Za-z-][0-9A-Za-z-]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/.test(e)?"":"Invalid version number"}),(t={types:(e=["none","Apache-2.0","BSD-3-Clause","BSD-2-Clause","GPL-2.0","GPL-3.0","MIT","MPL-2.0","CDDL-1.0","EPL-2.0"]).map(function(e){return{value:e,label:"none"===e?RED._("editor:subflow.licenseNone"):e,hasValue:!1}})}).types.push({value:"_custom_",label:RED._("editor:subflow.licenseOther"),icon:"red/images/typedInput/az.svg"}),o.license?-1<e.indexOf(o.license)?t.default=o.license:t.default="_custom_":t.default="none",$("#subflow-input-module-license").typedInput(t)},resize:function(e){},close:function(){},apply:function(e){var t,o,n=function(){var t,o={},e=(["module","type","version","author","desc","keywords"].forEach(function(e){(t=$("#subflow-input-module-"+e).val().trim())&&(o[e]=t)}),$("#subflow-input-module-license").typedInput("type"));"_custom_"===e?(t=$("#subflow-input-module-license").val())&&(o.license=t):"none"!==e&&(o.license=e);return o}();t=i.meta,o=n,JSON.stringify(t)!==JSON.stringify(o)&&(e.changes.meta=i.meta,i.meta=n,e.changed=!0)}}})}(),RED.editor.registerTypeEditor("_buffer",{show:function(i){var r,a,s=i.value,e=i.cancel,t=i.complete,d=(0===$("script[data-template-name='_buffer']").length&&$('<script type="text/x-red" data-template-name="_buffer"><div id="red-ui-editor-type-buffer-panels"><div id="red-ui-editor-type-buffer-panel-str" class="red-ui-panel"><div class="form-row" style="margin-bottom: 3px; text-align: right;"><button class="red-ui-editor-type-buffer-type red-ui-button red-ui-button-small"><i class="fa fa-exclamation-circle"></i> <span id="red-ui-editor-type-buffer-type-string" data-i18n="bufferEditor.modeString"></span><span id="red-ui-editor-type-buffer-type-array" data-i18n="bufferEditor.modeArray"></span></button></div><div class="form-row node-text-editor-row"><div class="node-text-editor" id="red-ui-editor-type-buffer-str"></div></div></div><div id="red-ui-editor-type-buffer-panel-bin" class="red-ui-panel"><div class="form-row node-text-editor-row" style="margin-top: 10px; margin-bottom:0;"><div class="node-text-editor" id="red-ui-editor-type-buffer-bin"></div></div></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),[]),o={title:i.title,focusElement:i.focusElement,width:"inherit",buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){d.saveView(),t&&t(JSON.stringify(r),null,d),RED.tray.close()}}],resize:function(e){var t=$("#dialog-form").height();a&&a.resize(t)},open:function(e){function n(e){for(var t=!0,o="string"==typeof e,n=[],i=0,a=(r=o?function(e){for(var t=[],o=0,n=e.length,o=0;o<n;o++){var i=e.charCodeAt(o);i<128?t.push(i):(i<2048?t.push(192|i>>6):(i<55296||57344<=i?t.push(224|i>>12):(o++,i=65536+((1023&i)<<10|1023&e.charAt(o)),t.push(240|i>>18),t.push(128|i>>12&63)),t.push(128|i>>6&63)),t.push(128|63&i))}return t}(e):e).length,i=0;i<a;i++){var s=parseInt(r[i]);if(!o&&(isNaN(s)||s<0||255<s)){t=!1;break}0<i&&(i%8==0?i%16==0?n.push("\n"):n.push(" "):n.push(" ")),n.push((s<16?"0":"")+s.toString(16).toUpperCase())}return t&&($("#red-ui-editor-type-buffer-type-string").toggle(o),$("#red-ui-editor-type-buffer-type-array").toggle(!o),bufferBinEditor.setValue(n.join(""),1)),t}function t(){var e=d.getValue(),t=!1;if(/^[\s]*\[[\s\S]*\][\s]*$/.test(e)){t=!0;try{var o=JSON.parse(e),t=n(o)}catch(e){t=!1}}t||n(e)}var o,e=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_buffer","editor");d=RED.editor.createEditor({id:"red-ui-editor-type-buffer-str",value:s||"",stateId:RED.editor.generateViewStateId("buffer",i,""),focus:!0,mode:"ace/mode/text"}),bufferBinEditor=RED.editor.createEditor({id:"red-ui-editor-type-buffer-bin",value:"",stateId:!1,focus:!1,mode:"ace/mode/text",readOnly:!0});d.getSession().on("change",function(){clearTimeout(o),o=setTimeout(t,200)}),t(),e.i18n(),a=RED.panels.create({id:"red-ui-editor-type-buffer-panels",resize:function(e,t){var o=$("#red-ui-editor-type-buffer-panel-str"),o=(e-=$(o.children()[0]).outerHeight(!0),$(o.children()[1])),e=(e-=parseInt(o.css("marginTop"))+parseInt(o.css("marginBottom")),$("#red-ui-editor-type-buffer-str").css("height",e-5+"px"),d.resize(),$("#red-ui-editor-type-buffer-panel-bin")),o=$(e.children()[0]);t-=parseInt(o.css("marginTop"))+parseInt(o.css("marginBottom")),$("#red-ui-editor-type-buffer-bin").css("height",t-5+"px"),bufferBinEditor.resize()}}),$(".red-ui-editor-type-buffer-type").on("click",function(e){e.preventDefault(),RED.sidebar.help.set(RED._("bufferEditor.modeDesc"))})},close:function(){i.onclose&&i.onclose(),d.destroy(),bufferBinEditor.destroy()},show:function(){}};RED.tray.show(o)}}),RED.editor.codeEditor=function(){const o="monaco",n=o,e={lib:n,options:{}};var i=null,a=!1;return{init:function(){var t=RED.editor.codeEditor.settings.lib===o?o:"ace";try{var e=RED.utils.getBrowserInfo();(i=RED.editor.codeEditor[t])&&(t!=o||!e.ie&&window.monaco)||(i=RED.editor.codeEditor[n]),a=i.init()}catch(e){i=null,console.warn("Problem initialising '"+t+"' code editor",e)}a||(i=RED.editor.codeEditor[n],a=i.init())},get settings(){return RED.settings.get("codeEditor")||e},get editor(){return i},create:function(e){return e||(console.warn("createEditor() options are missing"),e={}),this.editor.type===o&&(e.element||e.id||(e.id="node-backwards-compatability-dummy-editor"),e.element=e.element||$("#"+e.id)[0],e.element||(console.warn("createEditor() options.element or options.id is not valid",e),$("#dialog-form").append('<div id="'+e.id+'" style="display: none;" />'))),this.editor.create(e)}}}(),RED.editor.colorPicker=RED.colorPicker={create:function(c){function u(e){var t,o;"none"===e?(i.addClass("red-ui-color-picker-cell-none").css({"background-color":"",opacity:1}),n.css({"border-color":""})):(t=parseFloat(b.val()),i.removeClass("red-ui-color-picker-cell-none").css({"background-color":e,opacity:t}),"#"===(o=RED.utils.getDarkerColor(e))[0]?o+=Math.round(255*Math.floor(100*t)/100).toString(16):o="",n.css({"border-color":o})),c.hasOwnProperty("opacity")&&$(".red-ui-color-picker-opacity-slider-overlay").css({"background-image":"linear-gradient(90deg, transparent 0%, "+e+" 100%)"})}var e=c.value,t=c.id,p=c.palette||[],f=c.cellWidth||30,h=c.cellHeight||30,g=c.cellMargin||2,m=c.cellPerRow||6,o=$("<div>",{style:"display:inline-block"}),v=$("<input/>",{id:t,type:"hidden",value:e}).appendTo(o),b=$("<input/>",{id:t+"-opacity",type:"hidden",value:c.hasOwnProperty("opacity")?c.opacity:"1"}).appendTo(o),y=$('<button type="button" class="red-ui-button red-ui-editor-node-appearance-button">').appendTo(o),n=($('<i class="fa fa-caret-down"></i>').appendTo(y),$("<div>",{class:"red-ui-search-result-node"}).appendTo(y)),i=($("<div>",{class:"red-ui-color-picker-cell-none"}).appendTo(n),$("<div>",{class:"red-ui-color-picker-swatch"}).appendTo(n));return y.on("click",function(e){var t,o,n,i=p.length,a=$("<div/>",{class:"red-ui-color-picker"}).css({width:(f+g+g)*m+"px",height:Math.ceil(i/m)*(h+g+g)+"+px"}),s=0,r=null,d=(r=$("<div/>").appendTo(a),$("<input>",{type:"text",value:v.val()}).appendTo(r)),i=d,l=(d.on("change",function(e){var t=d.val();c.defaultValue&&!t.match(/^([a-z]+|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})$/)&&(t=c.defaultValue),v.val(t).trigger("change"),u(t)}),c.none&&(r=$("<div/>").appendTo(a),$("<button/>",{class:"red-ui-color-picker-cell red-ui-color-picker-cell-none"}).css({width:f+"px",height:h+"px",margin:g+"px"}).appendTo(r).on("click",function(e){e.preventDefault(),d.val("none"),d.trigger("change")})),p.forEach(function(t){s%m==0&&(r=$("<div/>").appendTo(a)),$("<button/>",{class:"red-ui-color-picker-cell"}).css({width:f+"px",height:h+"px",margin:g+"px",backgroundColor:t,"border-color":RED.utils.getDarkerColor(t)}).appendTo(r).on("click",function(e){e.preventDefault(),d.val(t),d.trigger("change")}),s++}),(c.none||c.hasOwnProperty("opacity"))&&(r=$("<div/>").appendTo(a),c.hasOwnProperty("opacity")&&((t=$("<div>",{class:"red-ui-color-picker-opacity-slider"}).appendTo(r)).on("mousedown",function(e){e.target!==o[0]&&(e=e.offsetX/t.width(),o.css({left:e*(t.width()-o.outerWidth())+"px"}),e=Math.floor(100*e),b.val(e/100),n.text(e+"%"),u(v.val()))}),$("<div>",{class:"red-ui-color-picker-opacity-slider-overlay"}).appendTo(t),o=$("<div>",{class:"red-ui-color-picker-opacity-slider-handle red-ui-button red-ui-button-small"}).appendTo(t).draggable({containment:"parent",axis:"x",drag:function(e,t){t=Math.max(0,t.position.left/($(this).parent().width()-$(this).outerWidth())),t=Math.floor(100*t);b.val((t=99===t?100:t)/100),n.text(t+"%"),u(v.val())}}),n=$("<small></small>").appendTo(r),setTimeout(function(){o.css({left:parseFloat(b.val())*(t.width()-o.outerWidth())+"px"}),n.text(Math.floor(100*b.val())+"%")},50))),RED.popover.panel(a));setTimeout(function(){u(v.val())},50),l.show({target:y,onclose:function(){y.focus()}}),i&&i.focus()}),setTimeout(function(){u(v.val())},50),o}},RED.editor.envVarList=function(){var E="en-US",D=["str","num","bool","json","bin","env"],R=["str","num","bool","json","bin","env","cred"];function x(e,t,o){if(e){if(e[o])return e[o];if(o){o=o.substring(0,2);if(e[o])return e[o]}}return t}return{create:function(b,y){var e,w="subflow"===y.type,o=(b.css({"min-height":"150px","min-width":"450px"}).editableList({header:w?$('<div><div><div></div><div data-i18n="common.label.name"></div><div data-i18n="editor-tab.defaultValue"></div><div></div></div></div>'):void 0,addItem:function(t,e,o){w&&t.addClass("red-ui-editor-subflow-env-editable");var n,s,i,a,r,d,l,c,u,p,f=$("<div/>").appendTo(t),h=null,g=null,h=$("<input/>",{class:"node-input-env-name",type:"text",placeholder:RED._("common.label.name")}).attr("autocomplete","disable").appendTo(f).val(o.name),g=$("<input/>",{style:"width:100%",class:"node-input-env-value",type:"text"}).attr("autocomplete","disable").appendTo(f),m=(m=o.ui&&o.ui.opts&&o.ui.opts.types)||(w?D:R),m=(g.typedInput({default:"str",types:m}),g.typedInput("type",o.type),"cred"!==o.type||o.value?g.typedInput("value",o.value):y.credentials&&y.credentials[o.name]?g.typedInput("value",y.credentials[o.name]):y.credentials&&y.credentials["has_"+o.name]?g.typedInput("value","__PWRD__"):g.typedInput("value",""),o.nameField=h,o.valueField=g,$("<a/>",{href:"#",class:"red-ui-editableList-item-remove red-ui-button red-ui-button-small"}).appendTo(f)),v=($("<i/>",{class:"fa "+(o.parent?"fa-reply":"fa-remove")}).appendTo(m),RED.popover.tooltip(m,RED._("subflow.env.remove")));m.on("click",function(e){e.preventDefault(),v.close(),t.parent().addClass("red-ui-editableList-item-deleting"),t.fadeOut(300,function(){b.editableList("removeItem",o)})}),w&&("cred"===o.type?(o.ui=o.ui||{icon:"",type:"cred"},o.ui.type="cred"):o.ui=o.ui||{icon:"",type:"input",opts:{types:D}},o.ui.label=o.ui.label||{},o.ui.type=o.ui.type||"input","cred"===o.ui.type&&o.ui.opts&&o.ui.opts.types&&(o.ui.type="input"),n=$("<div/>").appendTo(t).hide(),$('<a href="#"><i class="fa fa-angle-right"></a>').prependTo(f).on("click",function(e){e.preventDefault(),$(this).hasClass("expanded")?(n.slideUp(),$(this).removeClass("expanded")):(n.slideDown(),$(this).addClass("expanded"))}),m=n,s=o.ui,f=h,i=g,m.addClass("red-ui-editor-subflow-env-ui-row"),g=$("<div></div>").appendTo(m),$("<div></div>").appendTo(g),$("<div>").text(RED._("editor.icon")).appendTo(g),$("<div>").text(RED._("editor.label")).appendTo(g),$("<div>").text(RED._("editor.inputType")).appendTo(g),g=$("<div></div>").appendTo(m),$('<div><i class="red-ui-editableList-item-handle fa fa-bars"></i></div>').appendTo(g),a={input:{types:D},select:{opts:[]},spinner:{},cred:{}},s.opts?a[s.type]=s.opts:s.opts=a[s.type],m=$("<div></div>").appendTo(g),(r=$('<a href="#"></a>').appendTo(m)).on("click",function(e){e.preventDefault();e=s.icon||"",e=e?RED.utils.separateIconPath(e):{};RED.editor.iconPicker.show(r,null,e,!0,function(e){r.empty();var e=e||"",t=RED.utils.separateIconPath(e);t&&$('<i class="fa"></i>').addClass(t.file).appendTo(r),s.icon=e})}),s.icon&&(m=RED.utils.separateIconPath(s.icon),$('<i class="fa '+m.file+'"></i>').appendTo(r)),m=$("<div></div>").appendTo(g),u=s.label&&s.label[E]||"",c=$('<input type="text">').val(u).appendTo(m),(s.labelField=c).on("change",function(e){s.label=s.label||{};var t=$(this).val().trim();""===t?delete s.label[E]:s.label[E]=t}),u=$('<span class="red-ui-editor-subflow-env-lang-icon"><i class="fa fa-language"></i></span>').appendTo(m),RED.popover.tooltip(u,function(){var e=Object.keys(s.label),o=$("<div>");return-1===e.indexOf(E)&&(e.push(E),e.sort()),e.forEach(function(e){var t=$("<div>").appendTo(o);$("<span>").css({display:"inline-block",width:"120px"}).text(RED._("languages."+e)+(e===E?"*":"")).appendTo(t),$("<span>").text(s.label[e]||"").appendTo(t)}),o}),f.on("change",function(e){c.attr("placeholder",$(this).val())}),m=$("<div></div>").appendTo(g),p=$('<input type="text">').css("width","100%").appendTo(m),"input"===s.type&&p.val(s.opts.types.join(",")),p.typedInput({types:[{value:"input",label:RED._("editor.inputs.input"),icon:"fa fa-i-cursor",showLabel:!1,multiple:!0,options:[{value:"str",label:RED._("editor.types.str"),icon:"red/images/typedInput/az.svg"},{value:"num",label:RED._("editor.types.num"),icon:"red/images/typedInput/09.svg"},{value:"bool",label:RED._("editor.types.bool"),icon:"red/images/typedInput/bool.svg"},{value:"json",label:RED._("editor.types.json"),icon:"red/images/typedInput/json.svg"},{value:"bin",label:RED._("editor.types.bin"),icon:"red/images/typedInput/bin.svg"},{value:"env",label:RED._("editor.types.env"),icon:"red/images/typedInput/env.svg"},{value:"cred",label:RED._("editor.types.cred"),icon:"fa fa-lock"}],default:D,valueLabel:function(e,t){e.css("padding",0);var e=$('<div class="red-ui-editor-subflow-env-input-type"></div>').appendTo(e),o=$('<div class="placeholder-input">').appendTo(e);$('<span><i class="fa fa-i-cursor"></i></span>').appendTo(o),t.length?t.forEach(function(e){var t;/^fa /.test(e.icon)?(t=$("<span>",{style:"max-width:14px; padding: 0 3px; margin-top:-4px; margin-left: 1px"}).appendTo(o),$("<i>",{class:e.icon}).appendTo(t)):$("<img>",{src:e.icon,style:"max-width:14px; padding: 0 3px; margin-top:-4px; margin-left: 1px"}).appendTo(o)}):$('<span class="red-ui-editor-subflow-env-input-type-placeholder"></span>').text(RED._("editor.selectType")).appendTo(o)}},{value:"cred",label:RED._("typedInput.type.cred"),icon:"fa fa-lock",showLabel:!1,valueLabel:function(e,t){e.css("padding",0);e=$('<div class="red-ui-editor-subflow-env-input-type">').css({"border-top-right-radius":"4px","border-bottom-right-radius":"4px"}).appendTo(e);$('<div class="placeholder-input">').html("&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;").appendTo(e)}},{value:"select",label:RED._("editor.inputs.select"),icon:"fa fa-tasks",showLabel:!1,valueLabel:function(e,t){e.css("padding","0"),l=$("<select></select>").appendTo(e),s.opts&&Array.isArray(s.opts.opts)&&s.opts.opts.forEach(function(e){var t=x(e.l,e.l["en-US"]||e.v,E);$("<option>").val(e.v).text(t).appendTo(l)}),l.on("change",function(e){var t=l.val();i.typedInput("value",t)}),l.val(i.typedInput("value"))},expand:{icon:"fa-caret-down",minWidth:400,content:function(e){var e=$('<div class="red-ui-editor-subflow-ui-edit-panel">').appendTo(e),a=$("<ol>").appendTo(e).editableList({header:$("<div><div>"+RED._("editor.select.label")+"</div><div>"+RED._("editor.select.value")+"</div></div>"),addItem:function(e,t,n){var o=$("<div>").appendTo(e),i=x(n.l,"",E),i=(n.label=$('<input type="text">').val(i).appendTo(o),n.label.on("keydown",function(e){13===e.keyCode&&(n.input.focus(),e.preventDefault())}),$('<span class="red-ui-editor-subflow-env-lang-icon"><i class="fa fa-language"></i></span>').appendTo(o));RED.popover.tooltip(i,function(){return E}),n.input=$('<input type="text">').val(n.v).appendTo(e),n.input.on("keydown",function(e){var t,o;13===e.keyCode&&((o=a.editableList("indexOf",n))+1===a.editableList("length")?(t={},a.editableList("addItem",t),setTimeout(function(){t.label&&t.label.focus()},100)):(o=a.editableList("getItemAt",o+1)).label&&o.label.focus(),e.preventDefault())})},sortable:!0,removable:!0,height:160});return 0<s.opts.opts.length?s.opts.opts.forEach(function(e){a.editableList("addItem",$.extend(!0,{},e))}):a.editableList("addItem",{}),{onclose:function(){var e=a.editableList("items"),i=[];e.each(function(e,t){var t=t.data("data"),o=t.label.val().trim(),n=t.input.val();0<o.length&&(t.l=t.l||{},t.l[E]=o),t.v=n,(0<o.length||0<n.length)&&(o={l:t.l,v:t.v},i.push(o))}),s.opts.opts=i,p.typedInput("value",Date.now())}}}}},{value:"checkbox",label:RED._("editor.inputs.checkbox"),icon:"fa fa-check-square-o",showLabel:!1,valueLabel:function(e,t){e.css("padding",0),(d=$('<input type="checkbox">').appendTo(e)).on("change",function(e){i.typedInput("value",$(this).prop("checked")?"true":"false")}),d.prop("checked","true"===i.typedInput("value"))}},{value:"spinner",label:RED._("editor.inputs.spinner"),icon:"fa fa-sort-numeric-asc",showLabel:!1,valueLabel:function(e,t){e.css("padding",0);var e=$('<div class="red-ui-editor-subflow-env-input-type"></div>').appendTo(e),e=$('<div class="placeholder-input">').appendTo(e),o=($('<span><i class="fa fa-sort-numeric-asc"></i></span>').appendTo(e),s.opts&&s.opts.min),n=s.opts&&s.opts.max,i="";void 0!==o&&void 0!==n?i=Math.min(o,n)+" - "+Math.max(o,n):void 0!==o?i="> "+o:void 0!==n&&(i="< "+n),$("<span>").css("margin-left","15px").text(i).appendTo(e)},expand:{icon:"fa-caret-down",content:function(e){var e=$('<div class="red-ui-editor-subflow-ui-edit-panel">').appendTo(e),t=(e.css("padding","8px 5px"),s.opts.min),o=s.opts.max,n=$('<input type="number" style="margin-bottom:0; width:60px">'),i=(n.val(t),$('<input type="number" style="margin-bottom:0; width:60px">'));return i.val(o),$('<div class="form-row" style="margin-bottom:3px"><label>'+RED._("editor.spinner.min")+"</label></div>").append(n).appendTo(e),$('<div class="form-row" style="margin-bottom:0"><label>'+RED._("editor.spinner.max")+"</label></div>").append(i).appendTo(e),{onclose:function(){var e=n.val().trim(),t=i.val().trim();""!==e?s.opts.min=parseInt(e):delete s.opts.min,""!==t?s.opts.max=parseInt(t):delete s.opts.max,p.typedInput("value",Date.now())}}}}},{value:"none",label:RED._("editor.inputs.none"),icon:"fa fa-times",hasValue:!1},{value:"hide",label:RED._("editor.inputs.hidden"),icon:"fa fa-ban",hasValue:!1}],default:"none"}).on("typedinputtypechange",function(e,t){switch(s.type=$(this).typedInput("type"),s.opts=a[s.type],"input"===s.type?p.typedInput("value",s.opts.types.join(",")):p.typedInput("value",Date.now()),s.type){case"input":i.typedInput("types",s.opts.types);break;case"select":i.typedInput("types",["str"]);break;case"checkbox":i.typedInput("types",["bool"]);break;case"spinner":i.typedInput("types",["num"]);break;case"cred":i.typedInput("types",["cred"]);break;default:i.typedInput("types",D)}"checkbox"===s.type?i.typedInput("type","bool"):"spinner"===s.type&&i.typedInput("type","num"),"checkbox"!==s.type&&(d=null)}).on("change",function(e,t){var o;"input"===s.type&&(o=p.typedInput("value"),s.opts.types=""===o?["str"]:o.split(","),i.typedInput("types",s.opts.types))}),i.on("change",function(e){d&&d.prop("checked","true"===$(this).typedInput("value"))}),p.typedInput("type",s.type),h.trigger("change"))},sortable:".red-ui-editableList-item-handle",removable:!1}),{}),n=[];if(!/^subflow:/.test(y.type)||(e=RED.nodes.subflow(y.type.substring(8))).env&&e.env.forEach(function(e){var t={name:e.name,parent:{type:e.type,value:e.value,ui:e.ui}};n.push(t),o[e.name]=t}),y.env)for(var t=0;t<y.env.length;t++){var i=y.env[t];o.hasOwnProperty(i.name)?(o[i.name].type=i.type,o[i.name].value=i.value):n.push({name:i.name,type:i.type,value:i.value,ui:i.ui})}n.forEach(function(e){e.parent&&e.parent.ui&&"hide"===e.parent.ui.type||!w&&e.parent||b.editableList("addItem",JSON.parse(JSON.stringify(e)))})},setLocale:function(e,t){E=e,t&&t.editableList("items").each(function(e,t){var o=$(this).data("data"),n=o.ui.labelField;n.val(x(o.ui.label,"",E)),n.timeout&&(clearTimeout(n.timeout),delete n.timeout),n.addClass("input-updated"),n.timeout=setTimeout(function(){delete n.timeout,n.removeClass("input-updated")},3e3)})},lookupLabel:x,DEFAULT_ENV_TYPE_LIST:D,DEFAULT_ENV_TYPE_LIST_INC_CRED:R}}(),function(){var h={};RED.editor.registerTypeEditor("_expression",{show:function(n){var p,d,f,i,a=n.parent||"_",s=n.value,e=n.cancel,t=n.complete,r=(0===$("script[data-template-name='_expression']").length&&$('<script type="text/x-red" data-template-name="_expression"><div id="red-ui-editor-type-expression-panels"><div id="red-ui-editor-type-expression-panel-expr" class="red-ui-panel"><div class="form-row" style="margin-bottom: 3px; text-align: right;"><button class="red-ui-editor-type-expression-legacy red-ui-button red-ui-button-small"><i class="fa fa-exclamation-circle"></i> <span data-i18n="expressionEditor.compatMode"></span></button><button id="red-ui-editor-type-expression-reformat" class="red-ui-button red-ui-button-small"><span data-i18n="expressionEditor.format"></span></button></div><div class="form-row node-text-editor-row"><div class="node-text-editor" id="red-ui-editor-type-expression"></div></div></div><div id="red-ui-editor-type-expression-panel-info" class="red-ui-panel"><div class="form-row"><ul id="red-ui-editor-type-expression-tabs"></ul><div id="red-ui-editor-type-expression-tab-help" class="red-ui-editor-type-expression-tab-content hide"><div><select id="red-ui-editor-type-expression-func"></select><button id="red-ui-editor-type-expression-func-insert" class="red-ui-button" data-i18n="expressionEditor.insert"></button></div><div id="red-ui-editor-type-expression-help"></div></div><div id="red-ui-editor-type-expression-tab-test" class="red-ui-editor-type-expression-tab-content hide"><div><span style="display: inline-block; width: calc(50% - 5px);"><span data-i18n="expressionEditor.data"></span><button style="float: right; margin-right: 5px;" id="node-input-example-reformat" class="red-ui-button red-ui-button-small"><span data-i18n="jsonEditor.format"></span></button></span><span style="display: inline-block; margin-left: 10px; width: calc(50% - 5px);" data-i18n="expressionEditor.result"></span></div><div style="display: inline-block; width: calc(50% - 5px);" class="node-text-editor" id="red-ui-editor-type-expression-test-data"></div><div style="display: inline-block; margin-left: 10px; width:calc(50% - 5px);" class="node-text-editor" id="red-ui-editor-type-expression-test-result"></div></div></div></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),{title:n.title,focusElement:n.focusElement,width:"inherit",buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){$("#red-ui-editor-type-expression-help").text(""),p.saveView(),t&&t(p.getValue(),p.getCursorPosition(),p),RED.tray.close()}}],resize:function(e){var t=$("#dialog-form").height();i&&i.resize(t)},open:function(e){function t(){var e,t,o=d.getValue(),n=p.getValue(),i=!1,a=/(^|[^a-zA-Z0-9_'".])msg([^a-zA-Z0-9_'"]|$)/.test(n);$(".red-ui-editor-type-expression-legacy").toggle(a);try{(t=jsonata(n)).assign("flowContext",function(e){return i=!0,null}),t.assign("globalContext",function(e){return i=!0,null})}catch(e){return void f.setValue(RED._("expressionEditor.errors.invalid-expr",{message:e.message}),-1)}try{e=JSON.parse(o)}catch(e){return void f.setValue(RED._("expressionEditor.errors.invalid-msg",{message:e.toString()}))}try{var s,r=t.evaluate(a?{msg:e}:e);i?f.setValue(RED._("expressionEditor.errors.context-unsupported"),-1):(s=void 0!==r?JSON.stringify(r,null,4):RED._("expressionEditor.noMatch"),f.setValue(s,-1))}catch(e){f.setValue(RED._("expressionEditor.errors.eval",{message:e.message}),-1)}}e.find(".red-ui-tray-body").addClass("red-ui-editor-type-expression");var o,e=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_expression","editor"),l=$("#red-ui-editor-type-expression-func"),c=(Object.keys(jsonata.functions).forEach(function(e){l.append($("<option></option>").val(e).text(e))}),l.on("change",function(e){var t=$(this).val(),o="<h5>"+t+"("+RED._("jsonata:"+t+".args",{defaultValue:""})+")</h5>",t=RED.utils.renderMarkdown(RED._("jsonata:"+t+".desc",{defaultValue:""}));$("#red-ui-editor-type-expression-help").html(o+"<p>"+t+"</p>")}),p=RED.editor.createEditor({id:"red-ui-editor-type-expression",value:"",mode:"ace/mode/jsonata",stateId:n.stateId,focus:!0,options:{enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0}}),null),u=-1,e=(p.getSession().setValue(s||"",-1),"ace"==p.type&&p.on("changeSelection",function(){var e=p.getCursorPosition(),t=p.getSession().getTokenAt(e.row,e.column);if(t!==c||t&&/paren/.test(t.type)&&e.column!==u){var o,n=null;if((c=t)&&"keyword"===t.type)o=e.row,n=t;else for(var i=0,a=!1,s=t?("paren.rparen"===t.type&&(u=e.column,i=e.column-(t.start+t.value.length)),o=e.row,t.index):(o=e.row-1,-1);null===n&&-1<o;){var r=p.getSession().getTokens(o);for(-1===s&&(s=r.length-1);-1<s;){var d=r[s].type;if(a){if("keyword"===d){n=r[s];break}a=!1}"paren.lparen"===d?i-=r[s].value.length:"paren.rparen"===d&&(i+=r[s].value.length),i<0&&(a=!0,i=0),s--}n||o--}p.session.removeMarker(null),n&&l.val(n.value).trigger("change")}}),e.i18n(),$("#red-ui-editor-type-expression-func-insert").on("click",function(e){e.preventDefault();p.getCursorPosition();e=l.val(),e=jsonata.getFunctionSnippet(e);p.insertSnippet(e),p.focus()}),$("#red-ui-editor-type-expression-reformat").on("click",function(e){e.preventDefault();e=p.getValue()||"";try{e=jsonata.format(e)}catch(e){}p.getSession().setValue(e||"",-1)}),l.change(),RED.tabs.create({element:$("#red-ui-editor-type-expression-tabs"),onchange:function(e){$(".red-ui-editor-type-expression-tab-content").hide(),e.content.show(),r.resize()}}));e.addTab({id:"expression-help",label:RED._("expressionEditor.functionReference"),content:$("#red-ui-editor-type-expression-tab-help")}),e.addTab({id:"expression-tests",label:RED._("expressionEditor.test"),content:$("#red-ui-editor-type-expression-tab-test")}),d=RED.editor.createEditor({id:"red-ui-editor-type-expression-test-data",value:h[a]||'{\n "payload": "hello world"\n}',stateId:!1,focus:!1,mode:"ace/mode/json",lineNumbers:!1}),$(".red-ui-editor-type-expression-legacy").on("click",function(e){e.preventDefault(),RED.sidebar.help.set(RED._("expressionEditor.compatModeDesc"))});d.getSession().on("change",function(){clearTimeout(o),o=setTimeout(t,200),h[a]=d.getValue()}),p.getSession().on("change",function(){clearTimeout(o),o=setTimeout(t,200)}),f=RED.editor.createEditor({id:"red-ui-editor-type-expression-test-result",value:"",stateId:!1,focus:!1,mode:"ace/mode/json",lineNumbers:!1,readOnly:!0}),i=RED.panels.create({id:"red-ui-editor-type-expression-panels",resize:function(e,t){var o=$("#red-ui-editor-type-expression-panel-expr"),o=(e-=$(o.children()[0]).outerHeight(!0),$(o.children()[1]));e-=parseInt(o.css("marginTop"))+parseInt(o.css("marginBottom")),$("#red-ui-editor-type-expression").css("height",e-5+"px"),p.resize(),t-=$("#red-ui-editor-type-expression-panel-info > .form-row > div:first-child").outerHeight(!0)+20,$(".red-ui-editor-type-expression-tab-content").height(t),$("#red-ui-editor-type-expression-test-data").css("height",t-25+"px"),d.resize(),$("#red-ui-editor-type-expression-test-result").css("height",t-25+"px"),f.resize()}}),$("#node-input-example-reformat").on("click",function(e){e.preventDefault();e=d.getValue()||"";try{e=JSON.stringify(JSON.parse(e),null,4)}catch(e){}d.getSession().setValue(e||"",-1)}),t()},close:function(){n.onclose&&n.onclose(),p.destroy(),d.destroy(),f.destroy()},show:function(){}});RED.tray.show(r)}})}(),RED.editor.iconPicker={show:function(e,s,r,n,d){var t=$('<div class="red-ui-icon-picker">'),o=$("<div>",{class:"red-ui-search-container"}).appendTo(t),l=(searchInput=$('<input type="text">').attr("placeholder",RED._("editor.searchIcons")).appendTo(o).searchBox({delay:50,change:function(){var o=$(this).val().trim();""===o?(l.find(".red-ui-icon-list-module").show(),l.find(".red-ui-icon-list-icon").show()):(l.find(".red-ui-icon-list-module").hide(),l.find(".red-ui-icon-list-icon").each(function(e,t){-1===$(t).data("icon").indexOf(o)?$(t).hide():$(t).show()}))}}),$("<div>").appendTo(t),$('<div class="red-ui-icon-list">').appendTo(t)),o=$('<div class="red-ui-icon-meta"></div>').appendTo(t),c=$("<span>").appendTo(o),i=($('<button type="button" class="red-ui-button red-ui-button-small">'+RED._("editor.useDefault")+"</button>").appendTo(o).on("click",function(e){e.preventDefault(),u.hide(),d(null)}),!s&&n&&l.addClass("red-ui-icon-list-dark"),setTimeout(function(){var o=RED.nodes.getIconSets();Object.keys(o).forEach(function(a){var e,t;n&&"font-awesome"!==a||0<(e=o[a]).length&&(t=$('<div class="red-ui-icon-list-module"></div>').text(a).appendTo(l),$('<i class="fa fa-cube"></i>').prependTo(t),e.forEach(function(e){var t=$("<div>",{class:"red-ui-icon-list-icon"}).appendTo(l),o=$("<div>",{class:"red-ui-search-result-node"}).appendTo(t),n=RED.settings.apiRootUrl+"icons/"+a+"/"+e,i=(t.data("icon",n),s&&(o.css({backgroundColor:s}),(i=RED.utils.getDarkerColor(s))!==s&&o.css("border-color",i)),$("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(o));RED.utils.createIconElement(n,i,!0),r.module===a&&r.file===e&&t.addClass("selected"),t.on("mouseover",function(){c.text(e)}),t.on("mouseout",function(){c.html("&nbsp;")}),t.on("click",function(){u.hide(),d(a+"/"+e)})}))}),setTimeout(function(){i.remove()},50)},300),RED.utils.addSpinnerOverlay(l,!0)),u=RED.popover.panel(t);u.show({target:e}),t.slideDown(100),searchInput.trigger("focus")}},RED.editor.registerTypeEditor("_js",{show:function(t){var i,o=t.value,e=t.cancel,n=t.complete,a=(0===$("script[data-template-name='_js']").length&&$('<script type="text/x-red" data-template-name="_js"><div class="form-row node-text-editor-row"><div style="height: 200px;min-height: 150px;" class="node-text-editor" id="node-input-js"></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),{title:t.title,focusElement:t.focusElement,width:t.width||"inherit",buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){i.saveView(),n&&n(i.getValue(),i.getCursorPosition(),i),RED.tray.close()}}],resize:function(e){for(var t=$("#dialog-form>div:not(.node-text-editor-row)"),o=($("#dialog-form>div.node-text-editor-row"),$("#dialog-form").height()),n=0;n<t.size();n++)o-=$(t[n]).outerHeight(!0);$(".node-text-editor").css("height",o+"px"),i.resize()},open:function(e){e=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_js","editor");i=RED.editor.createEditor({id:"node-input-js",mode:t.mode||"ace/mode/javascript",stateId:t.stateId,focus:!0,value:o,globals:{msg:!0,context:!0,RED:!0,util:!0,flow:!0,global:!0,console:!0,Buffer:!0,setTimeout:!0,clearTimeout:!0,setInterval:!0,clearInterval:!0},extraLibs:t.extraLibs}),t.cursor&&!i._initState&&i.gotoLine(t.cursor.row+1,t.cursor.column,!1),e.i18n()},close:function(){t.onclose&&t.onclose(),i.destroy()},show:function(){}});RED.tray.show(a)}}),function(){var u;function h(e,t,o,n){var i="";if(0<e.children.length)switch(e.children[Math.max(0,Math.min(e.children.length-1,o))].type){case"string":i="";break;case"number":i=0;break;case"boolean":i=!0;break;case"null":i=null;break;case"object":i={};break;case"array":i=[]}if("array"===e.type)r=e.children.length;else for(var a={},s=(e.children.forEach(function(e){a[e.key]=!0}),2),r="item";a[r];)r="item-"+s++;o=g(r,i,e.depth+1,e,n);e.treeList.insertChildAt(o,t,!0),e.treeList.expand()}function g(e,t,o,n,a){var i,s,r,d,l,c={depth:o,type:typeof t},u=$('<span class="red-ui-editor-type-json-editor-label">'),p=(null!=e&&(i="string"==typeof(c.key=e)?'"'+e+'"':e,(s=$('<span class="red-ui-debug-msg-object-key red-ui-editor-type-json-editor-label-key">').text(i).appendTo(u)).addClass("red-ui-debug-msg-type-"+typeof e),n&&"array"===n.type&&s.addClass("red-ui-editor-type-json-editor-label-array-key"),a&&s.addClass("readonly"),s.on("click",function(e){var n;"array"===c.parent.type||a||(e.preventDefault(),e.stopPropagation(),e=Math.max(150,s.width()),n=$('<input type="text" class="red-ui-editor-type-json-editor-key">').css({width:e+"px"}).val(""+c.key).insertAfter(s).typedInput({types:["str"]}),$(document).on("mousedown.nr-ui-json-editor",function(e){for(var t=n.next(".red-ui-typedInput-container")[0],o=e.target;"BODY"!==o.nodeName&&o!==t&&!$(o).hasClass("red-ui-typedInput-options");)o=o.parentElement;"BODY"===o.nodeName&&(e=n.typedInput("value"),c.key=e,s.text("string"==typeof e?'"'+e+'"':e),n.remove(),s.show(),$(document).off("mousedown.nr-ui-json-editor"),$(document).off("keydown.nr-ui-json-editor"))}),$(document).on("keydown.nr-ui-json-editor",function(e){27===e.keyCode&&(n.remove(),s.show(),$(document).off("mousedown.nr-ui-json-editor"),$(document).off("keydown.nr-ui-json-editor"))}),s.hide())}),$("<span>").text(" : ").appendTo(u)),Array.isArray(t)?(c.expanded=o<2,c.type="array",c.deferBuild=2<=o,c.children=function(e,t,o,n){for(var i=[],a=e.length,s=0;s<a;s++)i.push(g(s,e[s],t,o,n));return i}(t,o+1,c,a)):null!==t&&"object"===c.type?(c.expanded=o<2,c.children=function(e,t,o,n){var i,a=[];for(i in e)e.hasOwnProperty(i)&&a.push(g(i,e[i],t,o,n));return a}(t,o+1,c,a),c.deferBuild=2<=o):null===(c.value=t)&&(c.type="null"),"");switch(c.type){case"string":r="str",p='"'+c.value+'"',d="red-ui-debug-msg-type-string";break;case"number":r="num",p=c.value,d="red-ui-debug-msg-type-number";break;case"boolean":r="bool",p=c.value,d="red-ui-debug-msg-type-other";break;case"null":r=c.type,p=c.type,d="red-ui-debug-msg-type-null";break;case"object":r=c.type,p=c.type,d="red-ui-debug-msg-type-meta";break;case"array":r=c.type,p=c.type+"["+c.children.length+"]",d="red-ui-debug-msg-type-meta"}var f=$('<span class="red-ui-editor-type-json-editor-label-value">').addClass(d).text(p).appendTo(u);return a&&f.addClass("readonly"),f.on("click",function(e){var i;a||(e.preventDefault(),e.stopPropagation(),"str"===r?p=p.substring(1,p.length-1):"array"!==r&&"object"!==r||(p=""),e=Math.max(150,f.width()),i=$('<input type="text" class="red-ui-editor-type-json-editor-value">').css({width:e+"px"}).val(""+p).insertAfter(f).typedInput({types:["str","num","bool",{value:"null",label:RED._("common.type.null"),hasValue:!1},{value:"array",label:RED._("common.type.array"),hasValue:!1,icon:"red/images/typedInput/json.svg"},{value:"object",label:RED._("common.type.object"),hasValue:!1,icon:"red/images/typedInput/json.svg"}],default:r}),$(document).on("mousedown.nr-ui-json-editor",function(e){for(var t,o=i.next(".red-ui-typedInput-container")[0],n=e.target;"BODY"!==n.nodeName&&n!==o&&!$(n).hasClass("red-ui-typedInput-options");)n=n.parentElement;if("BODY"===n.nodeName){switch(r=i.typedInput("type"),p=i.typedInput("value"),"num"===r&&(p=p.trim(),isNaN(p)?r="str":""===p&&(p=0)),c.value=p,r){case"str":c.children&&(l=c.children),c.treeList.makeLeaf(!0),c.type="string",t="red-ui-debug-msg-type-string",p='"'+p+'"';break;case"num":c.children&&(l=c.children),c.treeList.makeLeaf(!0),c.type="number",t="red-ui-debug-msg-type-number";break;case"bool":c.children&&(l=c.children),c.treeList.makeLeaf(!0),c.type="boolean",t="red-ui-debug-msg-type-other",c.value="true"===p;break;case"null":c.children&&(l=c.children),c.treeList.makeLeaf(!0),c.type="null",t="red-ui-debug-msg-type-null",c.value=p="null";break;case"object":c.treeList.makeParent(l),c.type="object",t="red-ui-debug-msg-type-meta",c.value=p="object",c.children.forEach(function(e,t){var o,n;e.hasOwnProperty("_key")&&(e.key=e._key,delete e._key,(n=e.element.find(".red-ui-editor-type-json-editor-label-key")).removeClass("red-ui-editor-type-json-editor-label-array-key"),"string"==typeof e.key?(o='"'+e.key+'"',n.addClass("red-ui-debug-msg-type-string"),n.removeClass("red-ui-debug-msg-type-number")):(o=e.key,n.removeClass("red-ui-debug-msg-type-string"),n.addClass("red-ui-debug-msg-type-number")),n.text(o))});break;case"array":c.treeList.makeParent(l),c.type="array",t="red-ui-debug-msg-type-meta",c.value=p="array["+c.children.length+"]",c.children.forEach(function(e,t){e._key=e.key,e.key=t,e.element.find(".red-ui-editor-type-json-editor-label-key").addClass("red-ui-editor-type-json-editor-label-array-key").text(""+e.key).removeClass("red-ui-debug-msg-type-string").addClass("red-ui-debug-msg-type-number")})}f.text(p).removeClass().addClass("red-ui-editor-type-json-editor-label-value "+t),i.remove(),f.show(),$(document).off("mousedown.nr-ui-json-editor"),$(document).off("keydown.nr-ui-json-editor")}}),$(document).on("keydown.nr-ui-json-editor",function(e){27===e.keyCode&&(i.remove(),f.show(),"str"===r&&(p='"'+p+'"'),$(document).off("mousedown.nr-ui-json-editor"),$(document).off("keydown.nr-ui-json-editor"))}),f.hide())}),c.gutter=$('<span class="red-ui-editor-type-json-editor-item-gutter"></span>'),a||((n?$('<span class="red-ui-editor-type-json-editor-item-handle"><i class="fa fa-bars"></span>'):$("<span></span>")).appendTo(c.gutter),$('<button type="button" class="editor-button editor-button-small"><i class="fa fa-caret-down"></button>').appendTo(c.gutter).on("click",function(e){e.preventDefault(),e.stopPropagation();var e=$(this),s=c,r=a,e=e.offset(),t=[],o=(s.parent&&(t.push({id:"red-ui-editor-type-json-menu-insert-above",icon:"fa fa-toggle-up",label:RED._("jsonEditor.insertAbove"),onselect:function(){var e=s.parent.children.indexOf(s);h(s.parent,e,e,r)}}),t.push({id:"red-ui-editor-type-json-menu-insert-below",icon:"fa fa-toggle-down",label:RED._("jsonEditor.insertBelow"),onselect:function(){var e=s.parent.children.indexOf(s)+1;h(s.parent,e,e-1,r)}})),"array"!==s.type&&"object"!==s.type||t.push({id:"red-ui-editor-type-json-menu-add-child",icon:"fa fa-plus",label:RED._("jsonEditor.addItem"),onselect:function(){h(s,s.children.length,s.children.length-1,r)}}),s.parent&&(t.push({id:"red-ui-editor-type-json-menu-copy-path",icon:"fa fa-terminal",label:RED._("jsonEditor.copyPath"),onselect:function(){for(var e=s,t="";e.parent;)t=("array"===e.parent.type?"["+e.key+"]":/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(e.key)?e.key:'["'+e.key.replace(/"/,'\\"')+'"]')+(0<t.length&&"["!==t[0]?".":"")+t,e=e.parent;RED.clipboard.copyText(t,s.element,"clipboard.copyMessagePath")}}),t.push({id:"red-ui-editor-type-json-menu-duplicate",icon:"fa fa-copy",label:RED._("jsonEditor.duplicate"),onselect:function(){var e=s.key;if("array"===s.parent.type)e=s.parent.children.length;else{var t=/^(.*?)(-(\d+))?$/.exec(e),o={},n=(s.parent.children.forEach(function(e){o[e.key]=!0}),t[1]),i=2;for(void 0!==t[3]&&(i=parseInt(t[3])),e=n;o[e];)e=n+"-"+i++}var t=g(e,m(s),s.parent.depth+1,s.parent,r),a=s.parent.children.indexOf(s)+1;s.parent.treeList.insertChildAt(t,a,!0),s.parent.treeList.expand()}}),t.push({id:"red-ui-editor-type-json-menu-delete",icon:"fa fa-times",label:RED._("common.label.delete"),onselect:function(){s.treeList.remove()}})),"array"!==s.type&&"object"!==s.type||(t.push(null),t.push({id:"red-ui-editor-type-json-menu-expand-children",icon:"fa fa-angle-double-down",label:RED._("jsonEditor.expandItems"),onselect:function(){s.treeList.expand(),s.children.forEach(function(e){e.treeList.expand()})}}),t.push({id:"red-ui-editor-type-json-menu-collapse-children",icon:"fa fa-angle-double-up",label:RED._("jsonEditor.collapseItems"),onselect:function(){s.treeList.collapse(),s.children.forEach(function(e){e.treeList.collapse()})}})),(t=RED.menu.init({id:"red-ui-editor-type-json-menu",options:t})).css({position:"absolute"}),t.on("mouseleave",function(){$(this).hide()}),t.on("mouseup",function(){$(this).hide()}),t.appendTo("body"),e.top),n=t.height(),i=$(window).height();i<o+n&&(o-=o+n-i+20),t.css({top:o+"px",left:e.left+"px"}),t.show()})),c.element=u,c}function m(e){var t;switch(e.type){case"string":t=e.value;break;case"number":t=Number(e.value);break;case"boolean":t=e.value;break;case"null":t=null;break;case"object":t={},e.children.forEach(function(e){t[e.key]=m(e)});break;case"array":t=e.children.map(m)}return t}RED.editor.registerTypeEditor("_json",{show:function(a){function o(){var e=s.getValue();try{return JSON.parse(e),$("#node-dialog-ok").removeClass("disabled"),!0}catch(e){return $("#node-dialog-ok").addClass("disabled"),!1}}var s,r,d,l=a.value,e=a.cancel,t=a.complete,c=(0===$("script[data-template-name='_json']").length&&$('<script type="text/x-red" data-template-name="_json"><ul id="red-ui-editor-type-json-tabs"></ul><div id="red-ui-editor-type-json-tab-raw" class="red-ui-editor-type-json-tab-content hide"><div class="form-row" style="margin-bottom: 3px; text-align: right;"><span class="button-group"><button id="node-input-json-reformat" class="red-ui-button red-ui-button-small"><span data-i18n="jsonEditor.format"></span></button><span class="button-group"></div><div class="form-row node-text-editor-row"><div style="height: 200px;min-height: 150px;" class="node-text-editor" id="node-input-json"></div></div></div><div id="red-ui-editor-type-json-tab-ui" class="red-ui-editor-type-json-tab-content hide"><div id="red-ui-editor-type-json-tab-ui-container"></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),{title:a.title,focusElement:a.focusElement,width:a.width||700,buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){var e;a.requireValid&&!o()||("json-ui"===u?e=d?JSON.stringify(m(d),null,4):s.getValue():"json-raw"===u&&(e=s.getValue()),s.saveView(),t&&t(e,null,s),RED.tray.close())}}],resize:function(e){var t=$(".red-ui-editor-type-json-tab-content").height();$(".node-text-editor").css("height",t-45+"px"),s.resize()},open:function(e){e.find(".red-ui-tray-body");var e=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_json","editor"),t=a.toolbarButtons||[],t=(t.length&&t.forEach(function(t){var o=$('<button type="button" class="red-ui-button red-ui-button-small"> </button>').insertBefore("#node-input-json-reformat").on("click",function(e){e.preventDefault(),void 0!==t.click&&t.click.call(o,e)});t.id&&o.attr("id",t.id),t.title&&o.attr("title",t.title),t.icon&&o.append($("<i></i>").attr("class",t.icon)),(t.label||t.text)&&o.append($("<span></span>").text(" "+(t.label||t.text)))}),$("#red-ui-editor-type-json-tab-ui-container").css({height:"100%"})),n=$('<div class="red-ui-debug-msg-payload red-ui-editor-type-json-editor">').appendTo(t).treeList({selectable:!1,rootSortable:!1,sortable:".red-ui-editor-type-json-editor-item-handle"}).on("treelistchangeparent",function(e,t){"array"===t.old.type&&t.old.element.find(".red-ui-editor-type-json-editor-label-type").text("array["+t.old.children.length+"]"),"array"===t.item.parent.type&&t.item.parent.element.find(".red-ui-editor-type-json-editor-label-type").text("array["+t.item.parent.children.length+"]")}).on("treelistsort",function(e,o){o.children.forEach(function(e,t){"array"===o.type?(e.key=t,e.element.find(".red-ui-editor-type-json-editor-label-key").text(e.key).removeClass("red-ui-debug-msg-type-string").addClass("red-ui-debug-msg-type-number")):e.element.find(".red-ui-editor-type-json-editor-label-key").text('"'+e.key+'"').removeClass("red-ui-debug-msg-type-number").addClass("red-ui-debug-msg-type-string")})}),i=(s=RED.editor.createEditor({id:"node-input-json",value:l||"",mode:"ace/mode/json",readOnly:!!a.readOnly,stateId:a.stateId,focus:!0}),a.requireValid&&(s.getSession().on("change",function(){clearTimeout(r),r=setTimeout(o,200)}),o()),$("#node-input-json-reformat").on("click",function(e){e.preventDefault();e=s.getValue()||"";try{e=JSON.stringify(JSON.parse(e),null,4)}catch(e){}s.getSession().setValue(e||"",-1)}),e.i18n(),!1),t=RED.tabs.create({element:$("#red-ui-editor-type-json-tabs"),onchange:function(e){if(u=e.id,$(".red-ui-editor-type-json-tab-content").hide(),i)if("json-raw"===e.id)d&&(t=JSON.stringify(m(d),null,4),s.getSession().setValue(t||"",-1));else if("json-ui"===e.id){var t=s.getValue().trim()||"{}";try{var o=JSON.parse(t);(d=g(null,o,0,null,a.readOnly)).class="red-ui-editor-type-json-root-node",n.treeList("data",[d])}catch(e){d=null,n.treeList("data",[{label:RED._("jsonEditor.error.invalidJSON")+e.toString()}])}}e.content.show(),c.resize()}});t.addTab({id:"json-raw",label:a.readOnly?RED._("jsonEditor.rawMode-readonly"):RED._("jsonEditor.rawMode"),content:$("#red-ui-editor-type-json-tab-raw")}),t.addTab({id:"json-ui",label:a.readOnly?RED._("jsonEditor.uiMode-readonly"):RED._("jsonEditor.uiMode"),content:$("#red-ui-editor-type-json-tab-ui")}),i=!0},close:function(){a.onclose&&a.onclose(),s.destroy()},show:function(){}});RED.tray.show(c)}})}(),function(){var s;RED.editor.registerTypeEditor("_markdown",{show:function(n){var i,a=n.value,e=n.cancel,t=n.complete,o=(0===$("script[data-template-name='_markdown']").length&&$('<script type="text/x-red" data-template-name="_markdown"><div id="red-ui-editor-type-markdown-panels"><div id="red-ui-editor-type-markdown-panel-editor" class="red-ui-panel"><div style="height: 100%; margin: auto;"><div id="red-ui-editor-type-markdown-toolbar"></div><div class="node-text-editor" style="height: 100%" id="red-ui-editor-type-markdown"></div></div></div><div class="red-ui-panel"><div class="red-ui-editor-type-markdown-panel-preview red-ui-help"></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),{title:n.title,focusElement:n.focusElement,width:n.width||1/0,buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){i.saveView(),t&&t(i.getValue(),i.getCursorPosition(),i),RED.tray.close()}}],resize:function(e){var t=$("#dialog-form").width();s&&s.resize(t)},open:function(e){e.find(".red-ui-tray-body").addClass("red-ui-editor-type-markdown-editor");var t,o=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_markdown","editor");(i=RED.editor.createEditor({id:"red-ui-editor-type-markdown",value:a,stateId:n.stateId,focus:!0,mode:"ace/mode/markdown",expandable:!1})).getSession().on("change",function(){clearTimeout(t),t=setTimeout(function(){var e=$(".red-ui-editor-type-markdown-panel-preview").scrollTop();$(".red-ui-editor-type-markdown-panel-preview").html(RED.utils.renderMarkdown(i.getValue())),$(".red-ui-editor-type-markdown-panel-preview").scrollTop(e)},200)}),n.header&&n.header.appendTo(e.find("#red-ui-editor-type-markdown-title")),a&&$(".red-ui-editor-type-markdown-panel-preview").html(RED.utils.renderMarkdown(i.getValue())),(s=RED.panels.create({id:"red-ui-editor-type-markdown-panels",dir:"horizontal",resize:function(e,t){i.resize()}})).ratio(1),$('<span class="button-group" style="float:right"><button type="button" id="node-btn-markdown-preview" class="red-ui-button toggle single"><i class="fa fa-eye"></i></button></span>').appendTo(i.toolbar),$("#node-btn-markdown-preview").on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?($(this).removeClass("selected"),s.ratio(1)):($(this).addClass("selected"),s.ratio(.5))}),RED.popover.tooltip($("#node-btn-markdown-preview"),RED._("markdownEditor.toggle-preview")),n.cursor&&!i._initState&&i.gotoLine(n.cursor.row+1,n.cursor.column,!1),o.i18n()},close:function(){n.onclose&&n.onclose(),i.destroy()},show:function(){}});RED.tray.show(o)},buildToolbar:function(e,r){var t={h1:{newline:!0,before:"# ",tooltip:RED._("markdownEditor.heading1")},h2:{newline:!0,before:"## ",tooltip:RED._("markdownEditor.heading2")},h3:{newline:!0,before:"### ",tooltip:RED._("markdownEditor.heading3")},b:{before:"**",after:"**",tooltip:RED._("markdownEditor.bold")},i:{before:"_",after:"_",tooltip:RED._("markdownEditor.italic")},code:{before:"`",after:"`",tooltip:RED._("markdownEditor.code")},ol:{before:" 1. ",newline:!0,tooltip:RED._("markdownEditor.ordered-list")},ul:{before:" - ",newline:!0,tooltip:RED._("markdownEditor.unordered-list")},bq:{before:"> ",newline:!0,tooltip:RED._("markdownEditor.quote")},link:{before:"[",after:"]()",tooltip:RED._("markdownEditor.link")},hr:{before:"\n---\n\n",tooltip:RED._("markdownEditor.horizontal-rule")}},e=$('<div style="margin-bottom: 5px"><span class="button-group"><button type="button" class="red-ui-button" data-style="h1" style="font-size:1.1em; font-weight: bold">h1</button><button type="button" class="red-ui-button" data-style="h2" style="font-size:1.0em; font-weight: bold">h2</button><button type="button" class="red-ui-button" data-style="h3" style="font-size:0.9em; font-weight: bold">h3</button></span><span class="button-group"><button type="button" class="red-ui-button" data-style="b"><i class="fa fa-bold"></i></button><button type="button" class="red-ui-button" data-style="i"><i class="fa fa-italic"></i></button><button type="button" class="red-ui-button" data-style="code"><i class="fa fa-code"></i></button></span><span class="button-group"><button type="button" class="red-ui-button" data-style="ol"><i class="fa fa-list-ol"></i></button><button type="button" class="red-ui-button" data-style="ul"><i class="fa fa-list-ul"></i></button><button type="button" class="red-ui-button" data-style="bq"><i class="fa fa-quote-left"></i></button><button type="button" class="red-ui-button" data-style="hr"><i class="fa fa-minus"></i></button><button type="button" class="red-ui-button" data-style="link"><i class="fa fa-link"></i></button></span></div>').appendTo(e);return e.find("button[data-style]").each(function(e){var s=t[$(this).data("style")];$(this).on("click",function(e){e.preventDefault();var e=r.getSelectedText(),t=r.selection.getRange();if(s.newline)for(var o=0,n=((s.before||"").match(/\n/g)||[]).length,i=((s.after||"").match(/\n/g)||[]).length,a=t.start.row;a<=t.end.row+o;a++)s.before&&(r.session.insert({row:a,column:0},s.before),o+=n,a+=n),s.after&&(r.session.insert({row:a,column:1/0},s.after),o+=i,a+=i);else r.session.replace(r.selection.getRange(),(s.before||"")+e+(s.after||"")),""===e&&r.gotoLine(t.start.row+1,t.start.column+(s.before||"").length,!1);r.focus()}),s.tooltip&&RED.popover.tooltip($(this),s.tooltip)}),e}})}(),RED.editor.registerTypeEditor("_text",{show:function(t){var o,n=t.value,e=t.cancel,i=t.complete,a=(0===$("script[data-template-name='_text']").length&&$('<script type="text/x-red" data-template-name="_text"><div class="form-row node-text-editor-row"><div style="height: 200px;min-height: 150px;" class="node-text-editor" id="node-input-text"></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.view.state(RED.state.EDITING),{title:t.title,focusElement:t.focusElement,width:t.width||"inherit",buttons:[{id:"node-dialog-cancel",text:RED._("common.label.cancel"),click:function(){e&&e(),RED.tray.close()}},{id:"node-dialog-ok",text:RED._("common.label.done"),class:"primary",click:function(){o.saveView(),i&&i(o.getValue(),o.getCursorPosition(),o),RED.tray.close()}}],resize:function(e){$("#dialog-form>div:not(.node-text-editor-row)"),$("#dialog-form>div.node-text-editor-row");var t=$("#dialog-form").height();$(".node-text-editor").css("height",t+"px"),o.resize()},open:function(e){RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_text","editor");o=RED.editor.createEditor({id:"node-input-text",value:n||"",stateId:t.stateId,mode:"ace/mode/"+(t.mode||"text"),focus:!0}),t.cursor&&!o._initState&&o.gotoLine(t.cursor.row+1,t.cursor.column,!1)},close:function(){t.onclose&&t.onclose(),o.destroy()},show:function(){}});RED.tray.show(a)}}),RED.editor.codeEditor.ace=function(){var t=!1,s={};return{get type(){return"ace"},get initialised(){return t},init:function(e){return s=e||{},t=!0},create:function(o){var e=RED.editor.codeEditor.settings||{},t=o.element||$("#"+o.id)[0],n=$("<div>").appendTo(t),t=$("<div>").appendTo(t).addClass("red-ui-editor-text-container")[0],i=window.ace.edit(t),a=(i.setTheme(e.theme||s.theme||"ace/theme/tomorrow"),i.getSession());return a.on("changeAnnotation",function(){for(var e=a.getAnnotations()||[],t=e.length,o=e.length;t--;)(/doctype first\. Expected/.test(e[t].text)||/Unexpected End of file\. Expected/.test(e[t].text))&&e.splice(t,1);o>e.length&&a.setAnnotations(e)}),o.mode&&a.setMode(o.mode),o.foldStyle?a.setFoldStyle(o.foldStyle):a.setFoldStyle("markbeginend"),o.options?i.setOptions(o.options):i.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,tooltipFollowsMouse:!1}),o.readOnly&&(i.setOption("readOnly",o.readOnly),i.container.classList.add("ace_read-only")),o.hasOwnProperty("lineNumbers")&&i.renderer.setOption("showGutter",o.lineNumbers),i.$blockScrolling=1/0,o.value&&a.setValue(o.value,-1),o.globals&&setTimeout(function(){a.$worker&&a.$worker.send("setOptions",[{globals:o.globals,maxerr:1e3}])},100),o.stateId||!1===o.stateId||(o.stateId=RED.editor.generateViewStateId("ace",o,(o.mode||o.title).split("/").pop())),"ace/mode/markdown"===o.mode&&($(t).addClass("red-ui-editor-text-container-toolbar"),i.toolbar=RED.editor.customEditTypes._markdown.buildToolbar(n,i),!1!==o.expandable&&(e=$('<button type="button" class="red-ui-button" style="float: right;"><i class="fa fa-expand"></i></button>').appendTo(i.toolbar),RED.popover.tooltip(e,RED._("markdownEditor.expand")),e.on("click",function(e){e.preventDefault();e=i.getValue();RED.editor.editMarkdown({value:e,width:"Infinity",stateId:o.stateId,focus:!0,cancel:function(){i.focus()},complete:function(e,t){i.setValue(e,-1),setTimeout(function(){i.restoreView(),i.focus()},300)}})})),e=$('<button type="button" class="red-ui-editor-text-help red-ui-button red-ui-button-small"><i class="fa fa-question"></i></button>').appendTo($(t).parent()),RED.popover.create({target:e,trigger:"click",size:"small",direction:"left",content:RED._("markdownEditor.format"),autoClose:50}),a.setUseWrapMode(!0)),i._destroy=i.destroy,i.destroy=function(){try{i.saveView(),i._initState=null,this._destroy()}catch(e){}$(t).remove(),$(n).remove()},i.on("blur",function(){i.focusMemory=!1,i.saveView()}),i.on("focus",function(){i._initState&&(i.restoreView(i._initState),i._initState=null)}),i.getView=function(){var e=i.getSession();return{selection:e.selection.toJSON(),scrollTop:e.getScrollTop(),scrollLeft:e.getScrollLeft(),options:e.getOptions()}},i.saveView=function(){var e;if(o.stateId)return window._editorStateAce=window._editorStateAce||{},e=i.getView(),window._editorStateAce[o.stateId]=e},i.restoreView=function(e){if(o.stateId){window._editorStateAce=window._editorStateAce||{};e=e||window._editorStateAce[o.stateId];if(e)try{var t=i.getSession();t.setOptions(e.options),t.selection.fromJSON(e.selection),t.setScrollTop(e.scrollTop),t.setScrollLeft(e.scrollLeft),i._initState=e}catch(e){delete window._editorStateMonaco[o.stateId]}}},i.restoreView(),i.type="ace",i}}}(),RED.editor.codeEditor.monaco=function(){var y=!1;const w=["vs","vs-dark","hc-black"];let E;const b={assert:{package:"node",module:"assert",path:"node/assert.d.ts"},async_hooks:{package:"node",module:"async_hooks",path:"node/async_hooks.d.ts"},buffer:{package:"node",module:"buffer",path:"node/buffer.d.ts"},child_process:{package:"node",module:"child_process",path:"node/child_process.d.ts"},cluster:{package:"node",module:"cluster",path:"node/cluster.d.ts"},console:{package:"node",module:"console",path:"node/console.d.ts"},constants:{package:"node",module:"constants",path:"node/constants.d.ts"},crypto:{package:"node",module:"crypto",path:"node/crypto.d.ts"},dgram:{package:"node",module:"dgram",path:"node/dgram.d.ts"},dns:{package:"node",module:"dns",path:"node/dns.d.ts"},domain:{package:"node",module:"domain",path:"node/domain.d.ts"},events:{package:"node",module:"events",path:"node/events.d.ts"},fs:{package:"node",module:"fs",path:"node/fs.d.ts"},globals:{package:"node",module:"globals",path:"node/globals.d.ts"},http:{package:"node",module:"http",path:"node/http.d.ts"},http2:{package:"node",module:"http2",path:"node/http2.d.ts"},https:{package:"node",module:"https",path:"node/https.d.ts"},module:{package:"node",module:"module",path:"node/module.d.ts"},net:{package:"node",module:"net",path:"node/net.d.ts"},os:{package:"node",module:"os",path:"node/os.d.ts"},path:{package:"node",module:"path",path:"node/path.d.ts"},perf_hooks:{package:"node",module:"perf_hooks",path:"node/perf_hooks.d.ts"},process:{package:"node",module:"process",path:"node/process.d.ts"},querystring:{package:"node",module:"querystring",path:"node/querystring.d.ts"},readline:{package:"node",module:"readline",path:"node/readline.d.ts"},stream:{package:"node",module:"stream",path:"node/stream.d.ts"},string_decoder:{package:"node",module:"string_decoder",path:"node/string_decoder.d.ts"},timers:{package:"node",module:"timers",path:"node/timers.d.ts"},tls:{package:"node",module:"tls",path:"node/tls.d.ts"},trace_events:{package:"node",module:"trace_events",path:"node/trace_events.d.ts"},tty:{package:"node",module:"tty",path:"node/tty.d.ts"},url:{package:"node",module:"url",path:"node/url.d.ts"},util:{package:"node",module:"util",path:"node/util.d.ts"},v8:{package:"node",module:"v8",path:"node/v8.d.ts"},vm:{package:"node",module:"vm",path:"node/vm.d.ts"},wasi:{package:"node",module:"wasi",path:"node/wasi.d.ts"},worker_threads:{package:"node",module:"worker_threads",path:"node/worker_threads.d.ts"},zlib:{package:"node",module:"zlib",path:"node/zlib.d.ts"},"node-red":{package:"node-red",module:"node-red",path:"node-red/index.d.ts"},"node-red-util":{package:"node-red",module:"util",path:"node-red/util.d.ts"},"node-red-func":{package:"node-red",module:"func",path:"node-red/func.d.ts"}},D=[b["node-red-util"],b["node-red-func"],b.globals,b.console,b.buffer],l={};function R(e,t,o,n){var i="object"==typeof e?e:b[e];if(i){const s=i.package,r=i.module,d=i.path;var a,e=l[d];e?(t||(o.JS[r]=monaco.languages.typescript.javascriptDefaults.addExtraLib(e,"file://types/"+s+"/"+r+"/index.d.ts")),n&&setTimeout(function(){n(null,i)},5)):(a="types/"+d,$.get(a).done(function(e){l[d]=e,t||(o.JS[r]=monaco.languages.typescript.javascriptDefaults.addExtraLib(e,"file://types/"+s+"/"+r+"/index.d.ts")),n&&n(null,i)}).fail(function(e){var t="Failed to load '"+a+"'";l[d]="/* "+t+" */\n",n&&n(e,i),console.warn(t)}))}}function x(e){return!(!e.offsetHeight&&!e.offsetWidth)&&"hidden"!==getComputedStyle(e).visibility}return{get type(){return"monaco"},get initialised(){return y},init:function(e){RED.events.on("editor:close",function(){var t=window.monaco?monaco.editor.getModels():null;if(t&&t.length){console.warn("Cleaning up monaco models left behind. Any node that calls createEditor() should call .destroy().");for(let e=0;e<t.length;e++){const o=t[e];o.isDisposed()||o.dispose()}}}),window.MonacoEnvironment=window.MonacoEnvironment||{},window.MonacoEnvironment.getWorkerUrl=window.MonacoEnvironment.getWorkerUrl||function(e,t){return"json"===t?"./vendor/monaco/dist/json.worker.js":"css"===t||"scss"===t?"./vendor/monaco/dist/css.worker.js":"html"===t||"handlebars"===t?"./vendor/monaco/dist/html.worker.js":"typescript"===t||"javascript"===t?"./vendor/monaco/dist/ts.worker.js":"./vendor/monaco/dist/editor.worker.js"};var o=(RED.editor.codeEditor.settings||{}).options||{};try{const b=function(e,t){(t.rules&&Array.isArray(t.rules)||t.colors)&&(w.push(e),monaco.editor.defineTheme(e,t),monaco.editor.setTheme(e),E=e)};if(o.theme)if("object"==typeof o.theme&&RED.settings.editorTheme.theme){var t=o.theme.name||RED.settings.editorTheme.theme;b(t,o.theme)}else if("string"==typeof o.theme){let t=o.theme;w.includes(t)||$.get("vendor/monaco/dist/theme/"+t+".json",function(e){b(t,e)})}}catch(e){console.warn(e)}function i(e,t,o,n,i){return Array.isArray(o)&&(o=o.join("\n")),{label:e,kind:null==i?monaco.languages.CompletionItemKind.Snippet:i,documentation:{value:o},insertText:t,insertTextRules:monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,range:n}}(t=monaco).languages.registerCompletionItemProvider("javascript",{provideCompletionItems:function(e,t){var e=e.getWordUntilPosition(t),t={startLineNumber:t.lineNumber,endLineNumber:t.lineNumber,startColumn:e.startColumn,endColumn:e.endColumn};return{suggestions:[i("dowhile","do {\n\t${2}\n} while (${1:condition});","Do-While Statement (JavaScript Language Basics)",e=t),i("while","while (${1:condition}) {\n\t${2}\n}","While Statement (JavaScript Language Basics)",e),i("switch",'switch (${1:msg.topic}) {\n\tcase ${2:"value"}:\n\t\t${3}\n\t\tbreak;\n\tdefault:\n\t\t\n}',"Switch Statement (JavaScript Language Basics)",e),i("trycatch","try {\n\t${2}\n} catch (${1:error}) {\n\t\n};","Try-Catch Statement (JavaScript Language Basics)",e),i("for (for loop)","for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {\n\tconst element = ${2:array}[${1:index}];\n\t${3}\n}","for loop",e),i("foreach","${1:array}.forEach(function(${2:element}) {\n\t${3}\n});","forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void\n\nA function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.",e),i("forin","for (${1:prop} in ${2:obj}) {\n\tif (${2:obj}.hasOwnProperty(${1:prop})) {\n\t\t${3}\n\t}\n}","for in",e),i("forof","for (const ${1:iterator} of ${2:object}) {\n\t${3}\n}","for of",e),i("function","function ${1:methodName}(${2:arguments}) {\n\t${3}\n}","Function Declaration",e),i("func (anonymous function)","var ${1:fn} = function(${2:arguments}) {\n\t${3}\n}","Function Expression",e),i("pt (prototype)","${1:ClassName}.prototype.${2:methodName} = function(${3:arguments}) {\n\t${4}\n}","prototype",e),i("iife","(function(${1:arg}) {\n\t${1}\n})(${1:arg});","immediately-invoked function expression",e),i("call (function call)","${1:methodName}.call(${2:context}, ${3:arguments})","function call",e),i("apply (function apply)","${1:methodName}.apply(${2:context}, [${3:arguments}])","function apply",e),i("jsonparse","JSON.parse(${1:json});","JSON.parse",e),i("jsonstringify","JSON.stringify(${1:obj});","JSON.stringify",e),i("setinterval","setInterval(function() {\n\t${2}\n}, ${1:delay});","setInterval",e),i("settimeout","setTimeout(function() {\n\t${2}\n}, ${1:delay});","setTimeout",e),i("node.log",'node.log(${1:"info"});',"Write an info message to the console (not sent to sidebar)",e),i("node.warn",'node.warn(${1:"my warning"});',"Write a warning to the console and debug sidebar",e),i("node.error",'node.error(${1:"my error message"}, ${2:msg});',"Send an error to the console and debug sidebar. To trigger a Catch node on the same tab, the function should call `node.error` with the original message as a second argument",e),i("node.send","node.send(${1:msg});","async send a msg to the next node",e),i("node.send (multiple)","var ${1:msg1} = {payload:${2:1}};\nvar ${3:msg2} = {payload:${4:2}};\nnode.send([[${1:msg1}, ${3:msg2}]]);","send 1 or more messages out of 1 output",e),i("node.send (multiple outputs)","var ${1:msg1} = {payload:${2:1}};\nvar ${3:msg2} = {payload:${4:2}};\nnode.send([${1:msg1}, ${3:msg2}]);","send more than 1 message out of multiple outputs",e),i("node.status",'node.status({fill:"${1|red,green,yellow,blue,grey|}",shape:"${2|ring,dot|}",text:"${3:message}"});',"Set the status icon and text underneath the function node",e),i("get (node context)",'context.get("${1:name}");',"Get a value from node context",e),i("set (node context)",'context.set("${1:name}", ${1:value});',"Set a value in node context",e),i("get (flow context)",'flow.get("${1:name}");',"Get a value from flow context",e),i("set (flow context)",'flow.set("${1:name}", ${1:value});',"Set a value in flow context",e),i("get (global context)",'global.get("${1:name}");',"Get a value from global context",e),i("set (global context)",'global.set("${1:name}", ${1:value});',"Set a value in global context",e),i("get (env)",'env.get("${1|NR_NODE_ID,NR_NODE_NAME,NR_NODE_PATH,NR_GROUP_ID,NR_GROUP_NAME,NR_FLOW_ID,NR_FLOW_NAME|}");',"Get env variable value",e),i("cloneMessage (RED.util)","RED.util.cloneMessage(${1:msg});",["```typescript","RED.util.cloneMessage<T extends registry.NodeMessage>(msg: T): T","```","Safely clones a message object. This handles msg.req/msg.res objects that must not be cloned\n","*@param* `msg` — the msg object\n"],e),i("getObjectProperty (RED.util)","RED.util.getObjectProperty(${1:msg},${2:prop});",["```typescript","RED.util.getObjectProperty(msg: object, expr: string): any;","```","Gets a property of an object\n","*@param* `msg` — the msg object\n","*@param* `prop` — the msg object"],e),i("setObjectProperty (RED.util)","RED.util.setObjectProperty(${1:msg},${2:prop},${3:value},${4:createMissing});",["```typescript","RED.util.setObjectProperty(msg: object, prop: string, value: any, createMissing?: boolean): boolean","```","Sets a property of an object\n","`msg` — the object\n","`prop` — the property expression\n","`value` — the value to set\n","`createMissing` — whether to create missing parent properties"],e),i("getMessageProperty (RED.util)","RED.util.getMessageProperty(${1:msg},${2:prop});",["```typescript","RED.util.getMessageProperty(msg: object, expr: string): any;","```","Gets a property of an object\n","*@param* `msg` — the msg object\n","*@param* `prop` — the msg object"],e),i("setMessageProperty (RED.util)","RED.util.setMessageProperty(${1:msg},${2:prop},${3:value},${4:createMissing});",["```typescript","RED.util.setMessageProperty(msg: object, prop: string, value: any, createMissing?: boolean): boolean","```","Sets a property of an object\n","`msg` — the object\n","`prop` — the property expression\n","`value` — the value to set\n","`createMissing` — whether to create missing parent properties"],e)]}}});try{var n={allowJs:!0,checkJs:!0,allowNonTsExtensions:!0,target:monaco.languages.typescript.ScriptTarget.ESNext,strictNullChecks:!1,strictPropertyInitialization:!0,strictFunctionTypes:!0,strictBindCallApply:!0,useDefineForClassFields:!0,moduleResolution:monaco.languages.typescript.ModuleResolutionKind.NodeJs,module:monaco.languages.typescript.ModuleKind.CommonJS,typeRoots:["types"],lib:["esnext"]},a=RED.settings.get("codeEditor.monaco.languages.typescript.javascriptDefaults.compilerOptions")||{},n=Object.assign({},n,a),s=(t.languages.typescript.javascriptDefaults.setCompilerOptions(n),{noSemanticValidation:!1,noSyntaxValidation:!1,diagnosticCodesToIgnore:[1108,1375,1378,2307,2322,2339,2345,7043,80001,80004]}),r=RED.settings.get("codeEditor.monaco.languages.typescript.javascriptDefaults.diagnosticsOptions")||{},s=Object.assign({},s,r);t.languages.typescript.javascriptDefaults.setDiagnosticsOptions(s)}catch(e){console.warn("monaco - Error setting javascriptDefaults",e)}(o=monaco).languages.register({id:"jsonata"}),o.languages.setMonarchTokensProvider("jsonata",{defaultToken:"invalid",tokenPostfix:".js",keywords:["function","true","true","null","Infinity","NaN","undefined"].concat(Object.keys(jsonata.functions)),operatorsKeywords:["and","or","in"],operators:["<=",">=","!=","==","!=","=>","+","-","*","/","%",":=","~>","?",":","..","@","#","|","^","*","**"],symbols:/[=><!~?:&|+\-*\/\^%@#]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,digits:/\d+(_+\d+)*/,octaldigits:/[0-7]+(_+[0-7]+)*/,binarydigits:/[0-1]+(_+[0-1]+)*/,hexdigits:/[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,regexpctl:/[(){}\[\]\$\^|\-*+?\.]/,regexpesc:/\\(?:[bBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})/,tokenizer:{root:[[/[{}]/,"delimiter.bracket"],{include:"common"}],common:[[/([a-zA-Z][\w$]*)|([$][\w$]*)/,{cases:{"@keywords":"keyword","@operatorsKeywords":"keyword",$2:"variable","@default":"identifier"}}],[/[$][\w\$]*/,"variable"],{include:"@whitespace"},[/\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|\/|,|\)|\]|\}|$))/,{token:"regexp",bracket:"@open",next:"@regexp"}],[/[()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/(@symbols)|(\.\.)/,{cases:{"@operators":"operator","@default":""}}],[/(@digits)[eE]([\-+]?(@digits))?/,"number.float"],[/(@digits)\.(@digits)([eE][\-+]?(@digits))?/,"number.float"],[/0[xX](@hexdigits)/,"number.hex"],[/0[oO]?(@octaldigits)/,"number.octal"],[/0[bB](@binarydigits)/,"number.binary"],[/(@digits)/,"number"],[/[?:;,.]/,"delimiter"],[/"([^"\\]|\\.)*$/,"string.invalid"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/"/,"string","@string_double"],[/'/,"string","@string_single"],[/`/,"string","@string_backtick"]],whitespace:[[/[ \t\r\n]+/,""],[/\/\*\*(?!\/)/,"comment.doc","@jsdoc"],[/\/\*/,"comment","@comment"],[/\/\/.*$/,"comment"]],comment:[[/[^\/*]+/,"comment"],[/\*\//,"comment","@pop"],[/[\/*]/,"comment"]],jsdoc:[[/[^\/*]+/,"comment.doc"],[/\*\//,"comment.doc","@pop"],[/[\/*]/,"comment.doc"]],regexp:[[/(\{)(\d+(?:,\d*)?)(\})/,["regexp.escape.control","regexp.escape.control","regexp.escape.control"]],[/(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,["regexp.escape.control",{token:"regexp.escape.control",next:"@regexrange"}]],[/(\()(\?:|\?=|\?!)/,["regexp.escape.control","regexp.escape.control"]],[/[()]/,"regexp.escape.control"],[/@regexpctl/,"regexp.escape.control"],[/[^\\\/]/,"regexp"],[/@regexpesc/,"regexp.escape"],[/\\\./,"regexp.invalid"],[/(\/)([gimsuy]*)/,[{token:"regexp",bracket:"@close",next:"@pop"},"keyword.other"]]],regexrange:[[/-/,"regexp.escape.control"],[/\^/,"regexp.invalid"],[/@regexpesc/,"regexp.escape"],[/[^\]]/,"regexp"],[/\]/,{token:"regexp.escape.control",next:"@pop",bracket:"@close"}]],string_double:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"/,"string","@pop"]],string_single:[[/[^\\']+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/'/,"string","@pop"]],string_backtick:[[/\$\{/,{token:"delimiter.bracket",next:"@bracketCounting"}],[/[^\\`$]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/`/,"string","@pop"]],bracketCounting:[[/\{/,"delimiter.bracket","@bracketCounting"],[/\}/,"delimiter.bracket","@pop"],{include:"common"}]}}),o.languages.setLanguageConfiguration("jsonata",{comments:{lineComment:"//",blockComment:["/*","*/"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"'",close:"'",notIn:["string","comment"]},{open:'"',close:'"',notIn:["string"]}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"},{open:"<",close:">"}],folding:{markers:{start:new RegExp("^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))"),end:new RegExp("^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))")}}}),o.languages.registerCompletionItemProvider("jsonata",{provideCompletionItems:function(e,t){var n,o,e=e.getWordUntilPosition(t);if(e)return o=e.startColumn,"$"!==e.word[0]&&1<t.column&&o--,n={startLineNumber:t.lineNumber,endLineNumber:t.lineNumber,startColumn:o,endColumn:e.endColumn},t=Object.keys(jsonata.functions),o=t.map(function(e){var t=e+"("+RED._("jsonata:"+e+".args",{defaultValue:""})+")",o=RED._("jsonata:"+e+".desc",{defaultValue:""});return i(e,(jsonata.getFunctionSnippet(e)+"").trim(),{value:"`"+t+"`\n\n"+o},n,monaco.languages.CompletionItemKind.Function)}),t.sort(function(e,t){return t.length-e.length}),o.unshift(i("randominteger","(\n\t\\$minimum := ${1:1};\n\t\\$maximum := ${2:10};\n\t\\$round((\\$random() * (\\$maximum-\\$minimum)) + \\$minimum, 0)\n)","Random integer between 2 numbers",n)),{suggestions:o}}}),o.languages.registerHoverProvider("jsonata",{provideHover:function(e,t){var e=e.getWordAtPosition(t),o=e&&e.word;if(o&&"$"!==o[0]&&1<t.column){var o="$"+o,n=RED._("jsonata:"+o+".args",{defaultValue:""});if(n)return n=o+"("+n+")",o=RED._("jsonata:"+o+".desc",{defaultValue:""}),{range:new monaco.Range(t.lineNumber,t.column,t.lineNumber,t.column+e.word.length),contents:[{value:"**`"+n+"`**"},{value:o}]}}}}),a=monaco;try{var d=RED.settings.get("codeEditor.monaco.languages.json.jsonDefaults.diagnosticOptions"),l=RED.settings.get("codeEditor.monaco.languages.json.jsonDefaults.modeConfiguration"),d=Object.assign({},{validate:!0},d||{});a.languages.json.jsonDefaults.setDiagnosticsOptions(d),l&&a.languages.json.jsonDefaults.setModeConfiguration(l)}catch(e){console.warn("monaco - Error setting up json options",err)}n=monaco;try{var c=RED.settings.get("codeEditor.monaco.languages.css.cssDefaults.diagnosticsOptions"),u=RED.settings.get("codeEditor.monaco.languages.css.lessDefaults.diagnosticsOption"),p=RED.settings.get("codeEditor.monaco.languages.css.scssDefaults.diagnosticsOption"),f=RED.settings.get("codeEditor.monaco.languages.css.cssDefaults.modeConfiguration"),h=RED.settings.get("codeEditor.monaco.languages.css.lessDefaults.modeConfiguration"),g=RED.settings.get("codeEditor.monaco.languages.css.scssDefaults.modeConfiguration");c&&n.languages.css.cssDefaults.setDiagnosticsOptions(c),u&&n.languages.css.cssDefaults.setDiagnosticsOptions(u),p&&n.languages.css.cssDefaults.setDiagnosticsOptions(p),f&&n.languages.css.cssDefaults.setDiagnosticsOptions(f),h&&n.languages.css.cssDefaults.setDiagnosticsOptions(h),g&&n.languages.css.cssDefaults.setDiagnosticsOptions(g)}catch(e){console.warn("monaco - Error setting up CSS/SCSS/LESS options",err)}r=monaco;try{var m=RED.settings.get("codeEditor.monaco.languages.html.htmlDefaults.options"),v=RED.settings.get("codeEditor.monaco.languages.html.handlebarDefaults.options");m&&r.languages.html.htmlDefaults.setOptions(m),v&&r.languages.html.handlebarDefaults.setOptions(v)}catch(e){console.warn("monaco - Error setting up html options",err)}return D.forEach(function(e){R(e,!0)}),y=!0},create:function(o){function c(e){switch(e=(e="object"==typeof e&&e.path?e.path:e)?e.replace("ace/mode/",""):"text"){case"nrjavascript":case"mjs":e="javascript";break;case"vue":e="html";break;case"appcache":case"sh":case"bash":e="shell";break;case"batchfile":e="bat";break;case"protobuf":e="proto"}return e}var a,e=RED.editor.codeEditor.settings||{},u={JS:{},TS:{}},s=(o.stateId||!1===o.stateId||(o.stateId=RED.editor.generateViewStateId("monaco",o,(o.mode||o.title||"").split("/").pop())),o.element||$("#"+o.id)[0]),r=$("<div>").appendTo(s),s=$("<div>").appendTo(s).addClass("red-ui-editor-text-container")[0];(e=$.extend({},e.options,o)).language=c(o.mode),E&&(e.theme=E),"javascript"==e.language&&(e._language=e.language,e.language="text"),e.minimap||(e.minimap={enabled:!0,maxColumn:50,scale:1,showSlider:"mouseover",renderCharacters:!0}),!1===o.enableBasicAutocompletion&&(e.showSnippets=!1,e.quickSuggestions=!1,e.parameterHints={enabled:!1},e.suggestOnTriggerCharacters=!1,e.acceptSuggestionOnEnter="off",e.tabCompletion="off",e.wordBasedSuggestions=!1),!1===o.enableSnippets&&(e.showSnippets=!1),null==e.mouseWheelZoom&&(e.mouseWheelZoom=!0),null==e.suggestFontSize&&(e.suggestFontSize=12),null==e.formatOnPaste&&(e.formatOnPaste=!0),null==e.foldingHighlight&&(e.foldingHighlight=!0),null==e.foldStyle&&(e.foldStyle=!0),null!=e.readOnly&&(e.readOnly=e.readOnly),!1===e.lineNumbers&&(e.lineNumbers=!1),null==e.theme&&(e.theme=w[0]),null==e.mode&&(e.mode=c(o.mode)),null==e.automaticLayout&&(e.automaticLayout=!0),o.foldStyle&&"none"===o.foldStyle?(e.foldStyle=!1,e.foldingHighlight=!1):(e.foldStyle=!0,e.foldingHighlight=!0),e.roundedSelection=!1!==e.roundedSelection,e.contextmenu=!1!==e.contextmenu,e.snippetSuggestions=!1!==e.enableSnippets,e.value=o.value||"",e.wordSeparators||"jsonata"!=e.language&&"json"!=e.language&&"javascript"!=e.language||(e.wordSeparators="`~!@#%^&*()-=+[{]}|;:'\",.<>/?"),e.fixedOverflowWidgets=!1!==e.fixedOverflowWidgets;((t=RED.utils.getBrowserInfo()).mobile||t.tablet)&&(e.minimap={enabled:!1},e.formatOnType=!1,e.formatOnPaste=!1,e.disableMonospaceOptimizations=!0,e.columnSelection=!1,e.matchBrackets="never",e.maxTokenizationLineLength=1e4,e.stopRenderingLineAfter=2e3,e.roundedSelection=!1,e.trimAutoWhitespace=!1,e.parameterHints={enabled:!1},e.suggestOnTriggerCharacters=!1,e.wordBasedSuggestions=!1,e.suggest={maxVisibleSuggestions:6},!e.accessibilitySupport&&t.android&&(e.accessibilitySupport="off"));var t=!1,n=(null==o.clientSideSuggestions&&(0<=(o.mode+"").indexOf("nrjavascript")||o.globals&&(o.globals.RED||o.globals.Buffer))&&(t=!0),monaco.languages.typescript.javascriptDefaults.getCompilerOptions());function i(t){var n=[],i=[];const a="extraModuleLibs/index.d.ts",s="file://types/extraModuleLibs/index.d.ts";if(t&&0!=t.length){var r=[],o=(Array.prototype.push.apply(r,t),{});for(let e=0;e<t.length;e++){var d=t[e],l=d.var,d=d.module,l=(l&&d&&(i.push("import "+l+"_import = require('"+d+"');\n"),n.push("var "+l+": typeof "+l+"_import;\n")),b[d]);o[d]=l||{package:"other",module:d,path:"other/"+d+".d.ts"}}Object.values(o).forEach(function(e){R(e,!1,u,function(e,t){var o;0==(r=r.filter(function(e){return e.module!=t.module})).length&&(o=i.join("")+("\ndeclare global {\n"+n.join("")+"\n}"),setTimeout(function(){u.JS[a]=monaco.languages.typescript.javascriptDefaults.addExtraLib(o,s)},500))})})}else u.JS[a]=monaco.languages.typescript.javascriptDefaults.addExtraLib(" ",s)}t?(n.lib=["esnext"],D.forEach(function(e){R(e,!1,u)})):n.lib=["esnext","dom"],monaco.languages.typescript.javascriptDefaults.setCompilerOptions(n),i(e.extraLibs);var p=monaco.editor.create(s,e);try{p._standaloneKeybindingService.addDynamicKeybinding("-editor.action.insertLineAfter",null,()=>{})}catch(e){}p.nodered={refreshModuleLibs:i};for(var d=0;d<w.length;d++){var l=w[d];p.addAction(function(t,e){return{id:"set-theme-"+t,label:RED._("monaco.setTheme")+" "+t,precondition:null,keybindingContext:e||null,run:function(e){return e.setTheme(t),null}}}(l))}function f(e,t,o){e.getOption(monaco.editor.EditorOptions.readOnly.id)?e.getModel().pushEditOperations(e.getSelections(),t,function(){return o||null}):e.executeEdits("editor",t)}function h(e,t,o){t=t||50,e?(p.focusMemory&&setTimeout(function(){o.parentElement&&p.focus()},300),p._initState&&setTimeout(function(){o.parentElement&&(p.restoreViewState(p._initState),p._initState=null)},t),"javascript"==p._mode&&"text"==p._tempMode&&(p._tempMode="",setTimeout(function(){o.parentElement&&p.setMode("javascript",void 0,!1)},t))):"javascript"==p._mode&&"text"!=p._tempMode&&o.parentElement&&(p.setMode("text",void 0,!1),p._tempMode="text")}p.selection={},(p.session=p).renderer={},p.setMode=function(e,t,o){null==o&&(o=!0),e=c(e);var n,i=p.getModel(),a=p.getValue();if(i){var s=p.getScrollTop(),r=p.getScrollLeft(),d=p.getSelections(),l=p.getPosition(),a=i.getValue()||"";try{i.isDisposed()||i.dispose()}catch(e){}p.setModel(null),n=monaco.editor.createModel(a||"",e),p.setModel(n),p.setScrollTop(s,1),p.setScrollLeft(r,1),p.setPosition(l),p.setSelections(d)}else n=monaco.editor.createModel(a||"",e),p.setModel(n);t&&"function"==typeof t&&t(),o&&this.resize()},p.getRange=function(){var e=p.getSelection();return e.start={row:e.selectionStartLineNumber-1,column:e.selectionStartColumn-1},e.end={row:e.endLineNumber-1,column:e.endColumn-1},e},p.selection.getRange=p.getRange,p.session.insert=function(e,t){f(this,[{range:new monaco.Range(e.row+1,e.column+1,e.row+1,e.column+1),text:t,forceMoveMarkers:!0}])},p.setReadOnly=function(e){p.updateOptions({readOnly:e})},p.session.replace=function(e,t){f(this,[{range:e,text:t,forceMoveMarkers:!0}])},p.selectAll=function(){var e=p.getModel().getFullModelRange();p.setSelection(e)},p.clearSelection=function(){p.setPosition({column:1,lineNumber:1})},p.getSelectedText=function(){return p.getModel().getValueInRange(p.getSelection())},p.insertSnippet=function(e){let t=p.getContribution("snippetController2");t.insert(e)},p.destroy=function(){a&&clearInterval(a);try{if(Object.keys(u.JS).length){var t=Object.entries(u.JS);for(let e=0;e<t.length;e++)try{var o=t[e][0];u.JS[o].dispose(),u.JS[o]=null,delete u.JS[o]}catch(e){}}if(Object.keys(u.TS).length){var n=Object.entries(u.TS);for(let e=0;e<n.length;e++)try{var i=n[e][0];u.TS[i].dispose(),u.TS[i]=null,delete u.TS[i]}catch(e){}}}catch(e){}try{var e=this.getModel();e&&!e.isDisposed()&&(p._initState=null,e.dispose()),this.setModel(null)}catch(e){}$(s).remove(),$(r).remove()},p.resize=function(){p.layout()},p.renderer.updateFull=p.resize.bind(p),p.getSession=function(){return p},p.getLength=function(){var e=p.getModel();return null!==e?e.getLineCount():0},p.scrollToLine=function(e,t){p.revealLine(e,t)},p.moveCursorTo=function(e,t){p.setPosition({lineNumber:e,column:t})},p.getAnnotations=function(){var e=[];try{var i,a,s,r,t=p.getModel();null!==t&&(i=t._languageId,a=t._associatedResource.authority,s=t._associatedResource.path,r=t._associatedResource.scheme,e=(monaco.editor.getModelMarkers(t)||[]).filter(function(e){var t=e.resource.authority,o=e.resource.path,n=e.resource.scheme;return e.owner==i&&t===a&&o===s&&n===r}).map(function(e){return{row:e.startLineNumber,column:e.startColumn,endColumn:e.endColumn,endRow:e.endLineNumber,text:e.message,type:monaco.MarkerSeverity[e.severity]?monaco.MarkerSeverity[e.severity].toLowerCase():e.severity}}))}catch(e){console.log("Failed to get editor Annotations",e)}return e||[]},p.gotoLine=function(e,t){p.setPosition({lineNumber:e+1,column:t+1})},p.getCursorPosition=function(){var e=p.getPosition();return{row:e.lineNumber-1,column:e.column-1}},p.setTheme=function(e){monaco.editor.setTheme(e),E=e},p.on=function(e,t){switch(e){case"change":case"input":e="onDidChangeModelContent";break;case"focus":e="onDidFocusEditorWidget";break;case"blur":e="onDidBlurEditorWidget";break;case"paste":e="onDidPaste"}var o;if(p[e])o=p[e];else{if(!monaco.editor[e])return void console.warn("monaco - unknown event: "+e);o=monaco.editor[e]}o(t)},p.getUndoManager=function(){var e={};return e.isClean=function(){try{return!1===p.getModel().canUndo()}catch(e){return!1}}.bind(p),e},p.setFontSize=function(e){p.updateOptions({fontSize:e})},p.focusMemory=o.focus,p._mode=e.language,e._language&&(p._mode=e._language,p._tempMode=e.language),p.onDidBlurEditorWidget(function(){p.focusMemory=!1,p.saveView(),0==x(s)&&h(!1,0,s)}),p.onDidFocusEditorWidget(function(){h(!0,10,s)});var g=s,m=h;try{var v={root:$(g).closest("div.red-ui-tray-content")[0]||document,attributes:!0,childList:!0};new IntersectionObserver(function(e,t){e.forEach(function(e){m(0<e.intersectionRatio,5,e.target)})},v).observe(g)}catch(e){try{let t=x(s);a=setInterval(function(){var e=x(s);e!=t&&m(e,5,g),t=e},100)}catch(e){}}return"markdown"===e.language&&($(s).addClass("red-ui-editor-text-container-toolbar"),p.toolbar=RED.editor.customEditTypes._markdown.buildToolbar(r,p),!1!==o.expandable&&(t=$('<button type="button" class="red-ui-button" style="float: right;"><i class="fa fa-expand"></i></button>').appendTo(p.toolbar),RED.popover.tooltip(t,RED._("markdownEditor.expand")),t.on("click",function(e){e.preventDefault();e=p.getValue();p.saveView(),RED.editor.editMarkdown({value:e,width:"Infinity",stateId:o.stateId,cancel:function(){p.focus()},complete:function(e,t){p.setValue(e,-1),setTimeout(function(){p.focus(),p.restoreView()},300)}})})),n=$('<button type="button" class="red-ui-editor-text-help red-ui-button red-ui-button-small"><i class="fa fa-question"></i></button>').appendTo($(s).parent()),RED.popover.create({target:n,trigger:"click",size:"small",direction:"left",content:RED._("markdownEditor.format"),autoClose:50})),p.getView=function(){return p.saveViewState()},p.saveView=function(e){var t;if(o.stateId)return window._editorStateMonaco=window._editorStateMonaco||{},t=p.getView(),window._editorStateMonaco[o.stateId]=t},p.restoreView=function(e){if(o.stateId){window._editorStateMonaco=window._editorStateMonaco||{};e=e||window._editorStateMonaco[o.stateId];if(e)try{p.type?p.restoreViewState(e):p._initState=e}catch(e){delete window._editorStateMonaco[o.stateId]}}},p.restoreView(),o.cursor&&!p._initState&&(v=o.cursor.row||o.cursor.lineNumber,e=o.cursor.column||o.cursor.col,p.gotoLine(v,e)),p.type="monaco",p}}}(),RED.eventLog=function(){var i,n=[],t=!1;return{init:function(){$('<script type="text/x-red" data-template-name="_eventLog"><div class="form-row node-text-editor-row"><div style="height: 100%;min-height: 150px;" class="node-text-editor" id="red-ui-event-log-editor"></div></div><\/script>').appendTo("#red-ui-editor-node-configs"),RED.actions.add("core:show-event-log",RED.eventLog.show)},show:function(){var e;t||(t=!0,e={title:RED._("eventLog.title"),width:1/0,buttons:[{id:"node-dialog-close",text:RED._("common.label.close"),click:function(){RED.tray.close()}}],resize:function(e){for(var t=$("#dialog-form>div:not(.node-text-editor-row)"),o=($("#dialog-form>div.node-text-editor-row"),$("#dialog-form").height()),n=0;n<t.size();n++)o-=$(t[n]).outerHeight(!0);o-=parseInt($("#dialog-form").css("marginTop"))+parseInt($("#dialog-form").css("marginBottom")),$(".node-text-editor").css("height",o+"px"),i.resize()},open:function(e){e.find(".red-ui-tray-body");e=RED.editor.buildEditForm(e.find(".red-ui-tray-body"),"dialog-form","_eventLog","editor");i=RED.editor.createEditor({mode:"ace/mode/shell",id:"red-ui-event-log-editor",value:n.join("\n"),lineNumbers:!1,readOnly:!0,options:{showPrintMargin:!1}}),setTimeout(function(){i.scrollToLine(i.getSession().getLength())},200),e.i18n()},close:function(){i.destroy(),i=null,t=!1},show:function(){}},RED.tray.show(e))},log:function(e,t){var o=new Date(t.ts).toISOString()+" ";t.type&&(o+="["+t.type+"] "),t.data&&(t=(t=t.data).endsWith("\n")?t.substring(0,t.length-1):t).split(/\n/).forEach(function(e){e=o+e,n.push(e),500<n.length&&(n=n.slice(-500)),i&&(i.getSession().insert({row:i.getSession().getLength(),column:0},"\n"+e),i.scrollToLine(i.getSession().getLength()))})},startEvent:function(e){n.push(""),n.push("-----------------------------------------------------------"),n.push((new Date).toISOString()+" "+e),n.push("")}}}(),RED.tray=function(){var h,g=[],m=!1,o=!1;function n(e){var t,o,n=$('<div class="red-ui-tray"></div>'),i=$('<div class="red-ui-tray-header editor-tray-header"></div>').appendTo(n),a=$('<div class="red-ui-tray-body-wrapper"></div>').appendTo(n),s=$('<div class="red-ui-tray-body editor-tray-body"></div>').appendTo(a),a=$('<div class="red-ui-tray-footer"></div>').appendTo(n),r=$('<div class="red-ui-tray-resize-handle"></div>').appendTo(n),d=(e.title&&((t=g.map(function(e){return e.options.title})).push(e.title),t='<ul class="red-ui-tray-breadcrumbs"><li>'+t.join("</li><li>")+"</li></ul>",$('<div class="red-ui-tray-titlebar">'+t+"</div>").appendTo(i)),e.width===1/0&&(e.maximized=!0,r.addClass("red-ui-tray-resize-maximised")),$('<div class="red-ui-tray-toolbar"></div>').appendTo(i));if(e.buttons)for(var l=0;l<e.buttons.length;l++){var c=e.buttons[l],u=$("<button>").button().appendTo(d);c.id&&u.attr("id",c.id),c.text&&u.text(c.text),c.click&&u.on("click",function(t){return function(e){$(this).hasClass("disabled")||t(e)}}(c.click)),c.class&&(u.addClass(c.class),"primary"===c.class&&(o=c))}n.appendTo(h);var p={tray:n,header:i,body:s,footer:a,options:e,primaryButton:o};function f(){$("#red-ui-header-shade").show(),$("#red-ui-editor-shade").show(),$("#red-ui-palette-shade").show(),$(".red-ui-sidebar-shade").show(),p.preferredWidth=Math.max(n.width(),500),e.maximized||s.css({minWidth:p.preferredWidth-40}),e.width?(e.width>$("#red-ui-editor-stack").position().left-8&&(e.width=$("#red-ui-editor-stack").position().left-8),n.width(e.width)):n.width(p.preferredWidth),p.width=n.width(),p.width>$("#red-ui-editor-stack").position().left-8&&(p.width=Math.max(0,$("#red-ui-editor-stack").position().left-8),n.width(p.width)),$("#red-ui-main-container").scrollLeft(0),n.css({right:-(n.width()+10)+"px",transition:"right 0.25s ease"}),v(),m=!0,setTimeout(function(){setTimeout(function(){e.width||n.width(Math.min(p.preferredWidth,$("#red-ui-editor-stack").position().left-8)),e.resize&&e.resize({width:n.width()}),e.show&&e.show(),setTimeout(function(){m=!1,b(),v()},200),e.hasOwnProperty("focusElement")?!1!==e.focusElement&&$(e.focusElement).trigger("focus"):s.find(":focusable:first").trigger("focus")},150),n.css({right:0})},0)}g.push(p),e.maximized||n.draggable({handle:r,axis:"x",start:function(e,t){n.width("auto")},drag:function(e,t){var o=h.position().left+t.position.left;o<7?t.position.left+=7-o:t.position.left>-p.preferredWidth-1&&(t.position.left=-Math.min(h.position().left-7,p.preferredWidth-1)),p.options.resize&&setTimeout(function(){p.options.resize({width:-t.position.left})},0),p.width=-t.position.left},stop:function(e,t){n.width(-t.position.left),n.css({left:""}),p.options.resize&&p.options.resize({width:-t.position.left}),p.width=-t.position.left}}),e.open?1===e.open.length?(e.open(n),f()):e.open(n,f):f()}function v(){var e,t;0<g.length&&((e=g[g.length-1]).options.maximized||e.width>$("#red-ui-editor-stack").position().left-8?(e.width=$("#red-ui-editor-stack").position().left-8,e.tray.width(e.width)):e.width<e.preferredWidth&&(e.width=Math.min($("#red-ui-editor-stack").position().left-8,e.preferredWidth),e.tray.width(e.width)),t=e.tray.height()-e.header.outerHeight()-e.footer.outerHeight(),e.body.height(t),e.options.resize&&e.options.resize({width:e.width,height:t}))}function b(){setTimeout(function(){$("#red-ui-editor-stack").css("zIndex","13")},300)}function i(){$("#red-ui-editor-stack").css("zIndex","9")}return{init:function(){h=$("#red-ui-editor-stack"),$(window).on("resize",v),RED.events.on("sidebar:resize",v),$("#red-ui-editor-shade").on("click",function(){var e;m||(e=g[g.length-1])&&e.primaryButton&&e.primaryButton.click()})},show:function(e){if(i(),e){if(o)throw new Error("Cannot add to stack whilst hidden");var t;0<g.length&&!e.overlay?(t=g[g.length-1],"inherit"===e.width&&(e.width=t.tray.width()),t.tray.css({right:-(t.tray.width()+10)+"px"}),setTimeout(function(){t.tray.detach(),n(e)},250)):(0<g.length&&g[g.length-1].tray.css("z-index",0),RED.events.emit("editor:open"),n(e))}else 0<g.length&&(g[g.length-1].tray.css({right:0}),$("#red-ui-header-shade").show(),$("#red-ui-editor-shade").show(),$("#red-ui-palette-shade").show(),$(".red-ui-sidebar-shade").show(),o=!1)},hide:function(){var e;i(),0<g.length&&((e=g[g.length-1]).tray.css({right:-(e.tray.width()+10)+"px"}),$("#red-ui-header-shade").hide(),$("#red-ui-editor-shade").hide(),$("#red-ui-palette-shade").hide(),$(".red-ui-sidebar-shade").hide(),o=!0)},resize:v,close:function(t){var o;i(),0<g.length&&((o=g.pop()).tray.css({right:-(o.tray.width()+10)+"px"}),setTimeout(function(){try{o.options.close&&o.options.close()}catch(e){}var e;o.tray.remove(),0<g.length&&((e=g[g.length-1]).options.overlay?(v(),e.options.show&&e.options.show()):(e.tray.appendTo("#red-ui-editor-stack"),setTimeout(function(){v(),e.tray.css({right:0}),e.options.show&&(b(),v(),e.options.show())},0))),t&&t(),0===g.length?($("#red-ui-header-shade").hide(),$("#red-ui-editor-shade").hide(),$("#red-ui-palette-shade").hide(),$(".red-ui-sidebar-shade").hide(),RED.events.emit("editor:close"),RED.view.focus()):g[g.length-1].tray.css("z-index","auto")},250))}}}(),RED.clipboard=function(){var m,v,o,i,c,u,r,b,e,t,a=!1,d={};function n(){m=$('<div id="red-ui-clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>').appendTo("#red-ui-editor").dialog({modal:!0,autoOpen:!1,width:700,resizable:!1,classes:{"ui-dialog":"red-ui-editor-dialog","ui-dialog-titlebar-close":"hide","ui-widget-overlay":"red-ui-editor-dialog"},buttons:[{id:"red-ui-clipboard-dialog-cancel",text:RED._("common.label.cancel"),click:function(){$(this).dialog("close"),RED.view.focus()}},{id:"red-ui-clipboard-dialog-download",class:"primary",text:RED._("clipboard.download"),click:function(){var e,t,o=$("#red-ui-clipboard-dialog-export-text").val();e="flows.json",o=o,window.navigator.msSaveBlob?(t=new Blob([o],{type:"data:text/plain;charset=utf-8"}),navigator.msSaveBlob(t,e)):((t=document.createElement("a")).setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(o)),t.setAttribute("download",e),t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t)),$(this).dialog("close"),RED.view.focus()}},{id:"red-ui-clipboard-dialog-export",class:"primary",text:RED._("clipboard.export.copy"),click:function(){var e,t,o,n,i,a,s;"red-ui-clipboard-dialog-export-tab-clipboard"===r?(e=$("#red-ui-clipboard-dialog-export-text").val(),$(this).dialog("close"),w(e),RED.notify(RED._("clipboard.nodesExported"),{id:"clipboard"}),RED.view.focus()):(t=$("#red-ui-clipboard-dialog-export-text").val(),(o=d[r].getSelected()).children||(o=o.parent),n=$("#red-ui-clipboard-dialog-tab-library-name").val().trim(),i=function(){$.ajax({url:"library/"+o.library+"/"+o.type+"/"+o.path+n,type:"POST",data:t,contentType:"application/json; charset=utf-8"}).done(function(){$(m).dialog("close"),RED.view.focus(),RED.notify(RED._("library.exportedToLibrary"),"success")}).fail(function(e,t,o){401===e.status?RED.notify(RED._("library.saveFailed",{message:RED._("user.notAuthorized")}),"error"):RED.notify(RED._("library.saveFailed",{message:e.responseText}),"error")})},o.children?(a=!1,o.children.forEach(function(e){e.label===n&&(a=!0)}),a?(m.dialog("close"),s=RED.notify(RED._("clipboard.export.exists",{file:RED.utils.sanitize(n)}),{type:"warning",fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){s.hideNotification(),m.dialog("open")}},{text:RED._("clipboard.export.overwrite"),click:function(){s.hideNotification(),i()}}]})):i()):i())}},{id:"red-ui-clipboard-dialog-ok",class:"primary",text:RED._("common.label.import"),click:function(){var e,t="red-ui-clipboard-dialog-import-opt-new"===$("#red-ui-clipboard-dialog-import-opt > a.selected").attr("id");"red-ui-clipboard-dialog-import-tab-clipboard"===r?E($("#red-ui-clipboard-dialog-import-text").val(),t):(e=d[r].getSelected()).path&&$.get("library/"+e.library+"/"+e.type+"/"+e.path,function(e){E(e,t)}),$(this).dialog("close"),RED.view.focus()}},{id:"red-ui-clipboard-dialog-import-conflict",class:"primary",text:RED._("clipboard.import.importSelected"),click:function(){var t={},e=($('#red-ui-clipboard-dialog-import-conflicts-list input[type="checkbox"]').each(function(){t[$(this).attr("data-node-id")]=this.checked?"import":"skip"}),$('.red-ui-clipboard-dialog-import-conflicts-controls input[type="checkbox"]').each(function(){$(this).attr("disabled")||(t[$(this).attr("data-node-id")]=this.checked?"replace":"copy")}),b.importOptions.importMap=t,b.importNodes.filter(function(e){return t[e.id]&&!t[e.z]||(t[e.id]=t[e.z]),"skip"!==t[e.id]}));RED.view.importNodes(e,b.importOptions),$(this).dialog("close"),RED.view.focus()}}],open:function(e,t){RED.keyboard.disable()},close:function(e){RED.keyboard.enable(),c&&(c.close(!0),u=null)}}),v=m.children(".dialog-form"),o='<div class="form-row"><label style="width:auto;margin-right: 10px;" data-i18n="common.label.export"></label><span id="red-ui-clipboard-dialog-export-rng-group" class="button-group"><a id="red-ui-clipboard-dialog-export-rng-selected" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.selected"></a><a id="red-ui-clipboard-dialog-export-rng-flow" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.current"></a><a id="red-ui-clipboard-dialog-export-rng-full" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.all"></a></span></div><div class="red-ui-clipboard-dialog-box"><div class="red-ui-clipboard-dialog-tabs"><ul id="red-ui-clipboard-dialog-export-tabs"></ul></div><div id="red-ui-clipboard-dialog-export-tabs-content" class="red-ui-clipboard-dialog-tabs-content"><div id="red-ui-clipboard-dialog-export-tab-clipboard" class="red-ui-clipboard-dialog-tab-clipboard"><div id="red-ui-clipboard-dialog-export-tab-clipboard-tab-bar"><ul id="red-ui-clipboard-dialog-export-tab-clipboard-tabs"></ul></div><div class="red-ui-clipboard-dialog-export-tab-clipboard-tab" id="red-ui-clipboard-dialog-export-tab-clipboard-preview"><div id="red-ui-clipboard-dialog-export-tab-clipboard-preview-list"></div></div><div class="red-ui-clipboard-dialog-export-tab-clipboard-tab" id="red-ui-clipboard-dialog-export-tab-clipboard-json"><div class="form-row" style="height:calc(100% - 40px)"><textarea readonly id="red-ui-clipboard-dialog-export-text"></textarea></div><div class="form-row" style="text-align: right;"><span id="red-ui-clipboard-dialog-export-fmt-group" class="button-group"><a id="red-ui-clipboard-dialog-export-fmt-mini" class="red-ui-button red-ui-button-small toggle" href="#" data-i18n="clipboard.export.compact"></a><a id="red-ui-clipboard-dialog-export-fmt-full" class="red-ui-button red-ui-button-small toggle" href="#" data-i18n="clipboard.export.formatted"></a></span></div></div></div><div class="form-row" id="red-ui-clipboard-dialog-export-tab-library-filename"><label data-i18n="clipboard.export.exportAs"></label><input id="red-ui-clipboard-dialog-tab-library-name" type="text"></div></div></div>',i='<div class="red-ui-clipboard-dialog-box" style="margin-bottom: 12px"><div class="red-ui-clipboard-dialog-tabs"><ul id="red-ui-clipboard-dialog-import-tabs"></ul></div><div id="red-ui-clipboard-dialog-import-tabs-content" class="red-ui-clipboard-dialog-tabs-content"><div id="red-ui-clipboard-dialog-import-tab-clipboard" class="red-ui-clipboard-dialog-tab-clipboard"><div class="form-row"><span data-i18n="clipboard.pasteNodes"></span> <a class="red-ui-button" id="red-ui-clipboard-dialog-import-file-upload-btn"><i class="fa fa-upload"></i> <span data-i18n="clipboard.selectFile"></span></a><input type="file" id="red-ui-clipboard-dialog-import-file-upload" accept=".json" style="display:none"></div><div class="form-row" style="height:calc(100% - 47px)"><textarea id="red-ui-clipboard-dialog-import-text"></textarea></div></div></div></div><div class="form-row"><label style="width:auto;margin-right: 10px;" data-i18n="clipboard.import.import"></label><span id="red-ui-clipboard-dialog-import-opt" class="button-group"><a id="red-ui-clipboard-dialog-import-opt-current" class="red-ui-button toggle selected" href="#" data-i18n="clipboard.export.current"></a><a id="red-ui-clipboard-dialog-import-opt-new" class="red-ui-button toggle" href="#" data-i18n="clipboard.import.newFlow"></a></span></div>',importConflictsDialog='<div class="form-row"><div class="form-row"><p data-i18n="clipboard.import.conflictNotification1"></p><p data-i18n="clipboard.import.conflictNotification2"></p></div><div class="red-ui-clipboard-dialog-import-conflicts-list-container"><div id="red-ui-clipboard-dialog-import-conflicts-list"></div></div></div>'}function s(){e&&clearTimeout(e),e=setTimeout(function(){var e=$("#red-ui-clipboard-dialog-tab-library-name"),t=e.val().trim();0<t.length&&!/[\/\\]/.test(t)?(e.removeClass("input-error"),$("#red-ui-clipboard-dialog-export").button("enable")):(e.addClass("input-error"),$("#red-ui-clipboard-dialog-export").button("disable"))},100)}function l(){var e;"red-ui-clipboard-dialog-import-tab-clipboard"===r?(t&&clearTimeout(t),t=setTimeout(function(){var t=$("#red-ui-clipboard-dialog-import-text");if(""===(n=t.val().trim()))c.close(!0),u=null,t.removeClass("input-error"),$("#red-ui-clipboard-dialog-ok").button("disable");else try{if(!/^\[[\s\S]*\]$/m.test(n))throw new Error(RED._("clipboard.import.errors.notArray"));for(var e=JSON.parse(n),o=0;o<e.length;o++){if("object"!=typeof e[o])throw new Error(RED._("clipboard.import.errors.itemNotObject",{index:o}));if(!e[o].hasOwnProperty("id"))throw new Error(RED._("clipboard.import.errors.missingId",{index:o}));if(!e[o].hasOwnProperty("type"))throw new Error(RED._("clipboard.import.errors.missingType",{index:o}))}u=null,c.close(!0),t.removeClass("input-error"),t.val(n),$("#red-ui-clipboard-dialog-ok").button("enable")}catch(e){if(""!==n){t.addClass("input-error");t=e.toString();if(t!==u){var n,i=$('<div class="red-ui-clipboard-import-error"></div>').text(t),a=/at position (\d+)/i.exec(t);if(a)l=parseInt(a[1]);else if(a=/at line (\d+) column (\d+)/i.exec(t)){for(var s=parseInt(a[1])-1,r=parseInt(a[2])-1,d=n.split("\n"),l=0,o=0;o<s;o++)l+=d[o].length+1;l+=r}void 0!==l&&(n=n.replace(/\n/g,"↵"),parseInt(a[1]),r=$("<div>").appendTo(i),a=$("<pre>").appendTo(r),$("<span>").text(n.substring(l-12,l)).appendTo(a),$('<span class="error">').text(n.charAt(l)).appendTo(a),$("<span>").text(n.substring(l+1,l+12)).appendTo(a)),c.close(!0).setContent(i).open(),u=t}}else u=null;$("#red-ui-clipboard-dialog-ok").button("disable")}},100)):(e=d[r].getSelected())&&e.label&&!e.children?$("#red-ui-clipboard-dialog-ok").button("enable"):$("#red-ui-clipboard-dialog-ok").button("disable")}function p(e){var n,t;a||(e=e||"clipboard",v.empty(),v.append($(i)),(n=RED.tabs.create({id:"red-ui-clipboard-dialog-import-tabs",vertical:!0,onchange:function(e){$("#red-ui-clipboard-dialog-import-tabs-content").children().hide(),$("#"+e.id).show(),r=e.id,c&&(c.close(!0),u=null),"red-ui-clipboard-dialog-import-tab-clipboard"===e.id?$("#red-ui-clipboard-dialog-import-text").trigger("focus"):d[e.id].focus(),l()}})).addTab({id:"red-ui-clipboard-dialog-import-tab-clipboard",label:RED._("clipboard.clipboard")}),(RED.settings.libraries||[]).forEach(function(e){var t="red-ui-clipboard-dialog-import-tab-"+e.id,o=(n.addTab({id:t,label:RED._(e.label||e.id)}),$('<div id="red-ui-clipboard-dialog-import-tab-library" class="red-ui-clipboard-dialog-tab-library"></div>').attr("id",t).hide().appendTo("#red-ui-clipboard-dialog-import-tabs-content")),o=RED.library.createBrowser({container:o,onselect:function(e){e&&e.label&&!e.children?$("#red-ui-clipboard-dialog-ok").button("enable"):$("#red-ui-clipboard-dialog-ok").button("disable")},onconfirm:function(e){e&&e.label&&!e.children&&$("#red-ui-clipboard-dialog-ok").trigger("click")}});g(o,e),d[t]=o}),$("#red-ui-clipboard-dialog-tab-library-name").on("keyup",s),$("#red-ui-clipboard-dialog-tab-library-name").on("paste",function(){setTimeout(s,10)}),$("#red-ui-clipboard-dialog-export").button("enable"),v.i18n(),$("#red-ui-clipboard-dialog-ok").show(),$("#red-ui-clipboard-dialog-cancel").show(),$("#red-ui-clipboard-dialog-export").hide(),$("#red-ui-clipboard-dialog-download").hide(),$("#red-ui-clipboard-dialog-import-conflict").hide(),$("#red-ui-clipboard-dialog-ok").button("disable"),$("#red-ui-clipboard-dialog-import-text").on("keyup",l),$("#red-ui-clipboard-dialog-import-text").on("paste",function(){setTimeout(l,10)}),0===RED.workspaces.active()?($("#red-ui-clipboard-dialog-import-opt-current").addClass("disabled").removeClass("selected"),$("#red-ui-clipboard-dialog-import-opt-new").addClass("selected")):($("#red-ui-clipboard-dialog-import-opt-current").removeClass("disabled").addClass("selected"),$("#red-ui-clipboard-dialog-import-opt-new").removeClass("selected")),$("#red-ui-clipboard-dialog-import-opt > a").on("click",function(e){e.preventDefault(),$(this).hasClass("disabled")||$(this).hasClass("selected")||($(this).parent().children().removeClass("selected"),$(this).addClass("selected"))}),$("#red-ui-clipboard-dialog-import-file-upload").on("change",function(){var e=new FileReader;e.onload=function(){$("#red-ui-clipboard-dialog-import-text").val(e.result),l()},e.readAsText($(this).prop("files")[0])}),$("#red-ui-clipboard-dialog-import-file-upload-btn").on("click",function(e){e.preventDefault(),$("#red-ui-clipboard-dialog-import-file-upload").trigger("click")}),n.activateTab("red-ui-clipboard-dialog-import-tab-"+e),"clipboard"===e&&setTimeout(function(){$("#red-ui-clipboard-dialog-import-text").trigger("focus")},100),e=400,(t=$(window).height())<600&&(e=400-(600-t)),$(".red-ui-clipboard-dialog-box").height(e),m.dialog("option","title",RED._("clipboard.importNodes")).dialog("option","width",700).dialog("open"),c=RED.popover.create({target:$("#red-ui-clipboard-dialog-import-text"),trigger:"manual",direction:"bottom",content:""}))}function f(e){var n,i,t;a||(e=e||"clipboard",v.empty(),v.append($(o)),(n=RED.tabs.create({id:"red-ui-clipboard-dialog-export-tabs",vertical:!0,onchange:function(e){$("#red-ui-clipboard-dialog-export-tabs-content").children().hide(),$("#"+e.id).show(),r=e.id,"red-ui-clipboard-dialog-export-tab-clipboard"===e.id?($("#red-ui-clipboard-dialog-export").button("option","label",RED._("clipboard.export.copy")),$("#red-ui-clipboard-dialog-download").show(),$("#red-ui-clipboard-dialog-export-tab-library-filename").hide()):($("#red-ui-clipboard-dialog-export").button("option","label",RED._("clipboard.export.export")),$("#red-ui-clipboard-dialog-download").hide(),$("#red-ui-clipboard-dialog-export-tab-library-filename").show(),d[r].focus())}})).addTab({id:"red-ui-clipboard-dialog-export-tab-clipboard",label:RED._("clipboard.clipboard")}),(RED.settings.libraries||[]).forEach(function(e){var t,o;e.readOnly||(t="red-ui-clipboard-dialog-export-tab-library-"+e.id,n.addTab({id:t,label:RED._(e.label||e.id)}),o=$('<div class="red-ui-clipboard-dialog-export-tab-library-browser red-ui-clipboard-dialog-tab-library"></div>').attr("id",t).hide().insertBefore("#red-ui-clipboard-dialog-export-tab-library-filename"),g(o=RED.library.createBrowser({container:o,folderTools:!0,onselect:function(e){e&&e.label&&!e.children&&$("#red-ui-clipboard-dialog-tab-library-name").val(e.label)}}),e),d[t]=o)}),$("#red-ui-clipboard-dialog-tab-library-name").on("keyup",s),$("#red-ui-clipboard-dialog-tab-library-name").on("paste",function(){setTimeout(s,10)}),$("#red-ui-clipboard-dialog-export").button("enable"),(t=RED.tabs.create({id:"red-ui-clipboard-dialog-export-tab-clipboard-tabs",onchange:function(e){$(".red-ui-clipboard-dialog-export-tab-clipboard-tab").hide(),$("#"+e.id).show()}})).addTab({id:"red-ui-clipboard-dialog-export-tab-clipboard-preview",label:RED._("clipboard.exportNodes")}),t.addTab({id:"red-ui-clipboard-dialog-export-tab-clipboard-json",label:RED._("editor.types.json")}),$("#red-ui-clipboard-dialog-export-tab-clipboard-preview-list").css({position:"absolute",top:0,right:0,bottom:0,left:0}).treeList({data:[]}),h(),$("#red-ui-clipboard-dialog-tab-library-name").val("flows.json").select(),v.i18n(),i=RED.settings.flowFilePretty?"red-ui-clipboard-dialog-export-fmt-full":"red-ui-clipboard-dialog-export-fmt-mini",$("#red-ui-clipboard-dialog-export-fmt-group > a").on("click",function(e){var t;e.preventDefault(),$(this).hasClass("disabled")||$(this).hasClass("selected")?$("#red-ui-clipboard-dialog-export-text").trigger("focus"):($(this).parent().children().removeClass("selected"),$(this).addClass("selected"),0<(e=$("#red-ui-clipboard-dialog-export-text").val()).length&&(t=JSON.parse(e),e="red-ui-clipboard-dialog-export-fmt-full"===(i=$(this).attr("id"))?JSON.stringify(t,null,4):JSON.stringify(t),$("#red-ui-clipboard-dialog-export-text").val(e),setTimeout(function(){$("#red-ui-clipboard-dialog-export-text").scrollTop(0)},50),$("#red-ui-clipboard-dialog-export-text").trigger("focus")))}),$("#red-ui-clipboard-dialog-export-rng-group > a").on("click",function(e){var t,o,n;e.preventDefault(),$(this).hasClass("disabled")||$(this).hasClass("selected")||($(this).parent().children().removeClass("selected"),$(this).addClass("selected"),t=$(this).attr("id").substring("red-ui-clipboard-dialog-export-rng-".length),e="",o=null,"selected"===t?(0<(n=RED.workspaces.selection()).length?(o=[],n.forEach(function(e){o.push(e),o=(o=o.concat(RED.nodes.groups(e.id))).concat(RED.nodes.filterNodes({z:e.id}))})):o=RED.view.selection().nodes||[],o=RED.nodes.createExportableNodeSet(o.filter(function(e){return"subflow"!==e.type}))):"flow"===t?(n=RED.workspaces.active(),o=(o=(o=RED.nodes.groups(n)).concat(RED.nodes.junctions(n))).concat(RED.nodes.filterNodes({z:n})),RED.nodes.eachConfig(function(e){e.z===RED.workspaces.active()&&!1===e._def.hasUsers&&o.push(e)}),n=RED.nodes.workspace(n)||RED.nodes.subflow(n),o.unshift(n),o=RED.nodes.createExportableNodeSet(o)):"full"===t&&(o=RED.nodes.createCompleteNodeSet(!1)),0<(e=null!==o?"red-ui-clipboard-dialog-export-fmt-full"===i?JSON.stringify(o,null,4):JSON.stringify(o):e).length?$("#red-ui-clipboard-dialog-export").removeClass("disabled"):$("#red-ui-clipboard-dialog-export").addClass("disabled"),$("#red-ui-clipboard-dialog-export-text").val(e),setTimeout(function(){$("#red-ui-clipboard-dialog-export-text").scrollTop(0),h(t)},50))}),$("#red-ui-clipboard-dialog-ok").hide(),$("#red-ui-clipboard-dialog-cancel").hide(),$("#red-ui-clipboard-dialog-export").hide(),$("#red-ui-clipboard-dialog-import-conflict").hide(),0===RED.workspaces.active()?($("#red-ui-clipboard-dialog-export-rng-selected").addClass("disabled").removeClass("selected"),$("#red-ui-clipboard-dialog-export-rng-flow").addClass("disabled").removeClass("selected"),$("#red-ui-clipboard-dialog-export-rng-full").trigger("click")):0<RED.workspaces.selection().length||RED.view.selection().nodes?$("#red-ui-clipboard-dialog-export-rng-selected").trigger("click"):($("#red-ui-clipboard-dialog-export-rng-selected").addClass("disabled").removeClass("selected"),$("#red-ui-clipboard-dialog-export-rng-flow").trigger("click")),("red-ui-clipboard-dialog-export-fmt-full"===i?$("#red-ui-clipboard-dialog-export-fmt-full"):$("#red-ui-clipboard-dialog-export-fmt-mini")).trigger("click"),n.activateTab("red-ui-clipboard-dialog-export-tab-"+e),t=400,(e=$(window).height())<600&&(t=400-(600-e)),$(".red-ui-clipboard-dialog-box").height(t),m.dialog("option","title",RED._("clipboard.exportNodes")).dialog("option","width",700).dialog("open"),$("#red-ui-clipboard-dialog-export-text").trigger("focus"),$("#red-ui-clipboard-dialog-cancel").show(),$("#red-ui-clipboard-dialog-export").show(),$("#red-ui-clipboard-dialog-download").show(),$("#red-ui-clipboard-dialog-import-conflict").hide())}function h(t){var e=$("#red-ui-clipboard-dialog-export-text").val()||"[]",e=JSON.parse(e),o={},n={},i=[],a=[],s=[],r=(e.forEach(function(e){"tab"===e.type?(o[e.id]={element:R(e),deferBuild:"flow"!==t,expanded:"flow"===t,children:[]},a.push(o[e.id])):"subflow"===e.type?(n[e.id]={element:x(e),deferBuild:!0,children:[]},s.push(n[e.id])):i.push(e)}),[]),d=[],e=(i.forEach(function(e){var t={element:x(e)};e.z?o[e.z]||n[e.z]?o[e.z]?o[e.z].children.push(t):n[e.z]&&n[e.z].children.push(t):d.push(t):r.push(t)}),[]);0<d.length&&(e=e.concat(d)),"flow"===t?e=e.concat(a):0<a.length&&e.push({label:RED._("menu.label.flows"),deferBuild:20<a.length,expanded:a.length<=20,children:a}),0<s.length&&e.push({label:RED._("menu.label.subflows"),deferBuild:10<s.length,expanded:s.length<=10,children:s}),0<r.length&&e.push({label:RED._("sidebar.info.globalConfig"),deferBuild:10<r.length,expanded:r.length<=10,children:r}),$("#red-ui-clipboard-dialog-export-tab-clipboard-preview-list").treeList("data",e)}function g(e,n){var t,o="fa fa-hdd-o";n.icon&&(o=("font-awesome"===(t=RED.utils.separateIconPath(n.icon)).module?"fa ":"")+t.file),e.data([{library:n.id,type:"flows",icon:o,label:RED._(n.label||n.id),path:"",expanded:!0,children:[{library:n.id,type:"flows",icon:"fa fa-cube",label:"flows",path:"",expanded:!0,children:function(t,o){RED.library.loadLibraryFolder(n.id,"flows","",function(e){o.children=e,t(e)})}}]}],!0)}function y(){$("#red-ui-drop-target").hide()}function w(e,t,o){var n,i=!1,a=document.activeElement,s=("string"!=typeof e&&(e=JSON.stringify(e,function(e,t){if(null!==t&&"object"==typeof t&&t.__enc__){if(t.hasOwnProperty("data")&&t.hasOwnProperty("length"))return i=t.data.length!==t.length,t.data;if("function"===t.type||"internal"===t.type)return;if("number"===t.type)return null;if("bigint"===t.type)return t.data.toString();if("undefined"===t.type)return}return t})),i&&(o+="_truncated"),$('<textarea type="text" id="red-ui-clipboard-hidden" tabIndex="-1">').appendTo(document.body)),e=(s.val(e).focus().select(),document.execCommand("copy"));return e&&t&&(n=RED.popover.create({target:t,direction:"left",size:"small",content:RED._(o)}),setTimeout(function(){n.close()},1e3),n.open()),s.remove(),a&&$(a).focus(),e}function E(t,e){var o=t;if("string"==typeof t)try{if(0===(t=t.trim()).length)return;o=JSON.parse(t)}catch(e){t=new Error(RED._("clipboard.invalidFlow",{message:e.message}));throw t.code="NODE_RED",t}var p,f,h,g,t={generateIds:!1,addFlow:e};try{RED.view.importNodes(o,t)}catch(e){console.log(e.importConfig),p=e.importConfig,f=o,h=t,g=RED.notify("<p>"+RED._("clipboard.import.conflictNotification1")+"</p>",{type:"info",fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){g.close()}},{text:RED._("clipboard.import.viewNodes"),click:function(){g.close();var e,t,o,n,i,a,s=p,r=f,d=h,l=[],c=!(b={importConfig:s,importNodes:r,importOptions:d});for(e in s.subflows)s.subflows.hasOwnProperty(e)&&(c||(l.push({gutter:$('<span data-i18n="menu.label.subflows"></span>'),label:"",class:"red-ui-clipboard-dialog-import-conflicts-item-header"}),c=!0),t=s.subflows[e],n=s.conflicted[t.id],a=D(t,n,i=!n),o={id:t.id,gutter:a.gutter.element,element:a.element,class:i?"":"disabled",deferBuild:!0,children:[]},l.push(o),s.zMap[e]&&s.zMap[e].forEach(function(e){var t=D(e,s.conflicted[e.id],i,a.gutter.cb);o.children.push({id:e.id,gutter:t.gutter.element,element:t.element,class:i?"":"disabled"})}));for(e in c=!1,s.tabs)s.tabs.hasOwnProperty(e)&&(c||(l.push({gutter:$('<span data-i18n="menu.label.flows"></span>'),label:"",class:"red-ui-clipboard-dialog-import-conflicts-item-header"}),c=!0),t=s.tabs[e],n=s.conflicted[t.id],a=D(t,n,i=!0),o={id:t.id,gutter:a.gutter.element,element:a.element,icon:"red-ui-icons red-ui-icons-flow",deferBuild:!0,class:i?"":"disabled",children:[]},l.push(o),s.zMap[e]&&s.zMap[e].forEach(function(e){var t=D(e,s.conflicted[e.id],i,a.gutter.cb);o.children.push({id:e.id,gutter:t.gutter.element,element:t.element,class:i?"":"disabled"})}));c=!1;var u=[];s.all.forEach(function(e){var t,o;"tab"===e.type||"subflow"===e.type||s.tabs[e.z]||s.subflows[e.z]||(o=D(e,t=s.conflicted[e.id],t=!t||!s.configs[e.id]),o={id:e.id,gutter:o.gutter.element,element:o.element,class:t?"":"disabled"},s.configs[e.id]?u.push(o):(c||(l.push({gutter:$('<span data-i18n="menu.label.nodes"></span>'),label:"",class:"red-ui-clipboard-dialog-import-conflicts-item-header"}),c=!0),l.push(o)))}),0<u.length&&(l.push({gutter:$('<span data-i18n="menu.label.displayConfig"></span>'),label:"",class:"red-ui-clipboard-dialog-import-conflicts-item-header"}),c=!0,l=l.concat(u)),v.empty(),v.append($(importConflictsDialog)),$("#red-ui-clipboard-dialog-import-conflicts-list").css({position:"absolute",top:0,right:0,bottom:0,left:0}).treeList({data:l}),v.i18n(),r=400,(d=$(window).height())<600&&(r=400-(600-d)),$(".red-ui-clipboard-dialog-box").height(r),$("#red-ui-clipboard-dialog-ok").hide(),$("#red-ui-clipboard-dialog-cancel").show(),$("#red-ui-clipboard-dialog-export").hide(),$("#red-ui-clipboard-dialog-download").hide(),$("#red-ui-clipboard-dialog-import-conflict").show(),m.dialog("option","title",RED._("clipboard.importNodes")).dialog("option","width",500).dialog("open")}},{text:RED._("clipboard.import.importCopy"),click:function(){g.close(),h.generateIds=!0,RED.view.importNodes(f,h)}}]})}}function D(e,t,o,n){var i="tab"===e.type?R(e):x(e),a=$("<div>",{class:"red-ui-clipboard-dialog-import-conflicts-controls"}).appendTo(i);return a.on("click",function(e){e.stopPropagation()}),t&&!n&&(t=$("<label><input "+(o?"":"disabled ")+'type="checkbox" data-node-id="'+e.id+'"> <span data-i18n="clipboard.import.replace"></span></label>').appendTo(a),("tab"===e.type||"subflow"!==e.type&&e.hasOwnProperty("x")&&e.hasOwnProperty("y"))&&t.hide()),{element:i,gutter:function(e,t,o){var n=$("<label>",{class:"red-ui-clipboard-dialog-import-conflicts-gutter"}),e=$('<input data-node-id="'+e.id+'" type="checkbox" '+(t?"checked":"")+">").appendTo(n);o&&(e.attr("disabled",!0),o.addChild(e));n.on("click",function(e){e.stopPropagation()}),e.on("change",function(e){var t=this.checked;n.parent().toggleClass("disabled",!t),n.parent().find('.red-ui-clipboard-dialog-import-conflicts-controls input[type="checkbox"]').attr("disabled",!t),i.forEach(function(e){e.attr("checked",t),e.trigger("change")})});var i=[];return{cb:{addChild:function(e){i.push(e)}},element:n}}(e,o,n)}}function R(e){(e=JSON.parse(JSON.stringify(e)))._def=RED.nodes.getType(e.type)||{},e._def&&(e._=e._def._);var t=$("<div>",{class:"red-ui-info-outline-item red-ui-info-outline-item-flow"}),o=$("<div>",{class:"red-ui-search-result-description red-ui-info-outline-item-label"}).appendTo(t),e="string"==typeof e?e:e.label,n=e.indexOf("\\n");return-1<n&&(e=e.substring(0,n)+"..."),o.text(e),t}function x(e){(e=JSON.parse(JSON.stringify(e)))._def=RED.nodes.getType(e.type)||{},e._def&&(e._=e._def._);var t=$("<div>",{class:"red-ui-node-list-item"});return RED.utils.createNodeIcon(e,!0).appendTo(t),t}return{init:function(){n(),RED.actions.add("core:show-export-dialog",f),RED.actions.add("core:show-import-dialog",p),RED.actions.add("core:show-library-export-dialog",function(){f("library")}),RED.actions.add("core:show-library-import-dialog",function(){p("library")}),RED.actions.add("core:show-examples-import-dialog",function(){p("examples")}),RED.events.on("editor:open",function(){a=!0}),RED.events.on("editor:close",function(){a=!1}),RED.events.on("search:open",function(){a=!0}),RED.events.on("search:close",function(){a=!1}),RED.events.on("actionList:open",function(){a=!0}),RED.events.on("actionList:close",function(){a=!1}),RED.events.on("type-search:open",function(){a=!0}),RED.events.on("type-search:close",function(){a=!1}),$('<div id="red-ui-drop-target"><div data-i18n="[append]workspace.dropFlowHere"><i class="fa fa-download"></i><br></div></div>').appendTo("#red-ui-editor"),RED.keyboard.add("#red-ui-drop-target","escape",y),$("#red-ui-workspace-chart").on("dragenter",function(e){-1==$.inArray("text/plain",e.originalEvent.dataTransfer.types)&&-1==$.inArray("Files",e.originalEvent.dataTransfer.types)||$("#red-ui-drop-target").css({display:"table"}).focus()}),$("#red-ui-drop-target").on("dragover",function(e){-1==$.inArray("text/plain",e.originalEvent.dataTransfer.types)&&-1==$.inArray("Files",e.originalEvent.dataTransfer.types)||e.preventDefault()}).on("dragleave",function(e){y()}).on("drop",function(e){try{var t,o,n,i;-1!=$.inArray("text/plain",e.originalEvent.dataTransfer.types)?E(t=(t=e.originalEvent.dataTransfer.getData("text/plain")).substring(t.indexOf("["),t.lastIndexOf("]")+1)):-1!=$.inArray("Files",e.originalEvent.dataTransfer.types)&&1===(o=e.originalEvent.dataTransfer.files).length&&(n=o[0],(i=new FileReader).onload=function(e){E(e.target.result)},i.readAsText(n))}catch(e){}y(),e.preventDefault()})},import:p,export:f,copyText:w}}(),RED.library=function(){var a,c,s,u,e;function r(n,i,a,t){$.getJSON("library/"+n+"/"+i+"/"+a,function(e){e=e.map(function(e){return"string"==typeof e?{library:n,type:i,icon:"fa fa-folder",label:e,path:a+e+"/",children:function(t,o){r(n,i,a+e+"/",function(e){o.children=e,t(e)})}}:{library:n,type:i,icon:"fa fa-file-o",label:e.fn,path:a+e.fn,props:e}});e.sort(function(e,t){return e.children&&!t.children?-1:!e.children&&t.children?1:e.label.localeCompare(t.label)}),t(e)})}function t(t){e&&clearTimeout(e),e=setTimeout(function(){var e=t.val().trim();0<e.length&&!/[\/\\]/.test(e)?(t.removeClass("input-error"),$("#red-ui-library-dialog-save-button").button("enable")):(t.addClass("input-error"),$("#red-ui-library-dialog-save-button").button("disable"))},100)}return{init:function(){$('<div id="red-ui-library-dialog-save" class="hide"><form class="form-horizontal"><div class="red-ui-library-dialog-box" style="height: 400px; position:relative; "><div id="red-ui-library-dialog-save-browser"></div><div class="form-row"><label data-i18n="clipboard.export.exportAs"></label><input id="red-ui-library-dialog-save-filename" type="text"></div></div></form></div>').appendTo("#red-ui-editor").i18n(),$('<div id="red-ui-library-dialog-load" class="hide"><form class="form-horizontal"><div class="red-ui-library-dialog-box" style="height: 400px; position:relative; "><div id="red-ui-library-dialog-load-panes"><div class="red-ui-panel" id="red-ui-library-dialog-load-browser"></div><div class="red-ui-panel"><div id="red-ui-library-dialog-load-preview"><div class="red-ui-panel" id="red-ui-library-dialog-load-preview-text" style="position:relative; height: 50%; overflow-y: hidden;"></div><div class="red-ui-panel" id="red-ui-library-dialog-load-preview-details"><table id="red-ui-library-dialog-load-preview-details-table" class="red-ui-info-table"></table></div></div></div></div></div></form></div>').appendTo("#red-ui-editor").i18n(),$("#red-ui-library-dialog-save").dialog({title:RED._("library.saveToLibrary"),modal:!0,autoOpen:!1,width:800,resizable:!1,open:function(e,t){RED.keyboard.disable()},close:function(e,t){RED.keyboard.enable()},classes:{"ui-dialog":"red-ui-editor-dialog","ui-dialog-titlebar-close":"hide","ui-widget-overlay":"red-ui-editor-dialog"},buttons:[{text:RED._("common.label.cancel"),click:function(){$(this).dialog("close")}},{id:"red-ui-library-dialog-save-button",text:RED._("common.label.save"),class:"primary",click:function(){for(var t,e,o=u.elementPrefix||"node-input-",n=$("#"+o+"name").val().trim(),i=(""===n&&(n=RED._("library.unnamedType",{type:u.type})),$("#red-ui-library-dialog-save-filename").val().trim()),a=c.getSelected(),s=(a.children||(a=a.parent),{}),r=0;r<u.fields.length;r++){var d=u.fields[r];"name"===d?s.name=n:"object"==typeof d?s[d.name]=d.get():s[d]=$("#"+o+d).val()}function l(){$.ajax({url:"library/"+a.library+"/"+a.type+"/"+a.path+i,type:"POST",data:JSON.stringify(s),contentType:"application/json; charset=utf-8"}).done(function(e,t,o){RED.notify(RED._("library.savedType",{type:u.type}),"success")}).fail(function(e,t,o){401===e.status?RED.notify(RED._("library.saveFailed",{message:RED._("user.notAuthorized")}),"error"):RED.notify(RED._("library.saveFailed",{message:e.responseText}),"error")})}s.text=u.editor.getValue(),a.children?(t=!1,a.children.forEach(function(e){e.label===i&&(t=!0)}),t?($("#red-ui-library-dialog-save").dialog("close"),e=RED.notify(RED._("clipboard.export.exists",{file:RED.utils.sanitize(i)}),{type:"warning",fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){e.hideNotification(),$("#red-ui-library-dialog-save").dialog("open")}},{text:RED._("clipboard.export.overwrite"),click:function(){e.hideNotification(),l()}}]})):l()):l(),$(this).dialog("close")}}]}),c=RED.library.createBrowser({container:$("#red-ui-library-dialog-save-browser"),folderTools:!0,onselect:function(e){e.label&&(e.children||($("#red-ui-library-dialog-save-filename").val(e.label),e=e.parent),!1===e.writable?$("#red-ui-library-dialog-save-button").button("disable"):$("#red-ui-library-dialog-save-button").button("enable"))}}),$("#red-ui-library-dialog-save-filename").on("keyup",function(){t($(this))}),$("#red-ui-library-dialog-save-filename").on("paste",function(){var e=$(this);setTimeout(function(){t(e)},10)}),$("#red-ui-library-dialog-load").dialog({modal:!0,autoOpen:!1,width:800,resizable:!1,classes:{"ui-dialog":"red-ui-editor-dialog","ui-dialog-titlebar-close":"hide","ui-widget-overlay":"red-ui-editor-dialog"},buttons:[{text:RED._("common.label.cancel"),click:function(){$(this).dialog("close")}},{text:RED._("common.label.load"),class:"primary",click:function(){if(selectedLibraryItem){for(var e=u.elementPrefix||"node-input-",t=0;t<u.fields.length;t++){var o,n=u.fields[t];"object"==typeof n?(o=selectedLibraryItem[n.name],n.set(o)):$("#"+e+n).val(selectedLibraryItem[n])}u.editor.setValue(s.getValue(),-1)}$(this).dialog("close")}}],open:function(e){RED.keyboard.disable(),$(this).parent().find(".ui-dialog-titlebar-close").hide(),s.resize()},close:function(e){RED.keyboard.enable(),s&&(s.destroy(),s=null)}}),a=RED.library.createBrowser({container:$("#red-ui-library-dialog-load-browser"),onselect:function(n){var i=$("#red-ui-library-dialog-load-preview-details-table").empty();selectedLibraryItem=n.props,n&&n.label&&!n.children?$.get("library/"+n.library+"/"+n.type+"/"+n.path,function(e){var t,o=$('<tr class="red-ui-help-info-row"><td>Type</td><td></td></tr>').appendTo(i);for(t in $(o.children()[1]).text(u.type),n.props.hasOwnProperty("name")&&(o=$('<tr class="red-ui-help-info-row"><td>Name</td><td>'+n.props.name+"</td></tr>").appendTo(i),$(o.children()[1]).text(n.props.name)),n.props)n.props.hasOwnProperty(t)&&"name"!==t&&"fn"!==t&&(o=$('<tr class="red-ui-help-info-row"><td></td><td></td></tr>').appendTo(i),$(o.children()[0]).text(t),RED.utils.createObjectElement(n.props[t]).appendTo(o.children()[1]));s.setValue(e,-1)}):s.setValue("",-1)}}),RED.panels.create({container:$("#red-ui-library-dialog-load-panes"),dir:"horizontal",resize:function(){s.resize()}}),RED.panels.create({container:$("#red-ui-library-dialog-load-preview"),dir:"vertical",resize:function(){s.resize()}})},create:function(n){var i=n.elementPrefix||"node-input-";n.editor.setText&&(n.editor.setValue=function(e,t){n.editor.setText.call(n.editor,e)}),n.editor.getText&&(n.editor.getValue=n.editor.getText),$("#"+i+"name").css("width","calc(100% - 52px)").after('<div style="margin-left:5px; display: inline-block;position: relative;"><a id="node-input-'+n.type+'-lookup" class="red-ui-button"><i class="fa fa-book"></i> <i class="fa fa-caret-down"></i></a></div>'),RED.menu.init({id:"node-input-"+n.type+"-lookup",options:[{id:"node-input-"+n.type+"-menu-open-library",label:RED._("library.openLibrary"),onselect:function(){var e={id:"red-ui-library-dialog-load-preview-text",mode:n.mode,readOnly:!0,highlightActiveLine:!1,highlightGutterLine:!1,contextmenu:!1},t=((s=RED.editor.createEditor(e)).isACE&&(n.mode&&s.getSession().setMode(n.mode),s.setOptions({readOnly:!0,highlightActiveLine:!1,highlightGutterLine:!1}),s.renderer.$cursorLayer.element.style.opacity=0,s.$blockScrolling=1/0),u=n,[]),e=((RED.settings.libraries||[]).forEach(function(e){e.types&&-1===e.types.indexOf(n.url)||t.push({library:e.id,type:n.url,icon:e.icon||"fa fa-hdd-o",label:RED._(e.label||e.id),path:"",expanded:!0,writable:!1,children:[{library:e.id,type:n.url,icon:"fa fa-cube",label:n.type,path:"",expanded:!1,children:function(t,o){r(e.id,n.url,"",function(e){o.children=e,t(e)})}}]})}),a.data(t),setTimeout(function(){a.select(t[0].children[0])},200),400),o=$(window).height();o<570&&(e=400-(570-o)),$("#red-ui-library-dialog-load .red-ui-library-dialog-box").height(e),$("#red-ui-library-dialog-load").dialog("option","title",RED._("library.typeLibrary",{type:n.type})).dialog("open")}},{id:"node-input-"+n.type+"-menu-save-library",label:RED._("library.saveToLibrary"),onselect:function(){u=n;var e=$("#"+i+"name").val().replace(/(^\s*)|(\s*$)/g,"").replace(/[^\w-]/g,"-"),t=(""===e&&(e="unnamed-"+n.type),$("#red-ui-library-dialog-save-filename").attr("value",e+"."+(n.ext||"txt")),[]),e=((RED.settings.libraries||[]).forEach(function(e){e.types&&-1===e.types.indexOf(n.url)||t.push({library:e.id,type:n.url,icon:e.icon||"fa fa-hdd-o",label:RED._(e.label||e.id),path:"",expanded:!0,writable:!1,children:[{library:e.id,type:n.url,icon:"fa fa-cube",label:n.type,path:"",expanded:!1,children:function(t,o){r(e.id,n.url,"",function(e){o.children=e,t(e)})}}]})}),c.data(t),setTimeout(function(){c.select(t[0].children[0])},200),400),o=$(window).height();o<570&&(e=400-(570-o)),$("#red-ui-library-dialog-save .red-ui-library-dialog-box").height(e),$("#red-ui-library-dialog-save").dialog("open")}}]})},createBrowser:function(o){var e=$('<div class="red-ui-library-browser"></div>').appendTo(o.container),n=$("<div>").css({width:"100%",height:"100%"}).appendTo(e).treeList({}).on("treelistselect",function(e,t){o.onselect&&o.onselect(t)}).on("treelistconfirm",function(e,t){o.onconfirm&&o.onconfirm(t)}),i=null;return o.folderTools&&n.on("treelistselect",function(e,t){var o;!1!==t.writable&&t.treeList&&(i&&i.remove(),i=$("<div>").css({position:"absolute",bottom:"6px",right:"8px"}),o=$('<button class="red-ui-button red-ui-button-small" type="button"><i class="fa fa-ellipsis-h"></i></button>').on("click",function(e){e.preventDefault(),e.stopPropagation();var e=o.offset(),t=RED.menu.init({id:"red-ui-library-browser-menu",options:[{id:"red-ui-library-browser-menu-addFolder",label:RED._("library.newFolder"),onselect:function(){var o="new-folder",s={},r=n.treeList("selected");(r=r.children?r:r.parent).treeList.expand(function(){r.children.forEach(function(e){/^new-folder/.test(e.label)&&(s[e.label]=!0)});for(var e=2;s[o];)o="new-folder-"+e++;r.treeList.expand();function t(){var e=i.val().trim();if(""===e)n();else{for(var t=0;t<r.children.length;t++)if(r.children[t].label===e)return n();a.treeList.remove();var o={library:r.library,type:r.type,icon:"fa fa-folder",children:[],label:e,path:a.path+e+"/"};r.treeList.addChild(o,!0)}}function n(){a.treeList.remove()}var i=$('<input type="text" class="red-ui-treeList-input">').val(o),a={icon:"fa fa-folder-o",children:[],path:r.path,element:i};i.on("keydown",function(e){e.stopPropagation(),13===e.keyCode?t():27===e.keyCode&&n()}),i.on("blur",function(){t()}),r.treeList.addChild(a),setTimeout(function(){i.trigger("focus"),i.select()},400)})}}]}).on("mouseleave",function(){$(this).remove(),n.focus()}).on("mouseup",function(){var e=$(this);e.hide(),n.focus(),setTimeout(function(){e.remove()},100)}).appendTo("body");t.css({position:"absolute",top:e.top+"px",left:e.left-t.width()+20+"px"}).show()}).appendTo(i),i.appendTo(t.treeList.label))}),{select:function(e){n.treeList("select",e)},getSelected:function(){return n.treeList("selected")},focus:function(){n.focus()},data:function(e,t){n.treeList("data",e),t&&setTimeout(function(){n.treeList("select",e[0])},100)}}},export:function(){console.warn("Deprecated call to RED.library.export")},loadLibraryFolder:r}}(),RED.notifications=function(){var e,m,v={},b={show:function(){e++,$("#red-ui-full-shade").show()},hide:function(){0===--e&&$("#red-ui-full-shade").hide()}},y=[],w=e=0;function t(e,i,a,s){var r={};if(null!==i&&"object"==typeof i?(a=(r=i).fixed,s=r.timeout,i=r.type):(r.type=i,r.fixed=a,r.timeout=r.timeout),r.id&&v.hasOwnProperty(r.id))return v[r.id].update(e,r),v[r.id];if(r.modal&&b.show(),4<y.length)for(var t=y.length,o=0;4<t&&o<y.length;o+=1){var n=y[o];n.fixed||(window.clearTimeout(n.timeoutid),n.close(),--t)}var d,l,c,u,p,f,h,g=document.createElement("div");return g.id="red-ui-notification-"+w,g.className="red-ui-notification",g.options=r,g.fixed=a,i&&(g.className="red-ui-notification red-ui-notification-"+i),r.width&&(d=$("#red-ui-notifications").width(),r.width>d&&(d=-(r.width-d)/2,$(g).css({width:r.width+"px",marginLeft:d+"px"}))),g.style.display="none","string"==typeof e?(/<p>/i.test(e)||(e="<p>"+e+"</p>"),g.innerHTML=e):$(g).append(e),r.buttons&&(l=$('<div class="ui-dialog-buttonset"></div>').appendTo(g),r.buttons.forEach(function(e){var t=$("<button>").html(e.text).on("click",e.click).appendTo(l);e.id&&t.attr("id",e.id),e.class&&t.addClass(e.class)})),$("#red-ui-notifications").append(g),RED.notifications.hide||$(g).slideDown(300),g.close=(c=g,function(){c.closed||(c.closed=!0,y.splice(y.indexOf(c),1),r.id&&(delete v[r.id],0===Object.keys(v).length&&m.hide()),RED.notifications.hide?c.parentNode.removeChild(c):$(c).slideUp(300,function(){c.parentNode.removeChild(c)}),c.options.modal&&b.hide())}),g.hideNotification=(u=g,function(){u.closed||(u.hidden=!0,RED.notifications.hide||$(u).slideUp(300))}),g.showNotification=(p=g,function(){!p.closed&&p.hidden&&(p.hidden=!1,RED.notifications.hide||$(p).slideDown(300))}),g.update=(f=g,function(e,t){var o,n;"string"==typeof e?(/<p>/i.test(e)||(e="<p>"+e+"</p>"),f.innerHTML=e):$(f).empty().append(e),"number"==typeof t?f.options.timeout=o=t:void 0!==t&&(!r.modal&&t.modal?(f.options.modal=!0,b.show()):r.modal&&!1===t.modal&&(f.options.modal=!1,b.hide()),(e=t.hasOwnProperty("type")?t.type:i)&&(g.className="red-ui-notification red-ui-notification-"+e),a&&!1!==t.fixed||(o=(t.hasOwnProperty("timeout")?t.timeout:s)||5e3),t.buttons&&(n=$('<div style="margin-top: 20px;" class="ui-dialog-buttonset"></div>').appendTo(f),t.buttons.forEach(function(e){var t=$("<button>").text(e.text).on("click",e.click).appendTo(n);e.id&&t.attr("id",e.id),e.class&&t.addClass(e.class)}))),$(f).off("click.red-ui-notification-close"),void 0!==o&&0<o?(window.clearTimeout(f.timeoutid),f.timeoutid=window.setTimeout(f.close,o),setTimeout(function(){$(f).on("click.red-ui-notification-close",function(){f.close(),window.clearTimeout(f.timeoutid)})},50)):window.clearTimeout(f.timeoutid),f.hidden?f.showNotification():t&&t.silent||($(f).addClass("red-ui-notification-shake-horizontal"),setTimeout(function(){$(f).removeClass("red-ui-notification-shake-horizontal")},300))}),a||($(g).on("click.red-ui-notification-close",(h=g,function(){h.close(),window.clearTimeout(h.timeoutid)})),g.timeoutid=window.setTimeout(g.close,s||5e3)),y.push(g),r.id&&(v[r.id]=g,r.fixed&&m.show()),w+=1,g}return{init:function(){$('<div id="red-ui-notifications"></div>').appendTo("#red-ui-editor"),m=$("<li></li>").prependTo(".red-ui-header-toolbar").hide(),$('<a class="button" href="#"><i class="fa fa-warning"></i></a>').appendTo(m).on("click",function(){for(var e in v)v.hasOwnProperty(e)&&v[e].showNotification()})},notify:RED.notify=t}}(),RED.search=function(){var s,r,o,n=!1,a=null,d=-1,l=!1,c=[],m={},u=[],p=[],f=0;function h(t,o,e){if("string"==typeof e||"number"==typeof e)e=(""+e).toLowerCase(),m[e]=m[e]||{},m[e][t.id]={node:t,label:o};else if(Array.isArray(e))e.forEach(function(e){h(t,o,e)});else if("object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&h(t,o,e[n])}function v(e,t,o){var n=new RegExp("(?:^| )is:"+t+"(?: |$)");return n.exec(e)&&(e=e.replace(n," ").trim(),o[t]=!0),e}function b(e,t,o){for(var n,i=new RegExp("(?:^| )"+t+":([^ ]+)(?: |$)");n=i.exec(e);)e=e.replace(i," ").trim(),o[t]=o[t]||[],o[t].push(n[1]);return e}function g(t){var o,e,n=[],i=/(?:^| )type:([^ ]+)/.exec(t),a=(i&&(t=t.replace(/(?:^| )type:[^ ]+/,""),o=i[1]),{}),i=(t=v(t,"invalid",a),t=v(t,"unused",a),t=v(t,"config",a),t=v(t,"subflow",a),t=v(t,"hidden",a),t=b(t=v(t,"modified",a),"flow",a),t=(t=b(t,"uses",a)).trim(),0<Object.keys(a).length);if(a.flow&&0<=a.flow.indexOf("current")&&(e=a.flow.indexOf("current"),a.flow[e]=RED.workspaces.active()),a.flow&&a.flow.length&&(a.flow=[...new Set(a.flow)]),0<t.length||o||i){t=t.toLowerCase();var s,r=[],d={};let e=[];for(e=a.uses||Object.keys(m),s=0;s<e.length;s++){var l=e[s],c=e[s].indexOf(t);if(-1<c)for(var u=Object.keys(m[l]||{}),p=0;p<u.length;p++){var f=m[l][u[p]],h="config"===f.node._def.category&&"group"!==f.node.type;if(!a.uses||l!==f.node.id){if(a.hasOwnProperty("invalid")){var g=!f.node.hasOwnProperty("valid")||f.node.valid;if(a.invalid===g)continue}if((!a.hasOwnProperty("config")||a.config===h)&&(!a.hasOwnProperty("subflow")||a.subflow===("subflow"===f.node.type))&&(!a.hasOwnProperty("modified")||f.node.changed||f.node.moved)){if(a.hasOwnProperty("hidden")){if("tab"!==f.node.type)continue;if(!RED.workspaces.isHidden(f.node.id))continue}if(a.hasOwnProperty("unused")){g="subflow"===f.node.type&&0===f.node.instances.length||h&&0===f.node.users.length&&!1!==f.node._def.hasUsers;if(a.unused!==g)continue}a.hasOwnProperty("flow")&&a.flow.indexOf(f.node.z||f.node.id)<0||o&&f.node.type!==o||(d[f.node.id]=d[f.node.id]={node:f.node,label:f.label},d[f.node.id].index=Math.min(d[f.node.id].index||1/0,c))}}}}for((r=Object.keys(d)).sort(function(e,t){return d[e].index-d[t].index}),s=0;s<r.length;s++)n.push(d[r[s]])}return n}function y(){var e,t,o,n=r.find("li.selected");1===n.length&&(t=(e=r.parent()).height(),e.scrollTop(),t<(o=n.position().top)+(n=n.height())?e.animate({scrollTop:"-="+(t-(o+n)-10)},50):o<0&&e.animate({scrollTop:"+="+(o-10)},50))}function w(){0<c.length&&(r.editableList("addItem",{historyHeader:!0}),c.forEach(function(e){r.editableList("addItem",{history:!0,value:e})}))}function E(e){var t=s.val(),o=c.indexOf(t);-1<o&&c.splice(o,1),c.unshift(t),$("#red-ui-view-searchtools-search").data("term",t),R(0,0<(p=Object.assign([],u)).length),RED.view.reveal(e.id)}function e(){var e;n?x():r&&p.length?(0<f?f--:f=p.length-1,(e=p[f])&&e.node&&e.node.id&&(RED.view.reveal(e.node.id),$("#red-ui-view-searchtools-prev").trigger("focus")),x()):D()}function t(){var e;n?x():r&&p.length?(f<p.length-1?f++:f=0,(e=p[f])&&e.node&&e.node.id&&(RED.view.reveal(e.node.id),$("#red-ui-view-searchtools-next").trigger("focus")),x()):D()}function D(e){var t;n?x():(l||(o=document.activeElement,$("#red-ui-header-shade").show(),$("#red-ui-editor-shade").show(),$("#red-ui-palette-shade").show(),$("#red-ui-sidebar-shade").show(),$("#red-ui-sidebar-separator").hide(),null===a?(a=$("<div>",{id:"red-ui-search",class:"red-ui-search"}).appendTo("#red-ui-main-container"),t=$("<div>",{class:"red-ui-search-container"}).appendTo(a),s=$('<input type="text" data-i18n="[placeholder]menu.label.searchInput">').appendTo(t).searchBox({delay:200,change:function(){r.editableList("empty"),d=-1;var e=$(this).val();if(""===e)w();else if(0<(u=g(e)).length){for(let e=0;e<Math.min(u.length,25);e++)r.editableList("addItem",u[e]);25<u.length&&r.editableList("addItem",{more:{results:u,start:25}})}else r.editableList("addItem",{})},options:L()}),$('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-caret-right"></button>').appendTo(t).on("click",function(e){e.preventDefault(),RED.sidebar.info.outliner.search(s.val()),R()}),s.on("keydown",function(e){if(0<u.length)if(40===e.keyCode)o=r.children(),d<o.length-1&&(-1<d&&$(o[d]).removeClass("selected"),d++),$(o[d]).addClass("selected"),y(),e.preventDefault();else if(38===e.keyCode)o=r.children(),0<d&&(d<o.length&&$(o[d]).removeClass("selected"),d--),$(o[d]).addClass("selected"),y(),e.preventDefault();else if(13===e.keyCode){var t,o=r.children();if($(o[d]).hasClass("red-ui-search-more"))if(t=$(o[d]).find(".red-ui-editableList-item-content").data("data")){for(r.editableList("removeItem",t),i=t.more.start;i<Math.min(u.length,t.more.start+25);i++)r.editableList("addItem",u[i]);u.length>t.more.start+25&&r.editableList("addItem",{more:{results:u,start:t.more.start+25}})}$(o[d]).hasClass("red-ui-search-history")?(t=$(o[d]).find(".red-ui-editableList-item-content").data("data"))&&s.searchBox("value",t.value):$(o[d]).hasClass("red-ui-search-historyHeader")||0<u.length&&(f=Math.max(0,d),E(u[f].node))}}),s.i18n(),t=$("<div>",{class:"red-ui-search-results-container"}).appendTo(a),r=$("<ol>",{style:"position: absolute;top: 5px;bottom: 5px;left: 5px;right: 5px;"}).appendTo(t).editableList({addButton:!1,addItem:function(e,t,o){var n,i,a=o.node;o.historyHeader?(e.parent().addClass("red-ui-search-historyHeader"),$("<div>",{class:"red-ui-search-empty"}).text(RED._("search.history")).appendTo(e),$('<button type="button" class="red-ui-button red-ui-button-small"></button>').text(RED._("search.clear")).appendTo(e).on("click",function(e){e.preventDefault(),c=[],r.editableList("empty")})):o.history?(e.parent().addClass("red-ui-search-history"),(n=$("<a>",{href:"#",class:"red-ui-search-result"}).appendTo(e)).text(o.value),n.on("click",function(e){e.preventDefault(),s.searchBox("value",o.value),s.focus()}),$('<button type="button" class="red-ui-button red-ui-button-small"><i class="fa fa-remove"></i></button>').appendTo(e).on("click",function(e){e.preventDefault();e=c.indexOf(o.value);c.splice(e,1),r.editableList("removeItem",o)})):o.more?(e.parent().addClass("red-ui-search-more"),(n=$("<a>",{href:"#",class:"red-ui-search-result red-ui-search-empty"}).appendTo(e)).text(RED._("palette.editor.more",{count:o.more.results.length-o.more.start})),n.on("click",function(e){for(e.preventDefault(),r.editableList("removeItem",o),t=o.more.start;t<Math.min(u.length,o.more.start+25);t++)r.editableList("addItem",u[t]);u.length>o.more.start+25&&r.editableList("addItem",{more:{results:u,start:o.more.start+25}})})):void 0===a?$("<div>",{class:"red-ui-search-empty"}).text(RED._("search.empty")).appendTo(e):(a._def,n=$("<a>",{href:"#",class:"red-ui-search-result"}).appendTo(e),RED.utils.createNodeIcon(a).appendTo(n),e=$("<div>",{class:"red-ui-search-result-node-description"}).appendTo(n),a.z&&(i=(i=RED.nodes.workspace(a.z))?"flow:"+i.label:"subflow:"+(i=RED.nodes.subflow(a.z)).name,$("<div>",{class:"red-ui-search-result-node-flow"}).text(i).appendTo(e)),$("<div>",{class:"red-ui-search-result-node-label"}).text(o.label||a.id).appendTo(e),$("<div>",{class:"red-ui-search-result-node-type"}).text(a.type).appendTo(e),$("<div>",{class:"red-ui-search-result-node-id"}).text(a.id).appendTo(e),n.on("click",function(e){e.preventDefault(),f=t,E(a)}))},scrollOnAdd:!1})):r.editableList("empty"),a.slideDown(300),s.searchBox("value",e),e&&""!==e||w(),RED.events.emit("search:open"),l=!0),s.trigger("focus"))}function R(e,t){l&&(l=!1,$("#red-ui-header-shade").hide(),$("#red-ui-editor-shade").hide(),$("#red-ui-palette-shade").hide(),$("#red-ui-sidebar-shade").hide(),$("#red-ui-sidebar-separator").show(),null!==a&&a.slideUp(200,function(){s.searchBox("value","")}),RED.events.emit("search:close"),!o||t&&p.length||$(o).trigger("focus"),o=null),t||j(),x(),t&&p.length&&$("#red-ui-view-searchtools-next").trigger("focus")}function x(){if(!n&&0<=f&&p&&p.length){let e=$("#red-ui-view-searchtools-search").data("term")||"";var t={term:e=16<e.length?e.substring(0,12)+"...":e,result:f+1,count:p.length};$("#red-ui-view-searchtools-counter").text(RED._("actions.search-counter",t)),$("#view-search-tools > :not(:first-child)").show()}else j(),$("#view-search-tools > :not(:first-child)").hide()}function _(){m={}}function k(e){{var t=e,o=RED.utils.getNodeLabel(t),n=(o&&(o=(""+o).toLowerCase(),m[o]=m[o]||{},m[o][t.id]={node:t,label:o}),o=o||t.label||t.name||t.id||"",["id","type","name","label","info"]);const s=t&&t._def;if(s&&(s.defaults&&(n=n.concat(Object.keys(s.defaults))),"group"!==t.type&&s.paletteLabel&&s.paletteLabel!==s.type))try{var i=(""+("function"==typeof s.paletteLabel?s.paletteLabel.call(s):s.paletteLabel)).toLowerCase();i&&i!==(""+s.type).toLowerCase()&&h(t,o,i)}catch(e){console.warn("error indexing "+o,e)}for(var a=0;a<n.length;a++)!t.hasOwnProperty(n[a])||"group"===t.type&&"nodes"===n[a]||h(t,o,t[n[a]])}}function T(e){for(var t=Object.keys(m),o=0,n=t.length;o<n;o++)delete m[t[o]][e.id],0===Object.keys(m[t[o]]).length&&delete m[t[o]]}function C(e){T(e),k(e)}function j(){p=[],f=0,$("#red-ui-view-searchtools-search").data("term","")}function L(){return[{label:RED._("search.options.configNodes"),value:"is:config"},{label:RED._("search.options.unusedConfigNodes"),value:"is:config is:unused"},{label:RED._("search.options.modifiedNodes"),value:"is:modified"},{label:RED._("search.options.invalidNodes"),value:"is:invalid"},{label:RED._("search.options.uknownNodes"),value:"type:unknown"},{label:RED._("search.options.unusedSubflows"),value:"is:subflow is:unused"},{label:RED._("search.options.hiddenFlows"),value:"is:hidden"},{label:RED._("search.options.thisFlow"),value:"flow:current"}]}return{init:function(){RED.actions.add("core:search",D),RED.actions.add("core:search-previous",e),RED.actions.add("core:search-next",t),RED.events.on("editor:open",function(){n=!0}),RED.events.on("editor:close",function(){n=!1}),RED.events.on("type-search:open",function(){n=!0}),RED.events.on("type-search:close",function(){n=!1}),RED.events.on("actionList:open",function(){n=!0}),RED.events.on("actionList:close",function(){n=!1}),RED.keyboard.add("red-ui-search","escape",R),RED.keyboard.add("view-search-tools","escape",function(){j(),x()}),$("#red-ui-header-shade").on("mousedown",R),$("#red-ui-editor-shade").on("mousedown",R),$("#red-ui-palette-shade").on("mousedown",R),$("#red-ui-sidebar-shade").on("mousedown",R),$("#red-ui-view-searchtools-close").on("click",function(){j(),x()}),$("#red-ui-view-searchtools-close").trigger("click"),RED.events.on("workspace:clear",_),RED.events.on("flows:add",k),RED.events.on("flows:remove",T),RED.events.on("flows:change",C),RED.events.on("subflows:add",k),RED.events.on("subflows:remove",T),RED.events.on("subflows:change",C),RED.events.on("nodes:add",k),RED.events.on("nodes:remove",T),RED.events.on("nodes:change",C),RED.events.on("groups:add",k),RED.events.on("groups:remove",T),RED.events.on("groups:change",C)},show:D,hide:R,search:g,getSearchOptions:L}}(),RED.contextMenu=function(){let p;function f(){$(document).off("mousedown.red-ui-workspace-context-menu"),p&&p.remove(),p=null}return RED.keyboard.add("red-ui-workspace-context-menu","escape",function(){RED.contextMenu.hide()}),RED.events.on("editor:open",function(){RED.contextMenu.hide()}),RED.events.on("search:open",function(){RED.contextMenu.hide()}),RED.events.on("type-search:open",function(){RED.contextMenu.hide()}),RED.events.on("actionList:open",function(){RED.contextMenu.hide()}),RED.events.on("view:selection-changed",function(){RED.contextMenu.hide()}),{show:function(e){p&&p.remove();const t=RED.view.selection();t&&Object.keys(t).length;var o=t.nodes&&0<t.nodes.length;o&&t.nodes.length,t.links&&t.links.filter(e=>!!e.link);var n=0<(a=t.links&&t.links.filter(e=>!e.link)||[]).length;const i=!o&&n&&1===a.length;!o&&n&&a.length;var a=o||n,s=o&&1===t.nodes.length&&"group"===t.nodes[0].type,r=o&&!!t.nodes[0].g,d=$("#red-ui-workspace-chart").offset();let l=(e.x+5-d.left+$("#red-ui-workspace-chart").scrollLeft())/RED.view.scale(),c=(e.y+5-d.top+$("#red-ui-workspace-chart").scrollTop())/RED.view.scale();const u=[{onselect:"core:show-action-list",onpostselect:function(){}},{label:RED._("contextMenu.insert"),options:[{label:RED._("contextMenu.node"),onselect:function(){RED.view.showQuickAddDialog({position:[l,c],touchTrigger:!0,splice:i?t.links[0]:void 0})},onpostselect:function(){$("#red-ui-type-search-input").trigger("focus")}},n?{label:RED._("contextMenu.junction"),onselect:"core:split-wires-with-junctions",disabled:!n}:{label:RED._("contextMenu.junction"),onselect:function(){var e={_def:{defaults:{}},type:"junction",z:RED.workspaces.active(),id:RED.nodes.id(),x:l,y:c,w:0,h:0,outputs:1,inputs:1,dirty:!0},t={dirty:RED.nodes.dirty(),t:"add",junctions:[e]};RED.nodes.addJunction(e),RED.history.push(t),RED.nodes.dirty(!0),RED.view.select({nodes:[e]}),RED.view.redraw(!0)}},{label:RED._("contextMenu.linkNodes"),onselect:"core:split-wire-with-link-nodes",disabled:!n}]}];u.push(null,{onselect:"core:undo",disabled:0===RED.history.list().length},{onselect:"core:redo",disabled:0===RED.history.listRedo().length},null,{onselect:"core:cut-selection-to-internal-clipboard",label:RED._("keyboard.cutNode"),disabled:!o},{onselect:"core:copy-selection-to-internal-clipboard",label:RED._("keyboard.copyNode"),disabled:!o},{onselect:"core:paste-from-internal-clipboard",label:RED._("keyboard.pasteNode"),disabled:!RED.view.clipboard()},{onselect:"core:delete-selection",disabled:!a},{onselect:"core:show-export-dialog",label:RED._("menu.label.export")},{onselect:"core:select-all-nodes"}),o&&(u.push(null,s?{onselect:"core:ungroup-selection",disabled:!s}:{onselect:"core:group-selection",disabled:!o}),r&&u.push({onselect:"core:remove-selection-from-group",label:RED._("menu.label.groupRemoveSelection")})),d="right",e.x-$(document).scrollLeft()>$(window).width()-500&&(d="left"),(p=RED.menu.init({direction:d,onpreselect:function(){f()},onpostselect:function(){RED.view.focus()},options:u})).attr("id","red-ui-workspace-context-menu"),p.css({position:"absolute"}),p.appendTo("body"),n=e.y,a=e.x,n+p.height()-$(document).scrollTop()>$(window).height()&&(n-=n+p.height()-$(window).height()+22),a+p.width()-$(document).scrollLeft()>$(window).width()&&(a-=a+p.width()-$(window).width()+18),p.css({top:n+"px",left:a+"px"}),$(".red-ui-menu.red-ui-menu-dropdown").hide(),$(document).on("mousedown.red-ui-workspace-context-menu",function(e){p&&p[0].contains(e.target)||f()}),p.show(),$("#red-ui-workspace-context-menu :first(ul) > a").trigger("focus")},hide:f}}(),RED.actionList=function(){var o,i,n,a=!1,s=null,r=!1,d="",l=[];function c(){var e,t,o,n=i.find("li.selected");1===n.length&&(t=(e=i.parent()).height(),e.scrollTop(),t<(o=n.position().top)+(n=n.height())?e.animate({scrollTop:"-="+(t-(o+n)-10)},50):o<0&&e.animate({scrollTop:"+="+(o-10)},50))}function u(e){t(),e&&RED.actions.invoke(e.id)}function e(e){var t;a||(r||(n=document.activeElement,$("#red-ui-header-shade").show(),$("#red-ui-editor-shade").show(),$("#red-ui-palette-shade").show(),$("#red-ui-sidebar-shade").show(),$("#red-ui-sidebar-separator").hide(),null===s&&(s=$("<div>",{id:"red-ui-actionList",class:"red-ui-search"}).appendTo("#red-ui-main-container"),t=$("<div>",{class:"red-ui-search-container"}).appendTo(s),(o=$('<input type="text" data-i18n="[placeholder]keyboard.filterActions">').appendTo(t).searchBox({change:function(){d=$(this).val().trim(),l=d.split(" "),i.editableList("filter"),i.find("li.selected").removeClass("selected");var e=i.children(":visible");e.length&&$(e[0]).addClass("selected")}})).on("keydown",function(e){var t,o,n;40===e.keyCode?((o=i.find("li.selected")).length?(n=o.nextAll(":visible").first()).length&&(o.removeClass("selected"),n.addClass("selected")):(t=i.children(":visible")).length&&$(t[0]).addClass("selected"),c(),e.preventDefault()):38===e.keyCode?((n=(o=i.find("li.selected")).prevAll(":visible").first()).length&&(o.removeClass("selected"),n.addClass("selected")),c(),e.preventDefault()):13===e.keyCode&&(o=i.find("li.selected"),u(i.editableList("getItem",o)))}),o.i18n(),t=$("<div>",{class:"red-ui-search-results-container"}).appendTo(s),i=$("<ol>",{style:"position: absolute;top: 5px;bottom: 5px;left: 5px;right: 5px;"}).appendTo(t).editableList({addButton:!1,addItem:function(e,t,o){var n;void 0===o.id?$("<div>",{class:"red-ui-search-empty"}).text(RED._("search.empty")).appendTo(e):(e=$("<a>",{href:"#",class:"red-ui-search-result"}).appendTo(e),n=$("<div>",{class:"red-ui-search-result-action"}).appendTo(e),$("<div>").text(o.label).appendTo(n),o.key&&$("<div>",{class:"red-ui-search-result-action-key"}).html(RED.keyboard.formatKey(o.key)).appendTo(n),e.on("click",function(e){e.preventDefault(),u(o)}))},scrollOnAdd:!1,filter:function(e){if(""!==d)for(var t=0,o=0;o<l.length;o++){var n=e._label.indexOf(l[o],t);if(!(-1<n))return!1;t=n}return!0}})),s.slideDown(300),o.searchBox("value",e),i.editableList("empty"),results=[],(t=RED.actions.list()).sort(function(e,t){e=e.label,t=t.label;return e.localeCompare(t)}),t.forEach(function(e){e._label=e.label.toLowerCase(),i.editableList("addItem",e)}),RED.events.emit("actionList:open"),r=!0),o.trigger("focus"),(e=i.children(":visible")).length&&$(e[0]).addClass("selected"))}function t(){r&&(r=!1,$("#red-ui-header-shade").hide(),$("#red-ui-editor-shade").hide(),$("#red-ui-palette-shade").hide(),$("#red-ui-sidebar-shade").hide(),$("#red-ui-sidebar-separator").show(),null!==s&&s.slideUp(200,function(){o.searchBox("value","")}),RED.events.emit("actionList:close"),n&&($(n).trigger("focus"),n=null))}return{init:function(){RED.actions.add("core:show-action-list",e),RED.events.on("editor:open",function(){a=!0}),RED.events.on("editor:close",function(){a=!1}),RED.events.on("search:open",function(){a=!0}),RED.events.on("search:close",function(){a=!1}),RED.events.on("type-search:open",function(){a=!0}),RED.events.on("type-search:close",function(){a=!1}),RED.keyboard.add("red-ui-actionList","escape",function(){t()}),$("#red-ui-header-shade").on("mousedown",t),$("#red-ui-editor-shade").on("mousedown",t),$("#red-ui-palette-shade").on("mousedown",t),$("#red-ui-sidebar-shade").on("mousedown",t)},show:e,hide:t}}(),RED.typeSearch=function(){var d,l,t,i,o,n,a=null,c=-1,s=!1,r="",u={};function p(){var e,t,o,n=l.find("li.selected");1===n.length&&(t=(e=l.parent()).height(),e.scrollTop(),t<(o=n.position().top)+(n=n.height())?e.animate({scrollTop:"-="+(t-(o+n)-10)},50):o<0&&e.animate({scrollTop:"+="+(o-10)},50))}function f(e,t){var o=a.position();o.top=o.top+t+"px",o.left=o.left+e+"px",a.css(o),n(e,t)}function h(){a=$("<div>",{id:"red-ui-type-search",class:"red-ui-search red-ui-type-search"}).appendTo("#red-ui-main-container");var e=$("<div>",{class:"red-ui-search-container"}).appendTo(a);(d=$('<input type="text" id="red-ui-type-search-input">').attr("placeholder",RED._("search.addNode")).appendTo(e).searchBox({delay:50,change:function(){var e;e=$(this).val(),r=e.toLowerCase(),l.editableList("filter"),l.editableList("sort"),setTimeout(function(){c=0,l.children().removeClass("selected"),l.children(":visible:first").addClass("selected")},100)}})).on("keydown",function(e){var t,o,n=l.children(":visible");40===e.keyCode&&e.shiftKey?(e.preventDefault(),f(0,10)):38===e.keyCode&&e.shiftKey?(e.preventDefault(),f(0,-10)):39===e.keyCode&&e.shiftKey?(e.preventDefault(),f(10,0)):37===e.keyCode&&e.shiftKey?(e.preventDefault(),f(-10,0)):0<n.length?40===e.keyCode?(c<n.length-1&&(-1<c&&$(n[c]).removeClass("selected"),c++),$(n[c]).addClass("selected"),p(),e.preventDefault()):38===e.keyCode?(0<c&&(c<n.length&&$(n[c]).removeClass("selected"),c--),$(n[c]).addClass("selected"),p(),e.preventDefault()):(e.metaKey||e.ctrlKey)&&13===e.keyCode?(e.preventDefault(),(o=Math.max(0,c))<n.length&&(t=$(n[o]).find(".red-ui-editableList-item-content").data("data"),/^_action_:/.test(t.type)||(u[t.type]=Date.now()),0===t.def.outputs?g(t):i(t.type,!0),$("#red-ui-type-search-input").val("").trigger("keyup"),setTimeout(function(){$("#red-ui-type-search-input").focus()},100))):13===e.keyCode&&(e.preventDefault(),(o=Math.max(0,c))<n.length&&g($(n[o]).find(".red-ui-editableList-item-content").data("data"))):13===e.keyCode&&(e.stopPropagation(),e.preventDefault())}),t=$("<div>",{class:"red-ui-search-results-container"}).appendTo(a),l=$("<ol>",{style:"position: absolute;top: 0;bottom: 0;left: 0;right: 0;"}).appendTo(t).editableList({addButton:!1,filter:function(e){return""===r||!e.recent&&!e.common&&(""===r||-1<e.index.indexOf(r))},sort:function(e,t){if(""===r)return e.i-t.i;var o=e.index.indexOf(r),n=t.index.indexOf(r);return-1===o?1:-1===n?-1:o===n?y(e,t):o-n},addItem:function(e,t,o){var n=o.def,e=(o.index=o.type.toLowerCase(),o.separator&&e.addClass("red-ui-search-result-separator"),$("<div>",{class:"red-ui-search-result"}).appendTo(e)),i=$("<div>",{class:"red-ui-search-result-node"}).appendTo(e),a=("junction"===o.type||/^_action_:/.test(o.type)?i.addClass("red-ui-palette-icon-junction"):(a=RED.utils.getNodeColor(o.type,n),i.css("backgroundColor",a)),RED.utils.getNodeIcon(n)),s=$("<div/>",{class:"red-ui-palette-icon-container"}).appendTo(i),a=(RED.utils.createIconElement(a,s,!1),/^_action_:/.test(o.type)||"junction"===o.type||(0<n.inputs&&$("<div/>",{class:"red-ui-search-result-node-port"}).appendTo(i),0<n.outputs&&$("<div/>",{class:"red-ui-search-result-node-port red-ui-search-result-node-output"}).appendTo(i)),$("<div>",{class:"red-ui-search-result-description"}).appendTo(e)),s=o.label;o.index+="|"+s.toLowerCase(),$("<div>",{class:"red-ui-search-result-node-label"}).text(s).appendTo(a),e.on("click",function(e){e.preventDefault(),g(o)})},scrollOnAdd:!1})}function g(e){v(),/^_action_:/.test(e.type)||(u[e.type]=Date.now()),i(e.type)}function m(e){if(s){for(var t=$(e.target);"body"!==t.prop("nodeName").toLowerCase();){if("red-ui-type-search"===t.attr("id"))return;t=t.parent()}v(!0),o&&o()}}function v(e){s&&(s=!1,null!==a&&t.slideUp(e?50:200,function(){a.hide(),d.searchBox("value","")}),RED.events.emit("type-search:close"),RED.view.focus(),$(document).off("mousedown.red-ui-type-search"),$(document).off("mouseup.red-ui-type-search"),$(document).off("click.red-ui-type-search"),$(document).off("touchstart.red-ui-type-search"))}function b(t,e){var o=t;if(void 0!==e.paletteLabel)try{o=("function"==typeof e.paletteLabel?e.paletteLabel.call(e):e.paletteLabel)||"",o+=" ("+t+")"}catch(e){console.log("Definition error: "+t+".paletteLabel",e)}return o}function y(e,t){e=e.label.toLowerCase(),t=t.label.toLowerCase();return e<t?-1:e===t?0:1}function w(e,t,o){return!e||!e.spliceMultiple&&(!e.type||t===e.type)&&(!e.input||"junction"===t||0<o.inputs)&&(!e.output||"junction"===t||0<o.outputs)}function E(t){l.editableList("empty"),d.searchBox("value","").focus(),c=-1;for(var e,o=["inject","debug","function","change","switch","junction"].filter(function(e){return w(t.filter,e,RED.nodes.getType(e))}),n=Object.keys(u),i=(n.sort(function(e,t){return u[t]-u[e]}),n=n.filter(function(e){return w(t.filter,e,RED.nodes.getType(e))&&-1===o.indexOf(e)}),[]),a=(RED.nodes.registry.getNodeTypes().forEach(function(e){var t=RED.nodes.getType(e);"config"!==t.category&&"unknown"!==e&&"tab"!==e&&i.push({type:e,def:t,label:b(e,t)})}),i.sort(y),0),s=0;s<o.length;s++){var r=RED.nodes.getType(o[s]);"junction"===o[s]?r={inputs:1,outputs:1,label:"junction",type:"junction"}:/^_action_:/.test(o[s])&&(r={inputs:1,outputs:1,label:o[s],type:o[s]}),r&&((e={type:o[s],common:!0,def:r,i:a++}).label=b(e.type,e.def),s===o.length-1&&(e.separator=!0),l.editableList("addItem",e))}for(s=0;s<Math.min(5,n.length);s++)(e={type:n[s],def:RED.nodes.getType(n[s]),recent:!0,i:a++}).label=b(e.type,e.def),s===n.length-1&&(e.separator=!0),l.editableList("addItem",e);for(s=0;s<i.length;s++)w(t.filter,i[s].type,i[s].def)&&(i[s].i=a++,l.editableList("addItem",i[s]));setTimeout(function(){c=0,l.children(":first").addClass("selected")},100)}return{show:function(e){s?(a.hide(),t.hide()):(null===a&&(h(),RED.keyboard.add("red-ui-type-search","escape",function(){v(),o&&o()})),s=!0),$(document).off("mousedown.red-ui-type-search"),$(document).off("mouseup.red-ui-type-search"),$(document).off("click.red-ui-type-search"),$(document).off("touchstart.red-ui-type-search"),$(document).off("mousedown.red-ui-type-search"),setTimeout(function(){$(document).on("mousedown.red-ui-type-search",m),$(document).on("mouseup.red-ui-type-search",m),$(document).on("click.red-ui-type-search",m),$(document).on("touchstart.red-ui-type-search",m)},200),E(e),i=e.add,o=e.cancel,n=e.move,RED.events.emit("type-search:open"),$("#red-ui-main-container").height()-e.y-195<0&&(e.y=e.y-275),a.css({left:e.x+"px",top:e.y+"px"}).show(),t.slideDown(300),setTimeout(function(){t.find(".red-ui-editableList-container").scrollTop(0),e.disableFocus||d.trigger("focus")},200)},refresh:E,hide:v}}(),RED.subflow=function(){function s(e,t){var o={x:50,y:30},n=(t||(o.x+=110),[].concat(e.out).concat(e.in));e.status&&n.push(e.status),n.sort(function(e,t){return e.x-t.x});for(var i=0;i<n.length;i++){var a=n[i];a.x==o.x&&a.y==o.y&&(o.x+=55)}return o}function r(){var t,o,n=RED.nodes.subflow(RED.workspaces.active());if(0!==n.in.length)return t=n.in[0],o=[],RED.nodes.eachLink(function(e){("subflow"==e.source.type&&e.source.z==n.id&&e.source.i==t.i||e.target.type=="subflow:"+n.id)&&o.push(e)}),o.forEach(function(e){RED.nodes.removeLink(e)}),n.in=[],$("#red-ui-subflow-input-add").removeClass("active"),$("#red-ui-subflow-input-remove").addClass("active"),n.changed=!0,RED.events.emit("subflows:change",n),{subflowInputs:[t],links:o}}function d(e){var t=RED.nodes.subflow(RED.workspaces.active());if(0!==t.out.length){var o=[];for((e=void 0===e?[t.out[t.out.length-1]]:e).sort(function(e,t){return t.i-e.i}),i=0;i<e.length;i++){var n=e[i],a=(t.out.splice(n.i,1),[]),s=[];RED.nodes.eachLink(function(e){"subflow"==e.target.type&&e.target.z==t.id&&e.target.i==n.i&&a.push(e),e.source.type=="subflow:"+t.id&&(e.sourcePort==n.i?a.push(e):e.sourcePort>n.i&&s.push(e))}),a.forEach(function(e){RED.nodes.removeLink(e)}),s.forEach(function(e){e.sourcePort--});for(var o=o.concat(a),r=n.i;r<t.out.length;r++)t.out[r].i--,t.out[r].dirty=!0}return t.changed=!0,RED.events.emit("subflows:change",t),{subflowOutputs:e,links:o}}}function l(){var t,o=RED.nodes.subflow(RED.workspaces.active());if(o.status)return t=[],RED.nodes.eachLink(function(e){"subflow"==e.target.type&&e.target.z==o.id&&"status"==e.target.direction&&t.push(e)}),t.forEach(function(e){RED.nodes.removeLink(e)}),delete o.status,$("#red-ui-subflow-status").prop("checked",!!o.status),$("#red-ui-subflow-status").parent().parent().toggleClass("active",!!o.status),{links:t}}function c(t){var o=RED.nodes.subflow(RED.workspaces.active()),n=(u(o),[]);if(o)return RED.nodes.filterNodes({type:"subflow:"+o.id}).forEach(function(e){n.push({id:e.id,changed:e.changed}),t&&(e.changed=!0),e.inputs=o.in.length,e.outputs=o.out.length,e.resize=!0,e.dirty=!0,RED.editor.updateNodeProperties(e)}),RED.editor.validateNode(o),{instances:n}}function u(e){e&&($("#red-ui-subflow-input-add").toggleClass("active",0!==e.in.length),$("#red-ui-subflow-input-remove").toggleClass("active",0===e.in.length),$("#red-ui-subflow-output .spinner-value").text(e.out.length),$("#red-ui-subflow-status").prop("checked",!!e.status),$("#red-ui-subflow-status").parent().parent().toggleClass("active",!!e.status))}function t(a){var e=$("#red-ui-workspace-toolbar");e.empty(),$('<a class="button" id="red-ui-subflow-edit" href="#" data-i18n="[append]subflow.editSubflowProperties"><i class="fa fa-pencil"></i> </a>').appendTo(e),$('<span style="margin-left: 5px;" data-i18n="subflow.input"></span> <div style="display: inline-block;" class="button-group"><a id="red-ui-subflow-input-remove" class="button active" href="#">0</a><a id="red-ui-subflow-input-add" class="button" href="#">1</a></div>').appendTo(e),$('<span style="margin-left: 5px;" data-i18n="subflow.output"></span> <div id="red-ui-subflow-output" style="display: inline-block;" class="button-group spinner-group"><a id="red-ui-subflow-output-remove" class="button" href="#"><i class="fa fa-minus"></i></a><div class="spinner-value">3</div><a id="red-ui-subflow-output-add" class="button" href="#"><i class="fa fa-plus"></i></a></div>').appendTo(e),$('<span class="button-group"><span class="button" style="padding:0"><label for="red-ui-subflow-status"><input id="red-ui-subflow-status" type="checkbox"> <span data-i18n="subflow.status"></span></label></span></span>').appendTo(e),$('<a class="button" id="red-ui-subflow-delete" href="#" data-i18n="[append]subflow.deleteSubflow"><i class="fa fa-trash"></i> </a>').appendTo(e),e.i18n(),$("#red-ui-subflow-output-remove").on("click",function(e){e.preventDefault();var t,e=RED.nodes.dirty(),o=a.changed,n=d();n&&(t=c(!0),RED.history.push({t:"delete",links:n.links,subflowOutputs:n.subflowOutputs,changed:o,dirty:e,subflow:{instances:t.instances}}),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw(!0))}),$("#red-ui-subflow-output-add").on("click",function(e){var t,o,n,i;e.preventDefault(),e=RED.nodes.subflow(RED.workspaces.active()),t=s(e,!1),t={type:"subflow",direction:"out",z:e.id,i:e.out.length,x:t.x,y:t.y,id:RED.nodes.id()},o=e.out.length,e.out.push(t),e.dirty=!0,t=RED.nodes.dirty(),n=e.changed,i=c(e.changed=!0),t={t:"edit",node:e,dirty:t,changed:n,subflow:{outputCount:o,instances:i.instances}},RED.history.push(t),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw(),$("#red-ui-subflow-output .spinner-value").text(e.out.length),RED.events.emit("subflows:change",e)}),$("#red-ui-subflow-input-add").on("click",function(e){var t,o,n,i;e.preventDefault(),1!==(e=RED.nodes.subflow(RED.workspaces.active())).in.length&&(i=s(e,!0),i={type:"subflow",direction:"in",z:e.id,i:e.in.length,x:i.x,y:i.y,id:RED.nodes.id()},t=e.in.length,e.in.push(i),e.dirty=!0,i=RED.nodes.dirty(),o=e.changed,n=c(e.changed=!0),i={t:"edit",node:e,dirty:i,changed:o,subflow:{inputCount:t,instances:n.instances}},RED.history.push(i),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw(),$("#red-ui-subflow-input-add").addClass("active"),$("#red-ui-subflow-input-remove").removeClass("active"),RED.events.emit("subflows:change",e))}),$("#red-ui-subflow-input-remove").on("click",function(e){e.preventDefault();var t,e=RED.nodes.dirty(),o=a.changed,n=(a.changed=!0,r());n&&(t=c(!0),RED.history.push({t:"delete",links:n.links,changed:o,subflowInputs:n.subflowInputs,dirty:e,subflow:{instances:t.instances}}),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw(!0))}),$("#red-ui-subflow-status").on("change",function(e){var t,o,n,i;this.checked?(i=RED.nodes.subflow(RED.workspaces.active())).status||(o=s(i,!1),o={type:"subflow",direction:"status",z:i.id,x:o.x,y:o.y,id:RED.nodes.id()},i.status=o,i.dirty=!0,o=RED.nodes.dirty(),n=i.changed,c(i.changed=!0),RED.history.push({t:"edit",node:i,dirty:o,changed:n,subflow:{status:!0}}),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw(),RED.events.emit("subflows:change",i),$("#red-ui-subflow-status").prop("checked",!!i.status),$("#red-ui-subflow-status").parent().parent().toggleClass("active",!!i.status)):(o=a.status,n=a.changed,(i=l())&&(a.changed=!0,t=RED.nodes.dirty(),RED.history.push({t:"delete",links:i.links,changed:n,dirty:t,subflow:{id:a.id,status:o}}),RED.view.select(),RED.nodes.dirty(!0),RED.view.redraw()))}),$("#red-ui-subflow-edit").on("click",function(e){RED.editor.editSubflow(RED.nodes.subflow(RED.workspaces.active())),e.preventDefault()}),$("#red-ui-subflow-delete").on("click",function(e){e.preventDefault();var t,o,e=RED.nodes.subflow(RED.workspaces.active());function n(){var e=RED.nodes.dirty(),t=p(RED.workspaces.active());t.t="delete",t.dirty=e,RED.history.push(t)}0<e.instances.length?(t=$("<div>"),$("<p>").text(RED._("subflow.subflowInstances",{count:e.instances.length})).appendTo(t),$("<p>").text(RED._("subflow.confirmDelete")).appendTo(t),o=RED.notify(t,{modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){o.close()}},{text:RED._("workspace.confirmDelete"),class:"primary",click:function(){o.close(),n()}}]})):n()}),u(a),$("#red-ui-workspace-chart").css({"margin-top":"40px"}),$("#red-ui-workspace-toolbar").show()}function p(t,o){for(var n=[],e=[],i=[],a=RED.nodes.subflow(t),s=(RED.nodes.eachNode(function(e){o||e.type!="subflow:"+t||n.push(e),e.z==t&&n.push(e)}),RED.nodes.eachConfig(function(e){e.z==t&&n.push(e)}),RED.nodes.groups(t).forEach(function(e){i.push(e)}),RED.nodes.junctions(t)),r=0;r<s.length;r++)var d=RED.nodes.removeJunction(s[r]),e=e.concat(d.links);for(var l=[],r=0;r<n.length;r++){d=RED.nodes.remove(n[r].id);e=e.concat(d.links),l=l.concat(d.nodes)}for(n=n.concat(l),i=RED.nodes.groups(t).filter(function(e){return!e.g}),r=0;r<i.length;r++)i[r].nodes.forEach(function(e){"group"===e.type&&i.push(e)});for(r=i.length-1;0<=r;r--)RED.nodes.removeGroup(i[r]);return RED.nodes.removeSubflow(a),RED.workspaces.remove(a),RED.nodes.dirty(!0),RED.view.redraw(),{nodes:n,links:e,groups:i,junctions:s,subflows:[a]}}function e(){var t=0,e=(RED.nodes.eachSubflow(function(e){e=new RegExp("^Subflow (\\d+)$").exec(e.name);e&&(t=Math.max(t,e[1]))}),"Subflow "+(t+1)),o=RED.nodes.id(),e={type:"subflow",id:o,name:e,info:"",in:[],out:[]};RED.nodes.addSubflow(e),RED.history.push({t:"createSubflow",subflow:{subflow:e},dirty:RED.nodes.dirty()}),RED.workspaces.show(o),RED.nodes.dirty(!0)}function R(e){return e=RED.settings.get("editor").view["view-snap-grid"]?Math.round(e/RED.view.gridSize())*RED.view.gridSize():e}function x(e){var t=RED.nodes.node(e);return t||RED.nodes.junction(e)}function o(){var e=RED.view.selection();if(e.nodes){for(var n,t=new Set,o=e.nodes.slice(),i=new Set;0<o.length;)"group"===(n=o.shift()).type&&(i.add(n.id),o=o.concat(n.nodes)),t.add(n);for(var a=(t=Array.from(t))[0].g,s=[],r=0;r<t.length;r++)if(t[r].g&&!i.has(t[r].g)&&a!==t[r].g)return void RED.notify("Cannot create subflow across multiple groups","error");var a=a&&RED.nodes.group(a),d={},l=[],c=[],u=[],p=[],f={},h=[t[0].x,t[0].y,t[0].x,t[0].y];for(r=0;r<t.length;r++)n=t[r],d[n.id]={n:n,outputs:{}},h=[Math.min(h[0],n.x),Math.min(h[1],n.y),Math.max(h[2],n.x),Math.max(h[3],n.y)];var g=R(h[0]-200),m=R(h[1]-80),e=[R((h[2]+h[0])/2),R((h[3]+h[1])/2)],v=(RED.nodes.eachLink(function(e){d[e.source.id]&&d[e.target.id],d[e.source.id]&&!d[e.target.id]&&(p.push(e),c.push(e)),!d[e.source.id]&&d[e.target.id]&&(u.push(e),f[e.target.id]=e.target,c.push(e))}),{});if((p=p.filter(function(e){return v[e.source.id+":"+e.sourcePort]?(v[e.source.id+":"+e.sourcePort].targets.push(e.target),!1):(e.targets=[],e.targets.push(e.target),v[e.source.id+":"+e.sourcePort]=e,!0)})).sort(function(e,t){return e.source.y-t.source.y}),1<Object.keys(f).length)RED.notify(RED._("subflow.errors.multipleInputsToSelection"),"error");else{var b=0,y=(RED.nodes.eachSubflow(function(e){e=new RegExp("^Subflow (\\d+)$").exec(e.name);e&&(b=Math.max(b,e[1]))}),"Subflow "+(b+1)),w=RED.nodes.id(),E={type:"subflow",id:w,name:y,info:"",in:Object.keys(f).map(function(e,t){return{type:"subflow",direction:"in",x:R(f[e].x-f[e].w/2-80-g),y:R(f[e].y-m),z:w,i:t,id:RED.nodes.id(),wires:[{id:f[e].id}]}}),out:p.map(function(e,t){return{type:"subflow",direction:"out",x:R(e.source.x+e.source.w/2+80-g),y:R(e.source.y-m),z:w,i:t,id:RED.nodes.id(),wires:[{id:e.source.id,port:e.sourcePort}]}})},D=(RED.nodes.addSubflow(E),{id:RED.nodes.id(),type:"subflow:"+E.id,x:e[0],y:e[1],z:RED.workspaces.active(),inputs:E.in.length,outputs:E.out.length,h:Math.max(30,15*(E.out.length||0)),changed:!0});for(D._def=RED.nodes.getType(D.type),RED.editor.validateNode(D),RED.nodes.add(D),a&&(RED.group.addToGroup(a,D),t.forEach(function(e){var t;e.g===a.id&&(delete e.g,t=a.nodes.indexOf(e),a.nodes.splice(t,1),s.push(e))}),a.dirty=!0),u.forEach(function(e){e={source:e.source,sourcePort:e.sourcePort,target:D};l.push(e),RED.nodes.addLink(e)}),p.forEach(function(e,t){e.targets.forEach(function(e){e={source:D,sourcePort:t,target:e};l.push(e),RED.nodes.addLink(e)})}),E.in.forEach(function(t){t.wires.forEach(function(e){e={source:t,sourcePort:0,target:x(e.id)};l.push(e),RED.nodes.addLink(e)})}),E.out.forEach(function(t,e){t.wires.forEach(function(e){e={source:x(e.id),sourcePort:e.port,target:t};l.push(e),RED.nodes.addLink(e)})}),r=0;r<c.length;r++)RED.nodes.removeLink(c[r]);for(r=0;r<t.length;r++)n=t[r],/^link /.test(n.type)&&(n.links=n.links.filter(function(e){var t,o=d.hasOwnProperty(e);return o||(e=x(e))&&e.links&&(-1<(t=e.links.indexOf(n.id))&&e.links.splice(t,1)),o})),n.x-=g,n.y-=m,RED.nodes.moveNodeToTab(n,E.id);y={t:"createSubflow",nodes:[D.id],links:l,subflow:{subflow:E,offsetX:g,offsetY:m},activeWorkspace:RED.workspaces.active(),removedLinks:c,dirty:RED.nodes.dirty()};a&&((y={t:"multi",events:[y]}).events.push({t:"addToGroup",group:a,nodes:[D]}),y.events.push({t:"removeFromGroup",group:a,nodes:s,reparent:!1})),RED.history.push(y),RED.editor.validateNode(E),RED.nodes.dirty(!0),RED.view.updateActive(),RED.view.select(null),RED.view.focus()}}else RED.notify(RED._("subflow.errors.noNodesSelected"),"error")}function f(e,t,o){e.empty();for(var n=0;n<t.length;n++){var i=t[n];i.ui&&"hide"===i.ui.type||!function(e,t,o,n){o.label=o.label||{},("cred"===t.type||t.parent&&"cred"===t.parent.type)&&!o.type?(o.type="cred",o.opts={}):o.type?o.opts||(o.opts="select"===o.type?{opts:[]}:{}):(o.type="input",o.opts={types:RED.editor.envVarList.DEFAULT_ENV_TYPE_LIST});var i=o.label||{},a=RED.i18n.lang(),s=RED.editor.envVarList.lookupLabel(i,i["en-US"]||t.name,a),r=$("<label>").appendTo(e),d=($("<span>&nbsp;</span>").appendTo(e),$("<span></span>").appendTo(r)),l=(!o.icon||(i=RED.utils.separateIconPath(o.icon))&&$("<i class='fa "+i.file+"'/>").appendTo(d),"checkbox"!==o.type&&(i=o.icon?{"padding-left":"5px"}:{},$("<span>").css(i).text(s).appendTo(r),"none"===o.type&&r.width("100%")),{value:"",type:"str"});switch(t.parent&&(l.value=t.parent.value,l.type=t.parent.type),t.hasOwnProperty("value")&&(l.value=t.value),t.hasOwnProperty("type")&&(l.type=t.type),o.type){case"input":var c=$('<input type="text">').css("width","70%").appendTo(e);o.opts.types&&0<o.opts.types.length?(u=l.type,-1===o.opts.types.indexOf(u)&&(u=o.opts.types[0]),c.typedInput({types:o.opts.types,default:u}),c.typedInput("value",l.value),"cred"===u&&n.credentials&&(n.credentials[t.name]?c.typedInput("value",n.credentials[t.name]):n.credentials["has_"+t.name]?c.typedInput("value","__PWRD__"):c.typedInput("value",""))):c.val(l.value);break;case"select":c=$("<select>").css("width","70%").appendTo(e),o.opts.opts&&o.opts.opts.forEach(function(e){$("<option>").val(e.v).text(RED.editor.envVarList.lookupLabel(e.l,e.l["en-US"]||e.v,a)).appendTo(c)}),c.val(l.value);break;case"checkbox":r.css("cursor","default");var u=$("<label>").css("width","70%").appendTo(e),u=(c=$('<input type="checkbox">').css({marginTop:0,width:"auto",height:"34px"}).appendTo(u),d.css({"padding-left":"5px"}).appendTo(u),$("<span>").css({"padding-left":"5px"}).text(s).appendTo(u),!1),u="bool"===l.type?"true"===l.value:"num"===l.type?"0"!==l.value:""!==l.value;c.prop("checked",u);break;case"spinner":c=$("<input>").css("width","70%").appendTo(e);u={};o.opts.hasOwnProperty("min")&&(u.min=o.opts.min),o.opts.hasOwnProperty("max")&&(u.max=o.opts.max),c.spinner(u).parent().width("70%"),c.val(l.value);break;case"cred":c=$('<input type="password">').css("width","70%").appendTo(e),n.credentials?n.credentials[t.name]?c.val(n.credentials[t.name]):n.credentials["has_"+t.name]?c.val("__PWRD__"):c.val(""):c.val(""),c.typedInput({types:["cred"],default:"cred"})}c&&c.attr("id",m(t.name))}($("<div/>",{class:"form-row"}).appendTo(e),i,i.ui||{},o)}}function h(e,r){var d;return e?(d=[],e.each(function(e){var t=$(this).data("data"),o=(t.parent?t.name:t.nameField.val()).trim();if(""!==o||t.ui&&"none"===t.ui.type){var n=t.valueField,i=n.typedInput("value"),n=n.typedInput("type");if(r||!t.parent||t.parent.value!==i||t.parent.type!==n){var a={name:o,type:n,value:i};if(t.ui){var s={icon:t.ui.icon,label:$.extend(!0,{},t.ui.label),type:t.ui.type,opts:$.extend(!0,{},t.ui.opts)};switch(s.icon||delete s.icon,$.isEmptyObject(s.label)&&delete s.label,s.type){case"input":JSON.stringify(s.opts)===JSON.stringify({types:RED.editor.envVarList.DEFAULT_ENV_TYPE_LIST})&&(delete s.type,delete s.opts);break;case"cred":"cred"===a.type&&delete s.type,delete s.opts;break;case"select":s.opts&&$.isEmptyObject(s.opts.opts)&&delete s.opts;break;case"spinner":$.isEmptyObject(s.opts)&&delete s.opts;break;default:delete s.opts}$.isEmptyObject(s)||(a.ui=s)}d.push(a)}}}),d):null}function g(a){var o={},s=[];if(/^subflow:/.test(a.type)){var e=RED.nodes.subflow(a.type.substring(8));if(e.env&&e.env.forEach(function(e){var t={name:e.name,parent:{type:e.type,value:e.value},ui:$.extend(!0,{},e.ui)};s.push(t),o[e.name]=t}),a.env)for(var t=0;t<a.env.length;t++){var n=a.env[t];o.hasOwnProperty(n.name)&&(o[n.name].type=n.type,o[n.name].value=n.value)}}else a._def.subflowModule&&Object.keys(a._def.defaults).forEach(function(e){if("name"!==e){var t,o=a._def.defaults[e],n=a[e],i=n;if(o.ui&&"cred"===o.ui.type)t="cred";else switch(typeof n){case"string":t="str";break;case"number":t="num";break;case"boolean":t="bool",i=n?"true":"false";break;default:t=n.type,i=n.value}e={name:e,type:t,value:i,parent:{type:o.type,value:o.value},ui:$.extend(!0,{},o.ui)};s.push(e)}});return s}function m(e){return"node-input-subflow-env-"+e.replace(/[^a-z0-9-_]/gi,"_")}return{init:function(){RED.events.on("workspace:change",function(e){e=RED.nodes.subflow(e.workspace);e?t(e):($("#red-ui-workspace-toolbar").hide().empty(),$("#red-ui-workspace-chart").css({"margin-top":"0"}))}),RED.events.on("view:selection-changed",function(e){e.nodes?RED.menu.setDisabled("menu-item-subflow-convert",!1):RED.menu.setDisabled("menu-item-subflow-convert",!0)}),RED.actions.add("core:create-subflow",e),RED.actions.add("core:convert-to-subflow",o),$('<script type="text/x-red" data-template-name="subflow"><div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></div><div id="subflow-input-ui"></div><\/script>').appendTo("#red-ui-editor-node-configs"),$('<script type="text/x-red" data-template-name="subflow-template"><div class="form-row"><label for="subflow-input-name" data-i18n="[append]common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="subflow-input-name" data-i18n="[placeholder]common.label.name"></div><div class="form-row"><ul style="margin-bottom: 20px;" id="subflow-env-tabs"></ul></div><div id="subflow-env-tabs-content"><div id="subflow-env-tab-edit"><div class="form-row node-input-env-container-row" id="subflow-input-edit-ui"><ol id="node-input-env-container"></ol><div class="node-input-env-locales-row"><i class="fa fa-language"></i> <select id="subflow-input-env-locale"></select></div></div></div><div id="subflow-env-tab-preview"><div id="subflow-input-ui"/></div></div><\/script>').appendTo("#red-ui-editor-node-configs")},createSubflow:e,convertToSubflow:o,removeSubflow:p,refresh:c,removeInput:r,removeOutput:d,removeStatus:l,buildEditForm:function(e,t){var o,n,i,a;"subflow-template"===e?(o=$("#node-input-env-container"),n=t,(i=RED.tabs.create({id:"subflow-env-tabs",onchange:function(e){"subflow-env-tab-preview"===e.id&&f($("#subflow-input-ui"),h(o.editableList("items"),!0),n),$("#subflow-env-tabs-content").children().hide(),$("#"+e.id).show()}})).addTab({id:"subflow-env-tab-edit",label:RED._("editor-tab.envProperties")}),i.addTab({id:"subflow-env-tab-preview",label:RED._("editor-tab.preview")}),i=RED.settings.theme("languages").map(function(e){var t=RED._("languages."+e);return{text:t||e,val:e}}).sort(function(e,t){return e.text.localeCompare(t.text)}),RED.popover.tooltip($(".node-input-env-locales-row i"),RED._("editor.locale")),a=$("#subflow-input-env-locale"),i.forEach(function(e){var t={value:e.val};"en-US"===e.val&&(t.selected=""),$("<option/>",t).text(e.text).appendTo(a)}),i=RED.i18n.lang(),a.val(i),a.on("change",function(){RED.editor.envVarList.setLocale($(this).val(),$("#node-input-env-container"))}),RED.editor.envVarList.setLocale(i),RED.editor.envVarList.create($("#node-input-env-container"),t)):"subflow"===e&&f($("#subflow-input-ui"),g(t),t)},exportSubflowTemplateEnv:h,exportSubflowInstanceEnv:function(e){var i=[];return g(e).forEach(function(e){var t,o=e.ui||{},n=(o.type?o.opts=o.opts||{}:e.parent&&"cred"===e.parent.type?o.type="cred":(o.type="input",o.opts={types:RED.editor.envVarList.DEFAULT_ENV_TYPE_LIST}),$("#"+m(e.name)));if(n.length||"cred"===o.type){switch(t={name:e.name},o.type){case"input":o.opts.types&&0<o.opts.types.length?(t.value=n.typedInput("value"),t.type=n.typedInput("type")):(t.value=n.val(),t.type="str");break;case"cred":t.value=n.val(),t.type="cred";break;case"spinner":t.value=n.val(),t.type="num";break;case"select":t.value=n.val(),t.type="str";break;case"checkbox":t.type="bool",t.value=""+n.prop("checked")}"cred"!==o.type&&t.type===e.parent.type&&t.value===e.parent.value||i.push(t)}}),i}}}(),RED.group=function(){for(var i=["#ff0000","#ffC000","#ffff00","#92d04f","#0070c0","#001f60","#6f2fa0","#000000","#777777"],a=i.length,e=0,t=3*i.length;e<t;e++){var o=e%a,n=Math.floor(e/a)+1,s=i[o],r=parseInt(s.substring(1,3),16),d=parseInt(s.substring(3,5),16),s=parseInt(s.substring(5,7),16),l=(255-d)/(3+(o==a-1?0:1)),c=(255-s)/(3+(o==a-1?0:1)),r=((Math.min(255,Math.floor(r+n*((255-r)/(3+(o==a-1?0:1)))))<<16)+(Math.min(255,Math.floor(d+n*l))<<8)+Math.min(255,Math.floor(s+n*c))).toString(16);i.push("#"+"000000".slice(0,6-r.length)+r)}var u,f={label:!0,"label-position":"nw"};function p(e){var t=/^rgb\((\d+), (\d+), (\d+)\)$/.exec(e);return t?(t=((parseInt(t[1])<<16)+(parseInt(t[2])<<8)+parseInt(t[3])).toString(16),"#"+"000000".slice(0,6-t.length)+t):e}function h(e){var t=[],o=RED.nodes.group(e.g);return e.nodes.forEach(function(e){t.push(e),o?(e.g=o.id,o.nodes.push(e),o.dirty=!0,e.dirty=!0):delete e.g,"group"===e.type?RED.events.emit("groups:change",e):"junction"!==e.type?RED.events.emit("nodes:change",e):RED.events.emit("junctions:change",e)}),RED.nodes.removeGroup(e),t}function g(e){if(0!==e.length){if(!(0<e.filter(function(e){return"subflow"===e.type}).length)){var t={id:RED.nodes.id(),type:"group",nodes:[],style:JSON.parse(JSON.stringify(f)),x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY,w:0,h:0,_def:RED.group.def};t.z=e[0].z,RED.nodes.addGroup(t);try{m(t,e)}catch(e){return void RED.notify(e,"error")}return t}RED.notify(RED._("group.errors.cannotAddSubflowPorts"),"error")}}function m(e,t){var o,n,i,a,s;for(Array.isArray(t)||(t=[t]),o=0;o<t.length;o++){if(!(s=t[o]).z)throw new Error("Cannot add node without a z property to a group");if(n){if(n!==s.z)throw new Error("Cannot add nooes with different z properties")}else n=s.z;if(s.g&&!i){if(0!==o)throw new Error(RED._("group.errors.cannotCreateDiffGroups"));i=s.g}if(i!==s.g)throw new Error(RED._("group.errors.cannotCreateDiffGroups"))}for(i&&((i=RED.nodes.group(i)).nodes.push(e),i.dirty=!0,e.g=i.id),o=0;o<t.length;o++)"subflow"!==(s=t[o]).type&&(i&&s.g===i.id&&-1<(a=i.nodes.indexOf(s))&&i.nodes.splice(a,1),s.g=e.id,s.dirty=!0,e.nodes.push(s),e.x=Math.min(e.x,s.x-s.w/2-25-(s._def.button&&"right"!==s._def.align?20:0)),e.y=Math.min(e.y,s.y-s.h/2-25),e.w=Math.max(e.w,s.x+s.w/2+25+(s._def.button&&"right"==s._def.align?20:0)-e.x),e.h=Math.max(e.h,s.y+s.h/2+25-e.y),"group"===s.type?RED.events.emit("groups:change",s):"junction"!==s.type?RED.events.emit("nodes:change",s):RED.events.emit("junctions:change",s));i&&RED.events.emit("groups:change",e),b(e)}function v(e,t,o){var n;Array.isArray(t)||(t=[t]);for(var i=0;i<t.length;i++)if(t[i].g!==e.id)return;for(var a=RED.nodes.group(e.g),i=0;i<t.length;i++){(n=t[i]).dirty=!0;var s=e.nodes.indexOf(n);e.nodes.splice(s,1),o&&e.g?(n.g=e.g,a.nodes.push(n)):delete n.g,"group"===n.type?RED.events.emit("groups:change",n):"junction"!==n.type?RED.events.emit("nodes:change",n):RED.events.emit("junctions:change",n)}b(e)}function b(e){for(e.dirty=!0;e;)e.dirty=!0,e=RED.nodes.group(e.g)}return{def:{defaults:{name:{value:""},style:{value:{label:!0}},nodes:{value:[]},env:{value:[]}},category:"config",oneditprepare:function(){var e,t,c,u,o,n=this.style||{};function p(){var e=c.val();o.removeClass().addClass("red-ui-group-layout-picker-cell-text red-ui-group-layout-text-pos-"+e)}RED.editor.colorPicker.create({id:"node-input-style-stroke",value:n.stroke||f.stroke||"#a4a4a4",defaultValue:"#a4a4a4",palette:i,cellPerRow:a,cellWidth:16,cellHeight:16,cellMargin:3,none:!0,opacity:n.hasOwnProperty("stroke-opacity")?n["stroke-opacity"]:f.hasOwnProperty("stroke-opacity")?f["stroke-opacity"]:1}).appendTo("#node-input-row-style-stroke"),RED.editor.colorPicker.create({id:"node-input-style-fill",value:n.fill||f.fill||"none",defaultValue:"none",palette:i,cellPerRow:a,cellWidth:16,cellHeight:16,cellMargin:3,none:!0,opacity:n.hasOwnProperty("fill-opacity")?n["fill-opacity"]:f.hasOwnProperty("fill-opacity")?f["fill-opacity"]:1}).appendTo("#node-input-row-style-fill"),e={id:"node-input-style-label-position",value:n["label-position"]||"nw"},t=$("<div>",{style:"display:inline-block"}),c=$("<input/>",{id:e.id,type:"hidden",value:e.value}).appendTo(t),u=$('<button type="button" class="red-ui-button red-ui-editor-node-appearance-button">').appendTo(t),$('<i class="fa fa-caret-down"></i>').appendTo(u),e=$("<div>",{class:"red-ui-search-result-node"}).appendTo(u),o=$("<div>",{class:"red-ui-group-layout-picker-cell-text red-ui-group-layout-text-pos-"}).appendTo(e),u.on("click",function(e){var t,o=$("<div/>",{class:"red-ui-group-layout-picker"}).css({width:"126px"});$("<div/>").appendTo(o);for(var n=0;n<2;n++)for(var i="ns"[n],a=$("<div/>").appendTo(o),s=0;s<3;s++){var r=i+["w","","e"][s],d=$("<button/>",{class:"red-ui-search-result-node red-ui-button","data-pos":r}).appendTo(a);d.on("click",function(e){e.preventDefault(),c.val($(this).data("pos")),l.hide(),p()}),$("<div>",{class:"red-ui-group-layout-picker-cell-text red-ui-group-layout-text-pos-"+r}).appendTo(d),r===c.val()&&(t=d)}p();var l=RED.popover.panel(o);l.show({target:u,onclose:function(){u.focus()}}),t&&t.focus()}),p(),t.appendTo("#node-input-row-style-label-position"),RED.editor.colorPicker.create({id:"node-input-style-color",value:n.color||f.color||"#a4a4a4",defaultValue:"#a4a4a4",palette:i,cellPerRow:a,cellWidth:16,cellHeight:16,cellMargin:3}).appendTo("#node-input-row-style-label-color"),$("#node-input-style-label").toggleButton({enabledLabel:RED._("editor.show"),disabledLabel:RED._("editor.show")}),$("#node-input-style-label").on("change",function(e){$("#node-input-row-style-label-options").toggle($(this).prop("checked"))}),$("#node-input-style-label").prop("checked",this.style.label),$("#node-input-style-label").trigger("change")},oneditresize:function(e){},oneditsave:function(){this.style.stroke=$("#node-input-style-stroke").val(),this.style.fill=$("#node-input-style-fill").val(),this.style["stroke-opacity"]=$("#node-input-style-stroke-opacity").val(),this.style["fill-opacity"]=$("#node-input-style-fill-opacity").val(),this.style.label=$("#node-input-style-label").prop("checked"),this.style.label?(this.style["label-position"]=$("#node-input-style-label-position").val(),this.style.color=$("#node-input-style-color").val()):(delete this.style["label-position"],delete this.style.color);var t=this;["stroke","fill","stroke-opacity","fill-opacity","color","label-position"].forEach(function(e){t.style[e]===f[e]&&delete t.style[e]}),this.resize=!0},set:{module:"node-red"}},init:function(){RED.events.on("view:selection-changed",function(e){var t=!!e.nodes,o=!1,n=!1,i=!1,a=!1;t&&(a=1===e.nodes.length&&"group"===e.nodes[0].type,e.nodes.forEach(function(e){"group"===e.type&&(o=!0),e.g&&(i=!0)}),o&&(n=1<e.nodes.length)),RED.menu.setDisabled("menu-item-group-group",!t),RED.menu.setDisabled("menu-item-group-ungroup",!o),RED.menu.setDisabled("menu-item-group-merge",!n),RED.menu.setDisabled("menu-item-group-remove",!i),RED.menu.setDisabled("menu-item-edit-copy-group-style",!a),RED.menu.setDisabled("menu-item-edit-paste-group-style",!o)}),RED.actions.add("core:group-selection",function(){var e,t;RED.view.state()===RED.state.DEFAULT&&(e=RED.view.selection()).nodes&&(e=g(e.nodes))&&(t={t:"createGroup",groups:[e],dirty:RED.nodes.dirty()},RED.history.push(t),RED.view.select({nodes:[e]}),RED.nodes.dirty(!0),RED.view.focus())}),RED.actions.add("core:ungroup-selection",function(){var e,t,o;RED.view.state()===RED.state.DEFAULT&&(e=RED.view.selection()).nodes&&(t=[],groups=e.nodes.filter(function(e){return"group"===e.type}),o={t:"ungroup",groups:[],dirty:RED.nodes.dirty()},groups.forEach(function(e){t=t.concat(h(e)),o.groups.push(e)}),RED.history.push(o),RED.view.select({nodes:t}),RED.nodes.dirty(!0),RED.view.focus())}),RED.actions.add("core:merge-selection-to-group",function(){if(RED.view.state()===RED.state.DEFAULT){var e=RED.view.selection();if(e.nodes){for(var t,o,n,i=[],a={t:"multi",events:[]},s={t:"ungroup",groups:[]},r=0;r<e.nodes.length;r++)if(t=e.nodes[r],0===r)o=t.g;else if(t.g!==o)return void RED.notify(RED._("group.errors.cannotCreateDiffGroups"),"error");for(r=0;r<e.nodes.length;r++)"group"===(t=e.nodes[r]).type?(n=n||t,s.groups.push(t),i=i.concat(h(t))):i.push(t),t.dirty=!0;0<s.groups.length&&a.events.push(s);var d=g(i);d&&(n&&(d.style=n.style,d.name=n.name),RED.view.select({nodes:[d]})),a.events.push({t:"createGroup",groups:[d],dirty:RED.nodes.dirty()}),RED.history.push(a),RED.nodes.dirty(!0),RED.view.focus()}}}),RED.actions.add("core:remove-selection-from-group",function(){if(RED.view.state()===RED.state.DEFAULT){var e=RED.view.selection();if(e.nodes){var t=RED.nodes.group(e.nodes[0].g);if(t)try{v(t,e.nodes,!0);var o={t:"removeFromGroup",dirty:RED.nodes.dirty(),group:t,nodes:e.nodes};RED.history.push(o),RED.nodes.dirty(!0)}catch(e){return void RED.notify(e,"error")}RED.view.select({nodes:e.nodes}),RED.view.focus()}}}),RED.actions.add("core:copy-group-style",function(){var e;RED.view.state()===RED.state.DEFAULT&&(e=RED.view.selection()).nodes&&1===e.nodes.length&&"group"===e.nodes[0].type&&(u=JSON.parse(JSON.stringify(e.nodes[0].style)),RED.notify(RED._("clipboard.groupStyleCopied"),{id:"clipboard"}),RED.menu.setDisabled("menu-item-edit-paste-group-style",!1))}),RED.actions.add("core:paste-group-style",function(){var e,t;RED.view.state()===RED.state.DEFAULT&&u&&(e=RED.view.selection()).nodes&&(t={t:"multi",events:[],dirty:RED.nodes.dirty()},e.nodes.forEach(function(e){"group"===e.type&&(t.events.push({t:"edit",node:e,changes:{style:JSON.parse(JSON.stringify(e.style))},dirty:RED.nodes.dirty()}),e.style=JSON.parse(JSON.stringify(u)),e.dirty=!0)}),0<t.events.length&&(RED.history.push(t),RED.nodes.dirty(!0),RED.view.redraw()))}),$('<script type="text/x-red" data-template-name="group"><div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></div><div class="form-row" id="node-input-row-style-stroke"><label data-i18n="editor:common.label.style"></label><label style="width: 70px;margin-right:10px" for="node-input-style-stroke" data-i18n="editor:common.label.line"></label></div><div class="form-row" style="padding-left: 100px;" id="node-input-row-style-fill"><label style="width: 70px;margin-right: 10px " for="node-input-style-fill" data-i18n="editor:common.label.fill"></label></div><div class="form-row"><label for="node-input-style-label" data-i18n="editor:common.label.label"></label><input type="checkbox" id="node-input-style-label"/></div><div class="form-row" id="node-input-row-style-label-options"><div style="margin-left: 100px; display: inline-block"><div class="form-row"><span style="display: inline-block; min-width: 140px" id="node-input-row-style-label-color"><label style="width: 70px;margin-right: 10px" for="node-input-style-fill" data-i18n="editor:common.label.color"></label></span></div><div class="form-row"><span style="display: inline-block; min-width: 140px;" id="node-input-row-style-label-position"><label style="width: 70px;margin-right: 10px " for="node-input-style-label-position" data-i18n="editor:common.label.position"></label></span></div></div></div><\/script>').appendTo("#red-ui-editor-node-configs");var e=$("<div>",{class:"red-ui-flow-group-body",style:"position: absolute; top: -1000px;"}).appendTo(document.body),t=getComputedStyle(e[0]);f={stroke:p(t.stroke),"stroke-opacity":t.strokeOpacity,fill:p(t.fill),"fill-opacity":t.fillOpacity,label:!0,"label-position":"nw"},e.remove(),e=$("<div>",{class:"red-ui-flow-group-label",style:"position: absolute; top: -1000px;"}).appendTo(document.body),t=getComputedStyle(e[0]),f.color=p(t.fill),e.remove()},createGroup:g,ungroup:h,addToGroup:m,removeFromGroup:v,getNodes:function t(e,o,n){var i=[];return e.nodes.forEach(function(e){"group"===e.type&&n||i.push(e),o&&"group"===e.type&&(i=i.concat(t(e,o,n)))}),i},contains:function e(t,o){if(o.g===t.id)return!0;for(var n=0;n<t.nodes.length;n++)if("group"===t.nodes[n].type&&e(t.nodes[n],o))return!0;return!1},markDirty:b}}(),RED.userSettings=function(){var t=700,o=!1,a=[];function e(e){a.push(e)}function s(i){var e;o||(RED.user.hasPermission("settings.write")?(o=!0,e={title:RED._("menu.label.userSettings"),buttons:[{id:"node-dialog-ok",text:RED._("common.label.close"),class:"primary",click:function(){RED.tray.close()}}],resize:function(e){t=e.width},open:function(e){var e=e.find(".red-ui-tray-body"),e=$("<div></div>").appendTo(e),t=$("<div></div>",{class:"red-ui-settings-tabs-container"}).appendTo(e),o=($("<ul></ul>",{id:"user-settings-tabs"}).appendTo(t),RED.tabs.create({id:"user-settings-tabs",vertical:!0,onchange:function(e){setTimeout(function(){n.children().hide(),$("#"+e.id).show(),e.pane.focus&&e.pane.focus()},50)}})),n=$("<div></div>",{class:"red-ui-settings-tabs-content"}).appendTo(e);a.forEach(function(e){o.addTab({id:"red-ui-settings-tab-"+e.id,label:e.title,pane:e}),e.get().hide().appendTo(n)}),e.i18n(),o.activateTab("red-ui-settings-tab-"+(i||"view")),$("#red-ui-sidebar-shade").show()},close:function(){o=!1,a.forEach(function(e){e.close&&e.close()}),$("#red-ui-sidebar-shade").hide()},show:function(){}},null!==t&&(e.width=t),RED.tray.show(e)):RED.notify(RED._("user.errors.settings"),"error"))}function n(e){var t=RED._("languages."+e);return{text:t||e,val:e}}function i(e,t){return e.text.localeCompare(t.text)}var r=[{options:[{setting:"editor-language",local:!0,label:"menu.label.view.language",options:function(e){e([{val:"",text:RED._("menu.label.view.browserDefault")}].concat(RED.settings.theme("languages").map(n).sort(i)))}}]},{title:"menu.label.view.view",options:[{setting:"view-store-zoom",label:"menu.label.view.storeZoom",default:!1,toggle:!0,onchange:function(e){e||RED.settings.removeLocal("zoom-level")}},{setting:"view-store-position",label:"menu.label.view.storePosition",default:!1,toggle:!0,onchange:function(e){e||RED.settings.removeLocal("scroll-positions")}}]},{title:"menu.label.view.grid",options:[{setting:"view-show-grid",oldSetting:"menu-menu-item-view-show-grid",label:"menu.label.view.showGrid",default:!0,toggle:!0,onchange:"core:toggle-show-grid"},{setting:"view-snap-grid",oldSetting:"menu-menu-item-view-snap-grid",label:"menu.label.view.snapGrid",default:!0,toggle:!0,onchange:"core:toggle-snap-grid"},{setting:"view-grid-size",label:"menu.label.view.gridSize",type:"number",default:20,onchange:RED.view.gridSize}]},{title:"menu.label.nodes",options:[{setting:"view-node-status",oldSetting:"menu-menu-item-status",label:"menu.label.displayStatus",default:!0,toggle:!0,onchange:"core:toggle-status"},{setting:"view-node-show-label",label:"menu.label.showNodeLabelDefault",default:!0,toggle:!0}]},{title:"menu.label.other",options:[{setting:"view-show-tips",oldSettings:"menu-menu-item-show-tips",label:"menu.label.showTips",toggle:!0,default:!0,onchange:"core:toggle-show-tips"},{setting:"view-show-welcome-tours",label:"menu.label.showWelcomeTours",toggle:!0,default:!0}]}],d={};function l(){var i=$('<div id="red-ui-settings-tab-view" class="red-ui-help"></div>'),a=RED.settings.get("editor")||{};return a.view=a.view||{},r.forEach(function(e){e.title&&$("<h3></h3>").text(RED._(e.title)).appendTo(i),e.options.forEach(function(e){var n,t=e.local?localStorage.getItem(e.setting):a.view[e.setting],o=$('<div class="red-ui-settings-row"></div>').appendTo(i);e.toggle?$('<label for="user-settings-'+e.setting+'"><input id="user-settings-'+e.setting+'" type="checkbox"> '+RED._(e.label)+"</label>").appendTo(o).find("input").prop("checked",t):e.options?($('<label for="user-settings-'+e.setting+'">'+RED._(e.label)+"</label>").appendTo(o),n=$('<select id="user-settings-'+e.setting+'"></select>').appendTo(o),"function"==typeof e.options&&(e.options(function(e){e.forEach(function(e){var t=e,o=e;"string"!=typeof e&&(t=e.val,o=e.text),$("<option>").val(t).text(o).appendTo(n)})}),n.val(t))):($('<label for="user-settings-'+e.setting+'">'+RED._(e.label)+"</label>").appendTo(o),$('<input id="user-settings-'+e.setting+'" type="'+(e.type||"text")+'">').appendTo(o).val(t))})}),i}function c(e,t){var o,e=d[e];e.local?localStorage.setItem(e.setting,t):((o=RED.settings.get("editor")||{}).view=o.view||{},o.view[e.setting]=t,RED.settings.set("editor",o),(o="string"==typeof(o=e.onchange)?RED.actions.get(o):o)&&o.call(e,t))}return{init:function(){RED.actions.add("core:show-user-settings",s),RED.actions.add("core:show-help",function(){s("keyboard")}),e({id:"view",title:RED._("menu.label.view.view"),get:l,close:function(){r.forEach(function(e){e.options.forEach(function(e){var t=$("#user-settings-"+e.setting);e.toggle?c(e.setting,t.prop("checked")):c(e.setting,t.val())})})}});var n=RED.settings.get("editor")||{},i=(n.view=n.view||{},!1);r.forEach(function(e){e.options.forEach(function(e){var t,o;e.local?d[e.setting]=e:(e.oldSetting&&null!=(t=RED.settings.get(e.oldSetting))&&(n.view[e.setting]=t,i=!0,RED.settings.remove(e.oldSetting)),d[e.setting]=e,null==(t=n.view[e.setting])&&e.hasOwnProperty("default")&&(t=e.default,n.view[e.setting]=t,i=!0),e.onchange&&(o="string"==typeof(o=e.onchange)?RED.actions.get(o):o)&&o.call(e,t))})}),i&&RED.settings.set("editor",n)},toggle:function(e){var t=d[e],o=RED.settings.get("editor")||{};o.view=o.view||{},c(e,!o.view[t.setting])},show:s,add:e}}(),RED.projects=function(){var T,i,U;function p(e){var t="git_missing_user"===e.code?RED.notify("<p>"+RED._("projects.errors.no-username-email")+"</p>",{fixed:!0,type:"error",buttons:[{text:RED._("common.label.cancel"),click:function(){t.close()}},{text:RED._("projects.config-git"),click:function(){RED.userSettings.show("gitconfig"),t.close()}}]}):(console.log(e),RED.notify("<p>"+RED._("projects.errors.unexpected")+":</p><p>"+e.message+"</p><small>"+RED._("projects.errors.code")+": "+e.code+"</small>",{fixed:!0,modal:!0,type:"error",buttons:[{text:RED._("common.label.close"),click:function(){t.close()}}]}))}var a={};function t(){var L,S,O,I,N,P,A,M,z,B,G,F,d,s,r,b,y,w,E,D,R,x,_,f,h,l,c,k=$('<div class="red-ui-projects-dialog-screen-start-hero"></div>'),g=($('<span><i class="fa fa-files-o fa-2x"></i> &nbsp; &nbsp; <i class="fa fa-long-arrow-right fa-2x"></i> &nbsp; &nbsp; <i class="fa fa-archive fa-2x"></i></span>').appendTo(k),$("<hr>").appendTo(k),{});a={welcome:{content:function(e){var t=$('<div class="red-ui-projects-dialog-screen-start"></div>'),o=(k.appendTo(t),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(t)),o=($("<p>").text(RED._("projects.welcome.hello")).appendTo(o),$("<p>").text(RED._("projects.welcome.desc0")).appendTo(o),$("<p>").text(RED._("projects.welcome.desc1")).appendTo(o),$("<p>").text(RED._("projects.welcome.desc2")).appendTo(o),$('<div style="text-align: center"></div>').appendTo(o)),n=$('<button data-type="empty" class="red-ui-button red-ui-projects-dialog-button red-ui-projects-dialog-screen-create-type"><i class="fa fa-archive fa-2x"></i><i style="position: absolute;" class="fa fa-asterisk"></i><br/>'+RED._("projects.welcome.create")+"</button>").appendTo(o),o=$('<button data-type="clone" class="red-ui-button red-ui-projects-dialog-button red-ui-projects-dialog-screen-create-type"><i class="fa fa-archive fa-2x"></i><i style="position: absolute;" class="fa fa-git"></i><br/>'+RED._("projects.welcome.clone")+"</button>").appendTo(o);return n.on("click",function(e){e.preventDefault(),g={action:"create"},u("git-config")}),o.on("click",function(e){e.preventDefault(),g={action:"clone"},u("git-config")}),t},buttons:[{text:RED._("projects.welcome.openExistingProject"),class:"secondary",click:function(){g={action:"open"},u("git-config")}},{text:RED._("projects.welcome.not-right-now"),click:function(){g={},$(this).dialog("close")}}]},"git-config":{content:function(e){function t(){var e=l.val().trim(),t=c.val().trim(),e=0<e.length&&0<t.length;$("#red-ui-projects-dialog-git-config").prop("disabled",!e).toggleClass("disabled ui-button-disabled ui-state-disabled",!e)}var o=!1,n=RED.settings.get("git"),i=(n&&n.user?n=n.user:RED.settings.git&&RED.settings.git.globalUser&&(o=!0,n=RED.settings.git.globalUser),$('<div class="red-ui-projects-dialog-screen-start"></div>')),a=(k.appendTo(i),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(i)),o=($("<p>").text(RED._("projects.git-config.setup")).appendTo(a),$("<p>").text(RED._("projects.git-config.desc0")).appendTo(a),$("<p>").text(RED._("projects.git-config.desc1")).appendTo(a),o&&$("<p>").text(RED._("projects.git-config.desc2")).appendTo(a),$("<p>").text(RED._("projects.git-config.desc3")).appendTo(a),$('<div class="form-row"></div>').appendTo(a));return $('<label for="">'+RED._("projects.git-config.username")+"</label>").appendTo(o),(l=$('<input type="text">').val(n&&n.name||"").appendTo(o)).on("change keyup paste",t),o=$('<div class="form-row"></div>').appendTo(a),$('<label for="">'+RED._("projects.git-config.email")+"</label>").appendTo(o),(c=$('<input type="text">').val(n&&n.email||"").appendTo(o)).on("change keyup paste",t),setTimeout(function(){l.trigger("focus"),t()},50),i},buttons:[{text:RED._("common.label.back"),click:function(){u("welcome")}},{id:"red-ui-projects-dialog-git-config",text:RED._("common.label.next"),class:"primary",click:function(){var e=RED.settings.get("git")||{};e.user=e.user||{},e.user.name=l.val(),e.user.email=c.val(),RED.settings.set("git",e),"create"===g.action?u("project-details"):"clone"===g.action?u("clone-project"):"open"===g.action&&u("create",{screen:"open"})}}]},"project-details":{content:function(e){var o,t,n=null,i=!1,a=($.getJSON("projects",function(e){n={},e.projects.forEach(function(e){n[e]=!0,i&&(i=!1,r())})}),$('<div class="red-ui-projects-dialog-screen-start"></div>')),s=(k.appendTo(a),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(a)),r=($("<p>").text(RED._("projects.project-details.create")).appendTo(s),$("<p>").text(RED._("projects.project-details.desc0")).appendTo(s),$("<p>").text(RED._("projects.project-details.desc1")).appendTo(s),$("<p>").text(RED._("projects.project-details.desc2")).appendTo(s),function(){var e=f.val(),t=!0;if(u){if(null===n)return void(i=!0);c.empty(),!/^[a-zA-Z0-9\-_]+$/.test(e)||n[e]?(f.addClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>').appendTo(c),t=o=!1,n[e]?projectNameSublabel.text(RED._("projects.project-details.already-exists")):projectNameSublabel.text(RED._("projects.project-details.must-contain"))):(f.removeClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-check"></i>').appendTo(c),projectNameSublabel.text(RED._("projects.project-details.must-contain")),o=!0),p=e}t=o,$("#red-ui-projects-dialog-create-name").prop("disabled",!t).toggleClass("disabled ui-button-disabled ui-state-disabled",!t)}),d=$('<div class="form-row"></div>').appendTo(s),l=($('<label for="red-ui-projects-dialog-screen-create-project-name">'+RED._("projects.project-details.project-name")+"</label>").appendTo(d),$('<div style="position:relative;"></div>').appendTo(d)),c=(f=$('<input id="red-ui-projects-dialog-screen-create-project-name" type="text"></input>').val(g.name||"").appendTo(l),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(l)),u=!1,p="";return f.on("change keyup paste",function(){if(u=f.val()!==p,t)clearTimeout(t);else if(u&&(c.empty(),$('<img src="red/images/spin.svg"/>').appendTo(c),""===f.val()))return void r();t=setTimeout(function(){r(),t=null},300)}),projectNameSublabel=$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.project-details.must-contain")+"</small></label>").appendTo(d).find("small"),d=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty"></div>').appendTo(s),$('<label for="red-ui-projects-dialog-screen-create-project-desc">'+RED._("projects.project-details.desc")+"</label>").appendTo(d),h=$('<input id="red-ui-projects-dialog-screen-create-project-desc" type="text">').val(g.summary||"").appendTo(d),$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.project-details.opt")+"</small></label>").appendTo(d),setTimeout(function(){f.trigger("focus"),f.trigger("change")},50),a},buttons:function(e){return[{text:RED._("common.label.back"),click:function(){u("git-config")}},{id:"red-ui-projects-dialog-create-name",disabled:!0,text:RED._("common.label.next"),class:"primary disabled",click:function(){g.name=f.val(),g.summary=h.val(),u("default-files",e)}}]}},"clone-project":{content:function(e){var n,t,o=$('<div class="red-ui-projects-dialog-screen-start"></div>'),i=(k.appendTo(o),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(o)),a=($("<p>").text(RED._("projects.clone-project.clone")).appendTo(i),$("<p>").text(RED._("projects.clone-project.desc0")).appendTo(i),null),s=!1,r=($.getJSON("projects",function(e){a={},e.projects.forEach(function(e){a[e]=!0,s&&(s=!1,r())})}),function(){var e=b.val(),t=!0;if(u){if(null===a)return void(s=!0);c.empty(),!/^[a-zA-Z0-9\-_]+$/.test(e)||a[e]?(b.addClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>').appendTo(c),t=n=!1,a[e]?R.text(RED._("projects.clone-project.already-exists")):R.text(RED._("projects.clone-project.must-contain"))):(b.removeClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-check"></i>').appendTo(c),R.text(RED._("projects.clone-project.must-contain")),n=!0),p=e}var t=n,e=w.val(),o=0<e.length&&!/\s/.test(e);/^https?:\/\/[^/]+@/i.test(e)&&($("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.no-info-in-url")),o=!1),o?w.removeClass("input-error"):(h&&w.addClass("input-error"),t=!1),/^https?:\/\//.test(e)?($(".red-ui-projects-dialog-screen-create-row-creds").show(),$(".red-ui-projects-dialog-screen-create-row-sshkey").hide()):/^(?:ssh|[\S]+?@[\S]+?):(?:\/\/)?/.test(e)?($(".red-ui-projects-dialog-screen-create-row-creds").hide(),$(".red-ui-projects-dialog-screen-create-row-sshkey").show()):($(".red-ui-projects-dialog-screen-create-row-creds").hide(),$(".red-ui-projects-dialog-screen-create-row-sshkey").hide()),$("#red-ui-projects-dialog-clone-project").prop("disabled",!t).toggleClass("disabled ui-button-disabled ui-state-disabled",!t)}),d=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(i),l=($('<label for="red-ui-projects-dialog-screen-create-project-name">'+RED._("projects.clone-project.project-name")+"</label>").appendTo(d),$('<div style="position:relative;"></div>').appendTo(d)),c=(b=$('<input id="red-ui-projects-dialog-screen-create-project-name" type="text"></input>').appendTo(l),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(l)),u=!1,p="",f="",h=(b.on("change keyup paste",function(){if(u=b.val()!==p,t)clearTimeout(t);else if(u&&(c.empty(),$('<img src="red/images/spin.svg"/>').appendTo(c),""===b.val()))return void r();t=setTimeout(function(){r(),t=null},300)}),R=$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.clone-project.must-contain")+"</small></label>").appendTo(d).find("small"),d=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(i),$('<label for="red-ui-projects-dialog-screen-create-project-repo">'+RED._("projects.clone-project.git-url")+"</label>").appendTo(d),w=$('<input id="red-ui-projects-dialog-screen-create-project-repo" type="text" placeholder="https://git.example.com/path/my-project.git"></input>').appendTo(d),$('<label id="red-ui-projects-dialog-screen-create-project-repo-label" class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.clone-project.protocols")+"</small></label>").appendTo(d),!1),g="",m=(w.on("change keyup paste",function(){h=!0;var e,t=$(this).val(),t=(g!==t&&$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.protocols")),g=t,/\/([^/]+?)(?:\.git)?$/.exec(t));!t||""!==(e=b.val())&&e!==f||(f=t[1],b.val(f),b.trigger("change")),r()}),$('<div class="red-ui-projects-dialog-screen-create-row"></div>').appendTo(i)),l=(d=$('<div class="form-row red-ui-projects-dialog-screen-create-row-auth-error"></div>').hide().appendTo(m),$('<div><i class="fa fa-warning"></i> '+RED._("projects.clone-project.auth-failed")+"</div>").appendTo(d),d=$('<div class="hide form-row red-ui-projects-dialog-screen-create-row-creds"></div>').hide().appendTo(m),$('<div style="width: calc(50% - 10px); display:inline-block;"></div>').appendTo(d)),v=($('<label for="red-ui-projects-dialog-screen-create-project-repo-user">'+RED._("projects.clone-project.username")+"</label>").appendTo(l),E=$('<input id="red-ui-projects-dialog-screen-create-project-repo-user" type="text"></input>').appendTo(l),l=$('<div style="width: calc(50% - 10px); margin-left: 20px; display:inline-block;"></div>').appendTo(d),$('<label for="red-ui-projects-dialog-screen-create-project-repo-pass">'+RED._("projects.clone-project.passwd")+"</label>").appendTo(l),(D=$('<input style="width:100%" id="red-ui-projects-dialog-screen-create-project-repo-pass" type="password"></input>').appendTo(l)).typedInput({type:"cred"}),d=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-sshkey"></div>').hide().appendTo(m),l=$('<div style="width: calc(50% - 10px); display:inline-block;"></div>').appendTo(d),$('<label for="red-ui-projects-dialog-screen-create-project-repo-passphrase">'+RED._("projects.clone-project.ssh-key")+"</label>").appendTo(l),x=$("<select>",{style:"width: 100%"}).appendTo(l),$.getJSON("settings/user/keys",function(e){var t=0;e.keys.forEach(function(e){x.append($("<option></option>").val(e.name).text(e.name)),t++}),0===t?(x.addClass("input-error"),x.attr("disabled",!0),v.show()):(x.removeClass("input-error"),x.attr("disabled",!1),v.hide())}),l=$('<div style="width: calc(50% - 10px); margin-left: 20px; display:inline-block;"></div>').appendTo(d),$('<label for="red-ui-projects-dialog-screen-create-project-repo-passphrase">'+RED._("projects.clone-project.passphrase")+"</label>").appendTo(l),(_=$('<input id="red-ui-projects-dialog-screen-create-project-repo-passphrase" type="password"></input>').appendTo(l)).typedInput({type:"cred"}),l=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-sshkey"></div>').appendTo(m),$('<div class="red-ui-projects-dialog-screen-create-row-auth-error-no-keys"></div>').hide().appendTo(l));return $('<div class="form-row"><i class="fa fa-warning"></i> '+RED._("projects.clone-project.ssh-key-desc")+"</div>").appendTo(v),l=$('<div style="text-align: center">').appendTo(v),$('<button class="red-ui-button red-ui-projects-dialog-button">'+RED._("projects.clone-project.ssh-key-add")+"</button>").appendTo(l).on("click",function(e){e.preventDefault(),T.dialog("close"),RED.userSettings.show("gitconfig"),setTimeout(function(){$("#user-settings-gitconfig-add-key").trigger("click")},500)}),d=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(i),$("<label>"+RED._("projects.clone-project.credential-key")+"</label>").appendTo(d),(y=$('<input style="width: 100%" type="password"></input>').appendTo(d)).typedInput({type:"cred"}),o},buttons:function(e){return[{text:RED._("common.label.back"),click:function(){u("git-config")}},{id:"red-ui-projects-dialog-clone-project",disabled:!0,text:RED._("common.label.clone"),class:"primary disabled",click:function(){$(".red-ui-projects-dialog-screen-create-type.selected").data("type");var e={name:b.val()},t=(e.credentialSecret=y.val(),w.val());if(/^(?:ssh|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?/.test(t)){var o=x.val();if(!o)return void console.log(RED._("projects.clone-project.cant-get-ssh-key"));e.git={remotes:{origin:{url:t,keyFile:o,passphrase:_.val()}}}}else e.git={remotes:{origin:{url:t,username:E.val(),password:D.val()}}};$(".red-ui-projects-dialog-screen-create-row-auth-error").hide(),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.protocols")),E.removeClass("input-error"),D.removeClass("input-error"),x.removeClass("input-error"),_.removeClass("input-error"),RED.deploy.setDeployInflight(!0),RED.projects.settings.switchProject(e.name),V({url:"projects",type:"POST",handleAuthFail:!1,responses:{200:function(e){T.dialog("close")},400:{project_exists:function(e){console.log(RED._("projects.clone-project.already-exists2"))},git_error:function(e){console.log(RED._("projects.clone-project.git-error"),e)},git_connection_failed:function(e){w.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.connection-failed"))},git_not_a_repository:function(e){w.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.not-git-repo"))},git_repository_not_found:function(e){w.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.clone-project.repo-not-found"))},git_auth_failed:function(e){$(".red-ui-projects-dialog-screen-create-row-auth-error").show(),E.addClass("input-error"),D.addClass("input-error"),x.addClass("input-error"),_.addClass("input-error")},missing_flow_file:function(e){T.dialog("close")},missing_package_file:function(e){T.dialog("close")},project_empty:function(e){T.dialog("close")},credentials_load_failed:function(e){T.dialog("close")},"*":function(e){p(e),$(T).dialog("close")}}}},e).then(function(){RED.menu.setDisabled("menu-item-projects-open",!1),RED.menu.setDisabled("menu-item-projects-settings",!1),RED.events.emit("project:change",{name:name})}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}}]}},"default-files":{content:function(e){function t(){var e=!0,t=s.val();""!==t&&/\.json$/.test(t)?(s.hasClass("input-error")&&(s.removeClass("input-error"),s.next().empty()),r.hasClass("input-error")&&(r.removeClass("input-error"),r.next().empty()),r.text(t.substring(0,t.length-5)+"_cred.json")):(e=!1,s.hasClass("input-error")||(s.addClass("input-error"),s.next().empty().append('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>')),r.text(""),r.hasClass("input-error")||(r.addClass("input-error"),r.next().empty().append('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>'))),$("#red-ui-projects-dialog-create-default-files").prop("disabled",!e).toggleClass("disabled ui-button-disabled ui-state-disabled",!e)}var o=$('<div class="red-ui-projects-dialog-screen-start"></div>'),n=(k.appendTo(o),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(o)),e=($("<p>").text(RED._("projects.default-files.create")).appendTo(n),$("<p>").text(RED._("projects.default-files.desc0")).appendTo(n),$("<p>").text(RED._("projects.default-files.desc1")).appendTo(n),!e.existingProject&&RED.settings.files&&$("<p>").text(RED._("projects.default-files.desc2")).appendTo(n),$('<div class="form-row"></div>').appendTo(n)),i=($('<label for="red-ui-projects-dialog-screen-create-project-file">'+RED._("projects.default-files.flow-file")+"</label>").appendTo(e),$('<div style="position:relative;"></div>').appendTo(e)),a=g.files&&g.files.flow||RED.settings.files&&RED.settings.files.flow||"flow.json",a=(s=$('<input id="red-ui-projects-dialog-screen-create-project-file" type="text">').val(a).on("change keyup paste",t).appendTo(i),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(i),$('<label class="red-ui-projects-edit-form-sublabel"><small>*.json</small></label>').appendTo(e),g.files&&g.files.credentials||RED.settings.files&&RED.settings.files.credentials||"flow_cred.json"),e=$('<div class="form-row"></div>').appendTo(n);return $('<label for="red-ui-projects-dialog-screen-create-project-credfile">'+RED._("projects.default-files.credentials-file")+"</label>").appendTo(e),i=$('<div style="position:relative;"></div>').appendTo(e),r=$('<div style="width: 100%" class="uneditable-input" id="red-ui-projects-dialog-screen-create-project-credentials">').text(a).appendTo(i),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(i),setTimeout(function(){s.trigger("focus"),t()},50),o},buttons:function(e){return[{text:RED._(e.existingProject?"common.label.cancel":"common.label.back"),click:function(){e.existingProject?$(this).dialog("close"):u("project-details",e)}},{id:"red-ui-projects-dialog-create-default-files",text:RED._("common.label.next"),class:"primary",click:function(){g.files={flow:s.val(),credentials:r.text()},e.existingProject||(g.migrateFiles=!0),u("encryption-config",e)}}]}},"encryption-config":{content:function(e){function n(){var e=!0;"enabled"===$("input[name=projects-encryption-type]:checked").val()&&"custom"===$("input[name=projects-encryption-key]:checked").val()&&(e=e&&""!==d.val()),$("#red-ui-projects-dialog-create-encryption").prop("disabled",!e).toggleClass("disabled ui-button-disabled ui-state-disabled",!e)}var t=$('<div class="red-ui-projects-dialog-screen-start"></div>'),o=(k.appendTo(t),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(t)),e=($("<p>").text(RED._("projects.encryption-config.setup")).appendTo(o),e.existingProject?($("<p>").text(RED._("projects.encryption-config.desc0")).appendTo(o),$("<p>").text(RED._("projects.encryption-config.desc1")).appendTo(o)):"disabled"===RED.settings.flowEncryptionType?($("<p>").text(RED._("projects.encryption-config.desc2")).appendTo(o),$("<p>").text(RED._("projects.encryption-config.desc3")).appendTo(o),$("<p>").text(RED._("projects.encryption-config.desc4")).appendTo(o)):("user"===RED.settings.flowEncryptionType?$("<p>").text(RED._("projects.encryption-config.desc5")).appendTo(o):"system"===RED.settings.flowEncryptionType&&$("<p>").text(RED._("projects.encryption-config.desc6")).appendTo(o),$("<p>").text(RED._("projects.encryption-config.desc7")).appendTo(o)),$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty"></div>').appendTo(o)),o=($("<label>"+RED._("projects.encryption-config.credentials")+"</label>").appendTo(e),$('<div class="red-ui-projects-dialog-credentials-box">').appendTo(e)),i=$('<div class="red-ui-projects-dialog-credentials-box-right">').appendTo(o),a=$('<div class="red-ui-projects-dialog-credentials-box-left">').appendTo(o),s=$('<div class="form-row red-ui-projects-dialog-credentials-box-enabled"></div>').appendTo(a),r=($('<label class="red-ui-projects-edit-form-inline-label"><input type="radio" name="projects-encryption-type" value="enabled"> <i class="fa fa-lock"></i> <span>'+RED._("projects.encryption-config.enable")+"</span></label>").appendTo(s),$('<div class="form-row red-ui-projects-dialog-credentials-box-disabled"></div>').appendTo(a));return $('<label class="red-ui-projects-edit-form-inline-label"><input type="radio" name="projects-encryption-type" value="disabled"> <i class="fa fa-unlock"></i> <span>'+RED._("projects.encryption-config.disable")+"</span></label>").appendTo(r),a.find("input[name=projects-encryption-type]").on("click",function(e){var t,o;"enabled"===$(this).val()?(t=s,o=r,$(".projects-encryption-enabled-row").show(),$(".projects-encryption-disabled-row").hide(),"custom"===$("input[name=projects-encryption-key]:checked").val()&&d.trigger("focus")):(o=s,t=r,$(".projects-encryption-enabled-row").hide(),$(".projects-encryption-disabled-row").show()),t.removeClass("disabled"),o.addClass("disabled"),n()}),e=$('<div class="form-row projects-encryption-enabled-row"></div>').appendTo(i),$('<label class="red-ui-projects-edit-form-inline-label '+("user"!==RED.settings.flowEncryptionType?"disabled":"")+'" style="margin-left: 5px"><input '+("user"!==RED.settings.flowEncryptionType?RED._("projects.encryption-config.disabled"):"")+' type="radio" style="vertical-align: middle; margin-top:0; margin-right: 10px;" value="default" name="projects-encryption-key"> <span style="vertical-align: middle;">'+RED._("projects.encryption-config.copy")+"</span></label>").appendTo(e),e=$('<div class="form-row projects-encryption-enabled-row"></div>').appendTo(i),$('<label class="red-ui-projects-edit-form-inline-label" style="margin-left: 5px"><input type="radio" style="vertical-align: middle; margin-top:0; margin-right: 10px;" value="custom" name="projects-encryption-key"> <span style="vertical-align: middle;">'+RED._("projects.encryption-config.use-custom")+"</span></label>").appendTo(e),e=$('<div class="projects-encryption-enabled-row"></div>').appendTo(i),(d=$('<input disabled type="password" style="margin-left: 25px; width: calc(100% - 30px);"></input>').appendTo(e)).typedInput({type:"cred"}),d.on("change keyup paste",n),e=$('<div class="form-row projects-encryption-disabled-row"></div>').hide().appendTo(i),$('<div class="" style="padding: 5px 20px;"><i class="fa fa-warning"></i> '+RED._("projects.encryption-config.desc8")+"</div>").appendTo(e),i.find("input[name=projects-encryption-key]").on("click",function(){var e=$(this).val();d.attr("disabled","default"===e),"custom"===e&&d.trigger("focus"),n()}),setTimeout(function(){a.find("input[name=projects-encryption-type][value=enabled]").trigger("click"),("user"!==RED.settings.flowEncryptionType?i.find("input[name=projects-encryption-key][value=custom]"):i.find("input[name=projects-encryption-key][value=default]")).trigger("click"),n()},100),t},buttons:function(n){return[{text:RED._("common.label.back"),click:function(){u("default-files",n)}},{id:"red-ui-projects-dialog-create-encryption",text:RED._(n.existingProject?"projects.encryption-config.create-project-files":"projects.encryption-config.create-project"),class:"primary disabled",disabled:!0,click:function(){"enabled"===$("input[name=projects-encryption-type]:checked").val()?"custom"===$("input[name=projects-encryption-key]:checked").val()&&(g.credentialSecret=d.val()):g.credentialSecret=!1,RED.deploy.setDeployInflight(!0),RED.projects.settings.switchProject(g.name);var e="POST",t="projects",o=(n.existingProject&&(g.initialise=!0,e="PUT",t="projects/"+U.name),this);V({url:t,type:e,requireCleanWorkspace:!0,handleAuthFail:!1,responses:{200:function(e){g={},n.existingProject?$(o).dialog("close"):(u("create-success"),RED.menu.setDisabled("menu-item-projects-open",!1),RED.menu.setDisabled("menu-item-projects-settings",!1))},400:{project_exists:function(e){console.log(RED._("projects.encryption-config.already-exists"))},git_error:function(e){console.log(RED._("projects.encryption-config.git-error"),e)},git_connection_failed:function(e){projectRepoInput.addClass("input-error")},git_auth_failed:function(e){projectRepoUserInput.addClass("input-error"),projectRepoPasswordInput.addClass("input-error"),console.log(RED._("projects.encryption-config.git-auth-error"),e)},"*":function(e){p(e),$(T).dialog("close")}}}},g).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}}]}},"create-success":{content:function(e){var t=$('<div class="red-ui-projects-dialog-screen-start"></div>'),o=(k.appendTo(t),$('<div class="red-ui-projects-dialog-screen-start-body"></div>').appendTo(t));return $("<p>").text(RED._("projects.create-success.success")).appendTo(o),$("<p>").text(RED._("projects.create-success.desc0")).appendTo(o),$("<p>").text(RED._("projects.create-success.desc1")).appendTo(o),$("<p>").text(RED._("projects.create-success.desc2")).appendTo(o),t},buttons:[{text:RED._("common.label.done"),click:function(){$(this).dialog("close")}}]},create:{title:RED._("projects.create.projects"),content:function(e){var s,n,t,r,d,i,l,a,o,c=null,u=(F=null,!1),p=($.getJSON("projects",function(e){c={},e.projects.forEach(function(e){c[e]=!0,u&&(u=!1,f())})}),$('<div class="red-ui-projects-dialog-screen-create"></div>')),f=function(){var e=L.val(),t=!0;if(w){if(null===c)return void(u=!0);y.empty(),!/^[a-zA-Z0-9\-_]+$/.test(e)||c[e]?(L.addClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>').appendTo(y),t=a=!1,c[e]?z.text(RED._("projects.create.already-exists")):z.text(RED._("projects.create.must-contain"))):(L.removeClass("input-error"),$('<i style="margin-top: 8px;" class="fa fa-check"></i>').appendTo(y),z.text(RED._("projects.create.must-contain")),a=!0),E=e}var o,n,t=a,e=$(".red-ui-projects-dialog-screen-create-type.selected").data("type");"copy"===e?t=!1:"clone"===e?(n=0<(o=N.val()).length&&!/\s/.test(o),/^https?:\/\/[^/]+@/i.test(o)&&($("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.no-info-in-url")),n=!1),n?N.removeClass("input-error"):(T&&N.addClass("input-error"),t=!1),/^https?:\/\//.test(o)?($(".red-ui-projects-dialog-screen-create-row-creds").show(),$(".red-ui-projects-dialog-screen-create-row-sshkey").hide()):/^(?:ssh|[\S]+?@[\S]+?):(?:\/\/)?/.test(o)?($(".red-ui-projects-dialog-screen-create-row-creds").hide(),$(".red-ui-projects-dialog-screen-create-row-sshkey").show()):($(".red-ui-projects-dialog-screen-create-row-creds").hide(),$(".red-ui-projects-dialog-screen-create-row-sshkey").hide())):"empty"===e?(""!==(n=O.val())&&/\.json$/.test(n)?O.hasClass("input-error")&&(O.removeClass("input-error"),O.next().empty()):(t=!1,O.hasClass("input-error")||(O.addClass("input-error"),O.next().empty().append('<i style="margin-top: 8px;" class="fa fa-exclamation-triangle"></i>'))),"enabled"===$("input[name=projects-encryption-type]:checked").val()&&"custom"===$("input[name=projects-encryption-key]:checked").val()&&(t=t&&""!==P.val())):"open"===e&&(t=!!F),$("#red-ui-projects-dialog-create").prop("disabled",!t).toggleClass("disabled ui-button-disabled ui-state-disabled",!t)},h=$('<div class="form-row button-group"></div>').appendTo(p),g=$('<button data-type="open" class="red-ui-button red-ui-projects-dialog-button red-ui-projects-dialog-screen-create-type toggle"><i class="fa fa-archive fa-2x"></i><i style="position: absolute;" class="fa fa-folder-open"></i><br/>'+RED._("projects.create.open")+"</button>").appendTo(h),m=$('<button data-type="empty" class="red-ui-button red-ui-projects-dialog-button red-ui-projects-dialog-screen-create-type toggle"><i class="fa fa-archive fa-2x"></i><i style="position: absolute;" class="fa fa-asterisk"></i><br/>'+RED._("projects.create.create")+"</button>").appendTo(h),v=$('<button data-type="clone" class="red-ui-button red-ui-projects-dialog-button red-ui-projects-dialog-screen-create-type toggle"><i class="fa fa-archive fa-2x"></i><i style="position: absolute;" class="fa fa-git"></i><br/>'+RED._("projects.create.clone")+"</button>").appendTo(h),b=(h.find(".red-ui-projects-dialog-screen-create-type").on("click",function(e){switch(e.preventDefault(),p.find(".red-ui-projects-dialog-screen-create-type").removeClass("selected"),$(this).addClass("selected"),p.find(".red-ui-projects-dialog-screen-create-row").hide(),p.find(".red-ui-projects-dialog-screen-create-row-"+$(this).data("type")).show(),f(),L.trigger("focus"),$(this).data("type")){case"open":$("#red-ui-projects-dialog-create").text(RED._("projects.create.open"));break;case"empty":$("#red-ui-projects-dialog-create").text(RED._("projects.create.create"));break;case"clone":$("#red-ui-projects-dialog-create").text(RED._("projects.create.clone"))}}),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-open"></div>').hide().appendTo(p),s=(s={canSelectActive:!1,dblclick:function(e){F=e,$("#red-ui-projects-dialog-create").trigger("click")},select:function(e){F=e,f()},delete:function(e){c&&delete c[e.name],F=null,f()}})||{},R=$("<div></div>",{class:"red-ui-projects-dialog-project-list-container"}),t="",b=$("<div>",{class:"red-ui-search-container"}).appendTo(R),(r=$('<input id="red-ui-projects-dialog-project-list-search" type="text" placeholder="'+RED._("projects.create-project-list.search")+'">').appendTo(b).searchBox({delay:200,change:function(){t=$(this).val().toLowerCase(),l.editableList("filter"),n&&!n.is(":visible")&&n.children().children().removeClass("selected"),(n=l.children(":visible").first()).children().children().addClass("selected"),s.select&&s.select(n.children().data("data")),d()}})).on("keydown",function(e){if(40===e.keyCode){e.preventDefault();var t=n;if(n){for(;0!==(t=t.next()).length&&!t.is(":visible"););if(0===t.length)return;n.children().children().removeClass("selected")}else t=l.children(":visible").first();(n=t).children().children().addClass("selected"),s.select&&s.select(n.children().data("data")),d()}else if(38===e.keyCode){e.preventDefault();var o=n;if(n){for(;0!==(o=o.prev()).length&&!o.is(":visible"););if(0===o.length)return;n.children().children().removeClass("selected")}else o=l.children(":visible").first();(n=o).children().children().addClass("selected"),s.select&&s.select(n.children().data("data")),d()}else 13===e.keyCode&&(e.preventDefault(),n&&s.dblclick&&s.dblclick(n.children().data("data")))}),r.i18n(),d=function(){var e,t,o,n=l.find(".red-ui-projects-dialog-project-list-entry.selected").parent().parent();1===n.length&&(t=(e=i).height(),e.scrollTop(),t<(o=n.position().top)+(n=n.height())?e.animate({scrollTop:"-="+(t-o-n)},50):o<0&&e.animate({scrollTop:"+="+o},50))},i=$("<div></div>",{class:"red-ui-projects-dialog-project-list-inner-container"}).appendTo(R),l=$("<ol>",{class:"red-ui-projects-dialog-project-list"}).appendTo(i).editableList({addButton:!1,height:"auto",scrollOnAdd:!1,addItem:function(i,e,a){var t,o=$("<div></div>",{class:"red-ui-projects-dialog-project-list-entry"}).appendTo(i);$('<span class="red-ui-projects-dialog-project-list-entry-icon"><i class="fa fa-archive"></i></span>').appendTo(o),$('<span class="red-ui-projects-dialog-project-list-entry-name" style=""></span>').text(a.name).appendTo(o),U&&U.name===a.name&&(o.addClass("projects-list-entry-current"),$('<span class="red-ui-projects-dialog-project-list-entry-current">'+RED._("projects.create-project-list.current")+"</span>").appendTo(o),!1===s.canSelectActive)||(o.addClass("selectable"),t=$('<div class="red-ui-projects-dialog-project-list-entry-tools"></div>').appendTo(o),$('<button class="red-ui-button red-ui-projects-dialog-button red-ui-button-small" style="float: right;"><i class="fa fa-trash"></i></button>').appendTo(t).on("click",function(e){var t,o,n;e.stopPropagation(),e.preventDefault(),e=i,t=a.name,o=function(e){e||i.fadeOut(300,function(){l.editableList("removeItem",a),s.delete&&s.delete(a)})},n=$('<div class="red-ui-projects-dialog-project-list-entry-delete-confirm"></div>').on("click",function(e){e.stopPropagation()}).appendTo(e),$("<span>").text(RED._("projects.delete.confirm")).appendTo(n),$('<button class="red-ui-button red-ui-projects-dialog-button">'+RED._("common.label.cancel")+"</button>").appendTo(n).on("click",function(e){e.stopPropagation(),n.remove(),o(!0)}),$('<button class="red-ui-button red-ui-projects-dialog-button primary">'+RED._("common.label.delete")+"</button>").appendTo(n).on("click",function(e){e.stopPropagation(),n.remove(),V({url:"projects/"+t,type:"DELETE",responses:{200:function(e){o(!1)},400:{unexpected_error:function(e){n.remove(),o(!0)}}}})}),setTimeout(function(){n.css("left",0)},50)}),i.on("click",function(e){$(".red-ui-projects-dialog-project-list-entry").removeClass("selected"),o.addClass("selected"),n=i.parent(),s.select&&s.select(a),d(),r.trigger("focus")}),s.dblclick&&i.on("dblclick",function(e){e.preventDefault(),s.dblclick(a)}))},filter:function(e){return""===t||-1!==e.name.toLowerCase().indexOf(t)}}),$.getJSON("projects",function(e){e.projects.forEach(function(e){l.editableList("addItem",{name:e})})}),R.appendTo(h),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-open"></div>').hide().appendTo(p),$('<span style="display: flex; align-items: center;"><input style="padding:0; margin: 0 5px 0 0" checked type="checkbox" id="red-ui-projects-dialog-screen-clear-context"> <label for="red-ui-projects-dialog-screen-clear-context" style="padding:0; margin: 0"> <span data-i18n="projects.create.clearContext"></span></label></span>').appendTo(h).i18n(),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(p),$('<label for="red-ui-projects-dialog-screen-create-project-name">'+RED._("projects.create.project-name")+"</label>").appendTo(h),$('<div style="position:relative;"></div>').appendTo(h)),y=(L=$('<input id="red-ui-projects-dialog-screen-create-project-name" type="text"></input>').appendTo(b),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(b)),w=!1,E="",D="",R=(L.on("change keyup paste",function(){if(w=L.val()!==E,o)clearTimeout(o);else if(w&&(y.empty(),$('<img src="red/images/spin.svg"/>').appendTo(y),""===L.val()))return void f();o=setTimeout(function(){f(),o=null},300)}),z=$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.create.must-contain")+"</small></label>").appendTo(h).find("small"),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty"></div>').appendTo(p),$('<label for="red-ui-projects-dialog-screen-create-project-desc">'+RED._("projects.create.desc")+"</label>").appendTo(h),S=$('<input id="red-ui-projects-dialog-screen-create-project-desc" type="text">').appendTo(h),$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.create.opt")+"</small></label>").appendTo(h),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty"></div>').appendTo(p),$('<label for="red-ui-projects-dialog-screen-create-project-file">'+RED._("projects.create.flow-file")+"</label>").appendTo(h),b=$('<div style="position:relative;"></div>').appendTo(h),O=$('<input id="red-ui-projects-dialog-screen-create-project-file" type="text">').val("flow.json").on("change keyup paste",f).appendTo(b),$('<div class="red-ui-projects-dialog-screen-input-status"></div>').appendTo(b),$('<label class="red-ui-projects-edit-form-sublabel"><small>*.json</small></label>').appendTo(h),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty"></div>').appendTo(p),$("<label>"+RED._("projects.create.credentials")+"</label>").appendTo(h),$('<div class="red-ui-projects-dialog-credentials-box">').appendTo(h)),x=$('<div class="red-ui-projects-dialog-credentials-box-right">').appendTo(R),R=$('<div class="red-ui-projects-dialog-credentials-box-left">').appendTo(R),_=$('<div class="form-row red-ui-projects-dialog-credentials-box-enabled"></div>').appendTo(R),k=($('<label class="red-ui-projects-edit-form-inline-label"><input type="radio" name="projects-encryption-type" value="enabled"> <i class="fa fa-lock"></i> <span>'+RED._("projects.encryption-config.enable")+"</span></label>").appendTo(_),$('<div class="form-row red-ui-projects-dialog-credentials-box-disabled disabled"></div>').appendTo(R)),T=($('<label class="red-ui-projects-edit-form-inline-label"><input type="radio" name="projects-encryption-type" value="disabled"> <i class="fa fa-unlock"></i> <span>'+RED._("projects.encryption-config.disable")+"</span></label>").appendTo(k),R.find("input[name=projects-encryption-type]").on("click",function(e){var t,o;"enabled"===$(this).val()?(t=_,o=k,$(".projects-encryption-enabled-row").show(),$(".projects-encryption-disabled-row").hide(),"custom"===$("input[name=projects-encryption-key]:checked").val()&&P.trigger("focus")):(o=_,t=k,$(".projects-encryption-enabled-row").hide(),$(".projects-encryption-disabled-row").show()),t.removeClass("disabled"),o.addClass("disabled"),f()}),h=$('<div class="form-row projects-encryption-enabled-row"></div>').appendTo(x),$('<label class="red-ui-projects-edit-form-inline-label">'+RED._("projects.create.encryption-key")+"</label>").appendTo(h),(P=$('<input type="password"></input>').appendTo(h)).typedInput({type:"cred"}),P.on("change keyup paste",f),$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.create.desc0")+"</small></label>").appendTo(h),h=$('<div class="form-row projects-encryption-disabled-row"></div>').hide().appendTo(x),$('<div class="" style="padding: 5px 20px;"><i class="fa fa-warning"></i> '+RED._("projects.create.desc1")+"</div>").appendTo(h),x.find("input[name=projects-encryption-key]").on("click",function(){var e=$(this).val();P.attr("disabled","default"===e),"custom"===e&&P.trigger("focus"),f()}),h=$('<div class="hide form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(p),$('<label for="red-ui-projects-dialog-screen-create-project-repo">'+RED._("projects.create.git-url")+"</label>").appendTo(h),N=$('<input id="red-ui-projects-dialog-screen-create-project-repo" type="text" placeholder="https://git.example.com/path/my-project.git"></input>').appendTo(h),$('<label id="red-ui-projects-dialog-screen-create-project-repo-label" class="red-ui-projects-edit-form-sublabel"><small>'+RED._("projects.create.protocols")+"</small></label>").appendTo(h),!1),C="",R=(N.on("change keyup paste",function(){T=!0;var e,t=$(this).val(),t=(C!==t&&$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.protocols")),C=t,/\/([^/]+?)(?:\.git)?$/.exec(t));!t||""!==(e=L.val())&&e!==D||(D=t[1],L.val(D),L.trigger("change")),f()}),$('<div class="hide red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-clone"></div>').hide().appendTo(p)),b=(h=$('<div class="form-row red-ui-projects-dialog-screen-create-row-auth-error"></div>').hide().appendTo(R),$('<div><i class="fa fa-warning"></i> '+RED._("projects.create.auth-failed")+"</div>").appendTo(h),h=$('<div class="hide form-row red-ui-projects-dialog-screen-create-row-creds"></div>').hide().appendTo(R),$('<div style="width: calc(50% - 10px); display:inline-block;"></div>').appendTo(h)),j=($('<label for="red-ui-projects-dialog-screen-create-project-repo-user">'+RED._("projects.create.username")+"</label>").appendTo(b),A=$('<input id="red-ui-projects-dialog-screen-create-project-repo-user" type="text"></input>').appendTo(b),b=$('<div style="width: calc(50% - 10px); margin-left: 20px; display:inline-block;"></div>').appendTo(h),$('<label for="red-ui-projects-dialog-screen-create-project-repo-pass">'+RED._("projects.create.password")+"</label>").appendTo(b),(M=$('<input style="width:100%" id="red-ui-projects-dialog-screen-create-project-repo-pass" type="password"></input>').appendTo(b)).typedInput({type:"cred"}),h=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-sshkey"></div>').hide().appendTo(R),b=$('<div style="width: calc(50% - 10px); display:inline-block;"></div>').appendTo(h),$('<label for="red-ui-projects-dialog-screen-create-project-repo-passphrase">'+RED._("projects.create.ssh-key")+"</label>").appendTo(b),B=$("<select>",{style:"width: 100%"}).appendTo(b),$.getJSON("settings/user/keys",function(e){var t=0;e.keys.forEach(function(e){B.append($("<option></option>").val(e.name).text(e.name)),t++}),0===t?(B.addClass("input-error"),B.attr("disabled",!0),j.show()):(B.removeClass("input-error"),B.attr("disabled",!1),j.hide())}),b=$('<div style="width: calc(50% - 10px); margin-left: 20px; display:inline-block;"></div>').appendTo(h),$('<label for="red-ui-projects-dialog-screen-create-project-repo-passphrase">'+RED._("projects.create.passphrase")+"</label>").appendTo(b),(G=$('<input id="red-ui-projects-dialog-screen-create-project-repo-passphrase" type="password"></input>').appendTo(b)).typedInput({type:"cred"}),b=$('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-sshkey"></div>').appendTo(R),$('<div class="red-ui-projects-dialog-screen-create-row-auth-error-no-keys"></div>').hide().appendTo(b));switch($('<div class="form-row"><i class="fa fa-warning"></i> '+RED._("projects.create.desc2")+"</div>").appendTo(j),b=$('<div style="text-align: center">').appendTo(j),$('<button class="red-ui-button red-ui-projects-dialog-button">'+RED._("projects.create.add-ssh-key")+"</button>").appendTo(b).on("click",function(e){e.preventDefault(),$("#red-ui-projects-dialog-cancel").trigger("click"),RED.userSettings.show("gitconfig"),setTimeout(function(){$("#user-settings-gitconfig-add-key").trigger("click")},500)}),h=$('<div class="hide form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(p),$("<label>"+RED._("projects.create.credentials-encryption-key")+"</label>").appendTo(h),(I=$('<input style="width:100%" type="password"></input>').appendTo(h)).typedInput({type:"cred"}),e.screen||"empty"){case"empty":m.trigger("click");break;case"open":g.trigger("click");break;case"clone":v.trigger("click")}return setTimeout(function(){("open"!==(e.screen||"empty")?L:$("#red-ui-projects-dialog-project-list-search")).trigger("focus")},50),p},buttons:function(e){var t;switch(e.screen||"empty"){case"open":t=RED._("projects.create.open");break;case"empty":t=RED._("projects.create.create");break;case"clone":t=RED._("projects.create.clone")}return[{id:"red-ui-projects-dialog-cancel",text:RED._("common.label.cancel"),click:function(){$(this).dialog("close")}},{id:"red-ui-projects-dialog-create",text:t,class:"primary disabled",disabled:!0,click:function(){var t,o,e=$(".red-ui-projects-dialog-screen-create-type.selected").data("type"),n={name:L.val()};if("empty"===e){n.summary=S.val(),n.files={flow:O.val()};var i=$("input[name=projects-encryption-type]:checked").val();n.credentialSecret="enabled"===i&&P.val()}else if("copy"===e)n.copy=(void 0).name;else if("clone"===e){n.credentialSecret=I.val();var i=N.val();if(/^(?:ssh|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?/.test(i)){var a=B.val();if(!a)return void console.log(RED._("projects.create.cant-get-ssh-key-path"));n.git={remotes:{origin:{url:i,keyFile:a,passphrase:G.val()}}}}else n.git={remotes:{origin:{url:i,username:A.val(),password:M.val()}}}}else if("open"===e)return a=$("#red-ui-projects-dialog-screen-clear-context").prop("checked"),t=F.name,i=a,o=function(e,t){e&&"credentials_load_failed"!==e.code&&console.log(RED._("projects.create.unexpected_error"),e)},RED.deploy.setDeployInflight(!0),RED.projects.settings.switchProject(t),void V({url:"projects/"+t,type:"PUT",responses:{200:function(e){o(null,e)},400:{credentials_load_failed:function(e){T.dialog("close"),RED.events.emit("project:change",{name:t}),o(null,e)},"*":o}}},{active:!0,clearContext:i}).then(function(){T.dialog("close"),RED.events.emit("project:change",{name:t})}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)});$(".red-ui-projects-dialog-screen-create-row-auth-error").hide(),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.protocols")),A.removeClass("input-error"),M.removeClass("input-error"),B.removeClass("input-error"),G.removeClass("input-error"),RED.deploy.setDeployInflight(!0),RED.projects.settings.switchProject(n.name),V({url:"projects",type:"POST",handleAuthFail:!1,responses:{200:function(e){T.dialog("close")},400:{project_exists:function(e){console.log(RED._("projects.create.already-exists-2"))},git_error:function(e){console.log(RED._("projects.create.git-error"),e)},git_connection_failed:function(e){N.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.con-failed"))},git_not_a_repository:function(e){N.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.not-git"))},git_repository_not_found:function(e){N.addClass("input-error"),$("#red-ui-projects-dialog-screen-create-project-repo-label small").text(RED._("projects.create.no-resource"))},git_auth_failed:function(e){$(".red-ui-projects-dialog-screen-create-row-auth-error").show(),A.addClass("input-error"),M.addClass("input-error"),B.addClass("input-error"),G.addClass("input-error")},missing_flow_file:function(e){T.dialog("close")},missing_package_file:function(e){T.dialog("close")},project_empty:function(e){T.dialog("close")},credentials_load_failed:function(e){T.dialog("close")},"*":function(e){p(e),$(T).dialog("close")}}}},n).then(function(){RED.events.emit("project:change",{name:name})}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}}]}}}}function u(e,t){T||RED.projects.init();var e=a[e],o=e.content(t||{}),n=(i.empty(),e.buttons),t=("function"==typeof n&&(n=n(t||{})),T.dialog("option","buttons",n),i.append(o),590),n=$(window).height();n<750&&(t=590-(750-n)),$(".red-ui-projects-dialog-box").height(t),$(".red-ui-projects-dialog-project-list-inner-container").height(Math.max(500,t)-210),T.dialog("option","title",e.title||""),T.dialog("open")}function e(e){var t,o;RED.nodes.dirty()&&(t=RED._("projects.require-clean.confirm"),o=RED.notify(t,{type:"info",fixed:!0,modal:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){o.close(),e(!0)}},{text:RED._("common.label.cont"),click:function(){o.close(),e(!1)}}]}))}function V(l,c){var t,o;if(l.requireCleanWorkspace&&RED.nodes.dirty())return e(function(e){e?l.cancel&&(l.cancel(),o&&o()):(delete l.requireCleanWorkspace,V(l,c).then(function(){t&&t()}).always(function(){o&&o()}))}),{then:function(e){return t=e,{always:function(e){o=e}}},always:function(e){o=e}};var u,p,n=Date.now();return $(".red-ui-component-spinner").show(),$("#red-ui-projects-dialog").parent().find(".ui-dialog-buttonset").children().css("visibility","hidden"),c&&(l.data=JSON.stringify(c),l.contentType="application/json; charset=utf-8"),$.ajax(l).done(function(e,t,o){l.responses&&l.responses[200]&&(u=l.responses[200],p=e)}).fail(function(o,e,t){var n,i,a,s,r,d;if(l.responses&&l.responses[o.status]){if("function"==typeof(n=l.responses[o.status]))return void(p={error:(u=n).statusText});if(!1===l.handleAuthFail||"git_auth_failed"!==o.responseJSON.code&&"git_host_key_verification_failed"!==o.responseJSON.code){if(n[o.responseJSON.code])return u=n[o.responseJSON.code],void(p=o.responseJSON);if(n["*"])return u=n["*"],void(p=o.responseJSON)}else{if("git_auth_failed"===o.responseJSON.code)return a=U.git.remotes[o.responseJSON.remote||l.remote||"origin"].fetch,r=$('<div><div class="form-row">'+RED._("projects.send-req.auth-req")+':</div><div class="form-row"><div style="margin-left: 20px;">'+a+"</div></div></div>"),i=!1,/^https?:\/\//.test(a)?($('<div class="form-row"><label for="projects-user-auth-username">'+RED._("projects.send-req.username")+'</label><input id="projects-user-auth-username" type="text"></input></div><div class="form-row"><label for="projects-user-auth-password">'+RED._("projects.send-req.password")+'</label><input id="projects-user-auth-password" type="password"></input></div>').appendTo(r),r.find("#projects-user-auth-password").typedInput({type:"cred"})):/^(?:ssh|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?/.test(a)&&(i=!0,a=$('<div class="form-row"></div>').appendTo(r),$('<label for="projects-user-auth-key">SSH Key</label>').appendTo(a),s=$('<select id="projects-user-auth-key">').width("70%").appendTo(a),$.getJSON("settings/user/keys",function(e){e.keys.forEach(function(e){s.append($("<option></option>").val(e.name).text(e.name)),0})}),a=$('<div class="form-row"></div>').appendTo(r),$('<label for="projects-user-auth-passphrase">'+RED._("projects.send-req.passphrase")+"</label>").appendTo(a),$('<input id="projects-user-auth-passphrase" type="password"></input>').appendTo(a).typedInput({type:"cred"})),void(d=RED.notify(r,{type:"error",fixed:!0,modal:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){d.close()}},{text:'<span><i class="fa fa-refresh"></i> '+RED._("projects.send-req.retry")+"</span>",click:function(){c=c||{};function t(e){e?(console.log(RED._("projects.send-req.update-failed")),console.log(e)):(V(l,c),d.close())}var e={};i?(e.keyFile=$("#projects-user-auth-key").val(),e.passphrase=$("#projects-user-auth-passphrase").val()):(e.username=$("#projects-user-auth-username").val(),e.password=$("#projects-user-auth-password").val());V({url:"projects/"+U.name+"/remotes/"+(o.responseJSON.remote||l.remote||"origin"),type:"PUT",responses:{0:function(e){t(e)},200:function(e){t(null)},400:{unexpected_error:function(e){t(e)}}}},{auth:e})}}]}));if("git_host_key_verification_failed"===o.responseJSON.code)return r=$('<div><div class="form-row">'+RED._("projects.send-req.host-key-verify-failed")+"</div></div>"),void(d=RED.notify(r,{type:"error",fixed:!0,modal:!0,buttons:[{text:RED._("common.label.close"),click:function(){d.close()}}]}))}}console.log(n),console.log(RED._("projects.send-req.unhandled")+":"),console.log(o),console.log(e),console.log(t)}).always(function(){var e=Date.now()-n,e=Math.max(0,500-e);setTimeout(function(){$(".red-ui-component-spinner").hide(),$("#red-ui-projects-dialog").parent().find(".ui-dialog-buttonset").children().css("visibility",""),u&&u(p)},e)})}function o(n){var i,a="",s=new Set,r=[],d="",l=$('<div class="red-ui-projects-branch-list">').appendTo(n.container),c=$('<input type="text">').attr("placeholder",n.placeholder).appendTo(l).searchBox({delay:200,change:function(){a=$(this).val();var e=!1,t=!1,o=/^([^/]+)\/[^/.~*?\[]/.exec(a);o&&-1<r.indexOf(o[1])&&(t=e=!0),!e&&/(\.\.|\/\.|[?*[~^: \\]|\/\/|\/.$|\/$)/.test(a)?(i.hasClass("input-error")||(i.addClass("input-error"),i.find("i").addClass("fa-warning").removeClass("fa-code-fork")),i.find("span").text(RED._("projects.create-branch-list.invalid")+": "+(t?"":d)+a)):(i.hasClass("input-error")&&(i.removeClass("input-error"),i.find("i").removeClass("fa-warning").addClass("fa-code-fork")),i.find("span").text(RED._("projects.create-branch-list.create")+":"),i.find(".red-ui-sidebar-vc-branch-list-entry-create-name").text((t?"":d)+a)),u.editableList("filter")}}),u=$("<ol>",{style:"height: 130px;"}).appendTo(l);return u.editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){e=$('<div class="red-ui-sidebar-vc-branch-list-entry">').appendTo(e);o.hasOwnProperty("commit")?($('<i class="fa fa-code-fork"></i>').appendTo(e),$("<span>").text(o.name).appendTo(e),o.current&&(e.addClass("selected"),$('<span class="current"></span>').text(n.currentLabel||RED._("projects.create-branch-list.current")).appendTo(e))):(i=e,$('<i class="fa fa-code-fork"></i>').appendTo(e),$("<span>").text(RED._("projects.create-branch-list.create")+":").appendTo(e),$('<div class="red-ui-sidebar-vc-branch-list-entry-create-name" style="margin-left: 10px;">').text(o.name).appendTo(e)),e.on("click",function(e){var t;e.preventDefault(),$(this).hasClass("input-error")||(e={},o.hasOwnProperty("commit")?($(this).hasClass("selected")&&(e.current=!0),e.name=o.name):(e.name=c.val(),e.create=!0,!n.remotes||(t=/^([^/]+)\/[^/.~*?\[]/.exec(e.name))&&-1!==r.indexOf(t[1])||(e.name=r[0]+"/"+e.name)),n.onselect&&n.onselect(e))})},filter:function(e){var t,o=!e.hasOwnProperty("commit"),n=a;return 0<r.length&&(t=/^([^/]+)\/[^/.~*?\[]/.exec(n),""===n||t&&-1!=r.indexOf(t[1])||(n=r[0]+"/"+n)),o&&""!==n&&!s.has(n)||!o&&-1!==e.name.indexOf(a)}}),{refresh:function(e){c.searchBox("value",""),u.editableList("empty");var t=Date.now(),o=f(l).addClass("red-ui-component-spinner-contain");n.remotes?(r=n.remotes(),d=r[0]+"/"):(d="",r=[]),s=new Set,V({url:e,type:"GET",responses:{0:function(e){console.log(e)},200:function(e){e.branches,e.branches.forEach(function(e){u.editableList("addItem",e),s.add(e.name)}),u.editableList("addItem",{}),setTimeout(function(){o.remove()},Math.max(300-(Date.now()-t),0))},400:{git_connection_failed:function(e){RED.notify(e.message,"error")},git_not_a_repository:function(e){RED.notify(e.message,"error")},git_repository_not_found:function(e){RED.notify(e.message,"error")},unexpected_error:function(e){p(e)}}}})},filter:function(){u.editableList("filter")},focus:function(){c.trigger("focus")}}}function f(e){return $('<div class="red-ui-component-spinner"><img src="red/images/spin.svg"/></div>').appendTo(e)}function n(){createProjectOptions={},U?u("create",{screen:"empty"}):u("welcome")}return{init:function(){T=$('<div id="red-ui-projects-dialog" class="hide red-ui-projects-edit-form"><div class="red-ui-projects-dialog-box"><form class="form-horizontal"></form><div class="red-ui-component-spinner hide"><img src="red/images/spin.svg"/></div></div></div>').appendTo("#red-ui-editor").dialog({modal:!0,autoOpen:!1,width:600,resizable:!1,open:function(e){RED.keyboard.disable()},close:function(e){RED.keyboard.enable()},classes:{"ui-dialog":"red-ui-editor-dialog","ui-dialog-titlebar-close":"hide","ui-widget-overlay":"red-ui-editor-dialog"}}),i=T.find("form"),RED.actions.add("core:new-project",RED.projects.newProject),RED.actions.add("core:open-project",RED.projects.selectProject),RED.actions.add("core:show-project-settings",RED.projects.settings.show);var e={sendRequest:V,createBranchList:o,addSpinnerOverlay:f,reportUnexpectedError:p};RED.projects.settings.init(e),RED.projects.userSettings.init(e),RED.sidebar.versionControl.init(e),t()},showStartup:function(){console.warn("showStartup"),RED.user.hasPermission("projects.write")?u("welcome"):RED.notify(RED._("user.errors.notAuthorized"),"error")},newProject:function(){if(RED.user.hasPermission("projects.write"))return RED.nodes.dirty()?e(function(e){e||n()}):void n();RED.notify(RED._("user.errors.notAuthorized"),"error")},selectProject:function(){if(RED.user.hasPermission("projects.write"))return RED.nodes.dirty()?e(function(e){e||u("create",{screen:"open"})}):void u("create",{screen:"open"});RED.notify(RED._("user.errors.notAuthorized"),"error")},showCredentialsPrompt:function(){RED.user.hasPermission("projects.write")?RED.projects.settings.show("settings"):RED.notify(RED._("user.errors.notAuthorized"),"error")},showFilesPrompt:function(){RED.user.hasPermission("projects.write")?(RED.projects.settings.show("settings"),setTimeout(function(){$("#project-settings-tab-settings-file-edit").trigger("click")},200)):RED.notify(RED._("user.errors.notAuthorized"),"error")},showProjectDependencies:function(){RED.projects.settings.show("deps")},createDefaultFileSet:function(){if(!U)throw new Error(RED._("projects.create-default-file-set.no-active"));if(!U.empty)throw new Error(RED._("projects.create-default-file-set.no-empty"));RED.user.hasPermission("projects.write")?(createProjectOptions={},u("default-files",{existingProject:!0})):RED.notify(RED._("user.errors.notAuthorized"),"error")},createDefaultPackageFile:function(){RED.deploy.setDeployInflight(!0),RED.projects.settings.switchProject(U.name),V({url:"projects/"+U.name,type:"PUT",requireCleanWorkspace:!0,handleAuthFail:!1,responses:{200:function(e){},400:{git_error:function(e){console.log(RED._("projects.create-default-file-set.git-error"),e)},missing_flow_file:function(e){$(T).dialog("close")},"*":function(e){p(e),$(T).dialog("close")}}}},{initialise:!0}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})},refresh:function(t){$.getJSON("projects",function(e){e.active?$.getJSON("projects/"+e.active,function(e){U=e,RED.events.emit("projects:load",U),RED.sidebar.versionControl.refresh(!0),t&&t(U)}):t&&t(null)})},editProject:function(){RED.projects.settings.show()},getActiveProject:function(){return U}}}(),RED.projects.settings=function(){var B,G,t=700,o=!1,s=[];function n(e){s.push(e)}function r(n,i){RED.editor.editMarkdown({title:RED._("sidebar.project.editDescription"),header:$('<span><i class="fa fa-book"></i> README.md</span>'),value:n.description,stateId:"sidebar.project.editDescription",complete:function(o){i.empty();function t(e,t){if(e)return r(n,i);n.description=o,d(n,i)}var e=G.addSpinnerOverlay(i);G.sendRequest({url:"projects/"+n.name,type:"PUT",responses:{0:function(e){t(e)},200:function(e){t(null),RED.sidebar.versionControl.refresh(!0)},400:{"*":function(e){G.reportUnexpectedError(e),t(e)}}}},{description:o}).always(function(){e.remove()})}})}function d(e,t){t.empty(),e=e.description?RED.utils.renderMarkdown(e.description):'<span class="red-ui-help-info-none">'+RED._("sidebar.project.noDescriptionAvailable")+"</span>",e=$('<span class="red-ui-text-bidi-aware" dir="'+RED.text.bidi.resolveBaseTextDir(e)+'">'+e+"</span>"),$(e).find("a").each(function(e){var t=$(this).attr("href");/^https?:/.test(t)&&$(this).attr("target","_blank")}),e.appendTo(t).find(".red-ui-text-bidi-aware").contents().filter(function(){return 3===this.nodeType&&""!==this.textContent.trim()}).wrap("<span></span>")}function f(a,s,r,d,l){var c=r.prev(),e=(c.hide(),r.empty(),l.empty(),$('<span class="button-row" style="position: relative; float: right; margin-right:0;"></span>').appendTo(r)),u=$('<input type="text" style="width: calc(100% - 150px); margin-right: 10px;">').val(s||"").appendTo(r),p=$('<input type="text" style="width: calc(100% - 150px); margin-right: 10px;">').val(d||"").appendTo(l);$('<button class="red-ui-button">'+RED._("common.label.cancel")+"</button>").appendTo(e).on("click",function(e){e.preventDefault(),h(a.summary,r),g(a.version,l),c.show()}),$('<button class="red-ui-button">'+RED._("common.label.save")+"</button>").appendTo(e).on("click",function(e){e.preventDefault();function t(e,t){if(e)return i.remove(),f(a,s,r,d,l);a.summary=o,a.version=n,i.remove(),h(a.summary,r),g(a.version,l),c.show()}var o=u.val(),n=p.val(),i=(h(o,r),g(n,l),G.addSpinnerOverlay(r).addClass("red-ui-component-spinner-contain"));G.sendRequest({url:"projects/"+a.name,type:"PUT",responses:{0:function(e){t(e)},200:function(e){RED.sidebar.versionControl.refresh(!0),t(null)},400:{"*":function(e){G.reportUnexpectedError(e),t(e)}}}},{summary:o,version:n})})}function h(e,t){t.empty(),e?t.text(e).removeClass("red-ui-help-info-none"):t.text(RED._("sidebar.project.noSummaryAvailable")).addClass("red-ui-help-info-none")}function g(e,t){t.empty(),e&&t.text(e)}function i(t){var e=$('<div id="red-ui-project-settings-tab-main" class="red-ui-project-settings-tab-pane red-ui-help"></div>'),o=($("<h1>").text(t.name).appendTo(e),$('<div style="position: relative">').appendTo(e)),n=$("<div></div>").appendTo(o),i=$("<div></div>").addClass("red-ui-help-info-none").appendTo(o),o=(h(t.summary,n),g(t.version,i),RED.user.hasPermission("projects.write")&&$('<button class="red-ui-button red-ui-button-small" style="float: right;">'+RED._("sidebar.project.editDescription")+"</button>").prependTo(o).on("click",function(e){e.preventDefault(),f(t,t.summary,n,t.version,i)}),$("<hr>").appendTo(e),$('<div class="red-ui-help" style="position: relative"></div>').appendTo(e)),a=$("<div>",{style:"min-height: 200px"}).appendTo(o);return d(t,a),RED.user.hasPermission("projects.write")&&$('<button class="red-ui-button red-ui-button-small" style="float: right;">'+RED._("sidebar.project.editReadme")+"</button>").prependTo(o).on("click",function(e){e.preventDefault(),r(t,a)}),e}function l(e,t){t.editableList("empty");var o,n=0;for(i in b)b.hasOwnProperty(i)&&(t.editableList("addItem",{id:b[i].module,version:b[i].version,count:b[i].count,known:e.dependencies.hasOwnProperty(i),installed:!0}),n++,0===b[i].count&&0,e.dependencies.hasOwnProperty(i)||0);if(e.dependencies)for(var i in e.dependencies)e.dependencies.hasOwnProperty(i)&&!b.hasOwnProperty(i)&&(o=!!RED.nodes.registry.getModule(i),t.editableList("addItem",{id:i,version:e.dependencies[i],count:0,known:!0,installed:o}),n++,o?0:0);0===n&&t.editableList("addItem",{index:0,label:RED._("sidebar.project.projectSettings.none")})}function c(e,t,o,n){function i(e,t){if(s.remove(),e)return n(e);a.dependencies=o,RED.sidebar.versionControl.refresh(!0),n()}var a=RED.projects.getActiveProject(),s=G.addSpinnerOverlay(t).addClass("red-ui-component-spinner-contain");G.sendRequest({url:"projects/"+a.name,type:"PUT",responses:{0:function(e){i(e)},200:function(e){RED.sidebar.versionControl.refresh(!0),i(null)},400:{"*":function(e){i(e)}}}},{dependencies:o})}function a(r){var t=$('<div id="red-ui-project-settings-tab-deps" class="red-ui-project-settings-tab-pane red-ui-help"></div>'),d=(RED.user.hasPermission("projects.write")&&$('<button class="red-ui-button red-ui-button-small" style="margin-top:10px;float: right;">'+RED._("sidebar.project.projectSettings.edit")+"</button>").appendTo(t).on("click",function(e){e.preventDefault(),function n(i,e,a,s){e=e||JSON.stringify(i.dependencies||{},"",4);"{}"===e&&(e="{\n\n}"),RED.editor.editJSON({title:RED._("sidebar.project.editDependencies"),value:e,requireValid:!0,complete:function(t){try{var o=JSON.parse(t);c(0,a,o,function(e){if(e)return n(i,t,a,s);i.dependencies=o,l(i,s)})}catch(e){n(i,t,a,s)}}})}(r,null,t,d)}),$("<ol>",{style:"position: absolute;top: 60px;bottom: 20px;left: 20px;right: 20px;"}).appendTo(t));return d.editableList({addButton:!1,addItem:function(t,e,o){var n,i,a,s=$("<div>",{class:"red-ui-palette-module-header"}).appendTo(t);o.label?(0===o.index?s.addClass("red-ui-search-empty"):t.parent().addClass("red-ui-palette-module-section"),s.text(o.label)):(s.addClass("red-ui-palette-module-header"),o.installed?0===o.count?s.addClass("red-ui-palette-module-unused"):o.known||s.addClass("red-ui-palette-module-unknown"):s.addClass("red-ui-palette-module-not-installed"),o.element=s,n=$('<div class="red-ui-palette-module-meta red-ui-palette-module-name"></div>').appendTo(s),i="fa-cube",o.installed||(i="fa-warning"),i=$('<i class="fa '+i+'"></i>').appendTo(n),o.icon=i,$("<span>").text(o.id).appendTo(n),i=$('<div class="red-ui-palette-module-meta red-ui-palette-module-version"><i class="fa fa-tag"></i></div>').appendTo(s),$("<span>").text(o.version).appendTo(i),i=$('<div class="red-ui-palette-module-meta"></div>').appendTo(s),a=$('<div class="red-ui-palette-module-button-group"></div>').appendTo(i),RED.user.hasPermission("projects.write")&&(o.installed||!1===RED.settings.get("externalModules.palette.allowInstall",!0)?o.known&&0===o.count?$('<a href="#" class="red-ui-button red-ui-button-small">'+RED._("sidebar.project.projectSettings.removeFromProject")+"</a>").appendTo(a).on("click",function(e){e.preventDefault();e=$.extend(!0,{},r.dependencies);delete e[o.id],c(0,t,e,function(e){e?console.log(e):t.fadeOut(200,function(){d.editableList("removeItem",o)})})}):o.known||$('<a href="#" class="red-ui-button red-ui-button-small">'+RED._("sidebar.project.projectSettings.addToProject")+"</a>").appendTo(a).on("click",function(e){e.preventDefault();e=$.extend(!0,{},r.dependencies);e[o.id]=b[o.id].version,c(0,t,e,function(e){e?console.log(e):(a.remove(),s.removeClass("red-ui-palette-module-unknown"))})}):$('<a href="#" class="red-ui-button red-ui-button-small">'+RED._("sidebar.project.projectSettings.install")+"</a>").appendTo(a).on("click",function(e){e.preventDefault(),RED.palette.editor.install(o,t,function(e){e||(o.installed=!0,RED.utils.addSpinnerOverlay(t,!0),setTimeout(function(){d.editableList("removeItem",o),b={},RED.nodes.eachNode(v),RED.nodes.eachConfig(v),b.hasOwnProperty(o.id)?o.count=b[o.id].count:o.count=0,d.editableList("addItem",o)},500))})})))},sort:function(e,t){return e.id.localeCompare(t.id)}}),l(r,d),t}function F(e,t,n,a,s){var r=$('<div class="red-ui-projects-file-listing-container"></div>',{style:"position: relative; min-height: 175px; height: 175px;"}).hide().appendTo(e),d=G.addSpinnerOverlay(r);return $.getJSON("projects/"+t.name+"/files",function(t){var e=(e=Object.keys(t)).filter(function(e){return!t[e].status||!/D/.test(t[e].status)}),o={},i=(e.sort(),e.forEach(function(e){e.split("/").reduce(function(e,t,o,n){if(t)return o<n.length-1?e[t]=e[t]||{}:e[t]=!0,e[t]},o)}),function(e,t,o){var n={name:e||"/",path:o+(o?"/":"")+e};return!0===t?n.type="f":(n.type="d",n.children=[],n.path=n.path,Object.keys(t).forEach(function(e){n.children.push(i(e,t[e],n.path))}),n.children.sort(function(e,t){return e.hasOwnProperty("children")&&!t.hasOwnProperty("children")?-1:!e.hasOwnProperty("children")&&t.hasOwnProperty("children")?1:e.name.localeCompare(t.name)})),n}),o=i("",o,"");!function a(e,t,s,r,d,o){o=o||"";var n=$("<ol>",{class:"red-ui-projects-dialog-file-list",style:o}).appendTo(e).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){var n,i=$("<div></div>",{class:"red-ui-projects-dialog-file-list-entry"}).appendTo(e);o.children?($('<span class="red-ui-projects-dialog-file-list-entry-folder"><i class="fa fa-angle-right"></i> <i class="fa fa-folder-o"></i></span>').appendTo(i),0<o.children.length&&(n=$("<div></div>",{style:"padding-left: 20px;"}).appendTo(e),0===s.indexOf(o.path+"/")?i.addClass("expanded"):n.hide(),a(n,o.children,s,r,d),i.addClass("selectable"),i.on("click",function(e){$(this).hasClass("expanded")?($(this).removeClass("expanded"),n.slideUp(200)):($(this).addClass("expanded"),n.slideDown(200))}))):(e="fa-file-o",/\.json$/i.test(o.name)?e="fa-file-code-o":/\.md$/i.test(o.name)?e="fa-book":/^\.git/i.test(o.name)&&(e="fa-code-fork",i.addClass("red-ui-projects-dialog-file-list-entry-file-type-git")),$('<span class="red-ui-projects-dialog-file-list-entry-file"> <i class="fa '+e+'"></i></span>').appendTo(i),r(o)?(i.addClass("selectable"),o.path===s&&i.addClass("selected"),i.on("click",function(e){$(".red-ui-projects-dialog-file-list-entry.selected").removeClass("selected"),$(this).addClass("selected"),d(o.path,!0)}),i.on("dblclick",function(e){e.preventDefault(),d(o.path,!0)})):i.addClass("unselectable")),$('<span class="red-ui-projects-dialog-file-list-entry-name" style=""></span>').text(o.name).appendTo(i)}});o||n.parent().css("overflow-y","");t.forEach(function(e){n.editableList("addItem",e)})}(r,o.children,n,a,s,"height: 175px"),d.remove()}),r}function u(a,e){function n(){t.show(),P.hide(),l.hide(),h.show(),m.hide(),v.hide(),R.removeClass("uneditable-input"),R.css("height",""),v.removeClass("selected"),u.find(".red-ui-projects-file-listing-container").remove(),u.css("height",""),u.css("color",""),$(".red-ui-settings-row-credentials").hide(),T.hide(),x.hide(),_.removeClass("selected"),k.removeClass("selected")}var t,o=$("<h3></h3>").text(RED._("sidebar.project.projectSettings.files")).appendTo(e),i=$('<div class="red-ui-settings-section"></div>').appendTo(e),s=(RED.user.hasPermission("projects.write")&&(t=$('<button type="button" id="red-ui-project-settings-tab-settings-file-edit" class="red-ui-button red-ui-button-small" style="float: right;">'+RED._("sidebar.project.projectSettings.edit")+"</button>").appendTo(o).on("click",function(e){e.preventDefault(),P.show(),t.hide(),a.files.package||(c.find(".red-ui-projects-edit-form-sublabel-text").text(RED._("sidebar.project.projectSettings.packageCreate")),c.show()),l.show(),h.hide(),m.show(),v.show(),g(),R.addClass("uneditable-input"),$(".red-ui-settings-row-credentials").show(),R.css("height","auto"),T.hide(),x.show()})),e=$('<div class="red-ui-settings-row"></div>').appendTo(i),$('<label for=""></label>').text(RED._("sidebar.project.projectSettings.package")).appendTo(e),$('<div class="uneditable-input" style="padding:0">').appendTo(e)),r=$('<span style="display:inline-block; padding: 6px">').text(a.files.package||"package.json").appendTo(s),d=$('<input type="hidden">').val(a.files.package||"package.json").appendTo(s),l=$('<button type="button" class="red-ui-button toggle single" style="border-top-right-radius: 4px; border-bottom-right-radius: 4px; width: 36px; height: 34px; position: absolute; top: -1px; right: -1px;"><i class="fa fa-folder-open-o"></i></button>').hide().appendTo(s).on("click",function(e){var t;$(this).hasClass("selected")?($(this).removeClass("selected"),s.find(".red-ui-projects-file-listing-container").slideUp(200,function(){$(this).remove(),s.css("height","")}),s.css("color","")):($(this).addClass("selected"),s.css("color","inherit"),t=F(s,a,d.val(),function(e){return e.children||/package\.json$/.test(e.path)},function(e,t){e&&(d.val(e),r.text(e),e=e.substring(0,e.length-12),p.text(e),y.text(e),g(),c.hide()),t&&$(l).trigger("click"),D()}),s.css("height","auto"),setTimeout(function(){t.slideDown(200)},50))}),c=(RED.popover.tooltip(l,RED._("sidebar.project.projectSettings.selectFile")),$('<label style="margin-left: 110px" class="red-ui-projects-edit-form-sublabel"><small><span class="form-warning"><i class="fa fa-warning"></i> <span class="red-ui-projects-edit-form-sublabel-text"></span></small></label>').appendTo(e).hide()),o=(a.files.package||(c.find(".red-ui-projects-edit-form-sublabel-text").text(RED._("sidebar.project.projectSettings.fileNotExist")),c.show()),a.files.package||"package.json"),o=o.substring(0,o.length-12),e=$('<div class="red-ui-settings-row"></div>').appendTo(i),u=($('<label for=""></label>').text(RED._("sidebar.project.projectSettings.flow")).appendTo(e),$('<div class="uneditable-input" style="padding:0">').appendTo(e)),p=$('<span style="display:inline-block; padding: 6px 0 6px 6px">').text(o).appendTo(u),f="flows.json",h=(a.files.flow&&(f=0===a.files.flow.indexOf(o)?a.files.flow.substring(o.length):a.files.flow),$('<span style="display:inline-block; padding: 6px 6px 6px 0">').text(f).appendTo(u)),g=function(){m.css({width:"calc(100% - "+(v.width()+p.width())+"px)"})},m=$('<input type="text" style="padding-left:1px; margin-top: -2px; margin-bottom: 0;border: none;">').val(f).hide().appendTo(u),v=$('<button type="button" class="red-ui-button toggle single" style="border-top-right-radius: 4px; border-bottom-right-radius: 4px; width: 36px; height: 34px; position: absolute; top: -1px; right: -1px;"><i class="fa fa-folder-open-o"></i></button>').hide().appendTo(u).on("click",function(e){var t,o,n,i;$(this).hasClass("selected")?($(this).removeClass("selected"),u.find(".red-ui-projects-file-listing-container").slideUp(200,function(){$(this).remove(),u.css("height","")}),u.css("color","")):($(this).addClass("selected"),u.css("color","inherit"),t=d.val(),o=t.substring(0,t.length-12),n=new RegExp("^"+o+".*.json$"),i=F(u,a,m.val(),function(e){return!/package.json$/.test(e.path)&&n.test(e.path)&&!/_cred\.json$/.test(e.path)},function(e,t){e&&m.val(e.substring(o.length)),t&&$(v).trigger("click"),D()}),u.css("height","auto"),setTimeout(function(){i.slideDown(200)},50))}),b=(RED.popover.tooltip(v,RED._("sidebar.project.projectSettings.selectFile")),e=$('<div class="red-ui-settings-row"></div>').appendTo(i),$('<label for=""></label>').text(RED._("sidebar.project.projectSettings.credentials")).appendTo(e),"flows_cred.json"),f=(a.files.credentials&&(b=0===a.files.flow.indexOf(o)?a.files.credentials.substring(o.length):a.files.credentials),$('<div class="uneditable-input" style="padding:0">').appendTo(e)),y=$('<span style="display:inline-block;padding: 6px 0 6px 6px">').text(o).appendTo(f),w=$('<span style="display:inline-block; padding: 6px 6px 6px 0">').text(b).appendTo(f),E=$('<input type="hidden">').val(b).insertAfter(f),D=function(){var e=m.val(),t=/^(.+?)(\.[^.]*)?$/.exec(e),t=(t?w.text(t[1]+"_cred"+(t[2]||".json")):""===e&&w.text(""),E.val(w.text()),""===e||/\.\./.test(e)||/\/$/.test(e)),e=t||""===w.text();S.is(":visible")&&(O.toggleClass("input-error",""===O.val()),e=e||""===O.val()),I.is(":visible")&&(N.toggleClass("input-error",""===N.val()),e=e||""===N.val()),m.toggleClass("input-error",t),M.toggleClass("disabled",e),M.prop("disabled",e)},R=(m.on("change keyup paste",D),e=$('<div class="red-ui-settings-row"></div>').appendTo(i),$("<label></label>").appendTo(e),$('<span><i class="user-settings-credentials-state-icon fa"></i> <span class="user-settings-credentials-state"></span></span>').appendTo(e)),x=$('<span class="button-group" style="margin-left: -72px;">').hide().appendTo(e),_=(R.css("color","#666"),x.css("vertical-align","top"),$('<button type="button" class="red-ui-button" style="vertical-align: top; width: 36px; margin-bottom: 10px"><i class="fa fa-trash-o"></i></button>').appendTo(x).on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?($(this).removeClass("selected"),T.hide()):(N.val(""),S.hide(),I.show(),$(this).addClass("selected"),k.removeClass("selected"),L.show(),A.show(),C.hide(),j.hide(),T.show()),D()})),k=(RED.popover.tooltip(_,RED._("sidebar.project.projectSettings.resetTheEncryptionKey")),$('<button type="button" class="red-ui-button" style="border-top-right-radius: 4px; border-bottom-right-radius: 4px; vertical-align: top; width: 36px; margin-bottom: 10px"><i class="fa fa-pencil"></i></button>').appendTo(x).on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?($(this).removeClass("selected"),T.hide()):(O.val(""),N.val(""),a.settings.credentialSecretInvalid||!a.settings.credentialsEncrypted?(C.show(),j.hide(),S.hide()):(S.show(),C.hide(),j.show()),I.show(),k.addClass("selected"),_.removeClass("selected"),L.hide(),A.hide(),T.show()),D()})),T=(RED.popover.tooltip(k,RED._("sidebar.project.projectSettings.changeTheEncryptionKey")),$('<div class="red-ui-settings-row red-ui-settings-row-credentials"></div>').hide().appendTo(i),$("<div>",{style:"margin-top:10px"}).hide().appendTo(R)),C=$('<div style="margin: 20px 0 10px 5px;">'+RED._("sidebar.project.projectSettings.setTheEncryptionKey")+"</div>").hide().appendTo(T),j=$('<div style="margin: 20px 0 10px 5px;">'+RED._("sidebar.project.projectSettings.changeTheEncryptionKey")+"</div>").hide().appendTo(T),L=$('<div style="margin: 20px 0 10px 5px;">'+RED._("sidebar.project.projectSettings.resetTheEncryptionKey")+"</div>").hide().appendTo(T),S=$('<div class="red-ui-settings-row red-ui-settings-row-credentials"></div>').appendTo(T),O=($('<label for=""></label>').text(RED._("sidebar.project.projectSettings.currentKey")).appendTo(S),$('<input type="text">').appendTo(S).typedInput({type:"cred"}).on("change keyup paste",function(){B&&(B.close(),B=null),D()})),I=$('<div class="red-ui-settings-row red-ui-settings-row-credentials"></div>').appendTo(T),N=($('<label for=""></label>').text(RED._("sidebar.project.projectSettings.newKey")).appendTo(I),$('<input type="text">').appendTo(I).typedInput({type:"cred"}).on("change keyup paste",D)),A=$('<div class="form-tips form-warning" style="margin: 10px;"><i class="fa fa-warning"></i>'+RED._("sidebar.project.projectSettings.credentialsAlert")+"</div>").hide().appendTo(T),P=$('<span class="button-row" style="position: relative; float: right; margin-right:0;"></span>').hide().appendTo(i),M=($('<button type="button" class="red-ui-button">'+RED._("common.label.cancel")+"</button>").appendTo(P).on("click",function(e){e.preventDefault();e=a.files.package||"package.json",e=e.substring(0,e.length-12);p.text(e),y.text(e),r.text(a.files.package||"package.json"),a.files.package?c.hide():(c.find(".red-ui-projects-edit-form-sublabel-text").text(RED._("sidebar.project.projectSettings.fileNotExist")),c.show()),m.val(h.text()),w.text(b),n()}),$('<button type="button" class="red-ui-button">'+RED._("common.label.save")+"</button>").appendTo(P).on("click",function(e){e.preventDefault();function t(e){o.remove(),e?G.reportUnexpectedError(e):(h.text(m.val()),w.text(E.val()),c.hide(),n())}var o=G.addSpinnerOverlay(i),e=(e=d.val()).substring(0,e.length-12),e={files:{package:d.val(),flow:e+m.val(),credentials:e+E.val()}};_.hasClass("selected")&&(e.resetCredentialSecret=!0),(_.hasClass("selected")||k.hasClass("selected"))&&(e.credentialSecret=N.val(),S.is(":visible")&&(e.currentCredentialSecret=O.val())),RED.deploy.setDeployInflight(!0),G.sendRequest({url:"projects/"+a.name,type:"PUT",responses:{0:function(e){t(e)},200:function(e){a=e,RED.sidebar.versionControl.refresh(!0),z(),t()},400:{credentials_load_failed:function(e){t(e)},missing_current_credential_key:function(e){O.addClass("input-error"),B=RED.popover.create({target:O,direction:"right",size:"small",content:"Incorrect key",autoClose:3e3}).open(),t(e)},"*":function(e){t(e)}}}},e).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})})),z=function(){a.settings.credentialSecretInvalid?(R.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-warning"),R.find(".user-settings-credentials-state").text(RED._("sidebar.project.projectSettings.invalidEncryptionKey"))):a.settings.credentialsEncrypted?(R.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-lock"),R.find(".user-settings-credentials-state").text(RED._("sidebar.project.projectSettings.encryptionEnabled"))):(R.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-unlock"),R.find(".user-settings-credentials-state").text(RED._("sidebar.project.projectSettings.encryptionDisabled"))),_.toggleClass("disabled",!a.settings.credentialSecretInvalid&&!a.settings.credentialsEncrypted),_.prop("disabled",!a.settings.credentialSecretInvalid&&!a.settings.credentialsEncrypted)};D(),z()}function p(a,e){function n(){o.attr("disabled",!1),c.hide(),g.val(""),m.val(""),i&&(i.close(),i=null)}$("<h3></h3>").text(RED._("sidebar.project.projectSettings.versionControl")).appendTo(e),s=a,t=e,t=$('<div class="red-ui-settings-section"></div>').appendTo(t),$("<h4></h4>").text(RED._("sidebar.project.projectSettings.branches")).appendTo(t),t=$('<div class="red-ui-settings-row red-ui-projects-dialog-list"></div>').appendTo(t),r=$("<ol>").appendTo(t).editableList({height:"auto",addButton:!1,scrollOnAdd:!1,addItem:function(i,e,a){var t,o,n=$('<div class="red-ui-projects-dialog-list-entry">').appendTo(i);a.empty?(n.addClass("red-ui-search-empty"),n.text(RED._("sidebar.project.projectSettings.noBranches"))):(a.current&&n.addClass("current"),$('<span class="entry-icon"><i class="fa fa-code-fork"></i></span>').appendTo(n),o=$("<span>").appendTo(n),t=$("<div>").appendTo(o),$('<span class="entry-name">').text(a.name).appendTo(t),a.commit&&$('<span class="entry-detail">').text(a.commit.sha).appendTo(t),a.remote&&(t=$("<div>").appendTo(o),$('<span class="entry-detail entry-remote-name">').text(a.remote||"").appendTo(t),0<a.status.ahead+a.status.behind&&$('<span class="entry-detail"><i class="fa fa-long-arrow-up"></i> <span>'+a.status.ahead+'</span> <i class="fa fa-long-arrow-down"></i> <span>'+a.status.behind+"</span></span>").appendTo(t)),a.current||(o=$('<span class="entry-tools">').appendTo(n),$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-trash"></i></button>').appendTo(o).on("click",function(e){e.preventDefault();var o=G.addSpinnerOverlay(i).addClass("red-ui-component-spinner-contain"),n=RED.notify(RED._("sidebar.project.projectSettings.deleteConfirm",{name:a.name}),{type:"warning",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){o.remove(),n.close()}},{text:"Delete branch",click:function(){n.close();var t={url:"projects/"+s.name+"/branches/"+a.name,type:"DELETE",responses:{200:function(e){i.fadeOut(200,function(){r.editableList("removeItem",a),o.remove()})},400:{git_delete_branch_unmerged:function(e){n=RED.notify(RED._("sidebar.project.projectSettings.unmergedConfirm",{name:a.name}),{type:"warning",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){o.remove(),n.close()}},{text:RED._("sidebar.project.projectSettings.deleteUnmergedBranch"),click:function(){t.url+="?force=true",n.close(),G.sendRequest(t)}}]})},"*":function(e){G.reportUnexpectedError(e),o.remove()}}}};G.sendRequest(t)}}]})})))}}),$.getJSON("projects/"+s.name+"/branches",function(e){e.branches&&(0<e.branches.length?(e.branches.sort(function(e,t){return e.current?-1:t.current?1:e.name.localeCompare(t.name)}),e.branches.forEach(function(e){r.editableList("addItem",e)})):r.editableList("addItem",{empty:!0}))});var s,r,i,t=$('<div class="red-ui-settings-section"></div>').appendTo(e),e=$("<h4></h4>").text(RED._("sidebar.project.projectSettings.gitRemotes")).appendTo(t),o=$('<button class="red-ui-button red-ui-button-small" style="float: right; margin-right: 10px;">'+RED._("sidebar.project.projectSettings.addRemote")+"</button>").appendTo(e).on("click",function(e){o.attr("disabled",!0),c.slideDown(200,function(){c[0].scrollIntoView(),l?(g.val("origin"),m.trigger("focus")):g.trigger("focus"),p()})}),d={empty:!0},l=!0,e=$('<div class="red-ui-settings-row"></div>').appendTo(t),c=$('<div class="red-ui-projects-dialog-list-dialog"></div>').hide().appendTo(e),e=$('<div class="red-ui-settings-row red-ui-projects-dialog-list"></div>').appendTo(t),u=$("<ol>").appendTo(e),p=(u.editableList({addButton:!1,height:"auto",addItem:function(n,e,i){var t,o=$('<div class="red-ui-projects-dialog-list-entry">').appendTo(n);i.empty?(o.addClass("red-ui-search-empty"),o.text(RED._("sidebar.project.projectSettings.noRemotes"))):($('<span class="entry-icon"><i class="fa fa-globe"></i></span>').appendTo(o),t=$("<span>").appendTo(o),$('<div class="entry-name">').text(i.name).appendTo(t),i.urls.fetch===i.urls.push?$('<div class="entry-detail">').text(i.urls.fetch).appendTo(t):($('<div class="entry-detail">').text("fetch: "+i.urls.fetch).appendTo(t),$('<div class="entry-detail">').text("push: "+i.urls.push).appendTo(t)),t=$('<span class="entry-tools">').appendTo(o),$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-trash"></i></button>').appendTo(t).on("click",function(e){e.preventDefault();var t=G.addSpinnerOverlay(n).addClass("red-ui-component-spinner-contain"),o=RED.notify(RED._("sidebar.project.projectSettings.deleteRemoteConfrim",{name:i.name}),{type:"warning",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){t.remove(),o.close()}},{text:RED._("sidebar.project.projectSettings.deleteRemote"),click:function(){o.close(),a.git.branches.remote&&0===a.git.branches.remote.indexOf(i.name+"/")&&delete a.git.branches.remote,a.git.branches.remoteAlt&&0===a.git.branches.remoteAlt.indexOf(i.name+"/")&&delete a.git.branches.remoteAlt;var e="projects/"+a.name+"/remotes/"+i.name;G.sendRequest({url:e,type:"DELETE",responses:{200:function(e){n.fadeOut(200,function(){u.editableList("removeItem",i),setTimeout(t.remove,100),0===e.remotes.length?(delete a.git.remotes,l=!0,u.editableList("addItem",d)):(a.git.remotes={},e.remotes.forEach(function(e){var t=e.name;delete e.name,a.git.remotes[t]=e})),delete a.git.branches.remoteAlt,RED.sidebar.versionControl.refresh()})},400:{"*":function(e){G.reportUnexpectedError(e),t.remove()}}}})}}]})}))}}),function(){var e=/^[a-zA-Z0-9\-_]+$/.test(g.val()),t=m.val(),o=0<t.length&&!/\s/.test(t);/^https?:\/\/[^/]+@/i.test(t)?(v.text(RED._("sidebar.project.projectSettings.urlRule2")),o=!1):v.text(RED._("sidebar.project.projectSettings.urlRule")),b.attr("disabled",!e||!o),g.toggleClass("input-error",f&&!e),m.toggleClass("input-error",h&&!o),i&&(i.close(),i=null)}),f=!1,h=!1,g=($('<div class="red-ui-projects-dialog-list-dialog-header">').text(RED._("sidebar.project.projectSettings.addRemote2")).appendTo(c),e=$('<div class="red-ui-settings-row"></div>').appendTo(c),$('<label for=""></label>').text(RED._("sidebar.project.projectSettings.remoteName")).appendTo(e),$('<input type="text">').appendTo(e).on("change keyup paste",function(){f=!0,p()})),m=($('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("sidebar.project.projectSettings.nameRule")+"</small></label>").appendTo(e).find("small"),e=$('<div class="red-ui-settings-row"></div>').appendTo(c),$('<label for=""></label>').text(RED._("sidebar.project.projectSettings.url")).appendTo(e),$('<input type="text">').appendTo(e).on("change keyup paste",function(){h=!0,p()})),v=$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("sidebar.project.projectSettings.urlRule")+"</small></label>").appendTo(e).find("small"),t=$('<span class="button-row" style="position: relative; float: right; margin: 10px;"></span>').appendTo(c),b=($('<button class="red-ui-button">'+RED._("common.label.cancel")+"</button>").appendTo(t).on("click",function(e){e.preventDefault(),n()}),$('<button class="red-ui-button">'+RED._("sidebar.project.projectSettings.addRemote2")+"</button>").appendTo(t).on("click",function(e){e.preventDefault();function t(e){o.remove(),e||n()}var o=G.addSpinnerOverlay(c).addClass("red-ui-component-spinner-contain"),e={name:g.val(),url:m.val()};RED.deploy.setDeployInflight(!0),G.sendRequest({url:"projects/"+a.name+"/remotes",type:"POST",responses:{0:function(e){t(e)},200:function(e){a.git.remotes={},e.remotes.forEach(function(e){var t=e.name;delete e.name,a.git.remotes[t]=e}),y(),RED.sidebar.versionControl.refresh(),t()},400:{git_remote_already_exists:function(e){i=RED.popover.create({target:g,direction:"right",size:"small",content:"Remote already exists",autoClose:6e3}).open(),g.addClass("input-error"),t(e)},"*":function(e){G.reportUnexpectedError(e),t(e)}}}},e)})),y=function(){u.editableList("empty");var e=0;if(a.git.hasOwnProperty("remotes"))for(var t in a.git.remotes)a.git.remotes.hasOwnProperty(t)&&(e++,u.editableList("addItem",{name:t,urls:a.git.remotes[t]}));(l=0===e)&&u.editableList("addItem",d)};y()}function m(e){var t=$('<div id="red-ui-project-settings-tab-settings" class="red-ui-project-settings-tab-pane red-ui-help"></div>');return u(e,t),p(e,t),t}function v(e){/^subflow:/.test(e.type)||"node-red"!==(e=RED.nodes.registry.getNodeSetForType(e.type).module)&&(b.hasOwnProperty(e)||(b[e]={module:e,version:RED.nodes.registry.getModule(e).version,count:0,known:!1}),b[e].count++)}var b={};return{init:function(e){G=e,n({id:"main",title:RED._("sidebar.project.name"),get:i,close:function(){}}),n({id:"deps",title:RED._("sidebar.project.dependencies"),get:a,close:function(){}}),n({id:"settings",title:RED._("sidebar.project.settings"),get:m,close:function(){B&&(B.close(),B=null)}}),RED.events.on("nodes:add",v),RED.events.on("nodes:remove",function(e){/^subflow:/.test(e.type)||"node-red"!==(e=RED.nodes.registry.getNodeSetForType(e.type).module)&&b.hasOwnProperty(e)&&(b[e].count--,0!==b[e].count||b[e].known||delete b[e])})},show:function(a){var e;o||(RED.user.hasPermission("projects.write")?(o=!0,e={title:RED._("sidebar.project.projectSettings.title"),buttons:[{id:"node-dialog-ok",text:RED._("common.label.close"),class:"primary",click:function(){RED.tray.close()}}],resize:function(e){t=e.width},open:function(e){var t=RED.projects.getActiveProject(),e=e.find(".red-ui-tray-body"),e=$("<div></div>").appendTo(e),o=$("<div></div>",{class:"red-ui-settings-tabs-container"}).appendTo(e),n=($("<ul></ul>",{id:"user-settings-tabs"}).appendTo(o),RED.tabs.create({id:"user-settings-tabs",vertical:!0,onchange:function(e){setTimeout(function(){i.children().hide(),$("#"+e.id).show(),e.pane.focus&&e.pane.focus()},50)}})),i=$("<div></div>",{class:"red-ui-settings-tabs-content"}).appendTo(e);s.forEach(function(e){n.addTab({id:"red-ui-project-settings-tab-"+e.id,label:e.title,pane:e}),e.get(t).hide().appendTo(i)}),e.i18n(),n.activateTab("red-ui-project-settings-tab-"+(a||"main")),$("#red-ui-sidebar-shade").show()},close:function(){o=!1,s.forEach(function(e){e.close&&e.close()}),$("#red-ui-sidebar-shade").hide()},show:function(){}},null!==t&&(e.width=t),RED.tray.show(e)):RED.notify(RED._("user.errors.notAuthorized"),"error"))},switchProject:function(e){b={}}}}(),RED.projects.userSettings=function(){var a,v,b;function s(e){$("<h3></h3>").text(RED._("editor:sidebar.project.userSettings.sshKeys")).appendTo(e);function t(){var e=/^[a-zA-Z0-9\-_]+$/.test(c.val()),t=(c.toggleClass("input-error",l&&!e),u.val()),o=0===t.length||8<=t.length;u.toggleClass("input-error",!o),o?0===t.length?p.text(RED._("editor:sidebar.project.userSettings.optional")):p.text(""):p.text(RED._("editor:sidebar.project.userSettings.passphraseShort")),f.attr("disabled",!(e=e&&o)),n&&(n.close(),n=null)}function i(){a.attr("disabled",!1),s.hide(),c.val(""),l=!1,u.val(""),n&&(n.close(),n=null)}function r(e,t){var e=$('<div class="red-ui-projects-dialog-ssh-public-key">',{style:"position:relative"}).appendTo(e),o=$("<pre>",{style:"min-height: 80px"}).appendTo(e),n=b.addSpinnerOverlay(o).addClass("red-ui-component-spinner-contain"),t={url:"settings/user/keys/"+t.name,type:"GET",responses:{200:function(e){o.text(e.publickey),n.remove()},400:{unexpected_error:function(e){console.log(e),n.remove()}}}},t=(b.sendRequest(t),$('<span class="button-row" style="position: relative; float: right; margin: 10px;"></span>').appendTo(e));return $('<button class="red-ui-button red-ui-button-small">'+RED._("editor:sidebar.project.userSettings.copyPublicKey")+"</button>").appendTo(t).on("click",function(e){try{e.stopPropagation(),e.preventDefault(),document.getSelection().selectAllChildren(o[0]);document.execCommand("copy");document.getSelection().empty()}catch(e){}}),e}var n,e=$('<div class="red-ui-settings-section"></div>').appendTo(e),o=$('<div class="red-ui-settings-section-description"></div>').appendTo(e).text(RED._("editor:sidebar.project.userSettings.sshKeysTip")),a=$('<button id="user-settings-gitconfig-add-key" class="red-ui-button red-ui-button-small" style="float: right; margin-right: 10px;">'+RED._("editor:sidebar.project.userSettings.add")+"</button>").appendTo(o).on("click",function(e){a.attr("disabled",!0),f.attr("disabled",!0),s.slideDown(200),c.trigger("focus")}),o=$('<div class="red-ui-settings-row"></div>').appendTo(e),s=$('<div class="red-ui-projects-dialog-list-dialog"></div>').hide().appendTo(o),d=($('<div class="red-ui-projects-dialog-list-dialog-header">').text(RED._("editor:sidebar.project.userSettings.addSshKey")).appendTo(s),$("<div>").appendTo(s)),o=$('<div class="red-ui-settings-row"></div>').appendTo(d),l=($('<div class="red-ui-settings-section-description"></div>').appendTo(o).text(RED._("editor:sidebar.project.userSettings.addSshKeyTip")),o=$('<div class="red-ui-settings-row"></div>').appendTo(d),$('<label for=""></label>').text(RED._("editor:sidebar.project.userSettings.name")).appendTo(o),!1),c=$('<input type="text">').appendTo(o).on("change keyup paste",function(){l=!0,t()}),d=($('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("editor:sidebar.project.userSettings.nameRule")+"</small></label>").appendTo(o).find("small"),$("<div>").appendTo(d)),u=(o=$('<div class="red-ui-settings-row"></div>').appendTo(d),$('<label for=""></label>').text(RED._("editor:sidebar.project.userSettings.passphrase")).appendTo(o),$('<input type="password">').appendTo(o).on("change keyup paste",t)),p=$('<label class="red-ui-projects-edit-form-sublabel"><small>'+RED._("editor:sidebar.project.userSettings.optional")+"</small></label>").appendTo(o).find("small"),d=$('<span class="button-row" style="position: relative; float: right; margin: 10px;"></span>').appendTo(s),f=($('<button class="red-ui-button">'+RED._("editor:sidebar.project.userSettings.cancel")+"</button>").appendTo(d).on("click",function(e){e.preventDefault(),i()}),$('<button class="red-ui-button">'+RED._("editor:sidebar.project.userSettings.generate")+"</button>").appendTo(d).on("click",function(e){e.preventDefault();function t(e){o.remove(),e||i()}var o=b.addSpinnerOverlay(s).addClass("red-ui-component-spinner-contain"),n={name:c.val(),type:"generate"};n.comment=v.val(),n.password=u.val(),n.size=4096;RED.deploy.setDeployInflight(!0),b.sendRequest({url:"settings/user/keys",type:"POST",responses:{0:function(e){t(e)},200:function(e){m(n.name),t()},400:{unexpected_error:function(e){console.log(e),t(e)}}}},n)})),h=(o=$('<div class="red-ui-settings-row red-ui-projects-dialog-list"></div>').appendTo(e),{empty:!0}),g=$('<ol class="red-ui-projects-dialog-ssh-key-list">').appendTo(o).editableList({height:"auto",addButton:!1,scrollOnAdd:!1,addItem:function(n,e,i){var t,o,a,s=$('<div class="red-ui-projects-dialog-list-entry">').appendTo(n);i.empty?(s.addClass("red-ui-search-empty"),s.text(RED._("editor:sidebar.project.userSettings.noSshKeys"))):(t=$('<div class="red-ui-projects-dialog-ssh-key-header">').appendTo(s),$('<span class="entry-icon"><i class="fa fa-key"></i></span>').appendTo(t),$('<span class="entry-name">').text(i.name).appendTo(t),o=$('<span class="button-row entry-tools">').appendTo(t),t.on("click",function(e){a?a.slideUp(200,function(){a.remove(),a=null}):a=r(s,i)}),i.system||$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-trash"></i></button>').appendTo(o).on("click",function(e){e.stopPropagation();var t=b.addSpinnerOverlay(n).addClass("red-ui-component-spinner-contain"),o=RED.notify(RED._("editor:sidebar.project.userSettings.deleteConfirm",{name:i.name}),{type:"warning",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){t.remove(),o.close()}},{text:RED._("editor:sidebar.project.userSettings.delete"),click:function(){o.close();var e="settings/user/keys/"+i.name;b.sendRequest({url:e,type:"DELETE",responses:{200:function(e){n.fadeOut(200,function(){g.editableList("removeItem",i),setTimeout(t.remove,100),0===g.editableList("length")&&g.editableList("addItem",h)})},400:{unexpected_error:function(e){console.log(e),t.remove()}}}})}}]})}),i.expand&&(a=r(s,i)))}}),m=function(t){$.getJSON("settings/user/keys",function(e){e.keys&&(e.keys.sort(function(e,t){return e.name.localeCompare(t.name)}),g.editableList("empty"),e.keys.forEach(function(e){e.name===t&&(e.expand=!0),g.editableList("addItem",e)}),0===g.editableList("length")&&g.editableList("addItem",h))})};m()}function t(e){var t,o,n,i=$('<div id="red-ui-settings-tab-gitconfig" class="project-settings-tab-pane red-ui-help"></div>');return t=i,(n=RED.settings.get("git")||{}).user=n.user||{},$("<h3></h3>").text(RED._("editor:sidebar.project.userSettings.committerDetail")).appendTo(t),t=$('<div class="red-ui-settings-section"></div>').appendTo(t),$('<div class="red-ui-settings-section-description"></div>').appendTo(t).text(RED._("editor:sidebar.project.userSettings.committerTip")),o=$('<div class="red-ui-settings-row"></div>').appendTo(t),$('<label for="user-settings-gitconfig-username"></label>').text(RED._("editor:sidebar.project.userSettings.userName")).appendTo(o),(a=$('<input type="text" id="user-settings-gitconfig-username">').appendTo(o)).val(n.user.name||""),o=$('<div class="red-ui-settings-row"></div>').appendTo(t),$('<label for="user-settings-gitconfig-email"></label>').text(RED._("editor:sidebar.project.userSettings.email")).appendTo(o),(v=$('<input type="text" id="user-settings-gitconfig-email">').appendTo(o)).val(n.user.email||""),t=i,o=RED.settings.theme("projects.workflow.mode","manual"),(n=RED.settings.get("git")||{}).workflow=n.workflow||{},n.workflow.mode=n.workflow.mode||o,$("<h3></h3>").text(RED._("editor:sidebar.project.userSettings.workflow")).appendTo(t),o=$('<div class="red-ui-settings-section"></div>').appendTo(t),$('<div class="red-ui-settings-section-description"></div>').appendTo(o).text(RED._("editor:sidebar.project.userSettings.workfowTip")),t=$('<div class="red-ui-settings-row"></div>').appendTo(o),$('<label><input type="radio" name="user-setting-gitworkflow" value="manual"> <div style="margin-left: 3px; display: inline-block"><div data-i18n="editor:sidebar.project.userSettings.workflowManual"></div><div style="color:#aaa;" data-i18n="editor:sidebar.project.userSettings.workflowManualTip"></div></div></label>').appendTo(t),t=$('<div class="red-ui-settings-row"></div>').appendTo(o),$('<label><input type="radio" name="user-setting-gitworkflow" value="auto"> <div style="margin-left: 3px; display: inline-block"><div data-i18n="editor:sidebar.project.userSettings.workflowAuto"></div><div style="color:#aaa;" data-i18n="editor:sidebar.project.userSettings.workflowAutoTip"></div></div></label>').appendTo(t),o.find('[name="user-setting-gitworkflow"][type="radio"][value="'+n.workflow.mode+'"]').prop("checked",!0),s(i),i}return{init:function(e){b=e,RED.userSettings.add({id:"gitconfig",title:RED._("editor:sidebar.project.userSettings.gitConfig"),get:t,close:function(){var e=RED.settings.get("git")||{};e.user=e.user||{},e.user.name=a.val(),e.user.email=v.val(),e.workflow=e.workflow||{},e.workflow.mode=$('[name="user-setting-gitworkflow"][type="radio"]:checked').val(),RED.settings.set("git",e)}})}}}(),RED.sidebar.versionControl=function(){var D,R,x,_,k,T,a,C,j,L,S,O,I,s,N,P,A,M={};function z(t,a,e,s){t.addClass("red-ui-sidebar-vc-change-entry");var n,i,r,o,d,l,c=$("<div>").appendTo(t);a.label?(t.addClass("red-ui-help-info-none"),c.text(a.label),a.button&&(c.css({display:"inline-block",maxWidth:"300px",textAlign:"left"}),l=$('<div style="float: right; margin: 5px; height: 50px;"></div>').appendTo(c),$('<button class="red-ui-button red-ui-button-small"></button>').text(a.button.label).appendTo(l).on("click",a.button.click))):(n=$('<i class=""></i>').appendTo(c),i=$('<a href="#">').appendTo(c).on("click",function(e){var o,n,i;e.preventDefault(),o=a,n=s,i=RED.projects.getActiveProject(),N.sendRequest({url:"projects/"+i.name+"/diff/"+("staged"===n?"index":"tree")+"/"+encodeURIComponent(o.file),type:"GET",responses:{0:function(e){console.log(e)},200:function(e){var t="unstaged"===n?RED._("sidebar.project.versionControl.unstagedChanges")+" : "+o.file:"staged"===n?RED._("sidebar.project.versionControl.stagedChanges")+" : "+o.file:RED._("sidebar.project.versionControl.resolveConflicts")+" : "+o.file,e={diff:e.diff,title:t,unmerged:"unmerged"===n,project:i};"unstaged"==n?(e.oldRevTitle=" "===o.indexStatus?RED._("sidebar.project.versionControl.head"):RED._("sidebar.project.versionControl.staged"),e.newRevTitle=RED._("sidebar.project.versionControl.unstaged"),e.oldRev=" "===o.indexStatus?"@":":0",e.newRev="_"):"staged"===n?(e.oldRevTitle=RED._("sidebar.project.versionControl.head"),e.newRevTitle=RED._("sidebar.project.versionControl.staged"),e.oldRev="@",e.newRev=":0"):(e.oldRevTitle=RED._("sidebar.project.versionControl.local"),e.newRevTitle=RED._("sidebar.project.versionControl.remote"),e.commonRev=":1",e.oldRev=":2",e.newRev=":3",e.onresolve=function(e){N.sendRequest({url:"projects/"+i.name+"/resolve/"+encodeURIComponent(o.file),type:"POST",responses:{0:function(e){console.log(e)},200:function(e){V(!0)},400:{unexpected_error:function(e){console.log(e)}}}},{resolutions:e.resolutions[o.file]})}),RED.diff.showUnifiedDiff(e)},400:{unexpected_error:function(e){console.log(e)}}}})}),r=$("<span>").appendTo(i),l=$('<div class="red-ui-sidebar-vc-change-entry-tools">').appendTo(t),"unstaged"===s&&(o=$('<span class="button-group" style="margin-right: 5px;"></span>').appendTo(l),d=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-reply"></i></button>').appendTo(o).on("click",function(e){e.preventDefault();var t=N.addSpinnerOverlay(c).addClass("red-ui-component-spinner-contain"),o=RED.notify(RED._("sidebar.project.versionControl.revert",{file:a.file}),{type:"warning",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){t.remove(),o.close()}},{text:RED._("sidebar.project.versionControl.revertChanges"),click:function(){o.close();var e={url:"projects/"+RED.projects.getActiveProject().name+"/files/_/"+a.file,type:"DELETE",responses:{200:function(e){t.remove()},400:{unexpected_error:function(e){t.remove(),console.log(e)}}}};RED.deploy.setDeployInflight(!0),N.sendRequest(e).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}}]})}),RED.popover.tooltip(d,RED._("sidebar.project.versionControl.revertChanges"))),o=$('<span class="button-group"></span>').appendTo(l),"unmerged"!==s&&(l=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-'+("unstaged"===s?"plus":"minus")+'"></i></button>').appendTo(o).on("click",function(e){e.preventDefault();e=RED.projects.getActiveProject();a.spinner=N.addSpinnerOverlay(t).addClass("projects-version-control-spinner-sidebar"),N.sendRequest({url:"projects/"+e.name+"/stage/"+encodeURIComponent(a.file),type:"unstaged"===s?"POST":"DELETE",responses:{0:function(e){console.log(e)},200:function(e){U(e)},400:{unexpected_error:function(e){console.log(e)}}}},{})}),RED.popover.tooltip(l,RED._("sidebar.project.versionControl."+("unstaged"===s?"stage":"unstage")+"Change"))),a["update"+("unstaged"===s?"Unstaged":"Staged")]=function(e,t){c.removeClass();var o="",o="A"===t?(c.addClass("red-ui-diff-state-added"),"fa-plus-square"):"?"===t?(c.addClass("red-ui-diff-state-unchanged"),"fa-question-circle-o"):"D"===t?(c.addClass("red-ui-diff-state-deleted"),"fa-minus-square"):"M"===t?(c.addClass("red-ui-diff-state-changed"),"fa-square"):"R"===t?(c.addClass("red-ui-diff-state-changed"),"fa-toggle-right"):("U"===t&&c.addClass("red-ui-diff-state-conflicted"),"fa-exclamation-triangle");r.empty(),$("<span>").text(e.file.replace(/\\(.)/g,"$1")).appendTo(r),e.oldName&&($('<i class="fa fa-long-arrow-right"></i>').prependTo(r),$("<span>").text(e.oldName.replace(/\\(.)/g,"$1")).prependTo(r)),n.removeClass(),n.addClass("fa "+o),e.spinner&&(e.spinner.remove(),delete e.spinner),d&&d.toggle("?"!==t),i.toggleClass("disabled","D"===t||"?"===t)},a["update"+("unstaged"===s?"Unstaged":"Staged")](a,e))}function B(e){var t=Date.now()/1e3-e,o=Math.floor(t/86400);if(30<o)return new Date(1e3*e).toLocaleDateString();if(0<o)return RED._("sidebar.project.versionControl.daysAgo",{count:o});e=Math.floor(t/3600);if(0<e)return RED._("sidebar.project.versionControl.hoursAgo",{count:e});o=Math.floor(t/60);return 0<o?RED._("sidebar.project.versionControl.minsAgo",{count:o}):RED._("sidebar.project.versionControl.secondsAgo")}function G(e,t){var o=RED.projects.getActiveProject(),e=((a=t?N.addSpinnerOverlay(x.parent()):N.addSpinnerOverlay(k.parent())).addClass("red-ui-component-spinner-sidebar"),t?{files:e}:void 0);N.sendRequest({url:"projects/"+o.name+"/stage",type:t?"POST":"DELETE",responses:{0:function(e){console.log(e)},200:function(e){U(e)},400:{unexpected_error:function(e){console.log(e)}}}},e)}var i=!1;function F(n,i,e,a,t){var s=N.addSpinnerOverlay(e),e=n+"?limit="+(a||20);t&&(e+="&before="+t),N.sendRequest({url:e,type:"GET",responses:{0:function(e){console.log(e)},200:function(e){e.commits.forEach(function(e){i.editableList("addItem",e),t=e.sha}),i.loadMoreItem&&(i.editableList("removeItem",i.loadMoreItem),delete i.loadMoreItem);var t,o=i.editableList("length");o<e.total&&(i.loadMoreItem={totalKnown:o,total:e.total,url:n,before:t+"~1",limit:a},i.editableList("addItem",i.loadMoreItem)),s.remove()},400:{unexpected_error:function(e){console.log(e)}}}})}function U(e){var n=e.files,e=(a&&(a.remove(),a=null),(s=!!e.merging)?(D.addClass("red-ui-sidebar-vc-merging"),C.show()):(D.removeClass("red-ui-sidebar-vc-merging"),C.hide()),x.editableList("removeItem",P),k.editableList("removeItem",P),j.editableList("removeItem",A),Object.keys(n).filter(function(e){return"f"===n[e].type})),i=(e.sort(),Date.now()+Math.floor(100*Math.random())),e=(e.forEach(function(e){var t=n[e],o=!1;t.status&&(t.file=e,t.indexStatus=t.status[0],t.treeStatus=t.status[1],("A"===t.indexStatus&&/[AU]/.test(t.treeStatus)||"U"===t.indexStatus&&/[DAU]/.test(t.treeStatus)||"D"===t.indexStatus&&/[DU]/.test(t.treeStatus))&&(t.unmerged=!0),M[e]?(M[e].unmerged&&!t.unmerged?(j.editableList("removeItem",M[e]),o=!0):!M[e].unmerged&&t.unmerged&&(x.editableList("removeItem",M[e]),k.editableList("removeItem",M[e])),M[e].status!==t.status&&(" "!==M[e].treeStatus?" "===t.treeStatus?x.editableList("removeItem",M[e]):t.treeStatus!==M[e].treeStatus&&M[e].updateUnstaged(t,t.treeStatus):o=!0," "!==M[e].indexStatus&&"?"!==M[e].indexStatus?" "===t.indexStatus||"?"===t.indexStatus?k.editableList("removeItem",M[e]):t.indexStatus!==M[e].indexStatus&&M[e].updateStaged(t,t.indexStatus):o=!0),M[e].status=t.status,M[e].indexStatus=t.indexStatus,M[e].treeStatus=t.treeStatus,M[e].oldName=t.oldName,M[e].unmerged=t.unmerged):(o=!0,M[e]=t),M[e].updateIndex=i,o&&(t.unmerged?j.editableList("addItem",M[e]):(" "!==t.treeStatus&&x.editableList("addItem",M[e])," "!==t.indexStatus&&"?"!==t.indexStatus&&k.editableList("addItem",M[e]))))}),Object.keys(M).forEach(function(e){M[e].updateIndex!==i&&(x.editableList("removeItem",M[e]),k.editableList("removeItem",M[e]),delete M[e])}),k.editableList("length")),t=x.editableList("length"),o=j.editableList("length");L.prop("disabled",s&&0<o||!s&&0===e),_.prop("disabled",0===t),T.prop("disabled",0===e),0===e&&k.editableList("addItem",P),0===t&&x.editableList("addItem",P),0===o&&j.editableList("addItem",A)}function V(e,t){var n;i||(e&&(M={},x.editableList("empty"),k.editableList("empty"),j.editableList("empty")),RED.user.hasPermission("projects.write")&&(i=!0,O.editableList("empty"),(e=RED.projects.getActiveProject())&&F("projects/"+e.name+"/commits",O,O.parent()),(n=RED.projects.getActiveProject())?(e="projects/"+n.name+"/status",t&&(e+="?remote=true"),$.getJSON(e,function(e){U(e),$("#red-ui-sidebar-vc-local-branch").text(e.branches.local),$("#red-ui-sidebar-vc-remote-branch").text(e.branches.remote||RED._("sidebar.project.versionControl.none"));var t=e.commits.ahead||0,o=e.commits.behind||0;n.git.hasOwnProperty("remotes")?e.branches.hasOwnProperty("remoteError")&&"git_remote_gone"!==e.branches.remoteError.code?($("#red-ui-sidebar-vc-repo-status-auth-issue").show(),$("#red-ui-sidebar-vc-repo-status-stats").hide(),$("#red-ui-sidebar-vc-repo-branch").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-toolbar-message").hide(),$("#red-ui-sidebar-vc-repo-toolbar-error-message").show()):($("#red-ui-sidebar-vc-repo-toolbar-message").show(),$("#red-ui-sidebar-vc-repo-toolbar-error-message").hide(),$("#red-ui-sidebar-vc-repo-status-auth-issue").hide(),$("#red-ui-sidebar-vc-repo-status-stats").show(),$("#red-ui-sidebar-vc-repo-branch").prop("disabled",!1),$("#red-ui-sidebar-vc-repo-status-button").show(),e.branches.hasOwnProperty("remote")?J(t,o):($("#red-ui-sidebar-vc-commits-ahead").text(""),$("#red-ui-sidebar-vc-commits-behind").text(""),$("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.notTracking")),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0))):$("#red-ui-sidebar-vc-repo-status-button").hide(),i=!1,$(".red-ui-sidebar-vc-shade").hide()}).fail(function(){i=!1})):($(".red-ui-sidebar-vc-shade").show(),x.editableList("empty"),k.editableList("empty"),j.editableList("empty"))))}function J(e,t){$("#red-ui-sidebar-vc-commits-ahead").text(e),$("#red-ui-sidebar-vc-commits-behind").text(t),s?($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.statusUnmergedChanged")),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0)):0<e&&0===t?($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.commitsAhead",{count:e})),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!1)):0===e&&0<t?($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.commitsBehind",{count:t})),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!1),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0)):0<e&&0<t?($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.commitsAheadAndBehind1",{count:t})+RED._("sidebar.project.versionControl.commitsAheadAndBehind2",{count:e})+RED._("sidebar.project.versionControl.commitsAheadAndBehind3",{count:t})),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!1),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0)):0===e&&0===t&&($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.repositoryUpToDate")),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!0))}function q(){V(),RED.sidebar.show("version-control")}return{init:function(e){function i(o){o=o||{};var e=N.addSpinnerOverlay(m).addClass("red-ui-component-spinner-contain"),t=$('<div style="position: relative; bottom: 60px;"></div>').appendTo(e),n=($('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(t).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.projects.getActiveProject()),t=(RED.eventLog.startEvent("Pull changes"+(n.git.branches.remoteAlt?" : "+n.git.branches.remoteAlt:"")),"projects/"+n.name+"/pull");n.git.branches.remoteAlt&&(t+="/"+n.git.branches.remoteAlt),(o.setUpstream||o.allowUnrelatedHistories)&&(t+="?"),o.setUpstream&&(t+="setUpstream=true",o.allowUnrelatedHistories&&(t+="&")),o.allowUnrelatedHistories&&(t+="allowUnrelatedHistories=true"),N.sendRequest({url:t,type:"POST",responses:{0:function(e){console.log(e)},200:function(e){o.setUpstream&&n.git.branches.remoteAlt&&(n.git.branches.remote=n.git.branches.remoteAlt,delete n.git.branches.remoteAlt),V(!0),v()},400:{git_local_overwrite:function(e){RED.notify(RED._("sidebar.project.versionControl.unablePull")+'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+RED._("sidebar.project.versionControl.showUnstagedChanges")+"</a></p>","error",!1,1e7)},git_pull_merge_conflict:function(e){V(!0),v()},git_connection_failed:function(e){RED.notify(RED._("sidebar.project.versionControl.connectionFailed")+e.toString(),"warning")},git_pull_unrelated_history:function(e){var t=RED.notify(RED._("sidebar.project.versionControl.pullUnrelatedHistory"),{type:"error",modal:!0,fixed:!0,buttons:[{text:RED._("common.label.cancel"),click:function(){t.close()}},{text:RED._("sidebar.project.versionControl.pullChanges"),click:function(){t.close(),o.allowUnrelatedHistories=!0,i(o)}}]})},"*":function(e){N.reportUnexpectedError(e)}}}},{}).always(function(){e.remove()})}N=e,RED.actions.add("core:show-version-control-tab",q),RED.events.on("deploy",function(){var e,t=RED.projects.getActiveProject();t&&(e=RED.settings.theme("projects.workflow.mode","manual"),"auto"===(((RED.settings.get("git")||{}).workflow||{}).mode||e)?V(!0):(M={},x.editableList("empty"),k.editableList("empty"),j.editableList("empty"),$.getJSON("projects/"+t.name+"/status",function(e){U(e)})))}),RED.events.on("login",function(){V(!0)}),D=$("<div>",{class:"red-ui-sidebar-vc"});var e=$("<div>",{class:"red-ui-sidebar-vc-stack"}).appendTo(D),e=(R=RED.stack.create({container:e,fill:!0,singleExpanded:!0}),(S=R.add({title:RED._("sidebar.project.versionControl.localChanges"),collapsible:!0})).expand(),S.content.css({height:"100%"}),$('<div style="float: right"></div>').appendTo(S.header)),t=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-refresh"></i></button>').appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation(),V(!0)}),o=(RED.popover.tooltip(t,RED._("sidebar.project.versionControl.refreshChanges")),P={label:RED._("sidebar.project.versionControl.none")},A={label:RED._("sidebar.project.versionControl.conflictResolve")},$('<div class="red-ui-sidebar-vc-change-container"></div>').appendTo(S.content)),n=$('<div class="red-ui-sidebar-vc-change-header">'+RED._("sidebar.project.versionControl.localFiles")+"</div>").appendTo(o),a=(_=$('<button class="red-ui-button red-ui-button-small" style="position: absolute; right: 5px; top: 5px;"><i class="fa fa-plus"></i> '+RED._("sidebar.project.versionControl.all")+"</button>").appendTo(n).on("click",function(e){e.preventDefault(),e.stopPropagation(),G(Object.keys(M).filter(function(e){return" "!==M[e].treeStatus}),!0)}),RED.popover.tooltip(_,RED._("sidebar.project.versionControl.stageAllChange")),(x=$("<ol>",{style:"position: absolute; top: 30px; bottom: 0; right:0; left:0;"}).appendTo(o)).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){z(e,o,o.treeStatus,"unstaged")},sort:function(e,t){return"?"===e.treeStatus&&"?"!==t.treeStatus?1:"?"!==e.treeStatus&&"?"===t.treeStatus?-1:e.file.localeCompare(t.file)}}),C=$('<div class="red-ui-sidebar-vc-change-container"></div>').appendTo(S.content),n=$('<div class="red-ui-sidebar-vc-change-header">'+RED._("sidebar.project.versionControl.unmergedChanges")+"</div>").appendTo(C),e=$('<div style="position: absolute; right: 5px; top: 5px;"></div>').appendTo(n),$('<button class="red-ui-button red-ui-button-small" style="margin-right: 5px;">'+RED._("sidebar.project.versionControl.abortMerge")+"</button>").appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation();var t=N.addSpinnerOverlay(C),e=RED.projects.getActiveProject();RED.deploy.setDeployInflight(!0),N.sendRequest({url:"projects/"+e.name+"/merge",type:"DELETE",responses:{0:function(e){console.log(e)},200:function(e){t.remove(),V(!0)},400:{unexpected_error:function(e){console.log(e)}}}}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})})),s=((j=$("<ol>",{style:"position: absolute; top: 30px; bottom: 0; right:0; left:0;"}).appendTo(C)).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){o===A&&(o.button={label:RED._("sidebar.project.versionControl.commit"),click:function(e){e.preventDefault(),e.stopPropagation(),r()}}),z(e,o,o.treeStatus,"unmerged")},sort:function(e,t){return"?"===e.treeStatus&&"?"!==t.treeStatus?1:"?"!==e.treeStatus&&"?"===t.treeStatus?-1:e.file.localeCompare(t.file)}}),$('<div class="red-ui-sidebar-vc-change-container"></div>').appendTo(S.content)),n=$('<div class="red-ui-sidebar-vc-change-header">'+RED._("sidebar.project.versionControl.changeToCommit")+"</div>").appendTo(s),e=$('<div style="position: absolute; right: 5px; top: 5px;"></div>').appendTo(n),r=function(){d.val(""),c.prop("disabled",!0),o.css("height","30px"),C.is(":visible")?(C.css("height","30px"),s.css("height","calc(100% - 60px - 175px)")):s.css("height","calc(100% - 30px - 175px)"),commitBox.show(),setTimeout(function(){commitBox.css("height","175px")},10),_.prop("disabled",!0),T.prop("disabled",!0),L.prop("disabled",!0),a.prop("disabled",!0),d.trigger("focus")},d=(L=$('<button class="red-ui-button red-ui-button-small" style="margin-right: 5px;">'+RED._("sidebar.project.versionControl.commit")+"</button>").appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation(),r()}),RED.popover.tooltip(L,RED._("sidebar.project.versionControl.commitChanges")),T=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-minus"></i> '+RED._("sidebar.project.versionControl.all")+"</button>").appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation(),G(Object.keys(M).filter(function(e){return" "!==M[e].indexStatus&&"?"!==M[e].indexStatus}),!1)}),RED.popover.tooltip(T,RED._("sidebar.project.versionControl.unstageAllChange")),(k=$("<ol>",{style:"position: absolute; top: 30px; bottom: 0; right:0; left:0;"}).appendTo(s)).editableList({addButton:!1,scrollOnAdd:!1,addItem:function(e,t,o){z(e,o,o.indexStatus,"staged")},sort:function(e,t){return e.file.localeCompare(t.file)}}),commitBox=$('<div class="red-ui-sidebar-vc-slide-box red-ui-sidebar-vc-slide-box-bottom"></div>').hide().appendTo(S.content),$("<textarea></textarea>").attr("placeholder",RED._("sidebar.project.versionControl.commitPlaceholder")).appendTo(commitBox).on("change keyup paste",function(){c.prop("disabled",""===$(this).val().trim())})),n=$('<div class="red-ui-sidebar-vc-slide-box-toolbar button-group">').appendTo(commitBox),l=$('<button class="red-ui-button">'+RED._("sidebar.project.versionControl.cancelCapital")+"</button>").appendTo(n).on("click",function(e){e.preventDefault(),d.val(""),o.css("height",""),C.css("height",""),s.css("height",""),commitBox.css("height",0),setTimeout(function(){commitBox.hide()},200),_.prop("disabled",!1),T.prop("disabled",!1),L.prop("disabled",!1),a.prop("disabled",!1)}),c=$('<button class="red-ui-button">'+RED._("sidebar.project.versionControl.commitCapital")+"</button>").appendTo(n).on("click",function(e){e.preventDefault();var t=N.addSpinnerOverlay(c).addClass("red-ui-component-spinner-sidebar"),e=RED.projects.getActiveProject();RED.deploy.setDeployInflight(!0),N.sendRequest({url:"projects/"+e.name+"/commit",type:"POST",responses:{0:function(e){console.log(e)},200:function(e){t.remove(),l.trigger("click"),V(!0)},400:{"*":function(e){N.reportUnexpectedError(e)}}}},{message:d.val()}).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}),n=R.add({title:RED._("sidebar.project.versionControl.commitHistory"),collapsible:!0}),e=(e=$('<div style="float: right"></div>').appendTo(n.header),t=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-refresh"></i></button>').appendTo(e).on("click",function(e){e.preventDefault(),e.stopPropagation(),V(!0,!0)}),RED.popover.tooltip(t,RED._("sidebar.project.versionControl.refreshCommitHistory")),$('<div class="red-ui-sidebar-vc-change-header" style="text-align: right;"></div>').appendTo(n.content)),u=$('<button class="red-ui-button red-ui-button-small"><i class="fa fa-code-fork"></i> '+RED._("sidebar.project.versionControl.branch")+' <span id="red-ui-sidebar-vc-local-branch"></span></button>').appendTo(e).on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?f():(v(),I.show(),$(this).addClass("selected"),e=RED.projects.getActiveProject(),g.refresh("projects/"+e.name+"/branches"),h.show(),setTimeout(function(){h.css("height","215px"),g.focus()},100))}),p=(RED.popover.tooltip(u,RED._("sidebar.project.versionControl.changeLocalBranch")),$('<button class="red-ui-button red-ui-button-small" style="margin-left: 10px;" id="red-ui-sidebar-vc-repo-status-button"><span id="red-ui-sidebar-vc-repo-status-stats"><i class="fa fa-long-arrow-up"></i> <span id="red-ui-sidebar-vc-commits-ahead"></span> <i class="fa fa-long-arrow-down"></i> <span id="red-ui-sidebar-vc-commits-behind"></span></span><span id="red-ui-sidebar-vc-repo-status-auth-issue"><i class="fa fa-warning"></i></span></button>').appendTo(e).on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?v():(f(),I.show(),$(this).addClass("selected"),e=RED.projects.getActiveProject(),$("#red-ui-sidebar-vc-repo-toolbar-set-upstream-row").toggle(!!e.git.branches.remoteAlt),m.show(),setTimeout(function(){m.css("height","265px")},100))})),f=(RED.popover.tooltip(p,RED._("sidebar.project.versionControl.manageRemoteBranch")),O=$("<ol>",{style:"position: absolute; top: 30px; bottom: 0px; right:0; left:0;"}).appendTo(n.content),I=$('<div class="red-ui-shade" style="z-Index: 3"></div>').css("top","30px").hide().appendTo(n.content),O.editableList({addButton:!1,scrollOnAdd:!1,addItem:function(t,e,o){var n,i;t.addClass("red-ui-sidebar-vc-commit-entry"),o.url?(t.addClass("red-ui-sidebar-vc-commit-more"),t.text("+ "+(o.total-o.totalKnown)+RED._("sidebar.project.versionControl.moreCommits")),t.on("click",function(e){e.preventDefault(),F(o.url,O,t,o.limit,o.before)})):(t.on("click",function(e){var t=RED.projects.getActiveProject();t&&$.getJSON("projects/"+t.name+"/commits/"+o.sha,function(e){e.project=t,e.parents=o.parents,e.oldRev=o.sha+"~1",e.newRev=o.sha,e.oldRevTitle=RED._("sidebar.project.versionControl.commitCapital")+" "+o.sha.substring(0,7)+"~1",e.newRevTitle=RED._("sidebar.project.versionControl.commitCapital")+" "+o.sha.substring(0,7),e.date=B(parseInt(o.date)),RED.diff.showCommitDiff(e)})}),n=$("<div>").appendTo(t),$('<div class="red-ui-sidebar-vc-commit-subject">').text(o.subject).appendTo(n),o.refs&&(i=$('<div class="red-ui-sidebar-vc-commit-refs">').appendTo(n),o.refs.forEach(function(e){var t=e;/HEAD -> /.test(e)&&(t=e.substring(8)),$('<span class="red-ui-sidebar-vc-commit-ref">').text(t).appendTo(i)}),t.addClass("red-ui-sidebar-vc-commit-head")),$('<div class="red-ui-sidebar-vc-commit-sha">').text(o.sha.substring(0,7)).appendTo(n),$('<div class="red-ui-sidebar-vc-commit-date">').text(B(parseInt(o.date))).appendTo(n))}}),function(e){u.removeClass("selected"),h.css("height","0"),I.hide(),setTimeout(function(){h.hide(),e&&e()},200)}),h=$('<div class="red-ui-sidebar-vc-slide-box red-ui-sidebar-vc-slide-box-top" style="top:30px;"></div>').hide().appendTo(n.content),g=($('<div class="red-ui-sidebar-vc-slide-box-header"></div>').text(RED._("sidebar.project.versionControl.changeLocalBranch")).appendTo(h),N.createBranchList({placeholder:RED._("sidebar.project.versionControl.createBranchPlaceholder"),container:h,onselect:function(e){if(e.current)return f();var t=N.addSpinnerOverlay(h),o=RED.projects.getActiveProject();RED.deploy.setDeployInflight(!0),N.sendRequest({url:"projects/"+o.name+"/branches",type:"POST",requireCleanWorkspace:!0,cancel:function(){t.remove()},responses:{0:function(e){t.remove(),console.log(e)},200:function(e){f(function(){t.remove()})},400:{git_local_overwrite:function(e){t.remove(),RED.notify(RED._("sidebar.project.versionControl.localOverwrite"),{type:"error",timeout:8e3})},unexpected_error:function(e){t.remove(),console.log(e)}}}},e).always(function(){setTimeout(function(){RED.deploy.setDeployInflight(!1)},500)})}})),m=$('<div class="red-ui-sidebar-vc-slide-box red-ui-sidebar-vc-slide-box-top" style="top:30px"></div>').hide().appendTo(n.content),v=function(){$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("checked",!1),p.removeClass("selected"),m.css("height","0"),I.hide(),setTimeout(function(){m.hide(),b()},200)},b=function(e){y.hasClass("selected")&&(y.removeClass("selected"),w.height(0),m.css("height","265px"),setTimeout(function(){w.hide(),e&&e()},200))},t=($('<div class="red-ui-sidebar-vc-slide-box-header"></div>').text(RED._("sidebar.project.versionControl.manageRemoteBranch")).appendTo(m),$('<div style="margin-bottom: 5px;"></div>').appendTo(m)),y=$('<button id="red-ui-sidebar-vc-repo-branch" class="red-ui-sidebar-vc-repo-action red-ui-button"><i class="fa fa-code-fork"></i> '+RED._("sidebar.project.versionControl.remote")+': <span id="red-ui-sidebar-vc-remote-branch"></span></button>').appendTo(t).on("click",function(e){e.preventDefault(),$(this).hasClass("selected")?b():($(this).addClass("selected"),e=RED.projects.getActiveProject(),E.refresh("projects/"+e.name+"/branches/remote"),w.show(),setTimeout(function(){w.height(180),m.css("height","445px"),E.focus()},100))}),e=($('<div id="red-ui-sidebar-vc-repo-toolbar-message" class="red-ui-sidebar-vc-slide-box-header" style="min-height: 100px;"></div>').appendTo(m),$('<div id="red-ui-sidebar-vc-repo-toolbar-error-message" class="red-ui-sidebar-vc-slide-box-header" style="min-height: 100px;"></div>').hide().appendTo(m)),n=($('<div style="margin-top: 10px;"><i class="fa fa-warning"></i> '+RED._("sidebar.project.versionControl.unableToAccess")+"</div>").appendTo(e),$('<div style="margin: 10px 30px; text-align: center"></div>').appendTo(e)),w=($('<button class="red-ui-button" style="width: 80%;"><i class="fa fa-refresh"></i> '+RED._("sidebar.project.versionControl.retry")+"</button>").appendTo(n).on("click",function(e){e.preventDefault();var e=RED.projects.getActiveProject(),t=N.addSpinnerOverlay(m).addClass("red-ui-component-spinner-contain");N.sendRequest({url:"projects/"+e.name+"/branches/remote",type:"GET",responses:{0:function(e){console.log(e)},200:function(e){V(!0)},400:{git_connection_failed:function(e){RED.notify(e.message,"error")},git_not_a_repository:function(e){RED.notify(e.message,"error")},git_repository_not_found:function(e){RED.notify(e.message,"error")},unexpected_error:function(e){console.log(e)}}}}).always(function(){t.remove()})}),$('<div class="red-ui-sidebar-vc-slide-box-header" style="height: 20px;"><label id="red-ui-sidebar-vc-repo-toolbar-set-upstream-row" for="red-ui-sidebar-vc-repo-toolbar-set-upstream" class="hide"><input type="checkbox" id="red-ui-sidebar-vc-repo-toolbar-set-upstream"> '+RED._("sidebar.project.versionControl.setUpstreamBranch")+"</label></div>").appendTo(m),$('<div style="height: 0;overflow:hidden; transition: height 0.2s ease-in-out;"></div>').hide().appendTo(t)),E=N.createBranchList({placeholder:RED._("sidebar.project.versionControl.createRemoteBranchPlaceholder"),currentLabel:RED._("sidebar.project.versionControl.upstream"),remotes:function(){var e=RED.projects.getActiveProject();return Object.keys(e.git.remotes)},container:w,onselect:function(e){$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("checked",!1),$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("disabled",!1),$("#red-ui-sidebar-vc-remote-branch").text(e.name+(e.create?" *":""));var n=RED.projects.getActiveProject();n.git.branches.remote===e.name?delete n.git.branches.remoteAlt:n.git.branches.remoteAlt=e.name,$("#red-ui-sidebar-vc-repo-toolbar-set-upstream-row").toggle(!!n.git.branches.remoteAlt),b(function(){var t,o;e.create?(n.git.branches.remote?$("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.selectUpstreamBranch")):($("#red-ui-sidebar-vc-repo-toolbar-message").text(RED._("sidebar.project.versionControl.trackedUpstreamBranch")),$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("checked",!0),$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("disabled",!0)),$("#red-ui-sidebar-vc-repo-pull").prop("disabled",!0),$("#red-ui-sidebar-vc-repo-push").prop("disabled",!1)):(t=Date.now(),o=N.addSpinnerOverlay($("#red-ui-sidebar-vc-repo-toolbar-message")).addClass("red-ui-component-spinner-contain"),$.getJSON("projects/"+n.name+"/branches/remote/"+e.name+"/status",function(e){setTimeout(function(){J(e.commits.ahead,e.commits.behind),o.remove()},Math.max(400-(Date.now()-t),0))}))})}}),e=$('<div style="margin-bottom: 5px;"></div>').appendTo(m);$('<button id="red-ui-sidebar-vc-repo-push" class="red-ui-sidebar-vc-repo-sub-action red-ui-button"><i class="fa fa-long-arrow-up"></i> <span data-i18n="sidebar.project.versionControl.push"></span></button>').appendTo(e).on("click",function(e){e.preventDefault();var t=N.addSpinnerOverlay(m).addClass("red-ui-component-spinner-contain"),e=$('<div style="position: relative; bottom: 60px;"></div>').appendTo(t),o=($('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(e).on("click",function(e){e.preventDefault(),RED.actions.invoke("core:show-event-log")}),RED.projects.getActiveProject()),e=(RED.eventLog.startEvent("Push changes"+(o.git.branches.remoteAlt?" : "+o.git.branches.remoteAlt:"")),"projects/"+o.name+"/push"),n=(o.git.branches.remoteAlt&&(e+="/"+o.git.branches.remoteAlt),$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("checked"));n&&(e+="?u=true"),N.sendRequest({url:e,type:"POST",responses:{0:function(e){console.log(e)},200:function(e){n&&o.git.branches.remoteAlt&&(o.git.branches.remote=o.git.branches.remoteAlt,delete o.git.branches.remoteAlt),V(!0),v()},400:{git_push_failed:function(e){RED.notify(RED._("sidebar.project.versionControl.pushFailed"),"error")},unexpected_error:function(e){console.log(e)}}}},{}).always(function(){t.remove()})}),$('<button id="red-ui-sidebar-vc-repo-pull" class="red-ui-sidebar-vc-repo-sub-action red-ui-button"><i class="fa fa-long-arrow-down"></i> <span data-i18n="sidebar.project.versionControl.pull"></span></button>').appendTo(e).on("click",function(e){e.preventDefault(),i({setUpstream:$("#red-ui-sidebar-vc-repo-toolbar-set-upstream").prop("checked")})}),$('<div class="red-ui-shade red-ui-sidebar-vc-shade">').appendTo(D),RED.sidebar.addTab({id:"version-control",label:RED._("sidebar.project.versionControl.history"),name:RED._("sidebar.project.versionControl.projectHistory"),content:D,enableOnEdit:!1,pinned:!0,iconClass:"fa fa-code-fork",action:"core:show-version-control-tab",onchange:function(){setTimeout(function(){R.resize()},10)}})},show:q,refresh:V,showLocalChanges:function(){RED.sidebar.show("version-control"),S.expand()}}}(),RED.touch=RED.touch||{},RED.touch.radialMenu=function(){var p=null,f=!1,h=!1,g=null;return{show:function(e,a,t){f=!0;try{for(var n=(p=d3.select("body").append("div").classed("red-ui-editor-radial-menu",!0).on("touchstart",function(){u(),d3.event.preventDefault()})).append("div").style({top:a[1]-80+"px",left:a[0]-80+"px"}),s=[],o=t.length,i=Math.max(Math.PI/(o-1),Math.PI/4),r=Math.PI,d=0;d<o;d++){var l=Math.floor(80*Math.cos(r)),c=Math.floor(80*Math.sin(r));t[d].name&&!function(e,t,o){o.el=n.append("div").classed("red-ui-editor-radial-menu-opt",!0).style({top:t+80-25+"px",left:e+80-25+"px"}).classed("red-ui-editor-radial-menu-opt-disabled",!!o.disabled),o.el.html(o.name),o.x=e,o.y=t,s.push(o),o.el.on("touchstart",function(){o.el.classed("red-ui-editor-radial-menu-opt-active",!0),d3.event.preventDefault(),d3.event.stopPropagation()}),o.el.on("touchend",function(){u(),o.onselect(),d3.event.preventDefault(),d3.event.stopPropagation()})}(l,c,t[d]),r+=i}var u=function(){f=!1,g=null,p.remove(),p=null};e.on("touchend.radial",function(){if(e.on("touchend.radial",null),e.on("touchmenu.radial",null),g){try{g.onselect()}catch(e){RED._debug(e)}u()}else h&&u()}),e.on("touchmove.radial",function(){try{for(var e,t=d3.event.touches.item(0),o=[t.pageX-a[0],t.pageY-a[1]],n=0;n<s.length;n++){var i=s[n];i.disabled||(o[0]>i.x-30&&o[0]<i.x+30&&o[1]>i.y-30&&o[1]<i.y+30?i!==g&&(i.el.classed("selected",!0),g=i):(i===g&&(g=null),i.el.classed("selected",!1)))}g||(e=Math.abs(o[0]*o[0]+o[1]*o[1]),h=6400<e)}catch(e){RED._debug(e)}})}catch(e){RED._debug(e)}},active:function(){return f}}}(),RED.tourGuide=function(){var p,f,h,g,m,v,b=[],n={};function t(t,o){n[t]?o(null,n[t]):import(t).then(function(e){n[t]=e.default,o(null,n[t])}).catch(function(e){o(e)})}function y(){var e,t;m&&(v?f.css({left:$(window).width()/2+"px",top:$(window).height()/2+"px",width:"0px",height:"0px"}):(e=m[0].getBoundingClientRect(),t=Math.max(50,1.5*Math.max(e.width,e.height)),f.css({left:e.left+e.width/2+"px",top:e.top+e.height/2+"px",width:2*t+"px",height:2*t+"px"}),f[0].offsetHeight,f.addClass("transition"),f.css({width:t+"px",height:t+"px"})),h&&h.move({target:m}))}function w(e,t,o){function n(){b.forEach(function(e){"dom-event"===e.type?e.target[0].removeEventListener(e.event,e.listener,e.opts):"nr-event"===e.type&&RED.events.off(e.event,e.listener)}),b=[],setTimeout(function(){o()},0)}if(e.complete){if(0!==e.complete.length)return h&&(h.element.hide(),v||(v=!0,y())),void e.complete.call(t,function(){h&&h.element.show(),n()});e.complete.call(t)}n()}function E(e){if("string"==typeof e)return e;var t=RED.i18n.lang()||"en-US",o=Object.keys(e);return e[t]||e["en-US"]||e[o[0]]}return{load:t,run:function(e,n){n=n||function(e){e&&console.error(e)},t(e,function(e,t){var a,o,s,r;function u(e){$(window).off("resize.red-ui-tourGuide"),$(document).off("keydown.red-ui-tourGuide"),h&&h.close(),h=g=null,p.remove(),p=null,o(e)}e?console.warn("Error loading tour:",e):(a=t,o=n,p=$('<div class="red-ui-tourGuide-shade"></div>').appendTo(document.body),f=$('<div class="red-ui-tourGuide-shade-focus"></div>').appendTo(p),$(window).on("resize.red-ui-tourGuide",function(){y()}),r={index:s=0,count:a.steps.length},function e(t){if(!1===t)u(!1);else if(s===a.steps.length)u();else{r.index=s;try{d=a.steps[s++],l=r,c=e,p.fadeIn();var o=d,n=l,i=function(){var e,t=d.direction||"bottom";if(v=!1,"string"==typeof d.element?m=$(d.element):"function"==typeof d.element?m=d.element.call(l):d.element?m=d.element:(m=$(".red-ui-editor"),v=!0,t="inset"),0===m.length)throw m=null,p.hide(),new Error("Element not found");$(window).width()<400&&(m=$(".red-ui-editor"),v=!0,t="inset"),e=m.css("z-index"),v||!d.interactive&&!d.wait||m.css("z-index",2002),y(),g?g.empty():g=$('<div style="position:relative"></div>'),$('<button type="button" class="red-ui-button red-ui-button-small" style="float: right; margin-top: -4px; margin-right: -4px;"><i class="fa fa-times"></i></button>').appendTo(g).click(function(e){e.preventDefault(),w(d,l,function(){c(!1)})});var o,n,i=$('<div class="red-ui-tourGuide-popover-description"></div>').appendTo(g),i=(d.titleIcon&&$('<h2><i class="'+d.titleIcon+'"></i></h2>').appendTo(i),d.title&&$("<h2>").text(E(d.title)).appendTo(i),$("<div>").css("text-align","left").html(E(d.description)).appendTo(i),d.image&&$(`<img src="red/tours/${d.image}" />`).appendTo(i),$("<div>",{class:"red-ui-tourGuide-toolbar"}).appendTo(g)),i=($("<small>").text(l.index+1+"/"+l.count).appendTo(i),!v&&d.wait||(o=$('<button type="button" class="red-ui-button" style="position: absolute; right:0;bottom:0;"></button>').appendTo(i).one("click",function(e){e.preventDefault(),r()}),l.index===l.count-1?$("<span></span>").text(RED._("common.label.close")).appendTo(o):0===l.index?($("<span>start</span>").text(RED._("tourGuide.start")).appendTo(o),$('<span style="margin-left: 6px"><i class="fa fa-chevron-right"></i></span>').appendTo(o)):l.index<l.count-1&&($("<span></span>").text(RED._("tourGuide.next")).appendTo(o),$('<span style="margin-left: 6px"><i class="fa fa-chevron-right"></i></span>').appendTo(o))),d.width),a=(v&&(i=500),Math.min($(window).width()-10,Math.max(i||0,300))),s=(h=h||RED.popover.create({target:m,width:i||"auto",maxWidth:a+"px",direction:t,class:"red-ui-tourGuide-popover"+(v?" ":""),trigger:"manual",content:g}).open(),$(document).off("keydown.red-ui-tourGuide"),$(document).on("keydown.red-ui-tourGuide",function(e){"Escape"!==e.key&&"Esc"!==e.key||(e.preventDefault(),e.stopPropagation(),w(d,l,function(){c(!1)}))}),h.element.toggleClass("red-ui-tourGuide-popover-full",!!v),h.move({target:m,width:i||"auto",maxWidth:a+"px",direction:t}),setTimeout(function(){h.element.position().left<0&&h.element.css({left:0})},100),o&&setTimeout(function(){o.focus()},100),m[0]instanceof SVGElement),r=(d.fallback&&f.one("mouseenter",function(e){setTimeout(function(){var e=m[0].getBoundingClientRect(),e=Math.max(50,1.5*Math.max(e.width,e.height));f.css({width:4*e+"px",height:4*e+"px"}),p.fadeOut(),h.move({target:$(".red-ui-editor"),direction:d.fallback,offset:10,transition:!0})},s?0:500)}),function(){f.removeClass("transition"),m.css("z-index",e),w(d,l,c)});d.wait&&("dom-event"===d.wait.type?(i=m,d.wait.element&&("string"==typeof d.wait.element?i=$(d.wait.element):"function"==typeof d.wait.element&&(i=d.wait.element.call(l))),n={type:d.wait.type,target:i,event:d.wait.event,listener:function(){r()},opts:{once:!0}},b.push(n),i[0].addEventListener(n.event,n.listener,n.opts)):"nr-event"===d.wait.type&&(n={type:d.wait.type,event:d.wait.event,listener:function(){d.wait.filter&&!d.wait.filter.apply(l,arguments)||r()}},b.push(n),RED.events.on(n.event,n.listener)))};if(o.prepare){if(0!==o.prepare.length)return h&&(h.element.hide(),v||(v=!0,y())),void o.prepare.call(n,function(){h&&h.element.show(),i()});o.prepare.call(n)}i()}catch(e){u(e)}var d,l,c}}())})},list:function(){return[{id:"3_0",label:"3.0",path:"./tours/welcome.js"},{id:"2_2",label:"2.2",path:"./tours/2.2/welcome.js"},{id:"2_1",label:"2.1",path:"./tours/2.1/welcome.js"}]},reset:function(){RED.settings.set("editor.tours.welcome","")}}}();