Skip to content

Commit

Permalink
Merge pull request #897 from FlowFuse/332-ui-theme-full-deploy
Browse files Browse the repository at this point in the history
UI Theme - Add "registerTheme" function to prevent ui-page dependency
  • Loading branch information
joepavitt authored May 29, 2024
2 parents 5df3dc1 + 24da889 commit f191e83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nodes/config/ui_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,11 @@ module.exports = function (RED) {
return fullPath
}

node.registerTheme = function (theme) {
const { _wireCount, _inputCallback, _inputCallbacks, _closeCallbacks, wires, type, ...t } = theme
node.ui.themes.set(t.id, t)
}

/**
* Register allows for pages, widgets, groups, etc. to register themselves with the Base UI Node
* @param {*} page
Expand Down Expand Up @@ -871,21 +876,21 @@ module.exports = function (RED) {
if (page && page.type === 'ui-page' && !node.ui.themes.has(page.theme)) {
const theme = RED.nodes.getNode(page.theme)
if (theme) {
const { _wireCount, _inputCallback, _inputCallbacks, _closeCallbacks, wires, type, ...t } = theme
node.ui.themes.set(page.theme, t)
node.registerTheme(theme)
} else {
node.warn(`Theme '${page.theme}' specified in page '${page.id}' does not exist`)
}
}

// map pages by their ID
if (page && !node.ui.pages.has(page?.id)) {
if (page) {
// ensure we have the latest instance of the page's node
const { _users, ...p } = page
node.ui.pages.set(page.id, p)
}

// map groups on a page-by-page basis
if (group && !node.ui.groups.has(group?.id)) {
if (group) {
const { _user, type, ...g } = group
node.ui.groups.set(group.id, g)
}
Expand Down
12 changes: 12 additions & 0 deletions nodes/config/ui_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ module.exports = function (RED) {

node.colors = { ...rest.colors }
node.sizes = sizes

let uiBase = null
RED.nodes.eachNode(n => {
if (n.type === 'ui-base' && !uiBase) {
uiBase = n
}
})
if (uiBase) {
config.ui = uiBase.id
uiBase = RED.nodes.getNode(config.ui)
}
uiBase?.registerTheme(node)
}
RED.nodes.registerType('ui-theme', UIThemeNode)
}

0 comments on commit f191e83

Please sign in to comment.