🌐 UIBUILDER Dev progress - v8.0

Realised that its been a while since I dropped an update as to the progress of UIBUILDER v8.

Didn't get much time over the summer to develop anything but back in the saddle now and making (somewhat slow) progress.

The slowness now is mostly due to having taken on some serious internal re-writing.

The latest re-write is around the uib-var/uib-topic responsive HTML attributes and the <uib-var> responsive HTML web component. These have been extensively re-written to consolidate their features and deal with a bunch of edge-cases that didn't work properly. Of course, this opens a bunch of rabbit holes that have to be navigated, including the documentation, examples and how Markweb works. So Markweb now moves to use <uib-var> with all of the extended features.

Being a major version release, there are some breaking changes I'm afraid. As usual, most of them won't affect most people but you should still review them.

Still a ways to go before I can release but I'm working hard on it. :smiley:


Changelog so far

:pushpin: Highlights

  • Potentially breaking changes - please make sure that you can meet the new baseline requirements before upgrading. More details are available later in the changelog:

    • Baselined to Node-RED v5+.
    • Baselined to Node.js v22.9+.
    • It is strongly recommended that you use a Node.js LTS version and the latest Node-RED version.
    • Additional Editor security (see below).
    • If using <main> element, it is no longer a grid by default. If <main> contains an <aside>, that will be floated right. Other content will be to the left. (RTL languages are not catered for in the default CSS I'm afraid, you will need custom CSS.) This will probably not affect most people.
    • <uib-var> component and uib-topic/uib-var attributes have been extensively rewritten. See notes below. Notably, for <uib-var>, the type attribute is now output to avoid processing issues on input elements.
    • The old v2 admin API's have been moved to v3 and so their URL's have changed. All admin API calles are now under ./uibuilder/admin/.
  • Examples:

    • The "basic-uib" example in the import examples library has been updated. It is now better labelled and will show the date/time on the web page when inject is triggered (demonstrating the use of the zero-code uib-topic HTML attribute for very simple page updates)
    • There is a new example demonstrating simple sparkline charts that do not need any JavaScript code.
  • Templates:

    • There is a new Single-page-app (SPA) Template to quickly get you started.
  • Documentation:

    • The Table of Contents in the sidebar now shows headings from level 2 to level 4 instead of 2-3. This greatly improves navigation on more complex pages.
    • Various pages have been update to better explain uibuilder's reactive attributes and components. Hopefully easier than ever to understand how to get data from Node-RED to your web pages.
  • There is a new, user-facing route GET ../uibuilder/apps - returns a simple formatted list of all installed apps. It uses the instance title and description (set on the uibuilder node's Advanced tab in the Editor). Note that this is user-facing, not admin-facing.

  • The uibuilder node now has a button to open a web page (controlled by admin access) that shows ALL uibuilder & Markweb instances with their type, title & description where provided (by the inputs on an instances advanced tab) and the link to the home page. This is the admin version of the user-facing list above.

  • DEGIT has been updated to the latest release now that the baseline node version is v20+. This should fix the git requirement bug and allow us to use the latest features and fixes in degit. It is also now wrapped into a local version which allows us to continue using as a CommonJS version (Degit v3 is ESM only). For reference, DEGIT is used for installing front-end templates.

  • Due to a bug in Node-RED, after initial install of UIBUILDER, you must reload the Editor page if you had it open. You will get an alert message telling you this if the bug is triggered.

  • UIBUILDER is now ready for ExpressJS v5 thanks to help from ryanmurdoc.

  • Front-end client library

    • Handling of the uib-var and uib-topic attributes has been significantly improved. Primitive (e.g. string/number) values now work for inputs. class & style properties now also support arrays/objects.
    • Finally! You can now actually set the msg variable in front-end JavaScript and it correctly triggers both onChange('msg', ...) and onTopic(...) handlers. This hasn't been properly working for the longest time, sorry about that. uibuilder.set('msg', {topic: 'more', payload: 'Hi'}). Great for testing without having to keep going back to Node-RED.
    • The uib-topic and uib-var custom HTML attributes now use the same processing and so fully support attributes, dataset, checked, and value properties which will update their target HTML element accordingly.
    • The uib-if custom HTML attribute now also works. Set it to a uibuilder managed variable that is truthy or falsy. Falsy hides the content. <div uib-if="myif"> uibuilder.set('myif', true).

Potential breaking changes

  • Baselined to Node-RED v5+ and Node.js v22.9+. Please make sure that you can meet these requirements before upgrading.

  • The style of a <main> element in the default CSS is no longer a grid by default. Add a grid class to it if you want it to be (grid, grid-2, grid-3, grid-4, and grid-fit are available classes). Alternatively, add a <content> sub-section with a grid class or style. The formating of an <aside> within a <main> is changed to float right. This will probably not affect most people.

  • The <uib-var> type attribute has been changed to output to avoid a clash with HTML input elements. In addition, the default is now "html" instead of "plain". This means you may need to change your HTML for uibuilder and if you have a custom page template for Markweb, that will certainly require a small change.

  • In the front-end, the custom uib-topic & uib-var attributes and the custom <uib-var> component have been extensively re-written and rationalised. This means that there is a possibility that previous outputs might work differently. The changes should just be extensions but the logic is complex. Let me know if you spot anything.

  • Additional security checks have been added to all admin API calls. This may affect some people who use Node-RED admin logins. Users logged into the Node-RED Editor must have at least flow.read authorisation to use any of the API's. API's that have consequences require the admin user to have flow.write authorisation. If you don't use Node-RED Editor authorisation, you will not be affected.

  • The old v2 API's have been moved to the v3 library which means that their URL's have changed. If you have used these API's manually, you will need to update your code to use the new URL. This should not affect most people.

Documentation

  • The Table of Contents in the sidebar now shows headings from level 2 to level 4 instead of 2-3. This greatly improves navigation on more complex pages.
  • Various pages have been update to better explain uibuilder's reactive attributes and components. Hopefully easier than ever to understand how to get data from Node-RED to your web pages.
  • Documentation now supports the shortTitle frontmatter. The page title (shown in the browser tab) is set to one of (in order of preference): fm shortTitle, fm title, sidebar link description or text in the sidebar.

Example Flows (See Node-RED's Import)

  • New Client-side code > no-js-charts-font - Shows how to create simple sparkline style charts without needing any JavaScript. Uses a web font.
  • Improvement The "basic-uib" example in the import examples library has been updated. It is now better labelled and will show the date/time on the web page when inject is triggered (demonstrating the use of the zero-code uib-topic HTML attribute for very simple page updates).

Code templates

  • New Single-page-app (SPA) Template (external) - Loads example code demonstrating how to use UIBUILDER's SPA Router library. Simply adjust for your own use. Note that there is already an existing example flow in the library as well but this template contains minimal code.
  • Error handling and notification messages have also been improved when loading templates.

Markweb

  • Improved processing of %%index%% directive. Attributes now correctly work if the values surrounding quotes are missed off.
  • Added page updated date to the title of index listing links.

uibuilder client library

  • Improvement Handling of the uib-var and uib-topic attributes has been significantly improved.

    • Primitive (e.g. string/number) values now work for inputs.
    • Class & style properties now also support arrays/objects. Note that, if using arrays/objects, classes/styles are ADDED or UPDATED, nothing is removed. Use a string value to fully replace as in previous versions.
    • uib-var and uib-topic will now work correctly on HTML input elements.
    • uib-var and uib-topic now both handle data-before and data-after HTML attributes. These add pre/post strings to the output. As these are HTML attributes, they can be set in the HTML but also overriden using the appropriate msg or variable object. Since the output supports HTML, these do as well.
    • Some edge-case bugs were also squashed along the way.
    • An updated example flow shows both the simple use and the extended features.
    • Console logging has been toned down slightly. Some 'info' (2) level outputs are now set to 'log' (3). This leaves 'info' more useful for general information without spamming the console.
  • Improvement The uib-topic and uib-var custom HTML attributes now use the same processing and so fully support attributes, dataset, checked, and value properties which will update their target HTML element accordingly.

  • Changed The <uib-var> built-in HTML component now uses the same prcessing as the custom attributes above.

    • The type attribute that controls output has been changed to output to avoid clashes with HTML input elements. In addition, the default has changed from plain text to html. Any HTML that uses this component are likely to need tweaking.
  • Fixed Finally! You can now actually set the msg variable in front-end JavaScript and it correctly triggers both onChange('msg', ...) and onTopic(...) handlers. This hasn't been properly working for the longest time, sorry about that. uibuilder.set('msg', {topic: 'more', payload: 'Hi'}). Great for front-end testing without having to keep going back to Node-RED.

  • Fixed The uib-if custom HTML attribute now also works. Set it to a uibuilder managed variable that is truthy or falsy. Falsy hides the content. <div uib-if="myvar"> uibuilder.set('myvar', true).

  • Improvement uibuilder.navigate (used with remote commands from Node-RED or called locally) now sets window.location.hash if the passed URL starts with # otherwise calls windows.location.assign(url). This is to avoid unnecessary page reloads if only changing the in-page navigation.

  • Improvement uibuilder.evaluateWithRetry gets an extra option noWarn (default=false). If set true, if the variable is not found, only a trace log is produced instead of a warning. This is used to deal with timing edge-cases where a variable might not be ready early in processing, the evaluation will be tried 3 times with a 300ms delay. Note that even the default warning won't be shown by default since the log output is error so warnings are not shown, uibuilder.set('logLevel', 1) to see warnings.

uibuilder

  • Now has a button to open a web page (controlled by admin access) that shows ALL uibuilder & Markweb instances with their type, title & description where provided (by the inputs on an instances advanced tab) and the link to the home page.

  • Added a palette category description tooltips for the uibuilder category.

  • When adding a new node, the Editor checks for an index.html file in the designated start folder. Previously, only a warning was given to the Editor browser console, there is now a notification with instructions on how to correct (reload the template or create the file). The check is delayed by 1 second to allow time for creation.

  • Update admin API calls to new standard and move off the v2 module.

  • FIXED - On the libraries tab, package updates are once again shown and the update button works correctly.

    [!NOTE]
    Currently, outdated packages are only checked on Node-RED startup.

    You may also need to reload the Node-RED Editor page to see the update button.

uib-html

  • The JSDOM library is now lazily loaded on first use in order to reduce the startup time of Node-RED.

Brand CSS styling

  • Fixed Fixed an edge case for links that could use light mode colours in dark mode.

  • Changed The style of a <main> element in the default CSS is no longer a grid by default. Add a grid class to it if you want it to be (grid, grid-2, grid-3, grid-4, and grid-fit are available classes). Alternatively, add a <content> sub-section with a grid class or style. The formating of an <aside> within a <main> is changed to float right. This will probably not affect most people. This makes grid layouts inside <main> more robust.

  • New CSS Classes:

    • .grid-span-all-cols, .grid-span-cols, .grid-span-2-cols, .grid-span-3-cols, .grid-span-4-cols classes for spanning all or some columns in a grid.
    • .grid-col-first, .grid-col-left, .grid-col-last, .grid-col-right classes for overriding the automatic grid column positioning.
  • New CSS Variables:

    • --callout-border-color - use with <blockquote> to change the left border colour from grey to something else. e.g. <blockquote style="--callout-border-color:var(--info-intense);"> - similar to GitHub-stle callouts/alerts.
  • The raw uib-brand.css resource now uses modern CSS including nesting, :has(), @supports, and selector(). For the best compatibility with older browsers, use the minimised version uib-brand.min.css. This is the default for all UIBUILDER templates and always has been. LightningCSS is used to build and compress the raw file, it takes care of compatibility, aiming for early 2019 browsers currently (the target is 7 year support).

Development and maintenance

  • Bump to v8.0.0, baseline to node.js v22.9, NR v5, degit 3.*. Remove gulp and dependencies, execa

  • Fix for Issue #648 - don't crash if telemetry file is corrupted in FS.

  • Browser Telemetry capture moved to uiblib from socket library for consistency.

  • Browser telemetry data improved to eliminate more "Not a brand" issues.

  • GULP is no longer used for build processes, there is now a unified custom node.js script that handles watches and builds. GULP dev-dependencies have been removed.

  • The build script is updated to match requirements for Node.js v22 LTS.

  • DEGIT external dependency has been moved to a separate uib-degit sub-package to allow the ESM-only latest versions to be used.

  • fs.cjs

    • Async remove(path) function now returns true if the path was removed, false if it was not.
    • Async removeSync(path) function now returns true if the path was removed, false if it was not.
    • Async replaceTemplate function now uses new function doDegit for external template processing.
    • doDegit updated to use the uib-degit sub-package.
  • uiblib.cjs

    • instanceClose function now uses a sync folder remove to ensure the folder is removed before Node-RED restarts the flows. This was previously occasionally causing issues. Log output also improved.
    • New function sanitiseUrl(urlPath) - matches the editor plugin function, see below. Used in API and npm processing.
  • web.cjs

    • Many thanks to ryanmurdoc for contributing 2 new methods: appStack and layerRegexp along with code to remove older ExpressJS v4 expressions, enabling this module and UIBUILDER to be ready for a switch to ExpressJS v5.
    • New user-facing route GET ./uibuilder/apps - returns a simple formatted list of all installed apps. It uses the instance title and description (set on the uibuilder node's Advanced tab in the Editor). Note that this is user-facing, not admin-facing.
  • Editor plugin (editor-common.js)

    • Added uibuilder.sanitiseUrl(urlPath) function to allow url paths (e.g. the "url" name of a uibuilder node) to be made safe for use in URLs. Returns null if path traversal, spaces, %, query params, # fragments, leading /, empty paths, absolute urls are included in the path. Else returns the path.
  • adminRouterV2.cjs - this has now been removed completely. Functions have been migrated to the v3 admin router.

  • adminRouterV3.cjs

    • Additional safety/security checks on user input.
    • Node-RED admin authorisation now required for all API calls. flow.read for GET calls, flow.write for POST, PUT, and DELETE calls. This only impacts when Node-RED Editor admin authorisation is used.
    • All v2 admin routes have now been migrated to v3.
    • New GET cmd's added/updated (there are now 16 cmd's):
      • showapps - the admin equivalent of the user-facing apps route with more detail.
      • showdetails - now has an output URL parameter: 'short'=Quick JSON listing of key web settings. 'diagnostics'=Long JSON output of uibuilder and web settings. 'json'=JSON output of uibuilder instances. 'urls'=JSON output of uibuilder names with node id. 'html'=The full uibuilder details (index) page showing all uibuilder, ExpressJS and Node-RED setings, routes, etc.
    • PUT route for npm install/update/remove of front-end packages updated to better handle async processing. Uses asyncLocalStorage to wrap async calls.
    • POST route gains the saveFile cmd. Migrated from admin v2.
  • New Module: logger.mjs - A custom logging class singleton with colourised output. Output is disabled by default. Setting the environment variable TI_ENV to "debug" before starting node-red will enable it. Otherwise control as shown below. Setting the environment variable TI_LOGGER not only enables output but also sets the output level, valid levels are error|warn|info|debug.

    Adds colour, timestamp and icons. Can be turned on/off. Gives correct traces. Passes through anything it doesn't enhance. Enhances 'log', 'info', 'warn', 'error', 'debug', and 'trace'. Can be set to output to a file instead of stdout/stderr. Output levels can also be set to one of 'error', 'warn', 'info', 'debug'/'log' or 1-4 (default=4). Also has a level map function if needed in case you want to override a log level.

    This module is mostly intended for internal logging.

    The enhanced methods have colorised output with a timestamp, level indicator and icons.

    Unlike Node-RED's native logging, this module allows multiple, complex outputs in a single log call.

    Default is for enabled to be false. The level can be set in the uibuilder property of settings.js. e.g. uibuilder{ logging: { enabled: true, level: 'debug'} },. However, do note that the settings are loaded early in the runtime plugin and so output will not happen until after the settings are loaded. If needed earlier, set clog.enabled = true manually.

    Manual settings are dynamic but they are global.

Phew - my word you have certainly been busy. :flexed_biceps: :technologist: :card_file_box:

Indeed - if that is "slow progress" then we don't have to worry about AI any time soon !

Some AI may have been involved along the way. :smiley: But some of the logic is quite complex and I fear that letting AI loose on it would hinder more than help. In any case, part of my reason for doing this is to stretch my aging brain.

When using AI, I will let it do smaller things where I can review the changes and accept or tweak things. But for bigger things, I tend to ask it to review and suggest then pick and choose what to change and implement it myself.

AI can be OK at working on more "direct" programming - a web page or some direct logic for example. But when it comes to the "indirect" programming used for creating logic that has to allow people to use it in flexible ways, I find it tends to misinterpret things quite a lot.

WOW! ...and breath!

Looking forward to V8, just checking for possible conflicts, but as my use is simple, should be OK.

I do try to keep breaking changes to a minimum and most won't affect most people.

You will like some of the changes though I think. Because the uib-topic and uib-var custom HTML attributes have been greatly improved so there are even fewer reasons to need to delve into JavaScript to get stuff done. :smiley: For example, if you want to simply dump some more complex data onto the page, you can now use something like this in your HTML:

<div uib-topic="mytopic" output="json">Waiting for message ...</div>

The output attribute is now the same as for <uib-var> so you can choose from: html, plain, list, json, and a few others.

data-before and data-after still work of course. But you now also get undefined, report and the new data-default (shows a default value if the data is undefined). You also get filter which is a massive improvement as it lets you apply a JavaScript function (which could be a pre-defined uibuilder function or your own) to the value before it is displayed.

Those changes also flow into Markweb, so anyone using that will find that the {{varname}} tags now support the same features. One that stands out is if you use tags in your frontmatter. You can now show the page tags in your page using {{tags [output="list"]}}. before, after, output, and default attributes are all supported.