Skip to content

Commit f17b631

Browse files
authored
Merge pull request #238 from node-red/api-updates
Add editor API docs
2 parents ef120b5 + 9d09197 commit f17b631

File tree

16 files changed

+1581
-993
lines changed

16 files changed

+1581
-993
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ node-red.github.io
66
### Contributing / Fixes
77

88
For simple typos and single line fixes please just raise an issue pointing out
9-
our mistakes. For larger changes, please raise them on the [mailing list](https://groups.google.com/forum/#!forum/node-red), or [Slack team](http://nodered.org/slack/) #docs channel, and if necessary provide content for review on the [wiki](https://github.com/node-red/node-red.github.io/wiki).
9+
our mistakes. For larger changes, please discuss them on the [forum](https://discourse.nodered.org) or [Slack team](http://nodered.org/slack/) #docs channel.
1010

1111
If you need to raise a pull request please read our
1212
[contribution guidelines](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
@@ -19,10 +19,10 @@ Fork the repository so you can make changes, commit them to your own repository
1919

2020
git clone https://github.com/{your-github}/node-red.github.io
2121

22-
First time you run jeykll you need to do bundle install 1st for the dependencies,
23-
22+
First time you run jeykll you need to do bundle install 1st for the dependencies,
23+
2424
cd node-red.github.io
25-
bundle install
25+
bundle install
2626
jekyll serve -w
2727

28-
Once the site is built and running you can preview it at [`http://127.0.0.1:4000/`](http://127.0.0.1:4000/).
28+
Once the site is built and running you can preview it at [`http://127.0.0.1:4000/`](http://127.0.0.1:4000/).

_includes/toc-api-ui.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
<li class="toc-expander">V</li>
33
<li class="tocheader">
44
<ul>
5-
<li class="{% if page.url == "/docs/api/ui/" %} active{% endif %}"><a href="/docs/api/ui/">Editor Widgets</a>
6-
<li {% if page.url contains "/docs/api/ui/editableList" %}class="active"{% endif %}><a href="/docs/api/ui/editableList">EditableList</a>
7-
<li {% if page.url contains "/docs/api/ui/searchBox" %}class="active"{% endif %}><a href="/docs/api/ui/searchBox">SearchBox</a>
8-
<li {% if page.url contains "/docs/api/ui/treeList" %}class="active"{% endif %}><a href="/docs/api/ui/treeList">TreeList</a>
9-
<li {% if page.url contains "/docs/api/ui/typedInput" %}class="active"{% endif %}><a href="/docs/api/ui/typedInput">TypedInput</a>
5+
<li class="{% if page.url == "/docs/api/ui/" %} active{% endif %}"><a href="/docs/api/ui/">Editor</a></li>
6+
<li><a style="text-decoration: none !important; font-weight: bold">APIs</a></li>
7+
<li {% if page.url contains "/docs/api/ui/actions" %}class="active"{% endif %}><a href="/docs/api/ui/actions">RED.actions</a></li>
8+
<li {% if page.url contains "/docs/api/ui/events" %}class="active"{% endif %}><a href="/docs/api/ui/events">RED.events</a></li>
9+
<li {% if page.url contains "/docs/api/ui/notifications" %}class="active"{% endif %}><a href="/docs/api/ui/notifications">RED.notify</a></li>
10+
<li {% if page.url contains "/docs/api/ui/sidebar" %}class="active"{% endif %}><a href="/docs/api/ui/sidebar">RED.sidebar</a></li>
11+
<li><a style="text-decoration: none !important; font-weight: bold">Widgets</a></li>
12+
<li {% if page.url contains "/docs/api/ui/editableList" %}class="active"{% endif %}><a href="/docs/api/ui/editableList">EditableList</a></li>
13+
<li {% if page.url contains "/docs/api/ui/searchBox" %}class="active"{% endif %}><a href="/docs/api/ui/searchBox">SearchBox</a></li>
14+
<li {% if page.url contains "/docs/api/ui/treeList" %}class="active"{% endif %}><a href="/docs/api/ui/treeList">TreeList</a></li>
15+
<li {% if page.url contains "/docs/api/ui/typedInput" %}class="active"{% endif %}><a href="/docs/api/ui/typedInput">TypedInput</a></li>
1016
</ul>
1117
</li>
1218
</ul>

css/editor-style.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ data.
2020

2121
#### [Context Store API](context)
2222

23-
**New in 0.19** : This API provides a pluggable way to store context data outside of the runtime.
23+
This API provides a pluggable way to store context data outside of the runtime.
2424

25-
#### [Editor UI Widgets](ui)
25+
#### [Editor APIs](ui)
2626

27-
A set of jQuery widgets that can be used within a node's edit template. _Since 0.14_
27+
The APIs available in the editor for nodes and plugins to use. This includes a set
28+
set of standard UI widgets that can be used within a node's edit template.

docs/api/ui/actions/index.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
layout: docs-api
3+
toc: toc-api-ui.html
4+
title: RED.events
5+
slug:
6+
- url: "/docs/api/ui"
7+
label: "ui"
8+
- 'actions'
9+
---
10+
11+
12+
This API can be used to register and invoke Actions in the editor. Actions are
13+
individual pieces of functionality that a user may want to trigger and can be
14+
bound to keyboard shortcuts.
15+
16+
- [`RED.actions` API](#redactions-api)
17+
- [`RED.actions.add( name, handler )`](#methods-add)
18+
- [`RED.actions.remove( name )`](#methods-remove)
19+
- [`RED.actions.invoke( name, [args...] )`](#methods-invoke)
20+
21+
22+
### `RED.actions` API
23+
24+
#### <a href="#methods-add" name="methods-add">RED.actions.add( name, handler )</a>
25+
26+
Register a new action.
27+
28+
The name should follow the pattern `[provider]:[name-of-action]`. For example `core:show-debug-tab`.
29+
30+
```javascript
31+
RED.actions.add("my-custom-tab:show-custom-tab",function() {
32+
RED.sidebar.show("my-custom-tab");
33+
});
34+
```
35+
36+
#### <a href="#methods-remove" name="methods-remove">RED.actions.remove( name )</a>
37+
38+
Remove a previously registered action.
39+
40+
```javascript
41+
RED.actions.remove("my-custom-tab:show-custom-tab")
42+
```
43+
44+
#### <a href="#methods-invoke" name="methods-invoke">RED.actions.invoke( name, [args...])</a>
45+
46+
Invoke an action by name.
47+
48+
When bound to a keyboard shortcut, the handler will be invoked without any arguments. But when
49+
invoked using this API, it is possible to pass in arguments.
50+
51+
```javascript
52+
RED.actions.invoke("my-custom-tab:show-custom-tab")
53+
```

docs/api/ui/editableList/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ toc: toc-api-ui.html
44
title: EditableList Widget
55
slug:
66
- url: "/docs/api/ui"
7-
label: "ui widgets"
7+
label: "ui"
88
- 'editablelist'
99
---
1010

@@ -121,7 +121,7 @@ $("ol.list").editableList({
121121
label: "with icon",
122122
icon: "fa fa-star",
123123
title: "my custom button",
124-
click: function(evt) {
124+
click: function(evt) {
125125
alert("button clicked");
126126
}
127127
}]

docs/api/ui/events/index.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
layout: docs-api
3+
toc: toc-api-ui.html
4+
title: RED.events
5+
slug:
6+
- url: "/docs/api/ui"
7+
label: "ui"
8+
- 'events'
9+
---
10+
11+
12+
The editor emits events that components can listen for so they can react as needed.
13+
14+
*Note: any events not on this list should be considered private, subject to change without notification and not for general use.*
15+
16+
- [`RED.events` API](#redevents-api)
17+
- [`RED.events.on( eventName, handlerFunction )`](#methods-on)
18+
- [`RED.events.off( eventName, handlerFunction )`](#methods-off)
19+
- [Available events](#available-events)
20+
- [Workspace events](#workspace-events)
21+
- [Flow configuration events](#flow-configuration-events)
22+
- [Palette events](#palette-events)
23+
24+
25+
### `RED.events` API
26+
27+
#### <a href="#methods-on" name="methods-on">RED.events.on( eventName, handlerFunction )</a>
28+
29+
Register a new handler for the given event.
30+
31+
32+
```javascript
33+
RED.events.on("nodes:add", function(node) {
34+
console.log("A node has been added to the workspace!")
35+
})
36+
```
37+
38+
#### <a href="#methods-off" name="methods-off">RED.events.off(eventName, handlerFunction)</a>
39+
40+
Remove a previously registered event handler.
41+
42+
### Available events
43+
44+
#### Workspace events
45+
46+
Event | Payload | Description
47+
------|---------|-----
48+
`deploy` | | A new flow has been deployed
49+
`login` | `"username"` | A user has logged into the editor. If `adminAuth` is not configured, this event is never emitted
50+
`view:selection-changed` | `{<selection object>}` | The current selection in the workspace has changed
51+
`workspace:change`| `{ old: "<previous-workspace-id>", workspace: "<new-workspace-id>" }`|The workspace has switched to a different tab
52+
`workspace:clear` | | The workspace has been cleared - this happens when switching projects.
53+
`workspace:dirty` | `{ dirty:<boolean> }` | The dirty state of the editor has changed. 'Dirty' means there are undeployed changes.
54+
`workspace:hide` | `{ workspace: <workspace-id> }` | A tab has been hidden
55+
`workspace:show` | `{ workspace: <workspace-id> }` | A previously hidden tab has been shown
56+
57+
#### Flow configuration events
58+
59+
Event | Payload | Description
60+
------|---------|-----
61+
`flows:add` | `{<flow object>}` | A new flow has been added
62+
`flows:change` | `{<flow object>}` | A flow's properties have been changed
63+
`flows:remove` | `{<flow object>}` | A flow has been removed
64+
`flows:reorder`| `[<Array of flow ids]` | The flows have been reordered
65+
`groups:add` | `{<group object>}` | A new group has been added
66+
`groups:change` | `{<group object>}` | A group's properties have been changed
67+
`groups:remove` | `{<group object>}` | A group has been removed
68+
`links:add` | `{<link object>}` | A new link has been added
69+
`links:remove` | `{<link object>}` | A link has been removed
70+
`nodes:add` | `{<node object>}` | A new node has been added
71+
`nodes:change` | `{<node object>}` | A node's properties have been changed
72+
`nodes:remove` | `{<node object>}` | A node has been removed
73+
`nodes:reorder`| `{z:"<flow-id>", nodes:[<Array of node ids>]}`| Nodes have been reordered on a flow
74+
`subflows:add` | `{<subflow object>}` | A new subflow has been added
75+
`subflows:change` | `{<subflow object>}` | A subflow's properties have been changed
76+
`subflows:remove` | `{<subflow object>}` | A subflow has been removed
77+
78+
79+
80+
#### Palette events
81+
82+
Event | Payload | Description
83+
------|---------|-----
84+
`registry:module-updated`|`{module:"<module-name>", version:"<module-version>"}`|A module has updated to a new version
85+
`registry:node-set-added`|`{<node-set object>}`| A new Node-Set has been added to the palette
86+
`registry:node-set-disabled`|`{<node-set object>}`|A Node-Set has been disabled
87+
`registry:node-set-enabled`|`{<node-set object>}`| A Node-Set has been enabled
88+
`registry:node-set-removed`|`{<node-set object>}`| A Node-Set has been removed
89+
`registry:node-type-added`|`"node-type"`| A new Node has been added to the palette
90+
`registry:node-type-removed`|`"node-type"`| A Node has been removed from the palette
91+
`registry:plugin-added`|`"plugin-id"`| A Plugin has been added

docs/api/ui/index.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
---
22
layout: docs-api
33
toc: toc-api-ui.html
4-
title: Editor UI Widgets
5-
slug: "ui widgets"
4+
title: Editor APIs
5+
slug: "ui"
66
---
77

8+
The editor provides a number of APIs for nodes and plugins to use to help them integrate with the editor.
9+
10+
- [`RED.actions`](actions) - register custom actions
11+
- [`RED.events`](events) - listen for events within the editor
12+
- [`RED.notify`](notification) - show notifications in the editor
13+
- [`RED.sidebar`](sidebar) - add sidebar tabs
14+
15+
### Widgets
16+
817
A set of jQuery widgets are available that can be used within a node's edit template.
918

1019
- [`TypedInput`](typedInput) - a replacement for a regular `<input>` that allows

docs/api/ui/notifications/index.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
layout: docs-api
3+
toc: toc-api-ui.html
4+
title: RED.notify
5+
slug:
6+
- url: "/docs/api/ui"
7+
label: "ui"
8+
- 'notifications'
9+
---
10+
11+
12+
This API can be used to display notifications that pop-down from the top of the editor.
13+
14+
As these notifications interrupt the user, they should be used sparingly.
15+
16+
- [`RED.notify`](#rednotifymessage-options)
17+
- [Configuration options](#configuration-options)
18+
- [Notification buttons](#notification-buttons)
19+
- [Notification object](#notification-object)
20+
- [Examples](#examples)
21+
- [Plain information notification](#plain-information-notification)
22+
- [Warning notification for 10 seconds](#warning-notification-for-10-seconds)
23+
- [Notification with buttons](#notification-with-buttons)
24+
25+
26+
### `RED.notify(message, [options])`
27+
28+
- `message` - the text to be displayed in the notification
29+
- `options` - configuration options for the notification
30+
31+
The function returns a `notification` object that can be used to interact with
32+
the notification.
33+
34+
#### Configuration options
35+
36+
The following properties can be provided in the `options` argument. All are optional.
37+
38+
Option | Description
39+
-------|--------------
40+
`type` | Sets the appearance of the notification. Available values are: `compact`, `success`, `warning`, `error`. If this value is not set, the notification uses the default 'info' appearance.
41+
`timeout` | How long the notification should be shown for, in milliseconds. Default: `5000`. This is ignored if the `fixed` property is set.
42+
`fixed` | Do not hide the notification after a timeout. This also prevents the click-to-close default behaviour of the notification.
43+
`modal` | If set to `true`, the notification should prevent interaction with any other UI element until the notification has been dismissed.
44+
`buttons` | An array of buttons to display on the notification to allow user interaction.
45+
46+
#### Notification buttons
47+
48+
The `buttons` option can be used to provide a set of buttons that should be displayed on the notification.
49+
50+
For example, to have a 'cancel' and 'okay' button, the following can be used (see further below for a fuller example that explains `myNotification.close()`).
51+
52+
```javascript
53+
buttons: [
54+
{
55+
text: "cancel",
56+
click: function(e) {
57+
myNotification.close();
58+
}
59+
},
60+
{
61+
text: "okay",
62+
class:"primary",
63+
click: function(e) {
64+
myNotification.close();
65+
}
66+
}
67+
```
68+
69+
The `class` property can be used to specify an additional CSS class for the button. If the notification has multiple buttons, there should be one with the class set to `primary` to indicate the primary button for the user to click.
70+
71+
#### Notification object
72+
73+
The `RED.notify()` call returns a `notification` object. This object provides the following functions:
74+
75+
Function | Description
76+
---------|---------
77+
`notification.close()` | Close the notification and dispose of it.
78+
`notification.update( message, options )` | Replace the contents of the notification.
79+
80+
### Examples
81+
82+
#### Plain information notification
83+
84+
```javascript
85+
RED.notify("Hello World");
86+
```
87+
88+
#### Warning notification for 10 seconds
89+
90+
```javascript
91+
RED.notify("Something has happened", { type: "warning", timeout: 10000 });
92+
```
93+
94+
#### Notification with buttons
95+
96+
This example shows how the returned `myNotification` object is then used in the button event handlers to close the notification.
97+
98+
```javascript
99+
let myNotification = RED.notify("This is the message to display",{
100+
modal: true,
101+
fixed: true,
102+
type: 'warning',
103+
buttons: [
104+
{
105+
text: "cancel",
106+
click: function(e) {
107+
myNotification.close();
108+
}
109+
},
110+
{
111+
text: "okay",
112+
class:"primary",
113+
click: function(e) {
114+
myNotification.close();
115+
}
116+
}
117+
]
118+
});
119+
```

docs/api/ui/searchBox/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ toc: toc-api-ui.html
44
title: SearchBox Widget
55
slug:
66
- url: "/docs/api/ui"
7-
label: "ui widgets"
7+
label: "ui"
88
- 'searchbox'
99
---
1010

0 commit comments

Comments
 (0)