Repository navigation
feat: Vue and Vuetify editing in the ui-template code editor - #2290
Conversation
I've looked at nr-assistant and the compatibility is something a bit more than first thought! Monaco picks inline-completion and CodeLens providers by the model's language. Up to and including 0.20.0, nr-assistant only registers them for proposalI'll add To cover that, this PR will only use // nr-assistant before 0.21.0 only provides Expert support for html
function assistantSupportsVueSfc () {
const version = RED.plugins.getModule('@flowfuse/nr-assistant')?.version
if (!version) return true
const [major, minor] = version.split('.').map(n => parseInt(n, 10))
return major > 0 || minor >= 21
}
const htmlMode = RED.editor.codeEditor?.editor?.type === 'monaco' && assistantSupportsVueSfc() && vueEditor?.ensure?.() ? 'ace/mode/vue-sfc' : 'ace/mode/html'
Users on an older nr-assistant miss the Vue IntelliSense until it updates, but they keep FIM and the CodeLens. The FIM backend will accept WDYT @n-lark |
|
Associated PR for nr-assistant: FlowFuse/nr-assistant#426 |
n-lark
left a comment
There was a problem hiding this comment.
Looks good thank you for adding this! Here is everything I tested:
Tested on: Node-RED 5.0.4 (Monaco 0.55, without node-red#5994) and 5.0.8 (main, Monaco 0.57, with #5994).
Build:
- Every build regenerates
vuetify.jsonfrom the installed Vuetify (3.11.3, 192 components) - Rebuilds produce identical output
- The npm package includes
vuetify.json - The release workflow builds before publishing
Both versions:
- Dashboard renders the template,
mountedruns, Send reaches Node-RED - Edit, Done and Deploy work
- Inline and expand editors use
vue-sfc - Completion: Vuetify tags, props, bound props, events, slots, prop values, Vue directives
- Hover shows prop types, defaults and docs
- CSS scopes switch the editor to
cssand back - Editor files load only when a ui-template editor opens
- No console errors
5.0.4 only:
- ACE stays on HTML
- Editor still works if
vuetify.jsonis missing
5.0.8 only:
-
<script>and<style>get highlighting only, with no JS/CSS completion (#2291 adds that)
|
Hey @Steve-Mcl the proposal and nr-assistant FlowFuse/nr-assistant#426 looks good to me. One nit - I'm pretty sure |
|
thanks Noley. I am gonna adjust the detection method by adding an explicit flag in nr-assistant and pick that up here (rather than rely on version numbers and support for getModule) |
|
I've dropped the version check and gone with a capability flag instead:
The check now lives in |
ec1839c to
c7540f4
Compare
|
Hey @n-lark FYI, the related work in Node-RED is merged so this new goodness will be available really soon (I think there may be a release today 🤞) Once merged and new Node-RED is released, a final test run of dashboard |
f1ac76a to
3eb30a7
Compare
|
Did another round of testing on this with the latest node-red release 5.0.9 - everything looks good to go. #2290: Vue / Vuetify editing
#2291:
|
|
Thank you thank you thank you 🙇 |
|
@n-lark feel free to merge and release at your leisure. (or let me know if you want me to) |
The ui-template editor treats a Vue template as plain HTML: no Vue syntax, no help
with Vuetify components. This adds a `vue-sfc` language for Node-RED's Monaco editor,
shipped as an editor plugin with the Dashboard, so nothing is added to Node-RED core.
- Vue highlighting: directives, bindings, events, slots and {{ }} as JavaScript;
<script> and <style> blocks (TS, SCSS and Less with lang=)
- Completion and hover for Vuetify components, props, bound props, events, slots,
prop values and directives, plus Vue's own directives and components
- Vuetify data is generated at build time from the Vuetify version the Dashboard
bundles (scripts/build-vue-editor-data.js), and loaded only when a ui-template
editor is first opened
- Plain HTML completion, hover and formatting from Monaco's html worker
- ui-template uses the new language with Monaco; ACE keeps the HTML mode
nr-assistant before 0.21.0 only registers its Expert completions and CodeLens for html, so switching ui-template to vue-sfc would drop them. nr-assistant 0.21.0 sets supportsVueSfc on its plugin. Read that with RED.plugins.getPlugin, which exists back to Node-RED 1.3, rather than RED.plugins.getModule, which only arrived in 4.0. - vue-sfc when nr-assistant isn't installed or sets supportsVueSfc - html when an older nr-assistant is installed - the check lives in the vue-editor plugin as useVueSfc()
3eb30a7 to
f0ecfae
Compare
Description
Related to node-red/nr-monaco-build#9 and node-red/node-red#5994
Summary
People regularly ask for better editing in ui-template (e.g. https://discourse.nodered.org/t/weather-card-struggling-with-methods/85434/6). Today the editor treats a Vue template as plain HTML: no Vue syntax and no help with Vuetify components.
This adds a
vue-sfclanguage to Node-RED's Monaco editor, shipped with the Dashboard as an editor plugin. Nothing is added to Node-RED core's editor bundle, which was the concern raised in node-red/nr-monaco-build#9. With it, the ui-template editor gets::prop), events (@click), slots (#activator) and{{ }}expressions highlighted as JavaScript.<script>and<style>blocks are highlighted too, includinglang="ts"/lang="scss"/lang="less".<v-lists the components.:), events (@), Vuetify directives, and, on a<template>inside a component, that component's slots (#).variant) suggest those values.v-if,v-for,<transition>, ...), with links to the Vue docs.It works offline, and works with any Node-RED that uses Monaco. Editors set to ACE keep the plain HTML mode.
How it works
nodes/plugins/vue-editor.html: a small editor plugin (registered undernode-red.pluginsin package.json). At startup it only registers thevue-sfclanguage and Monaco's HTML language service for it. Everything else loads the first time a ui-template editor opens.resources/vue-editor/vue-sfc.mjs: loaded on first use. The tokenizer, which is adapted from Monaco's HTML tokenizer (MIT, credited in the file), plus the Vue/Vuetify completion and hover providers. Only public Monaco APIs are used.scripts/build-vue-editor-data.js: generatesresources/vue-editor/vuetify.jsonfromvuetify/dist/json/web-types.json, so the editor always matches the Vuetify version the Dashboard bundles. It runs as part ofnpm run build(andbuild:dev/dev), and the output is gitignored. 192 components, 401 KB raw / 66 KB gzipped, with descriptions de-duplicated into a string table.nodes/widgets/ui_template.html: usesvue-sfcwhen the editor is Monaco and the plugin is loaded,htmlotherwise. The expand editor uses the same mode.package.json: addsresources/*tofiles, the build step, and the plugin entry.Choices worth flagging:
vue-sfc) rather thanvue. Node-RED maps thevuemode tohtml, while other ids pass through, so this needs no change in core.:col,@clior#actwould never matchcoloretc.vue-sfcto the html worker. feat: add JavaScript and CSS support to script and style blocks in HT… node-red/node-red#5994 does this in core for newer versions.Package size: about 434 KB more unpacked (the plugin 3.6 KB,
vue-sfc.mjs29 KB,vuetify.json401 KB) - BUT - it is only loaded when a ui-template editor opens!What's next
node-red/node-red#5994 adds JavaScript and CSS support to
<script>and<style>blocks in Node-RED's HTML editors, with an API that languages like this one can opt into. A follow-up PR builds on it so that, on Node-RED versions that have it, ui-template also gets JavaScript completion and error checking in<script>, withthistyped for the component (this.send(),this.msg, data/computed/methods), and CSS completion in<style>. This PR doesn't depend on it.Testing
test/resources/vue-editor.spec.js(20) for cursor context (including skipping script/style/comments/interpolation), parent tag for slots, completions, values and hover. The full suite passes.vue-sfc;<template #>and hover all work;css, and back again usesvue-sfc;noerr0;Notes
htmllanguage. With ui-template onvue-sfc, those won't show in the template part until nr-assistant also acceptsvue-sfc. That's a small change in nr-assistant (CodeLens registration,supportedInlineCompletions, andisInsideComment). I'll PR that as well.docs/en/nodes/widgets/ui-template.md) get a short "Code Editor" section. I've only done the English page.Related Issue(s)
Checklist
flowforge.yml?FlowFuse/helmto update ConfigMap TemplateFlowFuse/CloudProjectto update values for Staging/ProductionLabels
area:migrationlabel