From c6cfbb8755d0f9c3ff8bcce02719fab57700918e Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 20:16:34 +0100 Subject: [PATCH 1/2] use page&theme settings in a theme plugin --- .../@node-red/editor-api/lib/editor/theme.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js index 88b3eeb62..d74a5d251 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js @@ -266,6 +266,63 @@ module.exports = { theme.page = theme.page || {_:{}} theme.page._.scripts = scriptFiles.concat(theme.page._.scripts || []) } + // check and load page settings from theme + if (themePlugin.page) { + if (themePlugin.page.favicon && !theme.page.favicon) { + const result = serveFilesFromTheme( + [themePlugin.page.favicon], + themeApp, + "/", + themePlugin.path + ) + if(result && result.length > 0) { + // update themeContext page favicon + themeContext.page.favicon = result[0] + theme.page = theme.page || {_:{}} + theme.page._.favicon = result[0] + } + } + if (themePlugin.page.tabicon && themePlugin.page.tabicon.icon && !theme.page.tabicon) { + const result = serveFilesFromTheme( + [themePlugin.page.tabicon.icon], + themeApp, + "/page/", + themePlugin.path + ) + if(result && result.length > 0) { + // update themeContext page tabicon + themeContext.page.tabicon.icon = result[0] + themeContext.page.tabicon.colour = themeContext.page.tabicon.colour || themeContext.page.tabicon.colour + theme.page = theme.page || {_:{}} + theme.page._.tabicon = theme.page._.tabicon || {} + theme.page._.tabicon.icon = themeContext.page.tabicon.icon + theme.page._.tabicon.colour = themeContext.page.tabicon.colour + } + } + // if the plugin has a title AND the users settings.js does NOT have a title + if (themePlugin.page.title && !theme.page.title) { + themeContext.page.title = themePlugin.page.title || themeContext.page.title + } + } + // check and load header settings from theme + if (themePlugin.header) { + if (themePlugin.header.image && !theme.header.image) { + const result = serveFilesFromTheme( + [themePlugin.header.image], + themeApp, + "/header/", + themePlugin.path + ) + if(result && result.length > 0) { + // update themeContext header image + themeContext.header.image = result[0] + } + } + // if the plugin has a title AND the users settings.js does NOT have a title + if (themePlugin.header.title && !theme.header.title) { + themeContext.header.title = themePlugin.header.title || themeContext.header.title + } + } if(theme.codeEditor) { theme.codeEditor.options = Object.assign({}, themePlugin.monacoOptions, theme.codeEditor.options); } From 8bd02d0c36341331127f9b62ff489fbabe612871 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 20:36:27 +0100 Subject: [PATCH 2/2] update header url if set in theme and not settings --- .../node_modules/@node-red/editor-api/lib/editor/theme.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js index d74a5d251..7be8868d3 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/theme.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/theme.js @@ -299,7 +299,7 @@ module.exports = { theme.page._.tabicon.colour = themeContext.page.tabicon.colour } } - // if the plugin has a title AND the users settings.js does NOT have a title + // if the plugin has a title AND the users settings.js does NOT if (themePlugin.page.title && !theme.page.title) { themeContext.page.title = themePlugin.page.title || themeContext.page.title } @@ -322,6 +322,10 @@ module.exports = { if (themePlugin.header.title && !theme.header.title) { themeContext.header.title = themePlugin.header.title || themeContext.header.title } + // if the plugin has a header url AND the users settings.js does NOT + if (themePlugin.header.url && !theme.header.url) { + themeContext.header.url = themePlugin.header.url || themeContext.header.url + } } if(theme.codeEditor) { theme.codeEditor.options = Object.assign({}, themePlugin.monacoOptions, theme.codeEditor.options);