From 7531314e3feed1fab2235527c4b7e72724806899 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 14 Dec 2020 10:40:06 +0000 Subject: [PATCH] Add RED.plugins module to editor --- Gruntfile.js | 1 + .../@node-red/editor-client/src/js/plugins.js | 29 +++++++++++++++++++ .../test-plugin/test-editor-plugin.html | 8 +++-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 packages/node_modules/@node-red/editor-client/src/js/plugins.js diff --git a/Gruntfile.js b/Gruntfile.js index 2bdc2e3aa..23481f793 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -142,6 +142,7 @@ module.exports = function(grunt) { "packages/node_modules/@node-red/editor-client/src/js/text/bidi.js", "packages/node_modules/@node-red/editor-client/src/js/text/format.js", "packages/node_modules/@node-red/editor-client/src/js/ui/state.js", + "packages/node_modules/@node-red/editor-client/src/js/plugins.js", "packages/node_modules/@node-red/editor-client/src/js/nodes.js", "packages/node_modules/@node-red/editor-client/src/js/font-awesome.js", "packages/node_modules/@node-red/editor-client/src/js/history.js", diff --git a/packages/node_modules/@node-red/editor-client/src/js/plugins.js b/packages/node_modules/@node-red/editor-client/src/js/plugins.js new file mode 100644 index 000000000..25d6acf8a --- /dev/null +++ b/packages/node_modules/@node-red/editor-client/src/js/plugins.js @@ -0,0 +1,29 @@ +RED.plugins = (function() { + var plugins = {}; + var pluginsByType = {}; + + function registerPlugin(id,definition) { + plugins[id] = definition; + if (definition.type) { + pluginsByType[definition.type] = pluginsByType[definition.type] || []; + pluginsByType[definition.type].push(definition); + } + if (definition.onadd && typeof definition.onadd === 'function') { + definition.onadd(); + } + RED.events.emit("registry:plugin-added",id); + } + + function getPlugin(id) { + return plugins[id] + } + + function getPluginsByType(type) { + return pluginsByType[type] || []; + } + return { + registerPlugin: registerPlugin, + getPlugin: getPlugin, + getPluginsByType: getPluginsByType + } +})(); diff --git a/test/resources/plugin/test-plugin/test-editor-plugin.html b/test/resources/plugin/test-plugin/test-editor-plugin.html index 067d09d3c..177813526 100644 --- a/test/resources/plugin/test-plugin/test-editor-plugin.html +++ b/test/resources/plugin/test-plugin/test-editor-plugin.html @@ -1,5 +1,9 @@ \ No newline at end of file