/** * Copyright JS Foundation and other contributors, http://js.foundation * * 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. **/ RED.search = (function() { var disabled = false; var dialog = null; var searchInput; var searchResults; var selected = -1; var visible = false; var searchHistory = []; var index = {}; var currentResults = []; var activeResults = []; var currentIndex = 0; var previousActiveElement; function indexProperty(node,label,property) { if (typeof property === 'string' || typeof property === 'number') { property = (""+property).toLowerCase(); index[property] = index[property] || {}; index[property][node.id] = {node:node,label:label}; } else if (Array.isArray(property)) { property.forEach(function(prop) { indexProperty(node,label,prop); }) } else if (typeof property === 'object') { for (var prop in property) { if (property.hasOwnProperty(prop)) { indexProperty(node,label,property[prop]) } } } } function indexNode(n) { var l = RED.utils.getNodeLabel(n); if (l) { l = (""+l).toLowerCase(); index[l] = index[l] || {}; index[l][n.id] = {node:n,label:l} } l = l||n.label||n.name||n.id||""; var properties = ['id','type','name','label','info']; const node_def = n && n._def; if (node_def) { if (node_def.defaults) { properties = properties.concat(Object.keys(node_def.defaults)); } if (n.type !== "group" && node_def.paletteLabel && node_def.paletteLabel !== node_def.type) { try { const label = ("" + (typeof node_def.paletteLabel === "function" ? node_def.paletteLabel.call(node_def) : node_def.paletteLabel)).toLowerCase(); if(label && label !== (""+node_def.type).toLowerCase()) { indexProperty(n, l, label); } } catch(err) { console.warn(`error indexing ${l}`, err); } } } for (var i=0;i val = extractValue(val,"uses",flags);// uses: val = extractType(val,flags);// type: val = val.trim(); const hasFlags = Object.keys(flags).length > 0; const hasTypeFilter = flags.type && flags.type.length > 0 if (flags.flow && flags.flow.indexOf("current") >= 0) { let idx = flags.flow.indexOf("current"); flags.flow[idx] = RED.workspaces.active();//convert 'current' to active flow ID } if (flags.flow && flags.flow.length) { flags.flow = [ ...new Set(flags.flow) ]; //deduplicate } if (val.length > 0 || hasFlags) { val = val.toLowerCase(); let i; let j; let list = []; const nodes = {}; let keys = []; if (flags.uses) { keys = flags.uses; } else { keys = Object.keys(index); } for (i=0;i -1 || (val === "" && hasFlags)) { const ids = Object.keys(index[key]||{}); for (j=0;j