mirror of
https://github.com/node-red/node-red.git
synced 2025-12-27 07:31:07 +01:00
Add flow suggestion plugin api
This commit is contained in:
@@ -463,32 +463,34 @@ RED.typeSearch = (function() {
|
||||
|
||||
let index = 0;
|
||||
|
||||
// const suggestionItem = {
|
||||
// suggestionPlaceholder: true,
|
||||
// label: 'loading suggestions...',
|
||||
// separator: true,
|
||||
// i: index++
|
||||
// }
|
||||
// searchResults.editableList('addItem', suggestionItem);
|
||||
// setTimeout(function() {
|
||||
// searchResults.editableList('removeItem', suggestionItem);
|
||||
|
||||
// const suggestedItem = {
|
||||
// suggestion: true,
|
||||
// label: 'Change/Debug Combo',
|
||||
// separator: true,
|
||||
// i: suggestionItem.i,
|
||||
// nodes: [
|
||||
// { id: 'suggestion-1', type: 'change', x: 0, y: 0, wires:[['suggestion-2']] },
|
||||
// { id: 'suggestion-2', type: 'function', outputs: 3, x: 200, y: 0, wires:[['suggestion-3'],['suggestion-4'],['suggestion-6']] },
|
||||
// { id: 'suggestion-3', _g: 'suggestion-group-1', type: 'debug', x: 375, y: -40 },
|
||||
// { id: 'suggestion-4', _g: 'suggestion-group-1', type: 'debug', x: 375, y: 0 },
|
||||
// { id: 'suggestion-5', _g: 'suggestion-group-1', type: 'debug', x: 410, y: 40 },
|
||||
// { id: 'suggestion-6', type: 'junction', wires: [['suggestion-5']], x:325, y:40 }
|
||||
// ]
|
||||
// }
|
||||
// searchResults.editableList('addItem', suggestedItem);
|
||||
// }, 1000)
|
||||
if (!opts.context?.virtualLink) {
|
||||
// Check for suggestion plugins
|
||||
const suggestionPlugins = RED.plugins.getPluginsByType('node-red-flow-suggestion-source');
|
||||
if (suggestionPlugins.length > 0) {
|
||||
const suggestionItem = {
|
||||
suggestionPlaceholder: true,
|
||||
label: 'loading suggestions...', // TODO: NLS
|
||||
separator: true,
|
||||
i: index++
|
||||
}
|
||||
searchResults.editableList('addItem', suggestionItem);
|
||||
suggestionPlugins[0].getSuggestions(opts.context).then(function (suggestedFlows) {
|
||||
searchResults.editableList('removeItem', suggestionItem);
|
||||
if (!Array.isArray(suggestedFlows)) {
|
||||
suggestedFlows = [suggestedFlows];
|
||||
}
|
||||
suggestedFlows.forEach(function(suggestion, index) {
|
||||
const suggestedItem = {
|
||||
suggestion: true,
|
||||
separator: index === suggestedFlows.length - 1,
|
||||
i: suggestionItem.i,
|
||||
...suggestion
|
||||
}
|
||||
searchResults.editableList('addItem', suggestedItem);
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<common.length;i++) {
|
||||
let itemDef
|
||||
|
||||
@@ -1415,10 +1415,12 @@ RED.view = (function() {
|
||||
var lastAddedX;
|
||||
var lastAddedWidth;
|
||||
|
||||
const context = {}
|
||||
const context = {
|
||||
workspace: RED.workspaces.active()
|
||||
}
|
||||
|
||||
if (quickAddLink) {
|
||||
context.source = quickAddLink.node.id;
|
||||
context.source = quickAddLink.node;
|
||||
context.sourcePort = quickAddLink.port;
|
||||
context.sourcePortType = quickAddLink.portType;
|
||||
if (quickAddLink?.virtualLink) {
|
||||
@@ -1434,6 +1436,7 @@ RED.view = (function() {
|
||||
y:clientY-mainPos.top+ node_height/2 + 5 - (oy-point[1]),
|
||||
disableFocus: touchTrigger,
|
||||
filter: filter,
|
||||
context,
|
||||
move: function(dx,dy) {
|
||||
if (ghostNode) {
|
||||
var pos = d3.transform(ghostNode.attr("transform")).translate;
|
||||
|
||||
Reference in New Issue
Block a user