From 36b104d7d6b41e80630188a6e7ed22eba77f67a6 Mon Sep 17 00:00:00 2001 From: bartbutenaers Date: Sun, 17 Nov 2024 00:22:34 +0100 Subject: [PATCH 1/6] dynamic ui-template --- ui/src/widgets/ui-template/UITemplate.vue | 376 ++++++++++++---------- 1 file changed, 200 insertions(+), 176 deletions(-) diff --git a/ui/src/widgets/ui-template/UITemplate.vue b/ui/src/widgets/ui-template/UITemplate.vue index 4b479fdb4..ffb68147c 100644 --- a/ui/src/widgets/ui-template/UITemplate.vue +++ b/ui/src/widgets/ui-template/UITemplate.vue @@ -11,189 +11,25 @@ export default { inject: ['$socket', '$dataTracker'], props: { id: { type: String, required: true }, - props: { type: Object, default: () => ({}) } + props: { type: Object, default: () => ({}) }, + state: { type: Object, default: () => ({}) } }, - setup (props) { - const parser = new DOMParser() - const htmlDoc = parser.parseFromString(props.props.format, 'text/html') - - // check whether we have a fully defined Vue component, or _just_ HTML - const templates = htmlDoc.getElementsByTagName('template') - const template = templates.length ? templates[0] : props.props.format - - let head - - /* Check for any CSS +``` + +### Loading External Dependencies + +It is possible to load external dependencies into your `ui-template` node. This is useful if you want to use a library that isn't included in the core Node-RED Dashboard 2.0 nodes. + +To do this, you'll need to load the dependency in the ` ``` -Would send the following `msg` when submitted: -```js -{ "first": , "last": } + +You can then have _another_ ` + + ``` -#### Sending on Click -Here, we call it when someone clicks our "Send Hello World" button: +## Building Full Vue Components + +You can build full Vue components in the `ui-template` node, using VueJS's [Options API](https://vuejs.org/api/#options-api). This allows you to build your own bespoke behaviour, and gives you more control over the UI. + +A full list of the VueJS Options API properties that we currently support are: + +- `name` - The name of your component +- `data` - A function that returns data you want available across your component (in both `