Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_theme.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = function (RED) {
  2. /**
  3. *
  4. * @param {*} config
  5. */
  6. function UIThemeNode (config) {
  7. function hasProperty (obj, prop) {
  8. return !!Object.prototype.hasOwnProperty.call(obj, prop)
  9. }
  10. RED.nodes.createNode(this, config)
  11. const node = this
  12. const { id, name, type, _users, ...rest } = config
  13. const sizes = { ...rest.sizes }
  14. if (!hasProperty(sizes, 'pagePadding')) {
  15. // set defaults at runtime if not set - for backward compatability
  16. sizes.pagePadding = '12px'
  17. }
  18. if (!hasProperty(sizes, 'groupGap')) {
  19. // set defaults at runtime if not set - for backward compatability
  20. sizes.groupGap = '12px'
  21. }
  22. if (!hasProperty(sizes, 'groupBorderRadius')) {
  23. // set defaults at runtime if not set - for backward compatability
  24. sizes.groupBorderRadius = '4px'
  25. }
  26. if (!hasProperty(sizes, 'widgetGap')) {
  27. // set defaults at runtime if not set - for backward compatability
  28. sizes.widgetGap = '12px'
  29. }
  30. node.colors = { ...rest.colors }
  31. node.sizes = sizes
  32. let uiBase = null
  33. RED.nodes.eachNode(n => {
  34. if (n.type === 'ui-base' && !uiBase) {
  35. uiBase = n
  36. }
  37. })
  38. if (uiBase) {
  39. config.ui = uiBase.id
  40. uiBase = RED.nodes.getNode(config.ui)
  41. }
  42. uiBase?.registerTheme(node)
  43. }
  44. RED.nodes.registerType('ui-theme', UIThemeNode)
  45. }