mirror of
https://github.com/node-red/node-red.git
synced 2025-12-27 15:34:26 +01:00
Add node suggestion api to editor and apply to typeSearch
This commit is contained in:
@@ -689,7 +689,7 @@ RED.nodes = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
function addNode(n) {
|
||||
function addNode(n, opt) {
|
||||
let newNode
|
||||
if (!n.__isProxy__) {
|
||||
newNode = new Proxy(n, nodeProxyHandler)
|
||||
@@ -728,7 +728,7 @@ RED.nodes = (function() {
|
||||
nodeLinks[n.id] = {in:[],out:[]};
|
||||
}
|
||||
}
|
||||
RED.events.emit('nodes:add',newNode);
|
||||
RED.events.emit('nodes:add',newNode, opt);
|
||||
return newNode
|
||||
}
|
||||
function addLink(l) {
|
||||
@@ -1848,14 +1848,23 @@ RED.nodes = (function() {
|
||||
* - id:copy - import with new id
|
||||
* - id:replace - import over the top of existing
|
||||
* - modules: map of module:version - hints for unknown nodes
|
||||
* - applyNodeDefaults - whether to apply default values to the imported nodes (default: false)
|
||||
*/
|
||||
function importNodes(newNodesObj,options) { // createNewIds,createMissingWorkspace) {
|
||||
const defOpts = { generateIds: false, addFlow: false, markChanged: false, reimport: false, importMap: {} }
|
||||
const defOpts = {
|
||||
generateIds: false,
|
||||
addFlow: false,
|
||||
markChanged: false,
|
||||
reimport: false,
|
||||
importMap: {},
|
||||
applyNodeDefaults: false
|
||||
}
|
||||
options = Object.assign({}, defOpts, options)
|
||||
options.importMap = options.importMap || {}
|
||||
const createNewIds = options.generateIds;
|
||||
const reimport = (!createNewIds && !!options.reimport)
|
||||
const createMissingWorkspace = options.addFlow;
|
||||
const applyNodeDefaults = options.applyNodeDefaults;
|
||||
var i;
|
||||
var n;
|
||||
var newNodes;
|
||||
@@ -2234,6 +2243,13 @@ RED.nodes = (function() {
|
||||
for (d in def.defaults) {
|
||||
if (def.defaults.hasOwnProperty(d)) {
|
||||
configNode[d] = n[d];
|
||||
if (applyNodeDefaults && n[d] === undefined) {
|
||||
// If the node has a default value, but the imported node does not
|
||||
// set it, then set it to the default value
|
||||
if (def.defaults[d].value !== undefined) {
|
||||
configNode[d] = JSON.parse(JSON.stringify(def.defaults[d].value))
|
||||
}
|
||||
}
|
||||
configNode._config[d] = JSON.stringify(n[d]);
|
||||
if (def.defaults[d].type) {
|
||||
configNode._configNodeReferences.add(n[d])
|
||||
@@ -2508,6 +2524,13 @@ RED.nodes = (function() {
|
||||
for (d in node._def.defaults) {
|
||||
if (node._def.defaults.hasOwnProperty(d) && d !== 'inputs' && d !== 'outputs') {
|
||||
node[d] = n[d];
|
||||
if (applyNodeDefaults && n[d] === undefined) {
|
||||
// If the node has a default value, but the imported node does not
|
||||
// set it, then set it to the default value
|
||||
if (node._def.defaults[d].value !== undefined) {
|
||||
node[d] = JSON.parse(JSON.stringify(node._def.defaults[d].value))
|
||||
}
|
||||
}
|
||||
node._config[d] = JSON.stringify(n[d]);
|
||||
}
|
||||
}
|
||||
@@ -2761,7 +2784,8 @@ RED.nodes = (function() {
|
||||
workspaces:new_workspaces,
|
||||
subflows:new_subflows,
|
||||
missingWorkspace: missingWorkspace,
|
||||
removedNodes: removedNodes
|
||||
removedNodes: removedNodes,
|
||||
nodeMap: node_map
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user